Skip to content

Commit

Permalink
storage: Add commands for creating and deleting annotation snapshot. #…
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Apr 26, 2018
1 parent 89d1321 commit 4e8191a
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 6 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {

Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 4e8191a

Please sign in to comment.