Skip to content

Commit

Permalink
analysis: remove HS metrics from alignment QC analysis, and generate …
Browse files Browse the repository at this point in the history
…CLI, #TASK-2303, #TASK-2304
  • Loading branch information
jtarraga committed Nov 9, 2022
1 parent ad9f2b8 commit cd4c96c
Show file tree
Hide file tree
Showing 80 changed files with 223 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class AlignmentQcAnalysis extends OpenCgaToolScopeStudy {
private boolean runStats = true;
private boolean runFlagStats = true;
private boolean runFastqc = true;
private boolean runHsmetrics = true;

@Override
protected void check() throws Exception {
Expand Down Expand Up @@ -99,33 +98,10 @@ protected void check() throws Exception {
(!analysisParams.isOverwrite() && alignmentQc != null && alignmentQc.getFastQcMetrics() != null)) {
runFastqc = false;
}
if (skipValues.contains(AlignmentQcParams.HS_METRICS_SKIP_VALUE)
||
(!analysisParams.isOverwrite() && alignmentQc != null && alignmentQc.getHsMetrics() != null)
||
StringUtils.isEmpty(analysisParams.getBedFile())
||
StringUtils.isEmpty(analysisParams.getDictFile())) {
runHsmetrics = false;
}
}
} catch (CatalogException e) {
throw new ToolException("Error accessing to the BAM file '" + analysisParams.getBamFile() + "'", e);
}

if (runHsmetrics) {
try {
AnalysisUtils.getCatalogFile(analysisParams.getBedFile(), study, catalogManager.getFileManager(), token);
} catch (CatalogException e) {
throw new ToolException("Error accessing to the BED file '" + analysisParams.getBedFile() + "'", e);
}

try {
AnalysisUtils.getCatalogFile(analysisParams.getDictFile(), study, catalogManager.getFileManager(), token);
} catch (CatalogException e) {
throw new ToolException("Error accessing to the dictionary file '" + analysisParams.getDictFile() + "'", e);
}
}
}

