Skip to content

Commit

Permalink
lib: check pharmacogenomics collection in the target data release bef…
Browse files Browse the repository at this point in the history
…ore annotating variants, #TASK-5447
  • Loading branch information
jtarraga committed Jan 10, 2024
1 parent b178710 commit 6ade410
Show file tree
Hide file tree
Showing 38 changed files with 222 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import org.opencb.cellbase.app.cli.admin.AdminCliOptionsParser;
import org.opencb.cellbase.app.cli.admin.executors.validation.VEPVariant;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.managers.CellBaseManagerFactory;
import org.opencb.cellbase.lib.managers.DataReleaseManager;
import org.opencb.cellbase.lib.variant.annotation.VariantAnnotationCalculator;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.commons.utils.FileUtils;
Expand All @@ -44,7 +46,7 @@

public class ValidationCommandExecutor extends CommandExecutor {

// private MongoDBAdaptorFactory dbAdaptorFactory;
// private MongoDBAdaptorFactory dbAdaptorFactory;
private AdminCliOptionsParser.ValidationCommandOptions validationCommandOptions;
private ObjectMapper objectMapper;
private String resultsFile;
Expand All @@ -67,12 +69,15 @@ public ValidationCommandExecutor(AdminCliOptionsParser.ValidationCommandOptions
public void execute() {
checkFilesExist();

VariantAnnotationCalculator variantAnnotationCalculator;
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
// dbAdaptorFactory = new MongoDBAdaptorFactory(configuration);
VariantAnnotationCalculator variantAnnotationCalculator = null;

try {
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(validationCommandOptions.species,
validationCommandOptions.assembly);
DataRelease dataRelease = dataReleaseManager.get(validationCommandOptions.dataRelease);
variantAnnotationCalculator = new VariantAnnotationCalculator(validationCommandOptions.species,
validationCommandOptions.assembly, validationCommandOptions.dataRelease, validationCommandOptions.apiKey,
validationCommandOptions.assembly, dataRelease, validationCommandOptions.apiKey,
cellBaseManagerFactory);
} catch (CellBaseException e) {
e.printStackTrace();
Expand Down Expand Up @@ -241,7 +246,7 @@ private void compare(BufferedWriter mismatchWriter, BufferedWriter matchWriter,
// skip proteins if we are only processing transcripts
// skip transcripts if we are only processing proteins
if (("transcript".equalsIgnoreCase(category) && entityId.startsWith("ENSP"))
|| ("protein".equalsIgnoreCase(category) && entityId.startsWith("ENST"))) {
|| ("protein".equalsIgnoreCase(category) && entityId.startsWith("ENST"))) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
import org.opencb.cellbase.client.config.ClientConfiguration;
import org.opencb.cellbase.client.rest.CellBaseClient;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.impl.core.MongoDBAdaptorFactory;
import org.opencb.cellbase.lib.impl.core.VariantMongoDBAdaptor;
import org.opencb.cellbase.lib.managers.CellBaseManagerFactory;
import org.opencb.cellbase.lib.managers.DataReleaseManager;
import org.opencb.cellbase.lib.managers.GenomeManager;
import org.opencb.cellbase.lib.managers.VariantManager;
import org.opencb.cellbase.lib.variant.annotation.CellBaseNormalizerSequenceAdaptor;
Expand Down Expand Up @@ -202,9 +204,10 @@ private boolean runAnnotation() throws Exception {
List<Variant> variants = Variant.parseVariants(variantAnnotationCommandOptions.variant);
if (local) {
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
VariantAnnotationCalculator variantAnnotationCalculator =
new VariantAnnotationCalculator(this.species, this.assembly, variantAnnotationCommandOptions.dataRelease,
variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory);
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly);
DataRelease dataRelease = dataReleaseManager.get(variantAnnotationCommandOptions.dataRelease);
VariantAnnotationCalculator variantAnnotationCalculator = new VariantAnnotationCalculator(species, assembly,
dataRelease, variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory);
List<CellBaseDataResult<VariantAnnotation>> annotationByVariantList =
variantAnnotationCalculator.getAnnotationByVariantList(variants, serverQueryOptions);

Expand Down Expand Up @@ -479,9 +482,10 @@ private VariantAnnotator createCellBaseAnnotator() throws CellBaseException {
// corresponding *AnnotatorTask since the AnnotatorTasks need that the number of sent variants coincides
// equals the number of returned annotations
CellBaseManagerFactory cellBaseManagerFactory = new CellBaseManagerFactory(configuration);
return new CellBaseLocalVariantAnnotator(new VariantAnnotationCalculator(species, assembly,
variantAnnotationCommandOptions.dataRelease, variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory),
serverQueryOptions);
DataReleaseManager dataReleaseManager = cellBaseManagerFactory.getDataReleaseManager(species, assembly);
DataRelease dataRelease = dataReleaseManager.get(variantAnnotationCommandOptions.dataRelease);
return new CellBaseLocalVariantAnnotator(new VariantAnnotationCalculator(species, assembly, dataRelease,
variantAnnotationCommandOptions.apiKey, cellBaseManagerFactory), serverQueryOptions);
} else {
try {
ClientConfiguration clientConfiguration = ClientConfiguration.load(getClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,28 @@ public String getMaintainerContact() {
return configuration.getMaintainerContact();
}

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

List<DataRelease> dataReleases = getReleases().getResults();
for (DataRelease dataRelease : dataReleases) {
if (outRelease == dataRelease.getRelease()) {
return outRelease;
if (inRelease == dataRelease.getRelease()) {
return dataRelease;
}
}

throw new CellBaseException("Invalid data release " + outRelease + " for species = " + species + ", assembly = " + assembly
throw new CellBaseException("Invalid data release " + inRelease + " for species = " + species + ", assembly = " + assembly
+ ". Valid data releases are: " + StringUtils.join(dataReleases.stream().map(dr -> dr.getRelease())
.collect(Collectors.toList()), ","));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.opencb.cellbase.core.api.query.QueryException;
import org.opencb.cellbase.core.config.CellBaseConfiguration;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.core.variant.AnnotationBasedPhasedQueryManager;
import org.opencb.cellbase.lib.impl.core.CellBaseCoreDBAdaptor;
Expand Down Expand Up @@ -89,10 +90,10 @@ public CellBaseDataResult get(Query query, QueryOptions queryOptions, int dataRe
return variantDBAdaptor.nativeGet(query, queryOptions, dataRelease);
}

public List<CellBaseDataResult<String>> getHgvsByVariant(String variants, int dataRelease)
public List<CellBaseDataResult<String>> getHgvsByVariant(String variants, DataRelease dataRelease)
throws CellBaseException, QueryException, IllegalAccessException {
List<Variant> variantList = parseVariants(variants);
HgvsCalculator hgvsCalculator = new HgvsCalculator(genomeManager, dataRelease);
HgvsCalculator hgvsCalculator = new HgvsCalculator(genomeManager, dataRelease.getRelease());
List<CellBaseDataResult<String>> results = new ArrayList<>();
VariantAnnotationCalculator variantAnnotationCalculator = new VariantAnnotationCalculator(species, assembly,
dataRelease, "", cellbaseManagerFactory);
Expand All @@ -116,7 +117,7 @@ public List<CellBaseDataResult<String>> getHgvsByVariant(String variants, int da
* @throws CellBaseException if the species is incorrect
*/
public CellBaseDataResult<Variant> getNormalizationByVariant(String variants, boolean decompose, boolean leftAlign,
int dataRelease) throws CellBaseException {
DataRelease dataRelease) throws CellBaseException {
List<Variant> variantList = parseVariants(variants);
VariantAnnotationCalculator variantAnnotationCalculator = new VariantAnnotationCalculator(species, assembly,
dataRelease, "", cellbaseManagerFactory);
Expand All @@ -128,7 +129,7 @@ public CellBaseDataResult<Variant> getNormalizationByVariant(String variants, bo
// Set left alignment behaviour
if (leftAlign) {
variantAnnotationCalculator.getNormalizer().getConfig().enableLeftAlign(new CellBaseNormalizerSequenceAdaptor(genomeManager,
dataRelease));
dataRelease.getRelease()));
} else {
variantAnnotationCalculator.getNormalizer().getConfig().disableLeftAlign();
}
Expand All @@ -150,7 +151,7 @@ public List<CellBaseDataResult<VariantAnnotation>> getAnnotationByVariant(QueryO
Integer cnvExtraPadding,
Boolean checkAminoAcidChange,
String consequenceTypeSource,
int dataRelease,
DataRelease dataRelease,
String apiKey)
throws ExecutionException, InterruptedException, CellBaseException, QueryException, IllegalAccessException {
List<Variant> variantList = parseVariants(variants);
Expand Down
Loading

0 comments on commit 6ade410

Please sign in to comment.