From 4e8191a8e30e12676cb7e34a626fb3189ec7cbcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Coll=20Morag=C3=B3n?= Date: Thu, 26 Apr 2018 18:33:26 +0100 Subject: [PATCH] storage: Add commands for creating and deleting annotation snapshot. #830 --- .../analysis/AnalysisCliOptionsParser.java | 5 +++ .../executors/VariantCommandExecutor.java | 31 ++++++++++++++ .../options/VariantCommandOptions.java | 27 ++++++++++++ .../cli/client/ClientCliOptionsParser.java | 4 ++ .../executors/VariantCommandExecutor.java | 30 ++++++++++++++ .../options/StorageVariantCommandOptions.java | 41 +++++++++++++++++++ .../variant/VariantStorageManager.java | 27 ++++++++++++ .../variant/operations/StorageOperation.java | 10 ++--- .../VariantAnnotationStorageOperation.java | 2 +- 9 files changed, 171 insertions(+), 6 deletions(-) diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/AnalysisCliOptionsParser.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/AnalysisCliOptionsParser.java index 39fdc8f8a19..34deb4a6944 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/AnalysisCliOptionsParser.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/AnalysisCliOptionsParser.java @@ -28,10 +28,13 @@ import org.opencb.opencga.app.cli.analysis.options.AlignmentCommandOptions; import org.opencb.opencga.app.cli.analysis.options.ToolsCommandOptions; import org.opencb.opencga.core.common.GitRepositoryState; +import org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions; import org.opencb.opencga.storage.core.variant.annotation.annotators.VariantAnnotatorFactory; import java.util.List; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.CreateAnnotationSnapshotCommandOptions.COPY_ANNOTATION_COMMAND; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.DeleteAnnotationSnapshotCommandOptions.DELETE_ANNOTATION_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillGapsCommandOptions.FILL_GAPS_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillMissingCommandOptions.FILL_MISSING_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.VariantRemoveCommandOptions.VARIANT_REMOVE_COMMAND; @@ -81,6 +84,8 @@ public AnalysisCliOptionsParser() { variantSubCommands.addCommand(VARIANT_REMOVE_COMMAND, variantCommandOptions.variantRemoveCommandOptions); variantSubCommands.addCommand("stats", variantCommandOptions.statsVariantCommandOptions); variantSubCommands.addCommand("annotate", variantCommandOptions.annotateVariantCommandOptions); + variantSubCommands.addCommand(COPY_ANNOTATION_COMMAND, variantCommandOptions.createAnnotationSnapshotCommandOptions); + variantSubCommands.addCommand(DELETE_ANNOTATION_COMMAND, variantCommandOptions.deleteAnnotationSnapshotCommandOptions); variantSubCommands.addCommand(FILL_GAPS_COMMAND, variantCommandOptions.fillGapsVariantCommandOptions); variantSubCommands.addCommand(FILL_MISSING_COMMAND, variantCommandOptions.fillMissingCommandOptions); variantSubCommands.addCommand("query", variantCommandOptions.queryVariantCommandOptions); diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/executors/VariantCommandExecutor.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/executors/VariantCommandExecutor.java index 4409bde7809..2da7b6766a6 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/executors/VariantCommandExecutor.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/executors/VariantCommandExecutor.java @@ -32,6 +32,7 @@ import org.opencb.opencga.catalog.exceptions.CatalogException; import org.opencb.opencga.core.common.UriUtils; import org.opencb.opencga.core.models.File; +import org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions; import org.opencb.opencga.storage.core.exceptions.StorageEngineException; import org.opencb.opencga.storage.core.exceptions.VariantSearchException; import org.opencb.opencga.storage.core.manager.variant.VariantCatalogQueryUtils; @@ -53,6 +54,8 @@ import java.net.URISyntaxException; import java.util.*; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.CreateAnnotationSnapshotCommandOptions.COPY_ANNOTATION_COMMAND; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.DeleteAnnotationSnapshotCommandOptions.DELETE_ANNOTATION_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillGapsCommandOptions.FILL_GAPS_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillMissingCommandOptions.FILL_MISSING_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.VariantRemoveCommandOptions.VARIANT_REMOVE_COMMAND; @@ -111,6 +114,12 @@ public void execute() throws Exception { case "annotate": annotate(); break; + case COPY_ANNOTATION_COMMAND: + copyAnnotation(); + break; + case DELETE_ANNOTATION_COMMAND: + deleteAnnotation(); + break; case FILL_GAPS_COMMAND: fillGaps(); break; @@ -351,6 +360,28 @@ private void annotate() throws StorageEngineException, IOException, URISyntaxExc variantManager.annotate(cliOptions.project, cliOptions.study, query, cliOptions.outdir, options, sessionId); } + private void copyAnnotation() throws IllegalAccessException, StorageEngineException, InstantiationException, VariantAnnotatorException, CatalogException, ClassNotFoundException { + VariantCommandOptions.CreateAnnotationSnapshotCommandOptions cliOptions = variantCommandOptions.createAnnotationSnapshotCommandOptions; + VariantStorageManager variantManager = new VariantStorageManager(catalogManager, storageEngineFactory); + + QueryOptions options = new QueryOptions(); + options.putAll(cliOptions.commonOptions.params); + + + variantManager.createAnnotationSnapshot(cliOptions.project, cliOptions.name, options, sessionId); + } + + private void deleteAnnotation() throws IllegalAccessException, StorageEngineException, InstantiationException, VariantAnnotatorException, CatalogException, ClassNotFoundException { + VariantCommandOptions.CreateAnnotationSnapshotCommandOptions cliOptions = variantCommandOptions.createAnnotationSnapshotCommandOptions; + VariantStorageManager variantManager = new VariantStorageManager(catalogManager, storageEngineFactory); + + QueryOptions options = new QueryOptions(); + options.putAll(cliOptions.commonOptions.params); + + + variantManager.deleteAnnotationSnapshot(cliOptions.project, cliOptions.name, options, sessionId); + } + private void fillGaps() throws StorageEngineException, IOException, URISyntaxException, VariantAnnotatorException, CatalogException, AnalysisExecutionException, IllegalAccessException, InstantiationException, ClassNotFoundException { diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/options/VariantCommandOptions.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/options/VariantCommandOptions.java index 99221a6d13b..72101fc5581 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/options/VariantCommandOptions.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/analysis/options/VariantCommandOptions.java @@ -32,6 +32,8 @@ import java.util.List; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.CreateAnnotationSnapshotCommandOptions.COPY_ANNOTATION_COMMAND; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.DeleteAnnotationSnapshotCommandOptions.DELETE_ANNOTATION_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillGapsCommandOptions.FILL_GAPS_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillGapsCommandOptions.FILL_GAPS_COMMAND_DESCRIPTION; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillMissingCommandOptions.FILL_MISSING_COMMAND; @@ -54,6 +56,8 @@ public class VariantCommandOptions { public final VariantQueryCommandOptions queryVariantCommandOptions; public final VariantStatsCommandOptions statsVariantCommandOptions; public final VariantAnnotateCommandOptions annotateVariantCommandOptions; + public final CreateAnnotationSnapshotCommandOptions createAnnotationSnapshotCommandOptions; + public final DeleteAnnotationSnapshotCommandOptions deleteAnnotationSnapshotCommandOptions; public final FillGapsCommandOptions fillGapsVariantCommandOptions; public final FillMissingCommandOptions fillMissingCommandOptions; public final VariantExportStatsCommandOptions exportVariantStatsCommandOptions; @@ -81,6 +85,8 @@ public VariantCommandOptions(GeneralCliOptions.CommonCommandOptions commonComman this.queryVariantCommandOptions = new VariantQueryCommandOptions(); this.statsVariantCommandOptions = new VariantStatsCommandOptions(); this.annotateVariantCommandOptions = new VariantAnnotateCommandOptions(); + this.createAnnotationSnapshotCommandOptions = new CreateAnnotationSnapshotCommandOptions(); + this.deleteAnnotationSnapshotCommandOptions = new DeleteAnnotationSnapshotCommandOptions(); this.fillGapsVariantCommandOptions = new FillGapsCommandOptions(); this.fillMissingCommandOptions = new FillMissingCommandOptions(); this.exportVariantStatsCommandOptions = new VariantExportStatsCommandOptions(); @@ -539,6 +545,27 @@ public class VariantAnnotateCommandOptions extends GeneralCliOptions.StudyOption public String catalogPath; } + @Parameters(commandNames = {COPY_ANNOTATION_COMMAND}) + public class CreateAnnotationSnapshotCommandOptions extends StorageVariantCommandOptions.GenericCreateAnnotationSnapshotCommandOptions { + + @ParametersDelegate + public GeneralCliOptions.CommonCommandOptions commonOptions = commonCommandOptions; + + @Parameter(names = {"-p", "--project"}, description = PROJECT_DESC, arity = 1) + public String project; + } + + @Parameters(commandNames = {DELETE_ANNOTATION_COMMAND}) + public class DeleteAnnotationSnapshotCommandOptions extends StorageVariantCommandOptions.GenericDeleteAnnotationSnapshotCommandOptions { + + @ParametersDelegate + public GeneralCliOptions.CommonCommandOptions commonOptions = commonCommandOptions; + + @Parameter(names = {"-p", "--project"}, description = PROJECT_DESC, arity = 1) + public String project; + + } + @Deprecated public class AnnotateVariantCommandOptionsOld { //extends AnalysisCliOptionsParser.CatalogDatabaseCommandOptions { diff --git a/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/ClientCliOptionsParser.java b/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/ClientCliOptionsParser.java index 3ea981a78db..f64275ac425 100644 --- a/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/ClientCliOptionsParser.java +++ b/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/ClientCliOptionsParser.java @@ -25,6 +25,8 @@ import java.util.Map; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.CreateAnnotationSnapshotCommandOptions.COPY_ANNOTATION_COMMAND; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.DeleteAnnotationSnapshotCommandOptions.DELETE_ANNOTATION_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillGapsCommandOptions.FILL_GAPS_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.VariantRemoveCommandOptions.VARIANT_REMOVE_COMMAND; @@ -60,6 +62,8 @@ public ClientCliOptionsParser() { variantSubCommands.addCommand("query", variantCommandOptions.variantQueryCommandOptions); variantSubCommands.addCommand("import", variantCommandOptions.importVariantsCommandOptions); variantSubCommands.addCommand("annotate", variantCommandOptions.annotateVariantsCommandOptions); + variantSubCommands.addCommand(COPY_ANNOTATION_COMMAND, variantCommandOptions.createAnnotationSnapshotCommandOptions); + variantSubCommands.addCommand(DELETE_ANNOTATION_COMMAND, variantCommandOptions.deleteAnnotationSnapshotCommandOptions); // variantSubCommands.addCommand("benchmark", variantCommandOptions.benchmarkCommandOptions); variantSubCommands.addCommand("stats", variantCommandOptions.statsVariantsCommandOptions); variantSubCommands.addCommand(FILL_GAPS_COMMAND, variantCommandOptions.fillGapsCommandOptions); diff --git a/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/executors/VariantCommandExecutor.java b/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/executors/VariantCommandExecutor.java index 267a6ac5920..7a7bd292660 100644 --- a/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/executors/VariantCommandExecutor.java +++ b/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/executors/VariantCommandExecutor.java @@ -70,6 +70,8 @@ import java.util.function.Function; import java.util.stream.Collectors; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.CreateAnnotationSnapshotCommandOptions.COPY_ANNOTATION_COMMAND; +import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.DeleteAnnotationSnapshotCommandOptions.DELETE_ANNOTATION_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillGapsCommandOptions.FILL_GAPS_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.FillMissingCommandOptions.FILL_MISSING_COMMAND; import static org.opencb.opencga.storage.app.cli.client.options.StorageVariantCommandOptions.VariantRemoveCommandOptions.VARIANT_REMOVE_COMMAND; @@ -151,6 +153,16 @@ public void execute() throws Exception { variantCommandOptions.annotateVariantsCommandOptions.dbName); annotation(); break; + case COPY_ANNOTATION_COMMAND: + configure(variantCommandOptions.createAnnotationSnapshotCommandOptions.commonOptions, + variantCommandOptions.createAnnotationSnapshotCommandOptions.dbName); + copyAnnotation(); + break; + case DELETE_ANNOTATION_COMMAND: + configure(variantCommandOptions.deleteAnnotationSnapshotCommandOptions.commonOptions, + variantCommandOptions.deleteAnnotationSnapshotCommandOptions.dbName); + deleteAnnotation(); + break; case "stats": configure(variantCommandOptions.statsVariantsCommandOptions.commonOptions, variantCommandOptions.statsVariantsCommandOptions.dbName); @@ -432,6 +444,24 @@ private void annotation() throws StorageEngineException, IOException, URISyntaxE } } + private void copyAnnotation() throws VariantAnnotatorException, StorageEngineException { + StorageVariantCommandOptions.CreateAnnotationSnapshotCommandOptions cliOptions = variantCommandOptions.createAnnotationSnapshotCommandOptions; + + ObjectMap options = storageConfiguration.getVariant().getOptions(); + options.putAll(cliOptions.commonOptions.params); + + variantStorageEngine.createAnnotationSnapshot(cliOptions.name, options); + } + + private void deleteAnnotation() throws VariantAnnotatorException, StorageEngineException { + StorageVariantCommandOptions.DeleteAnnotationSnapshotCommandOptions cliOptions = variantCommandOptions.deleteAnnotationSnapshotCommandOptions; + + ObjectMap options = storageConfiguration.getVariant().getOptions(); + options.putAll(cliOptions.commonOptions.params); + + variantStorageEngine.deleteAnnotationSnapshot(cliOptions.name, options); + } + private void stats() throws IOException, URISyntaxException, StorageEngineException, IllegalAccessException, InstantiationException, ClassNotFoundException { StorageVariantCommandOptions.VariantStatsCommandOptions statsVariantsCommandOptions = variantCommandOptions.statsVariantsCommandOptions; diff --git a/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/options/StorageVariantCommandOptions.java b/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/options/StorageVariantCommandOptions.java index 4967938bf8d..33c157a44c8 100644 --- a/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/options/StorageVariantCommandOptions.java +++ b/opencga-storage/opencga-storage-app/src/main/java/org/opencb/opencga/storage/app/cli/client/options/StorageVariantCommandOptions.java @@ -41,6 +41,8 @@ public class StorageVariantCommandOptions { public final VariantQueryCommandOptions variantQueryCommandOptions; public final ImportVariantsCommandOptions importVariantsCommandOptions; public final VariantAnnotateCommandOptions annotateVariantsCommandOptions; + public final CreateAnnotationSnapshotCommandOptions createAnnotationSnapshotCommandOptions; + public final DeleteAnnotationSnapshotCommandOptions deleteAnnotationSnapshotCommandOptions; public final VariantStatsCommandOptions statsVariantsCommandOptions; public final FillGapsCommandOptions fillGapsCommandOptions; public final FillMissingCommandOptions fillMissingCommandOptions; @@ -64,6 +66,8 @@ public StorageVariantCommandOptions(GeneralCliOptions.CommonOptions commonOption this.variantQueryCommandOptions = new VariantQueryCommandOptions(); this.importVariantsCommandOptions = new ImportVariantsCommandOptions(); this.annotateVariantsCommandOptions = new VariantAnnotateCommandOptions(); + this.createAnnotationSnapshotCommandOptions = new CreateAnnotationSnapshotCommandOptions(); + this.deleteAnnotationSnapshotCommandOptions = new DeleteAnnotationSnapshotCommandOptions(); this.statsVariantsCommandOptions = new VariantStatsCommandOptions(); this.fillGapsCommandOptions = new FillGapsCommandOptions(); this.fillMissingCommandOptions = new FillMissingCommandOptions(); @@ -506,6 +510,43 @@ public class VariantAnnotateCommandOptions extends GenericVariantAnnotateOptions public String outdir; } + public static class GenericCreateAnnotationSnapshotCommandOptions { + @Parameter(names = {"--name"}, description = "Annotation snapshot name", required = true, arity = 1) + public String name; + } + + @Parameters(commandNames = {CreateAnnotationSnapshotCommandOptions.COPY_ANNOTATION_COMMAND}, commandDescription = CreateAnnotationSnapshotCommandOptions.COPY_ANNOTATION_COMMAND_DESCRIPTION) + public class CreateAnnotationSnapshotCommandOptions extends GenericCreateAnnotationSnapshotCommandOptions { + public static final String COPY_ANNOTATION_COMMAND = "copy-annotation"; + public static final String COPY_ANNOTATION_COMMAND_DESCRIPTION = "Creates a snapshot of the current variant annotation at the database."; + + @ParametersDelegate + public GeneralCliOptions.CommonOptions commonOptions = commonCommandOptions; + + @Parameter(names = {"-d", "--database"}, description = "DataBase name", required = true, arity = 1) + public String dbName; + + } + + public static class GenericDeleteAnnotationSnapshotCommandOptions { + + @Parameter(names = {"--name"}, description = "Annotation snapshot name", required = true, arity = 1) + public String name; + } + + @Parameters(commandNames = {DeleteAnnotationSnapshotCommandOptions.DELETE_ANNOTATION_COMMAND}, commandDescription = DeleteAnnotationSnapshotCommandOptions.DELETE_ANNOTATION_COMMAND_DESCRIPTION) + public class DeleteAnnotationSnapshotCommandOptions extends GenericDeleteAnnotationSnapshotCommandOptions { + public static final String DELETE_ANNOTATION_COMMAND = "delete-annotation"; + public static final String DELETE_ANNOTATION_COMMAND_DESCRIPTION = "Deletes a variant annotation snapshot."; + + @ParametersDelegate + public GeneralCliOptions.CommonOptions commonOptions = commonCommandOptions; + + @Parameter(names = {"-d", "--database"}, description = "DataBase name", required = true, arity = 1) + public String dbName; + + } + /** * annotate: generic and specific options */ diff --git a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/VariantStorageManager.java b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/VariantStorageManager.java index eab32055b3a..47f9ec1cb78 100644 --- a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/VariantStorageManager.java +++ b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/VariantStorageManager.java @@ -53,6 +53,7 @@ import org.opencb.opencga.storage.core.variant.BeaconResponse; import org.opencb.opencga.storage.core.variant.VariantStorageEngine; import org.opencb.opencga.storage.core.variant.adaptors.*; +import org.opencb.opencga.storage.core.variant.annotation.VariantAnnotatorException; import org.opencb.opencga.storage.core.variant.io.VariantWriterFactory.VariantOutputFormat; import java.io.IOException; @@ -243,6 +244,28 @@ public void deleteAnnotation(String annotationId, String studyId, String session throw new UnsupportedOperationException(); } + public void createAnnotationSnapshot(String project, String annotationName, ObjectMap params, String sessionId) + throws StorageEngineException, VariantAnnotatorException, CatalogException, IllegalAccessException, InstantiationException, + ClassNotFoundException { + + DataStore dataStore = getDataStoreByProjectId(project, sessionId); + VariantStorageEngine variantStorageEngine = + storageEngineFactory.getVariantStorageEngine(dataStore.getStorageEngine(), dataStore.getDbName()); + + variantStorageEngine.createAnnotationSnapshot(annotationName, params); + } + + public void deleteAnnotationSnapshot(String project, String annotationName, ObjectMap params, String sessionId) + throws StorageEngineException, VariantAnnotatorException, CatalogException, IllegalAccessException, + InstantiationException, ClassNotFoundException { + + DataStore dataStore = getDataStoreByProjectId(project, sessionId); + VariantStorageEngine variantStorageEngine = + storageEngineFactory.getVariantStorageEngine(dataStore.getStorageEngine(), dataStore.getDbName()); + + variantStorageEngine.deleteAnnotationSnapshot(annotationName, params); + } + public void stats(String study, List cohorts, String outDir, ObjectMap config, String sessionId) throws CatalogException, StorageEngineException, IOException, URISyntaxException { VariantStatsStorageOperation statsOperation = new VariantStatsStorageOperation(catalogManager, storageConfiguration); @@ -424,6 +447,10 @@ private DataStore getDataStore(long studyId, String sessionId) throws CatalogExc return StorageOperation.getDataStore(catalogManager, studyId, File.Bioformat.VARIANT, sessionId); } + private DataStore getDataStoreByProjectId(String project, String sessionId) throws CatalogException { + return StorageOperation.getDataStoreByProjectId(catalogManager, project, File.Bioformat.VARIANT, sessionId); + } + protected VariantStorageEngine getVariantStorageEngine(DataStore dataStore) throws CatalogException, StorageEngineException { try { return storageEngineFactory.getVariantStorageEngine(dataStore.getStorageEngine(), dataStore.getDbName()); diff --git a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/StorageOperation.java b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/StorageOperation.java index dfa41cd6a4c..78af4fe2510 100644 --- a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/StorageOperation.java +++ b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/StorageOperation.java @@ -217,23 +217,23 @@ public static DataStore getDataStore(CatalogManager catalogManager, Study study, dataStore = study.getDataStores().get(bioformat); } else { long projectId = catalogManager.getStudyManager().getProjectId(study.getId()); - dataStore = getDataStoreByProjectId(catalogManager, projectId, bioformat, sessionId); + dataStore = getDataStoreByProjectId(catalogManager, String.valueOf(projectId), bioformat, sessionId); } return dataStore; } - protected static DataStore getDataStoreByProjectId(CatalogManager catalogManager, long projectId, File.Bioformat bioformat, - String sessionId) + public static DataStore getDataStoreByProjectId(CatalogManager catalogManager, String projectStr, File.Bioformat bioformat, + String sessionId) throws CatalogException { DataStore dataStore; QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(ProjectDBAdaptor.QueryParams.ALIAS.key(), ProjectDBAdaptor.QueryParams.DATASTORES.key())); - Project project = catalogManager.getProjectManager().get(String.valueOf((Long) projectId), queryOptions, sessionId).first(); + Project project = catalogManager.getProjectManager().get(projectStr, queryOptions, sessionId).first(); if (project.getDataStores() != null && project.getDataStores().containsKey(bioformat)) { dataStore = project.getDataStores().get(bioformat); } else { //get default datastore //Must use the UserByStudyId instead of the file owner. - String userId = catalogManager.getProjectManager().getOwner(projectId); + String userId = catalogManager.getProjectManager().getOwner(project.getId()); // Replace possible dots at the userId. Usually a special character in almost all databases. See #532 userId = userId.replace('.', '_'); diff --git a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/VariantAnnotationStorageOperation.java b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/VariantAnnotationStorageOperation.java index ba1a9b4cab9..cf978998fa8 100644 --- a/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/VariantAnnotationStorageOperation.java +++ b/opencga-storage/opencga-storage-core/src/main/java/org/opencb/opencga/storage/core/manager/variant/operations/VariantAnnotationStorageOperation.java @@ -93,7 +93,7 @@ public List annotateVariants(@Nullable String projectStr, @Nullable List