From a479682f3790b58cc53cd760bd5003550b5f3fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20T=C3=A1rraga=20Gim=C3=A9nez?= Date: Wed, 11 Sep 2024 11:48:41 +0200 Subject: [PATCH] analysis: add the parameter resourcesDir for QC analysis, and update the code according to this change, #TASK-6772, #TASK-6766 --- .../family/qc/FamilyVariantQcAnalysis.java | 8 +- .../qc/IndividualVariantQcAnalysis.java | 11 +- .../variant/qc/VariantQcAnalysis.java | 222 +++++++----------- .../AnalysisVariantCommandExecutor.java | 11 +- .../AnalysisVariantCommandOptions.java | 27 +-- .../opencga/core/api/FieldConstants.java | 1 + .../variant/FamilyQcAnalysisParams.java | 39 +-- .../variant/IndividualQcAnalysisParams.java | 48 ++-- .../variant/QcInferredSexAnalysisParams.java | 50 ---- .../variant/QcRelatednessAnalysisParams.java | 78 ------ 10 files changed, 146 insertions(+), 349 deletions(-) delete mode 100644 opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcInferredSexAnalysisParams.java delete mode 100644 opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcRelatednessAnalysisParams.java diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyVariantQcAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyVariantQcAnalysis.java index 9d0739678d..32c4f9f5a2 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyVariantQcAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyVariantQcAnalysis.java @@ -73,8 +73,8 @@ protected void check() throws Exception { super.check(); checkParameters(analysisParams, getStudy(), catalogManager, token); - // Update paths from relatedness external files - updateRelatednessFilePaths(analysisParams.getRelatednessParams()); + // Prepare relatedness resource files + prepareRelatednessResources(analysisParams.getResourcesDir()); } @Override @@ -217,8 +217,8 @@ public static void checkParameters(FamilyQcAnalysisParams params, String studyId e -> "Family ID " + e.getKey() + ": " + e.getValue()).collect(Collectors.toList()), ",")); } - // Check relatedness files: pop. freq. file, pop. exclude var. file and threshold file - checkRelatednessParameters(params.getRelatednessParams(), studyId, catalogManager, token); + // Check resources dir + checkResourcesDir(params.getResourcesDir(), studyId, catalogManager, token); } private void updateFamilyQualityControl(List families) throws ToolException { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualVariantQcAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualVariantQcAnalysis.java index 74ad8412eb..c2a1fb42ba 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualVariantQcAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualVariantQcAnalysis.java @@ -78,7 +78,7 @@ protected void check() throws Exception { super.check(); checkParameters(analysisParams, getStudy(), catalogManager, token); - // Check for the presence of trios to compute relatedness + // Check for the presence of trios to compute relatedness, and then prepare relatedness resource files for (String individualId : analysisParams.getIndividuals()) { // Get individual Individual individual = catalogManager.getIndividualManager().get(study, individualId, QueryOptions.empty(), token).first(); @@ -87,10 +87,11 @@ protected void check() throws Exception { } } if (CollectionUtils.isNotEmpty(trios)) { - updateRelatednessFilePaths(analysisParams.getRelatednessParams()); + prepareRelatednessResources(analysisParams.getResourcesDir()); } - updateInferredSexFilePaths(analysisParams.getInferredSexParams()); + // Prepare inferred sex resource files + prepareInferredSexResources(analysisParams.getResourcesDir()); } @Override @@ -321,7 +322,7 @@ public static void checkParameters(IndividualQcAnalysisParams params, String stu e -> "Individual ID " + e.getKey() + ": " + e.getValue()).collect(Collectors.toList()), ",")); } - // Check relatedness files: pop. freq. file, pop. exclude var. file and threshold file - checkRelatednessParameters(params.getRelatednessParams(), studyId, catalogManager, token); + // Check resources dir + checkResourcesDir(params.getResourcesDir(), studyId, catalogManager, token); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/qc/VariantQcAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/qc/VariantQcAnalysis.java index 9221781315..03f432363c 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/qc/VariantQcAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/qc/VariantQcAnalysis.java @@ -23,13 +23,12 @@ import org.opencb.commons.datastore.core.QueryOptions; import org.opencb.opencga.analysis.ResourceUtils; import org.opencb.opencga.analysis.tools.OpenCgaToolScopeStudy; -import org.opencb.opencga.analysis.variant.relatedness.RelatednessAnalysis; +import org.opencb.opencga.catalog.db.api.FileDBAdaptor; import org.opencb.opencga.catalog.db.api.IndividualDBAdaptor; import org.opencb.opencga.catalog.exceptions.CatalogException; import org.opencb.opencga.catalog.managers.CatalogManager; import org.opencb.opencga.catalog.utils.CatalogFqn; import org.opencb.opencga.core.exceptions.ToolException; -import org.opencb.opencga.core.exceptions.ToolExecutorException; import org.opencb.opencga.core.models.JwtPayload; import org.opencb.opencga.core.models.common.QualityControlStatus; import org.opencb.opencga.core.models.family.Family; @@ -41,8 +40,6 @@ import org.opencb.opencga.core.models.sample.Sample; import org.opencb.opencga.core.models.study.Study; import org.opencb.opencga.core.models.study.StudyPermissions; -import org.opencb.opencga.core.models.variant.QcInferredSexAnalysisParams; -import org.opencb.opencga.core.models.variant.QcRelatednessAnalysisParams; import org.opencb.opencga.core.response.OpenCGAResult; import java.io.IOException; @@ -148,91 +145,50 @@ protected static void checkPermissions(StudyPermissions.Permissions permissions, } } - protected static void checkRelatednessParameters(QcRelatednessAnalysisParams relatednessParams, String studyId, - CatalogManager catalogManager, String token) throws ToolException { - if (StringUtils.isNotEmpty(relatednessParams.getPopulationFrequencyFile())) { - checkFileParameter(relatednessParams.getPopulationFrequencyFile(), RELATEDNESS_POP_FREQ_FILE_MSG, studyId, catalogManager, - token); - } - if (StringUtils.isNotEmpty(relatednessParams.getPopulationExcludeVariantsFile())) { - checkFileParameter(relatednessParams.getPopulationExcludeVariantsFile(), RELATEDNESS_POP_EXCLUDE_VAR_FILE_MSG, studyId, - catalogManager, token); - } - if (StringUtils.isNotEmpty(relatednessParams.getThresholdsFile())) { - checkFileParameter(relatednessParams.getThresholdsFile(), RELATEDNESS_THRESHOLDS_FILE_MSG, studyId, catalogManager, token); + protected static Path checkResourcesDir(String resourcesDir, String studyId, CatalogManager catalogManager, String token) + throws ToolException { + Path path = null; + if (StringUtils.isNotEmpty(resourcesDir)) { + try { + Query query = new Query(FileDBAdaptor.QueryParams.PATH.key(), resourcesDir); + OpenCGAResult fileResult = catalogManager.getFileManager().search(studyId, query, QueryOptions.empty(), token); + if (fileResult.getNumResults() == 0) { + throw new ToolException("Could not find the resources path '" + resourcesDir + "' in OpenCGA catalog"); + } + if (fileResult.getNumResults() > 1) { + throw new ToolException("Multiple results found (" + fileResult.getNumResults() + ") for resources path '" + + resourcesDir + "' in OpenCGA catalog"); + } + path = Paths.get(fileResult.first().getUri()); + if (!Files.exists(path)) { + throw new ToolException("Resources path '" + path + "' does not exist (OpenCGA path: " + resourcesDir + ")"); + } + return path; + } catch (CatalogException e) { + throw new ToolException("Error searching the OpenCGA catalog path '" + resourcesDir + "'", e); + } } + return path; } - protected void updateRelatednessFilePaths(QcRelatednessAnalysisParams relatednessParams) throws ToolException { - // Sanity check - if (relatednessParams == null) { - throw new ToolException("Internal error input parameter is null"); - } + protected void prepareRelatednessResources(String resourcesDir) throws ToolException { + Path path = checkResourcesDir(resourcesDir, getStudy(), getCatalogManager(), getToken()); - // Get relatedness population frequency - if (StringUtils.isNotEmpty(relatednessParams.getPopulationFrequencyFile())) { - Path path = checkFileParameter(relatednessParams.getPopulationFrequencyFile(), RELATEDNESS_POP_FREQ_FILE_MSG, getStudy(), - catalogManager, getToken()); - relatednessParams.setPopulationFrequencyFile(path.toAbsolutePath().toString()); - } else { - Path path = getExternalFilePath(RelatednessAnalysis.ID, RELATEDNESS_POP_FREQ_FILENAME); - relatednessParams.setPopulationFrequencyFile(path.toAbsolutePath().toString()); - } + // Copy relatedness population frequency file + copyQcResourceFile(path, RELATEDNESS_POP_FREQ_FILENAME); - // Get relatedness population exclude variant - if (StringUtils.isNotEmpty(relatednessParams.getPopulationExcludeVariantsFile())) { - Path path = checkFileParameter(relatednessParams.getPopulationExcludeVariantsFile(), RELATEDNESS_POP_EXCLUDE_VAR_FILE_MSG, - getStudy(), catalogManager, getToken()); - relatednessParams.setPopulationExcludeVariantsFile(path.toAbsolutePath().toString()); - } else { - Path path = getExternalFilePath(RelatednessAnalysis.ID, RELATEDNESS_POP_EXCLUDE_VAR_FILENAME); - relatednessParams.setPopulationExcludeVariantsFile(path.toAbsolutePath().toString()); - } + // Copy relatedness population exclude variant file + copyQcResourceFile(path, RELATEDNESS_POP_FREQ_FILENAME); - // Get relatedness thresholds - if (StringUtils.isNotEmpty(relatednessParams.getThresholdsFile())) { - Path path = checkFileParameter(relatednessParams.getThresholdsFile(), RELATEDNESS_THRESHOLDS_FILE_MSG, getStudy(), - catalogManager, getToken()); - relatednessParams.setThresholdsFile(path.toAbsolutePath().toString()); - } else { - Path path = getExternalFilePath(RELATEDNESS_ANALYSIS_ID, RELATEDNESS_THRESHOLDS_FILENAME); - relatednessParams.setThresholdsFile(path.toAbsolutePath().toString()); - } + // Copy relatedness thresholds file + copyQcResourceFile(path, RELATEDNESS_THRESHOLDS_FILENAME); } - protected void updateInferredSexFilePaths(QcInferredSexAnalysisParams inferredSexParams) throws ToolException { - // Sanity check - if (inferredSexParams == null) { - throw new ToolException("Internal error input parameter is null"); - } - - // Get inferred sex thresholds - if (StringUtils.isNotEmpty(inferredSexParams.getThresholdsFile())) { - Path path = checkFileParameter(inferredSexParams.getThresholdsFile(), INFERRED_SEX_THRESHOLDS_FILE_MSG, getStudy(), - catalogManager, getToken()); - inferredSexParams.setThresholdsFile(path.toAbsolutePath().toString()); - } else { - Path path = getExternalFilePath(INFERRED_SEX_ANALYSIS_ID, INFERRED_SEX_THRESHOLDS_FILENAME); - inferredSexParams.setThresholdsFile(path.toAbsolutePath().toString()); - } - } + protected void prepareInferredSexResources(String resourcesDir) throws ToolException { + Path path = checkResourcesDir(resourcesDir, getStudy(), getCatalogManager(), getToken()); - protected static Path checkFileParameter(String fileId, String msg, String studyId, CatalogManager catalogManager, String token) - throws ToolException { - if (StringUtils.isEmpty(fileId)) { - throw new ToolException(msg + " ID is empty"); - } - File file; - try { - file = catalogManager.getFileManager().get(studyId, fileId, QueryOptions.empty(), token).first(); - } catch (CatalogException e) { - throw new ToolExecutorException(msg + " ID '" + fileId + "' not found in OpenCGA catalog", e); - } - Path path = Paths.get(file.getUri()); - if (!Files.exists(path)) { - throw new ToolExecutorException(msg + " '" + path + "' does not exist (file ID: " + fileId + ")"); - } - return path; + // Copy inferred sex thresholds file + copyQcResourceFile(path, INFERRED_SEX_THRESHOLDS_FILENAME); } protected boolean setQualityControlStatus(QualityControlStatus qcStatus, String id, String qcType) throws ToolException { @@ -311,83 +267,75 @@ protected static List getNoSomaticSampleIds(Individual individual) { return sampleIds; } - protected Path getExternalFilePath(String analysisId, String resourceName) throws ToolException { - Path resourcesPath = getOutDir().resolve(RESOURCES_FOLDER); - if (!Files.exists(resourcesPath)) { + protected void copyQcResourceFile(Path path, String resourceName) throws ToolException { + // Copy resource file + if (path == null || !Files.exists(path.resolve(resourceName))) { + // Use the default resource file + copyQcResourceFile(resourceName); + } else { + // Use the custom resource file + copyQcResourceFile(path.resolve(resourceName)); + } + } + + protected void copyQcResourceFile(String resourceName) throws ToolException { + Path srcResourcesPath = getOpencgaHome().resolve(ANALYSIS_RESOURCES_FOLDER).resolve(QC_FOLDER); + Path destResourcesPath = checkResourcesPath(getOutDir().resolve(RESOURCES_FOLDER)); + if (Files.exists(srcResourcesPath.resolve(resourceName))) { + // Copy resource file + copyQcResourceFile(srcResourcesPath.resolve(resourceName)); + } else { + // Download directly into the job dir + // It can be improved by downloading once (the first time) in the analysis resources folder + URL url = null; try { - Files.createDirectories(resourcesPath); - if (!Files.exists(resourcesPath)) { - throw new ToolException("Something wrong happened when creating the resources folder at " + resourcesPath); - } + url = new URL(ResourceUtils.URL + ANALYSIS_FOLDER + QC_FOLDER + "/" + resourceName); + ResourceUtils.downloadThirdParty(url, destResourcesPath); } catch (IOException e) { - throw new ToolException("Error creating the resources folder at " + resourcesPath, e); + throw new ToolException("Something wrong happened when downloading the resource '" + resourceName + "' from '" + + url + "'", e); + } + + if (!Files.exists(destResourcesPath.resolve(resourceName))) { + throw new ToolException("Error downloading the resource '" + resourceName + "', it does not exist at " + destResourcesPath); } - } - switch (resourceName) { - case RELATEDNESS_THRESHOLDS_FILENAME: - case INFERRED_SEX_THRESHOLDS_FILENAME: - return copyExternalFile(getOpencgaHome().resolve(ANALYSIS_FOLDER).resolve(QC_RESOURCES_FOLDER).resolve(resourceName)); - default: - return downloadExternalFile(analysisId, resourceName); } } - protected Path copyExternalFile(Path source) throws ToolException { - Path dest = getOutDir().resolve(RESOURCES_FOLDER).resolve(source.getFileName()); + protected void copyQcResourceFile(Path srcResourcesPath) throws ToolException { + String resourceName = srcResourcesPath.getFileName().toString(); + Path destResourcesPath = checkResourcesPath(getOutDir().resolve(RESOURCES_FOLDER)); + + String msg = "Error copying resource file '" + resourceName + "'"; + + // Copy resource file try { - Files.copy(source, dest); + Files.copy(srcResourcesPath, destResourcesPath.resolve(resourceName)); } catch (IOException e) { - String msg = "Error copying resource file '" + source.getFileName() + "'"; - if (!Files.exists(dest) || source.toFile().length() != dest.toFile().length()) { + if (!Files.exists(destResourcesPath.resolve(resourceName)) + || srcResourcesPath.toFile().length() != destResourcesPath.resolve(resourceName).toFile().length()) { throw new ToolException(msg, e); } logger.warn(msg, e); } - return dest; - } - protected Path downloadExternalFile(String analysisId, String resourceName) throws ToolException { - URL url = null; - Path resourcesPath = getOutDir().resolve(RESOURCES_FOLDER); - try { - url = new URL(ResourceUtils.URL + ANALYSIS_FOLDER + analysisId + "/" + resourceName); - ResourceUtils.downloadThirdParty(url, resourcesPath); - } catch (IOException e) { - throw new ToolException("Something wrong happened when downloading the resource '" + resourceName + "' from '" + url + "'", e); + if (!Files.exists(destResourcesPath.resolve(resourceName))) { + throw new ToolException(msg + ", it does not exist at " + destResourcesPath); } - - if (!Files.exists(resourcesPath.resolve(resourceName))) { - throw new ToolException("After downloading the resource '" + resourceName + "', it does not exist at " + resourcesPath); - } - return resourcesPath.resolve(resourceName); } - protected Path downloadExternalFileAtResources(String analysisId, String resourceName) throws ToolException { - // Check if the resource has been downloaded previously - Path resourcePath = getOpencgaHome().resolve(ANALYSIS_RESOURCES_FOLDER + analysisId); - if (!Files.exists(resourcePath)) { - // Create the resource path if it does not exist yet - try { - Files.createDirectories(resourcePath); - } catch (IOException e) { - throw new ToolException("It could not create the resource path '" + resourcePath + "'", e); - } - } - if (!Files.exists(resourcePath.resolve(resourceName))) { - // Otherwise, download it from the resource repository - URL url = null; + protected Path checkResourcesPath(Path resourcesPath) throws ToolException { + if (!Files.exists(resourcesPath)) { try { - url = new URL(ResourceUtils.URL + ANALYSIS_FOLDER + analysisId + "/" + resourceName); - ResourceUtils.downloadThirdParty(url, resourcePath); + Files.createDirectories(resourcesPath); + if (!Files.exists(resourcesPath)) { + throw new ToolException("Something wrong happened when creating the resources folder at " + resourcesPath); + } } catch (IOException e) { - throw new ToolException("Something wrong happened downloading the resource '" + resourceName + "' from '" + url + "'", e); - } - - if (!Files.exists(resourcePath.resolve(resourceName))) { - throw new ToolException("After downloading the resource '" + resourceName + "', it does not exist at " + resourcePath); + throw new ToolException("Error creating the resources folder at " + resourcesPath, e); } } - return resourcePath.resolve(resourceName); + return resourcesPath; } protected boolean performQualityControl(QualityControlStatus qcStatus, Boolean overwrite) { diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/executors/AnalysisVariantCommandExecutor.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/executors/AnalysisVariantCommandExecutor.java index ef6671529c..4274e9624a 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/executors/AnalysisVariantCommandExecutor.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/executors/AnalysisVariantCommandExecutor.java @@ -44,8 +44,6 @@ import org.opencb.opencga.core.models.variant.MendelianErrorAnalysisParams; import org.opencb.opencga.core.models.variant.MutationalSignatureAnalysisParams; import org.opencb.opencga.core.models.variant.PlinkWrapperParams; -import org.opencb.opencga.core.models.variant.QcInferredSexAnalysisParams; -import org.opencb.opencga.core.models.variant.QcRelatednessAnalysisParams; import org.opencb.opencga.core.models.variant.RelatednessAnalysisParams; import org.opencb.opencga.core.models.variant.RvtestsWrapperParams; import org.opencb.opencga.core.models.variant.SampleEligibilityAnalysisParams; @@ -625,11 +623,9 @@ private RestResponse runFamilyQc() throws Exception { putNestedIfNotEmpty(beanParams, "family",commandOptions.family, true); putNestedIfNotEmpty(beanParams, "relatednessMethod",commandOptions.relatednessMethod, true); putNestedIfNotEmpty(beanParams, "relatednessMaf",commandOptions.relatednessMaf, true); - putNestedIfNotEmpty(beanParams, "relatednessParams.populationFrequencyFile",commandOptions.relatednessParamsPopulationFrequencyFile, true); - putNestedIfNotEmpty(beanParams, "relatednessParams.populationExcludeVariantsFile",commandOptions.relatednessParamsPopulationExcludeVariantsFile, true); - putNestedIfNotEmpty(beanParams, "relatednessParams.thresholdsFile",commandOptions.relatednessParamsThresholdsFile, true); putNestedIfNotNull(beanParams, "skipIndex",commandOptions.skipIndex, true); putNestedIfNotNull(beanParams, "overwrite",commandOptions.overwrite, true); + putNestedIfNotEmpty(beanParams, "resourcesDir",commandOptions.resourcesDir, true); putNestedIfNotEmpty(beanParams, "outdir",commandOptions.outdir, true); familyQcAnalysisParams = JacksonUtils.getDefaultObjectMapper().copy() @@ -948,11 +944,8 @@ private RestResponse runIndividualQc() throws Exception { putNestedIfNotNull(beanParams, "individuals",commandOptions.individuals, true); putNestedIfNotEmpty(beanParams, "individual",commandOptions.individual, true); putNestedIfNotEmpty(beanParams, "sample",commandOptions.sample, true); - putNestedIfNotEmpty(beanParams, "relatednessParams.populationFrequencyFile",commandOptions.relatednessParamsPopulationFrequencyFile, true); - putNestedIfNotEmpty(beanParams, "relatednessParams.populationExcludeVariantsFile",commandOptions.relatednessParamsPopulationExcludeVariantsFile, true); - putNestedIfNotEmpty(beanParams, "relatednessParams.thresholdsFile",commandOptions.relatednessParamsThresholdsFile, true); - putNestedIfNotEmpty(beanParams, "inferredSexParams.thresholdsFile",commandOptions.inferredSexParamsThresholdsFile, true); putNestedIfNotEmpty(beanParams, "inferredSexMethod",commandOptions.inferredSexMethod, true); + putNestedIfNotEmpty(beanParams, "resourcesDir",commandOptions.resourcesDir, true); putNestedIfNotNull(beanParams, "skip",commandOptions.skip, true); putNestedIfNotNull(beanParams, "skipIndex",commandOptions.skipIndex, true); putNestedIfNotNull(beanParams, "overwrite",commandOptions.overwrite, true); diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/options/AnalysisVariantCommandOptions.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/options/AnalysisVariantCommandOptions.java index 908b8665cf..dc08438c5c 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/options/AnalysisVariantCommandOptions.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/main/options/AnalysisVariantCommandOptions.java @@ -821,21 +821,15 @@ public class RunFamilyQcCommandOptions { @Parameter(names = {"--relatedness-maf"}, description = "Minor allele frequence (MAF) is used to filter variants before computing relatedness, e.g.: 1000G:CEU>0.35 or cohort:ALL>0.05", required = false, arity = 1) public String relatednessMaf; - @Parameter(names = {"--relatedness-params-population-frequency-file"}, description = "Population frequencies file ID for relatedness analysis", required = false, arity = 1) - public String relatednessParamsPopulationFrequencyFile; - - @Parameter(names = {"--relatedness-params-population-exclude-variants-file"}, description = "Population exclude variants file ID for relatedness analysis", required = false, arity = 1) - public String relatednessParamsPopulationExcludeVariantsFile; - - @Parameter(names = {"--relatedness-params-thresholds-file"}, description = "Threshold file ID for relatedness analysis", required = false, arity = 1) - public String relatednessParamsThresholdsFile; - @Parameter(names = {"--skip-index"}, description = "Do not save the computed quality control in catalog", required = false, arity = 1) public Boolean skipIndex; @Parameter(names = {"--overwrite"}, description = "Overwrite quality control in catalog", required = false, arity = 1) public Boolean overwrite; + @Parameter(names = {"--resources-dir"}, description = "Directory where the QC resource files are located", required = false, arity = 1) + public String resourcesDir; + @Parameter(names = {"--outdir"}, description = "Output dir for the job.", required = false, arity = 1) public String outdir; @@ -1303,21 +1297,12 @@ public class RunIndividualQcCommandOptions { @Parameter(names = {"--sample"}, description = "Sample ID (required when the individual has multiple samples)", required = false, arity = 1) public String sample; - @Parameter(names = {"--relatedness-params-population-frequency-file"}, description = "Population frequencies file ID for relatedness analysis", required = false, arity = 1) - public String relatednessParamsPopulationFrequencyFile; - - @Parameter(names = {"--relatedness-params-population-exclude-variants-file"}, description = "Population exclude variants file ID for relatedness analysis", required = false, arity = 1) - public String relatednessParamsPopulationExcludeVariantsFile; - - @Parameter(names = {"--relatedness-params-thresholds-file"}, description = "Threshold file ID for relatedness analysis", required = false, arity = 1) - public String relatednessParamsThresholdsFile; - - @Parameter(names = {"--inferred-sex-params-thresholds-file"}, description = "Karyotypic sex thresholds file ID for inferred sex analysis", required = false, arity = 1) - public String inferredSexParamsThresholdsFile; - @Parameter(names = {"--inferred-sex-method"}, description = "Inferred sex method. Valid values: CoverageRatio", required = false, arity = 1) public String inferredSexMethod = "CoverageRatio"; + @Parameter(names = {"--resources-dir"}, description = "Directory where the QC resource files are located", required = false, arity = 1) + public String resourcesDir; + @Parameter(names = {"--skip"}, description = "Individual QC analysis to skip. Valid values are: inferred-sex, mendelian-errors", required = false, arity = 1) public String skip; diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java b/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java index 4d7f5f7db3..46be78055d 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/api/FieldConstants.java @@ -183,6 +183,7 @@ public class FieldConstants { public static final String QC_OVERWRITE_DESCRIPTION = "Overwrite quality control in catalog"; public static final String QC_FILES_DESCRIPTION = "File IDs related to the quality control"; public static final String QC_COMMENTS_DESCRIPTION = "Comments related to the quality control"; + public static final String QC_RESOURCES_DIR_DESCRIPTION = "Directory where the QC resource files are located"; public static final String QC_RELATEDNESS_DESCRIPTION = "Parameters for relatedness analysis"; public static final String QC_RELATEDNESS_POP_FREQ_FILE_DESCRIPTION = "Population frequencies file ID for relatedness analysis"; public static final String QC_RELATEDNESS_POP_EXCLUDE_VAR_FILE_DESCRIPTION = "Population exclude variants file ID for" diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/FamilyQcAnalysisParams.java b/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/FamilyQcAnalysisParams.java index dd09807b7d..2ebc60abe1 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/FamilyQcAnalysisParams.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/FamilyQcAnalysisParams.java @@ -28,26 +28,35 @@ public class FamilyQcAnalysisParams extends ToolParams { @DataField(id = "families", description = FieldConstants.FAMILY_QC_FAMILY_ID_LIST_DESCRIPTION) private List families; + /** + * @deprecated to be removed when latest changes take place + */ @Deprecated @DataField(id = "family", description = FieldConstants.FAMILY_QC_FAMILY_ID_DESCRIPTION, deprecated = true) private String family; + /** + * @deprecated to be removed when latest changes take place + */ @Deprecated private String relatednessMethod; + /** + * @deprecated to be removed when latest changes take place + */ @Deprecated @DataField(id = "relatednessMaf", description = FieldConstants.FAMILY_QC_RELATEDNESS_MAF_DESCRIPTION, deprecated = true) private String relatednessMaf; - @DataField(id = "relatednessParams", description = FieldConstants.QC_RELATEDNESS_DESCRIPTION) - private QcRelatednessAnalysisParams relatednessParams; - @DataField(id = "skipIndex", description = FieldConstants.QC_SKIP_INDEX_DESCRIPTION) private Boolean skipIndex; @DataField(id = "overwrite", description = FieldConstants.QC_OVERWRITE_DESCRIPTION) private Boolean overwrite; + @DataField(id = "resourcesDir", description = FieldConstants.QC_RESOURCES_DIR_DESCRIPTION) + private String resourcesDir; + @DataField(id = "outdir", description = FieldConstants.JOB_OUT_DIR_DESCRIPTION) private String outdir; @@ -55,14 +64,14 @@ public FamilyQcAnalysisParams() { } public FamilyQcAnalysisParams(List families, String family, String relatednessMethod, String relatednessMaf, - QcRelatednessAnalysisParams relatednessParams, Boolean skipIndex, Boolean overwrite, String outdir) { + Boolean skipIndex, Boolean overwrite, String resourcesDir, String outdir) { this.families = families; this.family = family; this.relatednessMethod = relatednessMethod; this.relatednessMaf = relatednessMaf; - this.relatednessParams = relatednessParams; this.skipIndex = skipIndex; this.overwrite = overwrite; + this.resourcesDir = resourcesDir; this.outdir = outdir; } @@ -73,9 +82,9 @@ public String toString() { sb.append(", family='").append(family).append('\''); sb.append(", relatednessMethod='").append(relatednessMethod).append('\''); sb.append(", relatednessMaf='").append(relatednessMaf).append('\''); - sb.append(", relatednessParams=").append(relatednessParams); sb.append(", skipIndex=").append(skipIndex); sb.append(", overwrite=").append(overwrite); + sb.append(", resourcesDir='").append(resourcesDir).append('\''); sb.append(", outdir='").append(outdir).append('\''); sb.append('}'); return sb.toString(); @@ -117,15 +126,6 @@ public FamilyQcAnalysisParams setRelatednessMaf(String relatednessMaf) { return this; } - public QcRelatednessAnalysisParams getRelatednessParams() { - return relatednessParams; - } - - public FamilyQcAnalysisParams setRelatednessParams(QcRelatednessAnalysisParams relatednessParams) { - this.relatednessParams = relatednessParams; - return this; - } - public Boolean getSkipIndex() { return skipIndex; } @@ -144,6 +144,15 @@ public FamilyQcAnalysisParams setOverwrite(Boolean overwrite) { return this; } + public String getResourcesDir() { + return resourcesDir; + } + + public FamilyQcAnalysisParams setResourcesDir(String resourcesDir) { + this.resourcesDir = resourcesDir; + return this; + } + public String getOutdir() { return outdir; } diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/IndividualQcAnalysisParams.java b/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/IndividualQcAnalysisParams.java index 467a99ff79..774cb57c2a 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/IndividualQcAnalysisParams.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/IndividualQcAnalysisParams.java @@ -35,17 +35,17 @@ public class IndividualQcAnalysisParams extends ToolParams { @DataField(id = "sample", description = FieldConstants.INDIVIDUAL_QC_SAMPLE_ID_DESCRIPTION, deprecated = true) private String sample; - @DataField(id = "relatednessParams", description = FieldConstants.QC_RELATEDNESS_DESCRIPTION) - private QcRelatednessAnalysisParams relatednessParams; - - @DataField(id = "inferredSexParams", description = FieldConstants.QC_INFERRED_SEX_DESCRIPTION) - private QcInferredSexAnalysisParams inferredSexParams; - + /** + * @deprecated to be removed after latest changes take place + */ @Deprecated @DataField(id = "inferredSexMethod", description = FieldConstants.INFERRED_SEX_METHOD_DESCRIPTION, defaultValue = IndividualQcAnalysisExecutor.COVERAGE_RATIO_INFERRED_SEX_METHOD, deprecated = true) private String inferredSexMethod; + @DataField(id = "resourcesDir", description = FieldConstants.QC_RESOURCES_DIR_DESCRIPTION) + private String resourcesDir; + @DataField(id = "skip", description = FieldConstants.INDIVIDUAL_QC_SKIP_DESCRIPTION) private List skip; @@ -61,15 +61,13 @@ public class IndividualQcAnalysisParams extends ToolParams { public IndividualQcAnalysisParams() { } - public IndividualQcAnalysisParams(List individuals, String individual, String sample, - QcRelatednessAnalysisParams relatednessParams, QcInferredSexAnalysisParams inferredSexParams, - String inferredSexMethod, List skip, Boolean skipIndex, Boolean overwrite, String outdir) { + public IndividualQcAnalysisParams(List individuals, String individual, String sample, String inferredSexMethod, + String resourcesDir, List skip, Boolean skipIndex, Boolean overwrite, String outdir) { this.individuals = individuals; this.individual = individual; this.sample = sample; - this.relatednessParams = relatednessParams; - this.inferredSexParams = inferredSexParams; this.inferredSexMethod = inferredSexMethod; + this.resourcesDir = resourcesDir; this.skip = skip; this.skipIndex = skipIndex; this.overwrite = overwrite; @@ -82,9 +80,8 @@ public String toString() { sb.append("individuals=").append(individuals); sb.append(", individual='").append(individual).append('\''); sb.append(", sample='").append(sample).append('\''); - sb.append(", relatednessParams=").append(relatednessParams); - sb.append(", inferredSexParams=").append(inferredSexParams); sb.append(", inferredSexMethod='").append(inferredSexMethod).append('\''); + sb.append(", resourcesDir='").append(resourcesDir).append('\''); sb.append(", skip=").append(skip); sb.append(", skipIndex=").append(skipIndex); sb.append(", overwrite=").append(overwrite); @@ -120,30 +117,21 @@ public IndividualQcAnalysisParams setSample(String sample) { return this; } - public QcRelatednessAnalysisParams getRelatednessParams() { - return relatednessParams; - } - - public IndividualQcAnalysisParams setRelatednessParams(QcRelatednessAnalysisParams relatednessParams) { - this.relatednessParams = relatednessParams; - return this; - } - - public QcInferredSexAnalysisParams getInferredSexParams() { - return inferredSexParams; + public String getInferredSexMethod() { + return inferredSexMethod; } - public IndividualQcAnalysisParams setInferredSexParams(QcInferredSexAnalysisParams inferredSexParams) { - this.inferredSexParams = inferredSexParams; + public IndividualQcAnalysisParams setInferredSexMethod(String inferredSexMethod) { + this.inferredSexMethod = inferredSexMethod; return this; } - public String getInferredSexMethod() { - return inferredSexMethod; + public String getResourcesDir() { + return resourcesDir; } - public IndividualQcAnalysisParams setInferredSexMethod(String inferredSexMethod) { - this.inferredSexMethod = inferredSexMethod; + public IndividualQcAnalysisParams setResourcesDir(String resourcesDir) { + this.resourcesDir = resourcesDir; return this; } diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcInferredSexAnalysisParams.java b/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcInferredSexAnalysisParams.java deleted file mode 100644 index 9c8d47c7df..0000000000 --- a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcInferredSexAnalysisParams.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2015-2020 OpenCB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.opencb.opencga.core.models.variant; - -import org.opencb.commons.annotations.DataField; -import org.opencb.opencga.core.api.FieldConstants; - -public class QcInferredSexAnalysisParams { - - @DataField(id = "thresholdsFile", description = FieldConstants.QC_INFERRED_SEX_THRESHOLDS_FILE_DESCRIPTION) - private String thresholdsFile; - - public QcInferredSexAnalysisParams() { - } - - public QcInferredSexAnalysisParams(String thresholdsFile) { - this.thresholdsFile = thresholdsFile; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("QcInferredSexAnalysisParams{"); - sb.append(", thresholdsFile='").append(thresholdsFile).append('\''); - sb.append('}'); - return sb.toString(); - } - - public String getThresholdsFile() { - return thresholdsFile; - } - - public QcInferredSexAnalysisParams setThresholdsFile(String thresholdsFile) { - this.thresholdsFile = thresholdsFile; - return this; - } -} diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcRelatednessAnalysisParams.java b/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcRelatednessAnalysisParams.java deleted file mode 100644 index e0a75136c5..0000000000 --- a/opencga-core/src/main/java/org/opencb/opencga/core/models/variant/QcRelatednessAnalysisParams.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2015-2020 OpenCB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.opencb.opencga.core.models.variant; - -import org.opencb.commons.annotations.DataField; -import org.opencb.opencga.core.api.FieldConstants; - -public class QcRelatednessAnalysisParams { - - @DataField(id = "populationFrequencyFile", description = FieldConstants.QC_RELATEDNESS_POP_FREQ_FILE_DESCRIPTION) - private String populationFrequencyFile; - - @DataField(id = "populationExcludeVariantsFile", description = FieldConstants.QC_RELATEDNESS_POP_EXCLUDE_VAR_FILE_DESCRIPTION) - private String populationExcludeVariantsFile; - - @DataField(id = "thresholdsFile", description = FieldConstants.QC_RELATEDNESS_THRESHOLDS_FILE_DESCRIPTION) - private String thresholdsFile; - - public QcRelatednessAnalysisParams() { - } - - public QcRelatednessAnalysisParams(String populationFrequencyFile, String populationExcludeVariantsFile, String thresholdsFile) { - this.populationFrequencyFile = populationFrequencyFile; - this.populationExcludeVariantsFile = populationExcludeVariantsFile; - this.thresholdsFile = thresholdsFile; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("QcRelatednessAnalysisParams{"); - sb.append("populationFrequencyFile='").append(populationFrequencyFile).append('\''); - sb.append(", populationExcludeVariantsFile='").append(populationExcludeVariantsFile).append('\''); - sb.append(", thresholdsFile='").append(thresholdsFile).append('\''); - sb.append('}'); - return sb.toString(); - } - - public String getPopulationFrequencyFile() { - return populationFrequencyFile; - } - - public QcRelatednessAnalysisParams setPopulationFrequencyFile(String populationFrequencyFile) { - this.populationFrequencyFile = populationFrequencyFile; - return this; - } - - public String getPopulationExcludeVariantsFile() { - return populationExcludeVariantsFile; - } - - public QcRelatednessAnalysisParams setPopulationExcludeVariantsFile(String populationExcludeVariantsFile) { - this.populationExcludeVariantsFile = populationExcludeVariantsFile; - return this; - } - - public String getThresholdsFile() { - return thresholdsFile; - } - - public QcRelatednessAnalysisParams setThresholdsFile(String thresholdsFile) { - this.thresholdsFile = thresholdsFile; - return this; - } -}