Skip to content

Commit

Permalink
lib: update the load command to support PGS data, #TASK-5410, #TASK-5387
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Dec 19, 2023
1 parent fd6ac92 commit 53aa886
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.EtlCommons;
import org.opencb.cellbase.lib.builders.PolygenicScoreBuilder;
import org.opencb.cellbase.lib.impl.core.CellBaseDBAdaptor;
import org.opencb.cellbase.lib.indexer.IndexManager;
import org.opencb.cellbase.lib.loader.LoadRunner;
Expand Down Expand Up @@ -81,7 +82,7 @@ public LoadCommandExecutor(AdminCliOptionsParser.LoadCommandOptions loadCommandO
EtlCommons.PROTEIN_FUNCTIONAL_PREDICTION_DATA, EtlCommons.VARIATION_DATA,
EtlCommons.VARIATION_FUNCTIONAL_SCORE_DATA, EtlCommons.CLINICAL_VARIANTS_DATA, EtlCommons.REPEATS_DATA,
EtlCommons.OBO_DATA, EtlCommons.MISSENSE_VARIATION_SCORE_DATA, EtlCommons.SPLICE_SCORE_DATA, EtlCommons.PUBMED_DATA,
EtlCommons.PHARMACOGENOMICS_DATA};
EtlCommons.PHARMACOGENOMICS_DATA, EtlCommons.PGS_DATA};
} else {
loadOptions = loadCommandOptions.data.split(",");
}
Expand Down Expand Up @@ -299,6 +300,11 @@ public void execute() throws CellBaseException {
loadPharmacogenomica();
break;
}
case EtlCommons.PGS_DATA: {
// Load data, create index and update release
loadPolygenicScores();
break;
}
default:
logger.warn("Not valid 'data'. We should not reach this point");
break;
Expand Down Expand Up @@ -589,6 +595,49 @@ private void loadPharmacogenomica() throws IOException, CellBaseException {
dataReleaseManager.update(dataRelease, EtlCommons.PHARMACOGENOMICS_DATA, EtlCommons.PHARMACOGENOMICS_DATA, sources);
}

private void loadPolygenicScores() throws NoSuchMethodException, InterruptedException, ExecutionException, InstantiationException,
IllegalAccessException, InvocationTargetException, ClassNotFoundException, IOException, CellBaseException, LoaderException {
Path pgsPath = input.resolve(EtlCommons.PGS_DATA);

if (!Files.exists(pgsPath)) {
logger.warn("Polygenic scores (PGS) folder {} not found to load", pgsPath);
return;
}

// Load common polygenic scores data
Path pathToLoad = pgsPath.resolve(PolygenicScoreBuilder.COMMON_POLYGENIC_SCORE_FILENAME);
logger.info("Loading file '{}'", pathToLoad.toFile().getName());
try {
loadRunner.load(pathToLoad, "common_polygenic_score", dataRelease);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | InvocationTargetException
| IllegalAccessException | ExecutionException | IOException | InterruptedException | CellBaseException
| LoaderException e) {
logger.error("Error loading file '{}': {}", pathToLoad.toFile().getName(), e.toString());
}

// Load variant polygenic scores data
pathToLoad = pgsPath.resolve(PolygenicScoreBuilder.VARIANT_POLYGENIC_SCORE_FILENAME);
logger.info("Loading file '{}'", pathToLoad.toFile().getName());
try {
loadRunner.load(pathToLoad, "variant_polygenic_score", dataRelease);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | InvocationTargetException
| IllegalAccessException | ExecutionException | IOException | InterruptedException | CellBaseException
| LoaderException e) {
logger.error("Error loading file '{}': {}", pathToLoad.toFile().getName(), e.toString());
}

// Create index
createIndex("variant_polygenic_score");
createIndex("common_polygenic_score");

// Update release (collection and sources)
List<Path> sources = new ArrayList<>(Arrays.asList(
input.resolve(EtlCommons.PGS_DATA + "/" + EtlCommons.PGS_VERSION_FILENAME)
));
dataReleaseManager.update(dataRelease, "variant_polygenic_score", EtlCommons.PGS_DATA, sources);
dataReleaseManager.update(dataRelease, "common_polygenic_score", null, null);
}

private void createIndex(String collection) {
if (!createIndexes) {
return;
Expand Down
5 changes: 5 additions & 0 deletions cellbase-lib/src/main/resources/mongodb-indexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,8 @@
{"collection": "pharmacogenomics", "fields": {"variants.phenotypeType": 1}, "options": {"background": true}}
{"collection": "pharmacogenomics", "fields": {"variants.confidence": 1}, "options": {"background": true}}
{"collection": "pharmacogenomics", "fields": {"variants.evidences.pubmed": 1}, "options": {"background": true}}

{"collection": "common_polygenic_score", "fields": {"id": 1}, "options": {"background": true}}
{"collection": "variant_polygenic_score", "fields": {"_chunkIds": 1}, "options": {"background": true}}
{"collection": "variant_polygenic_score", "fields": {"chromosome": 1, "position": 1}, "options": {"background": true}}
{"collection": "variant_polygenic_score", "fields": {"polygenicScores.id": 1}, "options": {"background": true}}

0 comments on commit 53aa886

Please sign in to comment.