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

feat: add snv and sv variant filteration for loqusdb and swegen #1029

Merged
merged 4 commits into from Nov 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions BALSAMIC/commands/config/case.py
Expand Up @@ -243,23 +243,22 @@ def case_config(
with open(reference_config, "r") as f:
reference_dict = json.load(f)["reference"]

if not panel_bed:
variants_observations = {
"clinical_snv_observations": clinical_snv_observations,
"clinical_sv_observations": clinical_sv_observations,
"cancer_all_snv_observations": cancer_all_snv_observations,
"cancer_somatic_snv_observations": cancer_somatic_snv_observations,
"cancer_somatic_sv_observations": cancer_somatic_sv_observations,
"swegen_snv_frequency": swegen_snv,
"swegen_sv_frequency": swegen_sv,
variants_observations = {
"clinical_snv_observations": clinical_snv_observations,
"clinical_sv_observations": clinical_sv_observations,
"cancer_all_snv_observations": cancer_all_snv_observations,
"cancer_somatic_snv_observations": cancer_somatic_snv_observations,
"cancer_somatic_sv_observations": cancer_somatic_sv_observations,
"swegen_snv_frequency": swegen_snv,
"swegen_sv_frequency": swegen_sv,
}
reference_dict.update(
{
observations: path
for observations, path in variants_observations.items()
if path is not None
}
reference_dict.update(
{
observations: path
for observations, path in variants_observations.items()
if path is not None
}
)
)

config_collection_dict = BalsamicConfigModel(
QC={
Expand Down
38 changes: 38 additions & 0 deletions BALSAMIC/constants/variant_filters.py
Expand Up @@ -26,6 +26,16 @@
"filter_name": "balsamic_high_pop_freq",
"field": "INFO",
},
"swegen_snv_freq": {
"tag_value": 0.01,
"filter_name": "SWEGENAF",
"field": "INFO",
},
"loqusdb_clinical_snv_freq": {
"tag_value": 0.01,
"filter_name": "Frq",
"field": "INFO",
},
"varcaller_name": "VarDict",
"filter_type": "general",
"analysis_type": "tumor_only",
Expand Down Expand Up @@ -67,8 +77,36 @@
"filter_name": "balsamic_high_strand_oddsratio",
"field": "INFO",
},
"swegen_snv_freq": {
"tag_value": 0.01,
"filter_name": "SWEGENAF",
"field": "INFO",
},
"loqusdb_clinical_snv_freq": {
"tag_value": 0.01,
"filter_name": "Frq",
"field": "INFO",
},
"varcaller_name": "sentieon",
"filter_type": "general",
"analysis_type": "tumor_only",
"description": "General purpose filters used for filtering tnscope and tnhaplotyper",
}

# Configuration for SVDB settings:
SVDB_FILTER_SETTINGS = {
"swegen_sv_freq": {
"tag_value": 0.02,
"filter_name": "SWEGENAF",
"field": "INFO",
},
"loqusdb_clinical_sv_freq": {
"tag_value": 0.02,
"filter_name": "Frq",
"field": "INFO",
},
"varcaller_name": "svdb",
"filter_type": "general",
"analysis_type": "tumor_only,tumor_normal",
"description": "General purpose filters used for filtering svdb merged sv",
}
Expand Up @@ -17,6 +17,7 @@ rule bcftools_filter_vardict_research_tumor_normal:
params:
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "research"},
pop_freq = [VARDICT.pop_freq.tag_value, VARDICT.pop_freq.filter_name],
swegen_freq = [VARDICT.swegen_snv_freq.tag_value, VARDICT.swegen_snv_freq.filter_name],
khurrammaqbool marked this conversation as resolved.
Show resolved Hide resolved
case_name = '{case_name}',
edit_vcf_script = get_script_path("edit_vcf_info.py"),
variant_caller = "vardict"
Expand All @@ -29,6 +30,7 @@ rule bcftools_filter_vardict_research_tumor_normal:
"""
bcftools view {input.vcf_snv_research} | \
bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools view -f PASS -o {output.vcf_pass_vardict}.temp -O z;

tabix -p vcf -f {output.vcf_pass_vardict}.temp;
Expand Down Expand Up @@ -90,6 +92,7 @@ rule bcftools_filter_TNscope_umi_research_tumor_normal:
Path(singularity_image, config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
pop_freq = [SENTIEON_CALLER.pop_freq_umi.tag_value, SENTIEON_CALLER.pop_freq_umi.filter_name],
swegen_freq = [SENTIEON_CALLER.swegen_snv_freq.tag_value, SENTIEON_CALLER.swegen_snv_freq.filter_name],
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "research"},
case_name = '{case_name}',
edit_vcf_script = get_script_path("edit_vcf_info.py"),
Expand All @@ -101,8 +104,9 @@ rule bcftools_filter_TNscope_umi_research_tumor_normal:
"adding FOUND_IN tags to the output VCF file for {params.case_name} "
shell:
"""
bcftools view {input.vcf_snv_research} | \
bcftools view -f PASS,triallelic_site --threads {threads} {input.vcf_snv_research} | \
bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS,triallelic_site -o {output.vcf_pass_tnscope_umi}.temp -O z;