@Override
Expand All @@ -136,7 +112,6 @@ protected void run() throws ToolException {
String statsJobId = null;
String flagStatsJobId = null;
String fastQcMetricsJobId = null;
String hsMetricsJobId = null;

try {
if (runFlagStats) {
Expand Down Expand Up @@ -189,29 +164,10 @@ protected void run() throws ToolException {
addWarning("Error launching job for Alignment FastQC Metrics Analysis: " + e.getMessage());
}

try {
if (runHsmetrics) {
// HS metrics
params = new AlignmentHsMetricsParams(analysisParams.getBamFile(), analysisParams.getBedFile(),
analysisParams.getDictFile(), null).toParams(new ObjectMap(ParamConstants.STUDY_PARAM, study));

OpenCGAResult<Job> hsMetricsJobResult = catalogManager.getJobManager()
.submit(study, AlignmentHsMetricsAnalysis.ID, Enums.Priority.MEDIUM, params, null,
"Job generated by " + getId() + " - " + getJobId(), Collections.emptyList(), Collections.emptyList(),
token);
hsMetricsJobId = hsMetricsJobResult.first().getId();
addEvent(Event.Type.INFO, "Submit job " + hsMetricsJobId + " to compute HS metrics (" + AlignmentHsMetricsAnalysis.ID
+ ")");
}
} catch (CatalogException e) {
addWarning("Error launching job for Alignment HS Metrics Analysis: " + e.getMessage());
}

// Wait for those jobs before saving QC
SamtoolsFlagstats samtoolsFlagstats = null;
SamtoolsStats samtoolsStats = null;
FastQcMetrics fastQcMetrics = null;
HsMetrics hsMetrics = null;

if (flagStatsJobId != null) {
try {
Expand Down Expand Up @@ -249,17 +205,6 @@ protected void run() throws ToolException {
addWarning("Error waiting for job '" + fastQcMetricsJobId + "' (Alignment FastQC Metrics Analysis): " + e.getMessage());
}
}
if (hsMetricsJobId != null) {
try {
if (waitFor(hsMetricsJobId)) {
Job job = getJob(hsMetricsJobId);
logger.info("Alignment HS Metrics Analysis, job.outDir = " + job.getOutDir());
hsMetrics = AlignmentHsMetricsAnalysis.parseResults(Paths.get(job.getOutDir().getUri().getPath()));
}
} catch (Exception e) {
addWarning("Error waiting for job '" + hsMetricsJobId + "' (Alignment FastQC Metrics Analysis): " + e.getMessage());
}
}

// Update quality control for the catalog file
catalogBamFile = AnalysisUtils.getCatalogFile(analysisParams.getBamFile(), study, catalogManager.getFileManager(), token);
Expand All @@ -284,10 +229,6 @@ protected void run() throws ToolException {
qc.getAlignment().setFastQcMetrics(fastQcMetrics);
saveQc = true;
}
if (hsMetrics != null) {
qc.getAlignment().setHsMetrics(hsMetrics);
saveQc = true;
}

if (saveQc) {
catalogManager.getFileManager().update(getStudy(), catalogBamFile.getId(), new FileUpdateParams().setQualityControl(qc),
Expand Down Expand Up @@ -324,7 +265,7 @@ private boolean waitFor(String jobId) throws ToolException {
return status.equals(Enums.ExecutionStatus.DONE) ? true : false;
}

private Job getJob(String jobId) throws ToolException {
private Job getJob(String jobId) {
Job job = null;
try {
Query query = new Query("id", jobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ private void qcRun() throws ToolException {

ObjectMap params = new AlignmentQcParams(
cliOptions.bamFile,
cliOptions.bedFile,
cliOptions.dictFile,
cliOptions.skip,
cliOptions.overwrite,
cliOptions.outdir
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022-09-29 OpenCB
* Copyright 2015-2022-11-09 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022-09-29 OpenCB
* Copyright 2015-2022-11-09 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,6 @@ private RestResponse<Job> runQc() throws Exception {
} else {
ObjectMap beanParams = new ObjectMap();
putNestedIfNotEmpty(beanParams, "bamFile",commandOptions.bamFile, true);
putNestedIfNotEmpty(beanParams, "bedFile",commandOptions.bedFile, true);
putNestedIfNotEmpty(beanParams, "dictFile",commandOptions.dictFile, true);
putNestedIfNotEmpty(beanParams, "skip",commandOptions.skip, true);
putNestedIfNotNull(beanParams, "overwrite",commandOptions.overwrite, true);
putNestedIfNotEmpty(beanParams, "outdir",commandOptions.outdir, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public class RunPicardCommandOptions {

}

@Parameters(commandNames = {"qc-run"}, commandDescription ="Compute quality control (QC) metrics for a given alignment file (including samtools stats, samtools flag stats, FastQC and HS metrics)")
@Parameters(commandNames = {"qc-run"}, commandDescription ="Compute quality control (QC) metrics for a given alignment file: samtools stats, samtools flag stats and FastQC metrics.")
public class RunQcCommandOptions {

@ParametersDelegate
Expand All @@ -448,22 +448,16 @@ public class RunQcCommandOptions {
@Parameter(names = {"--job-tags"}, description = "Job tags", required = false, arity = 1)
public String jobTags;

@Parameter(names = {"--bam-file"}, description = "The body web service bamFile parameter", required = false, arity = 1)
@Parameter(names = {"--bam-file"}, description = "ID for the BAM file to process.", required = false, arity = 1)
public String bamFile;

@Parameter(names = {"--bed-file"}, description = "The body web service bedFile parameter", required = false, arity = 1)
public String bedFile;

@Parameter(names = {"--dict-file"}, description = "The body web service dictFile parameter", required = false, arity = 1)
public String dictFile;

@Parameter(names = {"--skip"}, description = "The body web service skip parameter", required = false, arity = 1)
@Parameter(names = {"--skip"}, description = "To skip any alignment QC metrics use the following keywords (separated by commas): stats, flagstats, fastqc", required = false, arity = 1)
public String skip;

@Parameter(names = {"--overwrite"}, description = "The body web service overwrite parameter", required = false, help = true, arity = 0)
@Parameter(names = {"--overwrite"}, description = "To overwrite the QC metrics already computed.", required = false, help = true, arity = 0)
public boolean overwrite = false;

@Parameter(names = {"--outdir"}, description = "The body web service outdir parameter", required = false, arity = 1)
@Parameter(names = {"--outdir"}, description = "Output dir for the job.", required = false, arity = 1)
public String outdir;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ public class QueryVariantCommandOptions {
@Parameter(names = {"--file-data"}, description = "Filter by file data (i.e. FILTER, QUAL and INFO columns from VCF file). [{file}:]{key}{op}{value}[,;]* . If no file is specified, will use all files from 'file' filter. e.g. AN>200 or file_1.vcf:AN>200;file_2.vcf:AN<10 . Many fields can be combined. e.g. file_1.vcf:AN>200;DB=true;file_2.vcf:AN<10,FILTER=PASS,LowDP", required = false, arity = 1)
public String fileData;

@Parameter(names = {"--sample"}, description = "Filter variants by sample genotype. This will automatically set 'includeSample' parameter when not provided. This filter accepts multiple 3 forms: 1) List of samples: Samples that contain the main variant. Accepts AND (;) and OR (,) operators. e.g. HG0097,HG0098 . 2) List of samples with genotypes: {sample}:{gt1},{gt2}. Accepts AND (;) and OR (,) operators. e.g. HG0097:0/0;HG0098:0/1,1/1 . Unphased genotypes (e.g. 0/1, 1/1) will also include phased genotypes (e.g. 0|1, 1|0, 1|1), but not vice versa. When filtering by multi-allelic genotypes, any secondary allele will match, regardless of its position e.g. 1/2 will match with genotypes 1/2, 1/3, 1/4, .... Genotype aliases accepted: HOM_REF, HOM_ALT, HET, HET_REF, HET_ALT, HET_MISS and MISS e.g. HG0097:HOM_REF;HG0098:HET_REF,HOM_ALT . 3) Sample with segregation mode: {sample}:{segregation}. Only one sample accepted.Accepted segregation modes: [ autosomalDominant, autosomalRecessive, XLinkedDominant, XLinkedRecessive, YLinked, mitochondrial, deNovo, mendelianError, compoundHeterozygous ]. Value is case insensitive. e.g. HG0097:DeNovo Sample must have parents defined and indexed. ", required = false, arity = 1)
@Parameter(names = {"--sample"}, description = "Filter variants by sample genotype. This will automatically set 'includeSample' parameter when not provided. This filter accepts multiple 3 forms: 1) List of samples: Samples that contain the main variant. Accepts AND (;) and OR (,) operators. e.g. HG0097,HG0098 . 2) List of samples with genotypes: {sample}:{gt1},{gt2}. Accepts AND (;) and OR (,) operators. e.g. HG0097:0/0;HG0098:0/1,1/1 . Unphased genotypes (e.g. 0/1, 1/1) will also include phased genotypes (e.g. 0|1, 1|0, 1|1), but not vice versa. When filtering by multi-allelic genotypes, any secondary allele will match, regardless of its position e.g. 1/2 will match with genotypes 1/2, 1/3, 1/4, .... Genotype aliases accepted: HOM_REF, HOM_ALT, HET, HET_REF, HET_ALT, HET_MISS and MISS e.g. HG0097:HOM_REF;HG0098:HET_REF,HOM_ALT . 3) Sample with segregation mode: {sample}:{segregation}. Only one sample accepted.Accepted segregation modes: [ autosomalDominant, autosomalRecessive, XLinkedDominant, XLinkedRecessive, YLinked, mitochondrial, deNovo, deNovoStrict, mendelianError, compoundHeterozygous ]. Value is case insensitive. e.g. HG0097:DeNovo Sample must have parents defined and indexed. ", required = false, arity = 1)
public String sample;

@Parameter(names = {"--sample-data"}, description = "Filter by any SampleData field from samples. [{sample}:]{key}{op}{value}[,;]* . If no sample is specified, will use all samples from 'sample' or 'genotype' filter. e.g. DP>200 or HG0097:DP>200,HG0098:DP<10 . Many FORMAT fields can be combined. e.g. HG0097:DP>200;GT=1/1,0/1,HG0098:DP<10", required = false, arity = 1)
Expand Down Expand Up @@ -1655,7 +1655,7 @@ public class QueryVariantCommandOptions {
@Parameter(names = {"--family-disorder"}, description = "Specify the disorder to use for the family segregation", required = false, arity = 1)
public String familyDisorder;

@Parameter(names = {"--family-segregation"}, description = "Filter by segregation mode from a given family. Accepted values: [ autosomalDominant, autosomalRecessive, XLinkedDominant, XLinkedRecessive, YLinked, mitochondrial, deNovo, mendelianError, compoundHeterozygous ]", required = false, arity = 1)
@Parameter(names = {"--family-segregation"}, description = "Filter by segregation mode from a given family. Accepted values: [ autosomalDominant, autosomalRecessive, XLinkedDominant, XLinkedRecessive, YLinked, mitochondrial, deNovo, deNovoStrict, mendelianError, compoundHeterozygous ]", required = false, arity = 1)
public String familySegregation;

@Parameter(names = {"--family-members"}, description = "Sub set of the members of a given family", required = false, arity = 1)
Expand Down
Loading

0 comments on commit cd4c96c

Please sign in to comment.