Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

313 Cleanup Extract Cohort params #7293

Merged
merged 26 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/variantstore/wdl/GvsExtractCallset.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ workflow GvsExtractCallset {

Boolean do_not_filter_override = false
String? filter_set_name
Boolean? vqslod_filter_by_site
String fq_filter_set_info_table = "~{data_project}.~{default_dataset}.filter_set_info"
String fq_filter_set_site_table = "~{data_project}.~{default_dataset}.filter_set_sites"
String fq_filter_set_tranches_table = "~{data_project}.~{default_dataset}.filter_set_tranches"
Expand Down Expand Up @@ -77,6 +78,7 @@ workflow GvsExtractCallset {
fq_filter_set_site_table = fq_filter_set_site_table,
fq_filter_set_tranches_table = fq_filter_set_tranches_table,
filter_set_name = filter_set_name,
vqslod_filter_by_site = vqslod_filter_by_site,
snps_truth_sensitivity_filter_level = snps_truth_sensitivity_filter_level_override,
indels_truth_sensitivity_filter_level = indels_truth_sensitivity_filter_level_override,
excluded_intervals = excluded_intervals,
Expand Down Expand Up @@ -117,6 +119,7 @@ task ExtractTask {
String fq_filter_set_site_table
String fq_filter_set_tranches_table
String? filter_set_name
Boolean? vqslod_filter_by_site
Float? snps_truth_sensitivity_filter_level
Float? indels_truth_sensitivity_filter_level

Expand Down Expand Up @@ -151,12 +154,13 @@ task ExtractTask {
df -h

if [ ~{do_not_filter_override} = 'true' ]; then
FILTERING_ARGS='--vqslod-filter-genotypes false'
FILTERING_ARGS=''
else
FILTERING_ARGS='--filter-set-info-table ~{fq_filter_set_info_table}
--filter-set-site-table ~{fq_filter_set_site_table}
--tranches-table ~{fq_filter_set_tranches_table}
--filter-set-name ~{filter_set_name}
--vqslod-filter-by-site ~{vqslod_filter_by_site}
~{"--snps-truth-sensitivity-filter-level " + snps_truth_sensitivity_filter_level}
~{"--indels-truth-sensitivity-filter-level " + indels_truth_sensitivity_filter_level}'
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ public abstract class ExtractTool extends GATKTool {
optional = true)
protected boolean printDebugInformation = false;

@Argument(
fullName = "vqslog-SNP-threshold",
doc = "The minimum value required for a SNP to pass.",
optional = true)
protected double vqsLodSNPThreshold = 0;

@Argument(
fullName = "vqslog-INDEL-threshold",
doc = "The minimum value required for an INDEL to pass.",
optional = true)
protected double vqsLodINDELThreshold = 0;

@Argument(
fullName = "local-sort-max-records-in-ram",
doc = "When doing local sort, store at most this many records in memory at once",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public class ExtractCohort extends ExtractTool {
private static final Logger logger = LogManager.getLogger(ExtractCohort.class);
private ExtractCohortEngine engine;

@Argument(
public enum VQSLODFilteringType { GENOTYPE, SITES, NONE }

@Argument(
fullName = "filter-set-info-table",
doc = "Fully qualified name of the filtering set info table to use for cohort extraction",
optional = true
Expand Down Expand Up @@ -86,29 +88,27 @@ public class ExtractCohort extends ExtractTool {
)
private boolean emitPLs = false;

@Argument(
fullName = "disable-gnarly",
doc = "Disable use of GnarlyGenotyper",
optional = true
)
private boolean disableGnarlyGenotyper = true;
// what if this was a flag input only?

@Argument(
fullName = "vqslod-filter-genotypes",
doc = "Should VQSLOD filtering be applied at the genotype level",
fullName = "vqslod-filter-by-site",
doc = "If VQSLOD filtering is applied, it should be at a site level. Default is false",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice docs

optional = true
)
private boolean performGenotypeVQSLODFiltering = true;
private boolean performSiteSpecificVQSLODFiltering = false;
private VQSLODFilteringType vqslodfilteringType = VQSLODFilteringType.NONE;

@Argument(
fullName ="snps-truth-sensitivity-filter-level",
mutex = {"snps-lod-score-cutoff"},
doc = "The truth sensitivity level at which to start filtering SNPs",
optional = true
)
private Double truthSensitivitySNPThreshold = null;

@Argument(
fullName = "indels-truth-sensitivity-filter-level",
mutex = {"indels-lod-score-cutoff"},
doc = "The truth sensitivity level at which to start filtering INDELs",
optional = true
)
Expand All @@ -117,13 +117,15 @@ public class ExtractCohort extends ExtractTool {
@Advanced
@Argument(
fullName = "snps-lod-score-cutoff",
mutex = {"snps-truth-sensitivity-filter-level"},
doc = "The VQSLOD score below which to start filtering SNPs",
optional = true)
private Double vqsLodSNPThreshold = null;

@Advanced
@Argument(
fullName = "indels-lod-score-cutoff",
mutex = {"indels-truth-sensitivity-filter-level"},
doc = "The VQSLOD score below which to start filtering INDELs",
optional = true)
private Double vqsLodINDELThreshold = null;
Expand All @@ -143,30 +145,41 @@ public class ExtractCohort extends ExtractTool {
protected void onStartup() {
super.onStartup();

if ( (filterSetInfoTableName != null || filterSetSiteTableName != null) && (filterSetName == null || filterSetName.equals(""))) {
throw new UserException("--filter-set-name must be specified if any filtering related operations are requested");
Set<VCFHeaderLine> extraHeaderLines = new HashSet<>();

if (filterSetInfoTableName != null) { // filter using vqslod-- default to GENOTYPE unless SITES specifically selected
vqslodfilteringType = performSiteSpecificVQSLODFiltering ? VQSLODFilteringType.SITES : VQSLODFilteringType.GENOTYPE;
}

Set<VCFHeaderLine> extraHeaderLines = new HashSet<>();
if (filterSetInfoTableName != null) {
FilterSensitivityTools.validateFilteringCutoffs(truthSensitivitySNPThreshold, truthSensitivityINDELThreshold, vqsLodSNPThreshold, vqsLodINDELThreshold, tranchesTableName);
Map<String, Map<Double, Double>> trancheMaps = FilterSensitivityTools.getTrancheMaps(filterSetName, tranchesTableName, projectID);

if (vqsLodSNPThreshold != null) { // we already have vqslod thresholds directly
extraHeaderLines.add(FilterSensitivityTools.getVqsLodHeader(vqsLodSNPThreshold, GATKVCFConstants.SNP));
extraHeaderLines.add(FilterSensitivityTools.getVqsLodHeader(vqsLodINDELThreshold, GATKVCFConstants.INDEL));
} else { // using sensitivity threshold inputs; need to convert these to vqslod thresholds
vqsLodSNPThreshold = FilterSensitivityTools.getVqslodThreshold(trancheMaps.get(GATKVCFConstants.SNP), truthSensitivitySNPThreshold, GATKVCFConstants.SNP);
vqsLodINDELThreshold = FilterSensitivityTools.getVqslodThreshold(trancheMaps.get(GATKVCFConstants.INDEL), truthSensitivityINDELThreshold, GATKVCFConstants.INDEL);
// set headers
extraHeaderLines.add(FilterSensitivityTools.getTruthSensitivityHeader(truthSensitivitySNPThreshold, vqsLodSNPThreshold, GATKVCFConstants.SNP));
extraHeaderLines.add(FilterSensitivityTools.getTruthSensitivityHeader(truthSensitivityINDELThreshold, vqsLodINDELThreshold, GATKVCFConstants.INDEL));
}
// filter at a site level (but not necesarily use vqslod)
if ((filterSetSiteTableName != null && filterSetName == null) || (filterSetSiteTableName == null && filterSetName != null)) {
throw new UserException("--filter-set-name and --filter-set-site-table are both necessary for any filtering related operations");
}
if (!vqslodfilteringType.equals(VQSLODFilteringType.NONE)) {
if (filterSetInfoTableName == null || filterSetSiteTableName == null || filterSetName == null) {
throw new UserException(" --filter-set-site-table, --filter-set-name and --filter-set-site-table are all necessary for any vqslod filtering operations");
}
}

if (!vqslodfilteringType.equals(VQSLODFilteringType.NONE)) {
FilterSensitivityTools.validateFilteringCutoffs(truthSensitivitySNPThreshold, truthSensitivityINDELThreshold, vqsLodSNPThreshold, vqsLodINDELThreshold, tranchesTableName);
Map<String, Map<Double, Double>> trancheMaps = FilterSensitivityTools.getTrancheMaps(filterSetName, tranchesTableName, projectID);

if (vqsLodSNPThreshold != null) { // we already have vqslod thresholds directly
extraHeaderLines.add(FilterSensitivityTools.getVqsLodHeader(vqsLodSNPThreshold, GATKVCFConstants.SNP));
extraHeaderLines.add(FilterSensitivityTools.getVqsLodHeader(vqsLodINDELThreshold, GATKVCFConstants.INDEL));
} else { // using sensitivity threshold inputs; need to convert these to vqslod thresholds
vqsLodSNPThreshold = FilterSensitivityTools.getVqslodThreshold(trancheMaps.get(GATKVCFConstants.SNP), truthSensitivitySNPThreshold, GATKVCFConstants.SNP);
vqsLodINDELThreshold = FilterSensitivityTools.getVqslodThreshold(trancheMaps.get(GATKVCFConstants.INDEL), truthSensitivityINDELThreshold, GATKVCFConstants.INDEL);
// set headers
extraHeaderLines.add(FilterSensitivityTools.getTruthSensitivityHeader(truthSensitivitySNPThreshold, vqsLodSNPThreshold, GATKVCFConstants.SNP));
extraHeaderLines.add(FilterSensitivityTools.getTruthSensitivityHeader(truthSensitivityINDELThreshold, vqsLodINDELThreshold, GATKVCFConstants.INDEL));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not for this PR, but I'm wondering if we should make FilterSensititvityTools an class where we create instances. We would pass it all the params on construction, it would do the validation. It could also add the headers and then we just ask it for the 2 thresholds so all the logic is encapsulated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true---it does seem like a lot of params to be passing around

}

extraHeaderLines.add(GATKVCFHeaderLines.getFilterLine(GATKVCFConstants.LOW_QUAL_FILTER_NAME));

if (performGenotypeVQSLODFiltering) {
if (vqslodfilteringType.equals(VQSLODFilteringType.GENOTYPE)) {
extraHeaderLines.add(new VCFFormatHeaderLine("FT", 1, VCFHeaderLineType.String, "Genotype Filter Field"));
}

Expand Down Expand Up @@ -223,8 +236,7 @@ protected void onStartup() {
progressMeter,
filterSetName,
emitPLs,
disableGnarlyGenotyper,
performGenotypeVQSLODFiltering,
vqslodfilteringType,
excludeFilteredSites);

vcfWriter.writeHeader(header);
Expand All @@ -236,7 +248,7 @@ public void traverse() {
progressMeter.setRecordsBetweenTimeChecks(100L);

if ( filterSetInfoTableName == null || filterSetInfoTableName.equals("") ) {
logger.warn("--variant-filter-table is not specified, no filtering of cohort! ");
logger.warn("--filter-set-info-table is not specified, no filtering of cohort! ");
}

engine.traverse();
Expand Down
Loading