tabix -p vcf -f {output.vcf_pass_tnscope_umi}.temp;
Expand Down Expand Up @@ -133,6 +137,8 @@ rule bcftools_filter_vardict_clinical_tumor_normal:
params:
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "clinical"},
pop_freq = [VARDICT.pop_freq.tag_value, VARDICT.pop_freq.filter_name],
swegen_freq = [VARDICT.swegen_snv_freq.tag_value, VARDICT.swegen_snv_freq.filter_name],
loqusdb_clinical_freq = [VARDICT.loqusdb_clinical_snv_freq.tag_value, VARDICT.loqusdb_clinical_snv_freq.filter_name],
case_name = '{case_name}',
edit_vcf_script = get_script_path("edit_vcf_info.py"),
variant_caller = "vardict"
Expand All @@ -145,6 +151,8 @@ rule bcftools_filter_vardict_clinical_tumor_normal:
"""
bcftools view {input.vcf_snv_clinical} | \
bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools filter --threads {threads} --include 'INFO/Frq <= {params.loqusdb_clinical_freq[0]} || INFO/Frq == \".\"' --soft-filter '{params.loqusdb_clinical_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS -o {output.vcf_pass_vardict}.temp -O z;

tabix -p vcf -f {output.vcf_pass_vardict}.temp;
Expand Down Expand Up @@ -174,6 +182,8 @@ rule bcftools_filter_TNscope_umi_clinical_tumor_normal:
Path(singularity_image, config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
pop_freq = [SENTIEON_CALLER.pop_freq_umi.tag_value, SENTIEON_CALLER.pop_freq_umi.filter_name],
swegen_freq = [SENTIEON_CALLER.swegen_snv_freq.tag_value, SENTIEON_CALLER.swegen_snv_freq.filter_name],
loqusdb_clinical_freq = [SENTIEON_CALLER.loqusdb_clinical_snv_freq.tag_value, SENTIEON_CALLER.loqusdb_clinical_snv_freq.filter_name],
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "clinical"},
case_name = '{case_name}',
edit_vcf_script = get_script_path("edit_vcf_info.py"),
Expand All @@ -185,8 +195,10 @@ rule bcftools_filter_TNscope_umi_clinical_tumor_normal:
"adding FOUND_IN tags to the output VCF file for {params.case_name} "
shell:
"""
bcftools view {input.vcf_snv_clinical} | \
bcftools view -f PASS,triallelic_site --threads {threads} {input.vcf_snv_clinical} | \
bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools filter --threads {threads} --include 'INFO/Frq <= {params.loqusdb_clinical_freq[0]} || INFO/Frq == \".\"' --soft-filter '{params.loqusdb_clinical_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS,triallelic_site -o {output.vcf_pass_tnscope_umi}.temp -O z;

tabix -p vcf -f {output.vcf_pass_tnscope_umi}.temp;
Expand Down
Expand Up @@ -17,6 +17,7 @@ rule bcftools_filter_vardict_research_tumor_only:
params:
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "research"},
pop_freq = [VARDICT.pop_freq.tag_value, VARDICT.pop_freq.filter_name],
swegen_freq = [VARDICT.swegen_snv_freq.tag_value, VARDICT.swegen_snv_freq.filter_name],
case_name = '{case_name}',
edit_vcf_script = get_script_path("edit_vcf_info.py"),
variant_caller = "vardict"
Expand All @@ -29,6 +30,7 @@ rule bcftools_filter_vardict_research_tumor_only:
"""
bcftools view {input.vcf_snv_research} | \
bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS -o {output.vcf_pass_vardict}.temp -O z;

tabix -p vcf -f {output.vcf_pass_vardict}.temp;
Expand Down Expand Up @@ -90,6 +92,7 @@ rule bcftools_filter_TNscope_umi_research_tumor_only:
Path(singularity_image, config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
pop_freq = [SENTIEON_CALLER.pop_freq_umi.tag_value, SENTIEON_CALLER.pop_freq_umi.filter_name],
swegen_freq = [SENTIEON_CALLER.swegen_snv_freq.tag_value, SENTIEON_CALLER.swegen_snv_freq.filter_name],
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "research"},
case_name = '{case_name}',
edit_vcf_script = get_script_path("edit_vcf_info.py"),
Expand All @@ -103,6 +106,7 @@ rule bcftools_filter_TNscope_umi_research_tumor_only:
"""
bcftools view {input.vcf_snv_research} | \
bcftools filter --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS,triallelic_site -o {output.vcf_pass_tnscope_umi}.temp -O z;

