Skip to content

Commit 6ade410

Browse files
committed
lib: check pharmacogenomics collection in the target data release before annotating variants, #TASK-5447
1 parent b178710 commit 6ade410

38 files changed

+222
-301
lines changed

cellbase-app/src/main/java/org/opencb/cellbase/app/cli/admin/executors/ValidationCommandExecutor.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import org.opencb.cellbase.app.cli.admin.AdminCliOptionsParser;
2727
import org.opencb.cellbase.app.cli.admin.executors.validation.VEPVariant;
2828
import org.opencb.cellbase.core.exception.CellBaseException;
29+
import org.opencb.cellbase.core.models.DataRelease;
2930
import org.opencb.cellbase.core.result.CellBaseDataResult;
3031
import org.opencb.cellbase.lib.managers.CellBaseManagerFactory;
32+
import org.opencb.cellbase.lib.managers.DataReleaseManager;
3133
import org.opencb.cellbase.lib.variant.annotation.VariantAnnotationCalculator;
3234
import org.opencb.commons.datastore.core.QueryOptions;
3335
import org.opencb.commons.utils.FileUtils;
@@ -44,7 +46,7 @@
4446

4547
public class ValidationCommandExecutor extends CommandExecutor {
4648

47-
// private MongoDBAdaptorFactory dbAdaptorFactory;
49+
// private MongoDBAdaptorFactory dbAdaptorFactory;
4850
private AdminCliOptionsParser.ValidationCommandOptions validationCommandOptions;
4951
private ObjectMapper objectMapper;
5052
private String resultsFile;
@@ -67,12 +69,15 @@ public ValidationCommandExecutor(AdminCliOptionsParser.ValidationCommandOptions
6769
public void execute() {
6870
checkFilesExist();
6971

72+
VariantAnnotationCalculator variantAnnotationCalculator;
7073
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
71-
// dbAdaptorFactory = new MongoDBAdaptorFactory(configuration);
72-
VariantAnnotationCalculator variantAnnotationCalculator = null;
74+
7375
try {
76+
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(validationCommandOptions.species,
77+
validationCommandOptions.assembly);
78+
DataRelease dataRelease = dataReleaseManager.get(validationCommandOptions.dataRelease);
7479
variantAnnotationCalculator = new VariantAnnotationCalculator(validationCommandOptions.species,
75-
validationCommandOptions.assembly, validationCommandOptions.dataRelease, validationCommandOptions.apiKey,
80+
validationCommandOptions.assembly, dataRelease, validationCommandOptions.apiKey,
7681
cellBaseManagerFactory);
7782
} catch (CellBaseException e) {
7883
e.printStackTrace();
@@ -241,7 +246,7 @@ private void compare(BufferedWriter mismatchWriter, BufferedWriter matchWriter,
241246
// skip proteins if we are only processing transcripts
242247
// skip transcripts if we are only processing proteins
243248
if (("transcript".equalsIgnoreCase(category) && entityId.startsWith("ENSP"))
244-
|| ("protein".equalsIgnoreCase(category) && entityId.startsWith("ENST"))) {
249+
|| ("protein".equalsIgnoreCase(category) && entityId.startsWith("ENST"))) {
245250
continue;
246251
}
247252

cellbase-app/src/main/java/org/opencb/cellbase/app/cli/main/executors/VariantAnnotationCommandExecutor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
import org.opencb.cellbase.client.config.ClientConfiguration;
4545
import org.opencb.cellbase.client.rest.CellBaseClient;
4646
import org.opencb.cellbase.core.exception.CellBaseException;
47+
import org.opencb.cellbase.core.models.DataRelease;
4748
import org.opencb.cellbase.core.result.CellBaseDataResult;
4849
import org.opencb.cellbase.lib.impl.core.MongoDBAdaptorFactory;
4950
import org.opencb.cellbase.lib.impl.core.VariantMongoDBAdaptor;
5051
import org.opencb.cellbase.lib.managers.CellBaseManagerFactory;
52+
import org.opencb.cellbase.lib.managers.DataReleaseManager;
5153
import org.opencb.cellbase.lib.managers.GenomeManager;
5254
import org.opencb.cellbase.lib.managers.VariantManager;
5355
import org.opencb.cellbase.lib.variant.annotation.CellBaseNormalizerSequenceAdaptor;
@@ -202,9 +204,10 @@ private boolean runAnnotation() throws Exception {
202204
List<Variant> variants = Variant.parseVariants(variantAnnotationCommandOptions.variant);
203205
if (local) {
204206
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
205-
VariantAnnotationCalculator variantAnnotationCalculator =
206-
new VariantAnnotationCalculator(this.species, this.assembly, variantAnnotationCommandOptions.dataRelease,
207-
variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory);
207+
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly);
208+
DataRelease dataRelease = dataReleaseManager.get(variantAnnotationCommandOptions.dataRelease);
209+
VariantAnnotationCalculator variantAnnotationCalculator = new VariantAnnotationCalculator(species, assembly,
210+
dataRelease, variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory);
208211
List<CellBaseDataResult<VariantAnnotation>> annotationByVariantList =
209212
variantAnnotationCalculator.getAnnotationByVariantList(variants, serverQueryOptions);
210213

@@ -479,9 +482,10 @@ private VariantAnnotator createCellBaseAnnotator() throws CellBaseException {
479482
// corresponding *AnnotatorTask since the AnnotatorTasks need that the number of sent variants coincides
480483
// equals the number of returned annotations
481484
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
482-
return new CellBaseLocalVariantAnnotator(new VariantAnnotationCalculator(species, assembly,
483-
variantAnnotationCommandOptions.dataRelease, variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory),
484-
serverQueryOptions);
485+
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly);
486+
DataRelease dataRelease = dataReleaseManager.get(variantAnnotationCommandOptions.dataRelease);
487+
return new CellBaseLocalVariantAnnotator(new VariantAnnotationCalculator(species, assembly, dataRelease,
488+
variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory), serverQueryOptions);
485489
} else {
486490
try {
487491
ClientConfiguration clientConfiguration = ClientConfiguration.load(getClass()

cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/DataReleaseManager.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,28 +215,28 @@ public String getMaintainerContact() {
215215
return configuration.getMaintainerContact();
216216
}
217217

218-
public int checkDataRelease(int inRelease) throws CellBaseException {
219-
int outRelease = inRelease;
220-
if (outRelease < 0) {
221-
throw new CellBaseException("Invalid data release " + outRelease + ". Data release must be greater or equal to 0");
218+
public DataRelease checkDataRelease(int inRelease) throws CellBaseException {
219+
DataRelease outRelease;
220+
if (inRelease < 0) {
221+
throw new CellBaseException("Invalid data release " + inRelease + ". Data release must be greater or equal to 0");
222222
}
223-
if (outRelease == 0) {
223+
if (inRelease == 0) {
224224
String[] split = GitRepositoryState.get().getBuildVersion().split("[.-]");
225225
String version = "v" + split[0] + "." + split[1];
226-
outRelease = getDefault(version).getRelease();
227-
logger.info("Using data release 0: it means to take default data release '" + outRelease + "' for CellBase version '"
228-
+ version + "'");
226+
outRelease = getDefault(version);
227+
logger.info("Using data release 0: it means to take default data release '" + outRelease.getRelease()
228+
+ "' for CellBase version '" + version + "'");
229229
return outRelease;
230230
}
231231

232232
List<DataRelease> dataReleases = getReleases().getResults();
233233
for (DataRelease dataRelease : dataReleases) {
234-
if (outRelease == dataRelease.getRelease()) {
235-
return outRelease;
234+
if (inRelease == dataRelease.getRelease()) {
235+
return dataRelease;
236236
}
237237
}
238238

239-
throw new CellBaseException("Invalid data release " + outRelease + " for species = " + species + ", assembly = " + assembly
239+
throw new CellBaseException("Invalid data release " + inRelease + " for species = " + species + ", assembly = " + assembly
240240
+ ". Valid data releases are: " + StringUtils.join(dataReleases.stream().map(dr -> dr.getRelease())
241241
.collect(Collectors.toList()), ","));
242242
}

cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/VariantManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.opencb.cellbase.core.api.query.QueryException;
3333
import org.opencb.cellbase.core.config.CellBaseConfiguration;
3434
import org.opencb.cellbase.core.exception.CellBaseException;
35+
import org.opencb.cellbase.core.models.DataRelease;
3536
import org.opencb.cellbase.core.result.CellBaseDataResult;
3637
import org.opencb.cellbase.core.variant.AnnotationBasedPhasedQueryManager;
3738
import org.opencb.cellbase.lib.impl.core.CellBaseCoreDBAdaptor;
@@ -89,10 +90,10 @@ public CellBaseDataResult get(Query query, QueryOptions queryOptions, int dataRe
8990
return variantDBAdaptor.nativeGet(query, queryOptions, dataRelease);
9091
}
9192

92-
public List<CellBaseDataResult<String>> getHgvsByVariant(String variants, int dataRelease)
93+
public List<CellBaseDataResult<String>> getHgvsByVariant(String variants, DataRelease dataRelease)
9394
throws CellBaseException, QueryException, IllegalAccessException {
9495
List<Variant> variantList = parseVariants(variants);
95-
HgvsCalculator hgvsCalculator = new HgvsCalculator(genomeManager, dataRelease);
96+
HgvsCalculator hgvsCalculator = new HgvsCalculator(genomeManager, dataRelease.getRelease());
9697
List<CellBaseDataResult<String>> results = new ArrayList<>();
9798
VariantAnnotationCalculator variantAnnotationCalculator = new VariantAnnotationCalculator(species, assembly,
9899
dataRelease, "", cellbaseManagerFactory);
@@ -116,7 +117,7 @@ public List<CellBaseDataResult<String>> getHgvsByVariant(String variants, int da
116117
* @throws CellBaseException if the species is incorrect
117118
*/
118119
public CellBaseDataResult<Variant> getNormalizationByVariant(String variants, boolean decompose, boolean leftAlign,
119-
int dataRelease) throws CellBaseException {
120+
DataRelease dataRelease) throws CellBaseException {
120121
List<Variant> variantList = parseVariants(variants);
121122
VariantAnnotationCalculator variantAnnotationCalculator = new VariantAnnotationCalculator(species, assembly,
122123
dataRelease, "", cellbaseManagerFactory);
@@ -128,7 +129,7 @@ public CellBaseDataResult<Variant> getNormalizationByVariant(String variants, bo
128129
// Set left alignment behaviour
129130
if (leftAlign) {
130131
variantAnnotationCalculator.getNormalizer().getConfig().enableLeftAlign(new CellBaseNormalizerSequenceAdaptor(genomeManager,
131-
dataRelease));
132+
dataRelease.getRelease()));
132133
} else {
133134
variantAnnotationCalculator.getNormalizer().getConfig().disableLeftAlign();
134135
}
@@ -150,7 +151,7 @@ public List<CellBaseDataResult<VariantAnnotation>> getAnnotationByVariant(QueryO
150151
Integer cnvExtraPadding,
151152
Boolean checkAminoAcidChange,
152153
String consequenceTypeSource,
153-
int dataRelease,
154+
DataRelease dataRelease,
154155
String apiKey)
155156
throws ExecutionException, InterruptedException, CellBaseException, QueryException, IllegalAccessException {
156157
List<Variant> variantList = parseVariants(variants);

0 commit comments

Comments
 (0)