|
| 1 | +""" |
| 2 | +This pipeline annotates VCF using Variant Effect Predictor |
| 3 | +1. Sets up VEP cache and plugins |
| 4 | +2. Using cache, plugins and other locally available datasets, annoate variants in VCF |
| 5 | +""" |
| 6 | + |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +# datasets to use for annotations |
| 10 | +configfile: config["datasets"] |
| 11 | + |
| 12 | + |
| 13 | +#### VEP parameters #### |
| 14 | +VEP_CACHE = 'homo_sapiens_refseq' |
| 15 | +SPECIES = 'homo_sapiens' |
| 16 | +REF_BUILD = "GRCh38" |
| 17 | +ENSEMBL_DATASET_VERSION = "102" |
| 18 | +HGVS = False |
| 19 | +STATS = False |
| 20 | + |
| 21 | +### I/O parameters |
| 22 | +INPUT_VCF = config["vcf"] |
| 23 | +PROCESSED_DIR = Path(config["outdir"]) |
| 24 | +EXTERNAL_DIR = Path("data/external") |
| 25 | + |
| 26 | +if not (INPUT_VCF.endswith('vcf') or INPUT_VCF.endswith('vcf.gz')): |
| 27 | + print (f"Error: Input file extension not in expected format: found {INPUT_VCF}, expecting *.vcf or *.vcf.gz") |
| 28 | + raise SystemExit(1) |
| 29 | + |
| 30 | +INPUT_VCF = Path(INPUT_VCF) |
| 31 | +OUTPUT_VCF = PROCESSED_DIR / ((INPUT_VCF.name).rstrip(".gz").rstrip(".vcf") + "_vep-annotated.vcf.gz") |
| 32 | + |
| 33 | + |
| 34 | +rule all: |
| 35 | + input: |
| 36 | + OUTPUT_VCF |
| 37 | + |
| 38 | + |
| 39 | +rule get_vep_cache: |
| 40 | + output: |
| 41 | + cache = directory(EXTERNAL_DIR / "vep" / "cache" / VEP_CACHE), |
| 42 | + params: |
| 43 | + species = VEP_CACHE, |
| 44 | + build = REF_BUILD, |
| 45 | + release = ENSEMBL_DATASET_VERSION, |
| 46 | + plugins = "CADD" |
| 47 | + message: |
| 48 | + "Retrieves VEP cache data" |
| 49 | + conda: |
| 50 | + "../configs/env/vep.yaml" |
| 51 | + shell: |
| 52 | + r""" |
| 53 | + vep_install --AUTO cfp \ |
| 54 | + --SPECIES {params.species} \ |
| 55 | + --ASSEMBLY {params.build} \ |
| 56 | + --PLUGINS {params.plugins} \ |
| 57 | + --CACHE_VERSION {params.release} \ |
| 58 | + --CACHEDIR {output.cache} \ |
| 59 | + --CONVERT \ |
| 60 | + --NO_UPDATE |
| 61 | + """ |
| 62 | + |
| 63 | + |
| 64 | +rule get_vep_plugins: |
| 65 | + output: |
| 66 | + directory(EXTERNAL_DIR / "vep" / "plugins"), |
| 67 | + message: |
| 68 | + "Downloads VEP plugins" |
| 69 | + params: |
| 70 | + release = ENSEMBL_DATASET_VERSION |
| 71 | + wrapper: |
| 72 | + "0.59.2/bio/vep/plugins" |
| 73 | + |
| 74 | + |
| 75 | +rule annotate_variants: |
| 76 | + input: |
| 77 | + calls = INPUT_VCF, |
| 78 | + cache = EXTERNAL_DIR / "vep" / "cache" / VEP_CACHE, |
| 79 | + plugins = EXTERNAL_DIR / "vep" / "plugins", |
| 80 | + cadd_snv = config['cadd_snv'], |
| 81 | + cadd_indel = config['cadd_indel'], |
| 82 | + gerp = config['gerp'], |
| 83 | + gnomad_genomes = config['gnomad_genomes'], |
| 84 | + clinvar = config['clinvar'], |
| 85 | + dbNSFP = config['dbNSFP'], |
| 86 | + output: |
| 87 | + calls = OUTPUT_VCF, |
| 88 | + message: |
| 89 | + "Annotated vcf using VEP with CADD, gnomad-exomes, gnomad-genomes and GERP. " |
| 90 | + f"VEP cache used: {VEP_CACHE}, ref build: {REF_BUILD}, Ensemble version: {ENSEMBL_DATASET_VERSION}" |
| 91 | + params: |
| 92 | + release = ENSEMBL_DATASET_VERSION, |
| 93 | + species = SPECIES, |
| 94 | + build = REF_BUILD, |
| 95 | + refseq_flag = "--refseq" if 'refseq' in VEP_CACHE else "", |
| 96 | + hgvs_flag = "--hgvs" if HGVS else "", |
| 97 | + stats_flag = lambda wildcards, output: f"--stats_file {output.stats}" if STATS else "--no_stats", |
| 98 | + gnomad_fields = "AC,AN,AF,AF_afr,AF_afr_female,AF_afr_male,AF_ami,AF_ami_female,AF_ami_male,AF_amr,AF_amr_female,AF_amr_male,AF_asj,AF_asj_female," \ |
| 99 | + "AF_asj_male,AF_eas,AF_eas_female,AF_eas_male,AF_female,AF_fin,AF_fin_female,AF_fin_male,AF_male,AF_nfe,AF_nfe_female,AF_nfe_male," \ |
| 100 | + "AF_oth,AF_oth_female,AF_oth_male,AF_raw,AF_sas,AF_sas_female,AF_sas_male", |
| 101 | + clinvar_fields = "AF_ESP,AF_EXAC,AF_TGP,ALLELEID,CLNDN,CLNDNINCL,CLNDISDB,CLNDISDBINCL,CLNREVSTAT,CLNSIG,CLNSIGCONF,CLNSIGINCL,CLNVC,GENEINFO,MC,ORIGIN,RS,SSR", |
| 102 | + dbNSFP_fields = "LRT_score,MutationTaster_score,MutationAssessor_score,FATHMM_score,PROVEAN_score,VEST4_score,MetaSVM_score,MetaLR_score,M-CAP_score," \ |
| 103 | + "CADD_phred,DANN_score,fathmm-MKL_coding_score,GenoCanyon_score,integrated_fitCons_score,GERP++_RS,phyloP100way_vertebrate,phyloP30way_mammalian," \ |
| 104 | + "phastCons100way_vertebrate,phastCons30way_mammalian,SiPhy_29way_logOdds,Eigen-raw_coding,Eigen-raw_coding_rankscore,Eigen-phred_coding," \ |
| 105 | + "Eigen-PC-raw_coding,Eigen-PC-raw_coding_rankscore,Eigen-PC-phred_coding", |
| 106 | + warnings_file = lambda wildcards, output: str(output.calls).replace('.vcf.gz', '_STDOUT_warnings.txt'), |
| 107 | + threads: 8 |
| 108 | + conda: |
| 109 | + "../configs/env/vep.yaml" |
| 110 | + shell: |
| 111 | + r""" |
| 112 | + # using bcftools view as it might catch vcf-related errors (https://stackoverflow.com/a/63371639/3998252) |
| 113 | + bcftools view {input.calls} | \ |
| 114 | + vep --fork {threads} \ |
| 115 | + --format vcf \ |
| 116 | + --vcf \ |
| 117 | + --offline \ |
| 118 | + --cache \ |
| 119 | + --cache_version {params.release} \ |
| 120 | + --species {params.species} \ |
| 121 | + --assembly {params.build} \ |
| 122 | + {params.refseq_flag} {params.hgvs_flag} \ |
| 123 | + --sift s --polyphen s \ |
| 124 | + --dir_cache {input.cache} \ |
| 125 | + --dir_plugins {input.plugins} \ |
| 126 | + --plugin CADD,{input.cadd_snv},{input.cadd_indel} \ |
| 127 | + --plugin dbNSFP,{input.dbNSFP},{params.dbNSFP_fields} \ |
| 128 | + --custom {input.gerp},GERP,bed \ |
| 129 | + --custom {input.gnomad_genomes},gnomADv3,vcf,exact,0,{params.gnomad_fields} \ |
| 130 | + --custom {input.clinvar},clinvar,vcf,exact,0,{params.clinvar_fields} \ |
| 131 | + {params.stats_flag} \ |
| 132 | + --warning_file {params.warnings_file} \ |
| 133 | + --compress_output bgzip \ |
| 134 | + --output_file {output.calls} |
| 135 | + """ |
0 commit comments