tabix -p vcf -f {output.vcf_pass_tnscope_umi}.temp;
Expand Down Expand Up @@ -133,6 +137,8 @@ rule bcftools_filter_vardict_clinical_tumor_only:
params:
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "clinical"},
pop_freq = [VARDICT.pop_freq.tag_value, VARDICT.pop_freq.filter_name],
swegen_freq = [VARDICT.swegen_snv_freq.tag_value, VARDICT.swegen_snv_freq.filter_name],
loqusdb_clinical_freq = [VARDICT.loqusdb_clinical_snv_freq.tag_value, VARDICT.loqusdb_clinical_snv_freq.filter_name],
case_name = '{case_name}',
edit_vcf_script = get_script_path("edit_vcf_info.py"),
variant_caller = "vardict"
Expand All @@ -145,6 +151,8 @@ rule bcftools_filter_vardict_clinical_tumor_only:
"""
bcftools view {input.vcf_snv_clinical} | \
bcftools filter --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools filter --threads {threads} --include 'INFO/Frq <= {params.loqusdb_clinical_freq[0]} || INFO/Frq == \".\"' --soft-filter '{params.loqusdb_clinical_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS -o {output.vcf_pass_vardict}.temp -O z;

tabix -p vcf -f {output.vcf_pass_vardict}.temp;
Expand Down Expand Up @@ -174,6 +182,8 @@ rule bcftools_filter_TNscope_umi_clinical_tumor_only:
Path(singularity_image,config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
pop_freq=[SENTIEON_CALLER.pop_freq_umi.tag_value, SENTIEON_CALLER.pop_freq_umi.filter_name],
swegen_freq = [SENTIEON_CALLER.swegen_snv_freq.tag_value, SENTIEON_CALLER.swegen_snv_freq.filter_name],
loqusdb_clinical_freq = [SENTIEON_CALLER.loqusdb_clinical_snv_freq.tag_value, SENTIEON_CALLER.loqusdb_clinical_snv_freq.filter_name],
housekeeper_id={"id": config["analysis"]["case_id"], "tags": "clinical"},
case_name='{case_name}',
edit_vcf_script=get_script_path("edit_vcf_info.py"),
Expand All @@ -187,6 +197,8 @@ rule bcftools_filter_TNscope_umi_clinical_tumor_only:
"""
bcftools view {input.vcf_snv_clinical} | \
bcftools filter --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools filter --threads {threads} --include 'INFO/Frq <= {params.loqusdb_clinical_freq[0]} || INFO/Frq == \".\"' --soft-filter '{params.loqusdb_clinical_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS,triallelic_site -o {output.vcf_pass_tnscope_umi}.temp -O z;

tabix -p vcf -f {output.vcf_pass_tnscope_umi}.temp;
Expand Down
14 changes: 12 additions & 2 deletions BALSAMIC/snakemake_rules/annotation/varcaller_sv_filter.rule
Expand Up @@ -14,14 +14,19 @@ rule bcftools_filter_sv_research:
Path(singularity_image,config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
case_name = "{case_name}",
swegen_freq = [SVDB_FILTERS.swegen_sv_freq.tag_value, SVDB_FILTERS.swegen_sv_freq.filter_name],
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "research"},
threads:
get_threads(cluster_config, "bcftools_filter_svdb_research")
message:
"Filtering merged research structural and copy number variants using bcftools for {params.case_name}"
shell:
"""
bcftools view --threads {threads} -f .,PASS,MaxDepth -o {output.vcf_pass_svdb} -O z {input.vcf_sv_research};
bcftools view --threads {threads} -f .,PASS,MaxDepth {input.vcf_sv_research} |\
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f .,PASS,MaxDepth -O z -o {output.vcf_pass_svdb};



tabix -p vcf -f {output.vcf_pass_svdb};

Expand All @@ -41,14 +46,19 @@ rule bcftools_filter_sv_clinical:
Path(singularity_image,config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
case_name = "{case_name}",
swegen_freq = [SVDB_FILTERS.swegen_sv_freq.tag_value, SVDB_FILTERS.swegen_sv_freq.filter_name],
loqusdb_clinical_freq = [SVDB_FILTERS.loqusdb_clinical_sv_freq.tag_value, SVDB_FILTERS.loqusdb_clinical_sv_freq.filter_name],
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "clinical"},
threads:
get_threads(cluster_config, "bcftools_filter_svdb_clinical")
message:
"Filtering merged clinical structural and copy number variants using bcftools for {params.case_name}"
shell:
"""
bcftools view --threads {threads} -f .,PASS,MaxDepth -o {output.vcf_pass_svdb} -O z {input.vcf_sv_clinical};
bcftools view --threads {threads} -f .,PASS,MaxDepth {input.vcf_sv_clinical} |\
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools filter --threads {threads} --include 'INFO/Frq <= {params.loqusdb_clinical_freq[0]} || INFO/Frq == \".\"' --soft-filter '{params.loqusdb_clinical_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f .,PASS,MaxDepth -O z -o {output.vcf_pass_svdb};

tabix -p vcf -f {output.vcf_pass_svdb};

Expand Down
Expand Up @@ -16,6 +16,7 @@ rule bcftools_filter_tnscope_research_tumor_normal:
Path(singularity_image, config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
pop_freq = [SENTIEON_CALLER.pop_freq.tag_value, SENTIEON_CALLER.pop_freq.filter_name],
swegen_freq = [SENTIEON_CALLER.swegen_snv_freq.tag_value, SENTIEON_CALLER.swegen_snv_freq.filter_name],
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "research"},
case_name = '{case_name}'
threads:
Expand All @@ -24,9 +25,10 @@ rule bcftools_filter_tnscope_research_tumor_normal:
"Filtering WGS tumor-normal tnscope annotated research variants using bcftools for {params.case_name}"
shell:
"""
bcftools view {input.vcf_snv_research} \
| bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' \
| bcftools view --threads {threads} -f PASS,triallelic_site -o {output.vcf_pass_tnscope} -O z;
bcftools view -f PASS,triallelic_site --threads {threads} {input.vcf_snv_research} |\
bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' |\
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS,triallelic_site -o {output.vcf_pass_tnscope} -O z;

tabix -p vcf -f {output.vcf_pass_tnscope};

Expand All @@ -46,6 +48,8 @@ rule bcftools_filter_tnscope_clinical_tumor_normal:
Path(singularity_image, config["bioinfo_tools"].get("bcftools") + ".sif").as_posix()
params:
pop_freq = [SENTIEON_CALLER.pop_freq.tag_value, SENTIEON_CALLER.pop_freq.filter_name],
swegen_freq = [SENTIEON_CALLER.swegen_snv_freq.tag_value, SENTIEON_CALLER.swegen_snv_freq.filter_name],
loqusdb_clinical_freq = [SENTIEON_CALLER.loqusdb_clinical_snv_freq.tag_value, SENTIEON_CALLER.loqusdb_clinical_snv_freq.filter_name],
housekeeper_id = {"id": config["analysis"]["case_id"], "tags": "clinical"},
case_name = '{case_name}'
threads:
Expand All @@ -54,8 +58,10 @@ rule bcftools_filter_tnscope_clinical_tumor_normal:
"Filtering WGS tumor-normal tnscope annotated clinical variants using bcftools for {params.case_name}"
shell:
"""
bcftools view {input.vcf_snv_clinical} | \
bcftools view -f PASS,triallelic_site --threads {threads} {input.vcf_snv_clinical} | \
bcftools filter --threads {threads} --include 'INFO/GNOMADAF_popmax <= {params.pop_freq[0]} || INFO/GNOMADAF_popmax == \".\"' --soft-filter '{params.pop_freq[1]}' --mode '+' | \
bcftools filter --threads {threads} --include 'INFO/SWEGENAF <= {params.swegen_freq[0]} || INFO/SWEGENAF == \".\"' --soft-filter '{params.swegen_freq[1]}' --mode '+' |\
bcftools filter --threads {threads} --include 'INFO/Frq <= {params.loqusdb_clinical_freq[0]} || INFO/Frq == \".\"' --soft-filter '{params.loqusdb_clinical_freq[1]}' --mode '+' |\
bcftools view --threads {threads} -f PASS,triallelic_site -o {output.vcf_pass_tnscope} -O z;

tabix -p vcf -f {output.vcf_pass_tnscope};
Expand Down