From 3501f147a7dc62f7a4ec629abaaa8a7f8fb79872 Mon Sep 17 00:00:00 2001 From: jbelyeu Date: Tue, 20 Oct 2020 14:17:00 -0600 Subject: [PATCH] bugfixes for errors in vcf with translocations and CIs --- samplot/samplot.py | 2 ++ samplot/samplot_vcf.py | 17 ++++++++++------- samplot/templates/samplot_vcf.html | 3 +++ test/data/test.vcf | 5 ++++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/samplot/samplot.py b/samplot/samplot.py index bd27cd3..de1bf88 100755 --- a/samplot/samplot.py +++ b/samplot/samplot.py @@ -1712,6 +1712,8 @@ def plot_variant(sv, sv_type, ax, ranges): sv_title = "" if sv[0].chrm == sv[-1].chrm: sv_size = float(sv[0].end) - float(sv[0].start) + if len(sv) > 1: + sv_size = abs(int(float(sv[0].end) - float(sv[-1].start))) sv_size_unit = "bp" if sv_size > 1000000: diff --git a/samplot/samplot_vcf.py b/samplot/samplot_vcf.py index 62b334d..6272f7c 100644 --- a/samplot/samplot_vcf.py +++ b/samplot/samplot_vcf.py @@ -441,11 +441,14 @@ def vcf(parser): out_file = open(args.command_file, "w") for var_count,variant in enumerate(vcf): - try: - translocation_chrom = variant.info.get("CHR2") - except: - translocation_chrom = None + translocation_chrom = None svtype = variant.info.get("SVTYPE", "SV") + if svtype in ["BND","TRA"]: + try: + translocation_chrom = variant.info.get("CHR2") + except: + pass + if args.important_regions: if not var_in_important_regions( important_regions, variant.chrom, variant.start, variant.stop @@ -639,12 +642,12 @@ def vcf(parser): if "CIPOS" in variant.info: v = variant.info["CIPOS"] - cipos = "--start_ci '%s,%s'" % (abs(v[0]), abs(v[1])) + cipos = "--start_ci '%s,%s'" % (abs(int(v[0])), abs(int(v[1]))) else: cipos = "" if "CIEND" in variant.info: v = variant.info["CIEND"] - ciend = "--end_ci '%s,%s'" % (abs(v[0]), abs(v[1])) + ciend = "--end_ci '%s,%s'" % (abs(int(v[0])), abs(int(v[1]))) else: ciend = "" # dynamically set Z to speed drawing and remove noise for larger events @@ -668,7 +671,7 @@ def vcf(parser): else: title_list.append(variant_sample) - template = ("samplot plot {extra_args} -z {z} -n {titles}" + template = ("samplot plot {extra_args} -z {z} -n {titles} " + "{cipos} {ciend} {svtype} -c {chrom} -s {start} " + "-e {end} -o {fig_path} -d {downsample} -b {bams}") start = variant.start diff --git a/samplot/templates/samplot_vcf.html b/samplot/templates/samplot_vcf.html index 2e00208..4164e69 100644 --- a/samplot/templates/samplot_vcf.html +++ b/samplot/templates/samplot_vcf.html @@ -241,6 +241,9 @@
SV Overlaps
let row = table.rows('.selected').data()[0] let img = new Image() img.src = `${row.svtype}_${row.chrom}_${row.start}_${row.end}.${plot_type}` + if ( row.chrom2) { + img.src = `${row.svtype}_${row.chrom}_${row.start}_${row.chrom2}_${row.end}.${plot_type}` + } let viewer = new Viewer(img, { hidden: function () { viewer.destroy() diff --git a/test/data/test.vcf b/test/data/test.vcf index e96609c..689dfd3 100644 --- a/test/data/test.vcf +++ b/test/data/test.vcf @@ -1,6 +1,7 @@ ##fileformat=VCFv4.1 ##fileDate=20170929 ##reference=ftp://ftp.1000genomes.ebi.ac.uk//vol1/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz +##INFO= ##INFO= ##INFO= ##INFO= @@ -73,7 +74,9 @@ ##bcftools_viewCommand=view -c 1 -s NA12878 ALL.wgs.mergedSV.v8.20130502.svs.genotypes.vcf.gz ##bcftools_viewCommand=view -i '(SVTYPE="DEL" || SVTYPE="DUP" || SVTYPE="INV" || SVTYPE="INS")' test.vcf #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT HG002 HG003 HG004 -1 24804398 1 T 2087.90 PASS SVTYPE=DEL;CIEND=0,0;CIPOS=0,0;END=24807302; GT:GQ:SQ:GL:DP:RO:AO:QR:QA:RS:AS:ASC:RP:AP:AB 0/1:146:581.24:-64,-6,-51:109:77:31:76:30:52:9:2:24:18:0.28 0/0:130:1506.66:-153,-15,-2:52:0:52:0:51:0:23:3:0:24:1 1/0:200:0.00:-0,-54,-181:182:182:0:181:0:120:0:0:61:0:0 +1 24804398 1 T 2087.90 PASS SVTYPE=DEL;CIEND=100,100;CIPOS=1000,1000;END=24807302; GT:GQ:SQ:GL:DP:RO:AO:QR:QA:RS:AS:ASC:RP:AP:AB 0/1:146:581.24:-64,-6,-51:109:77:31:76:30:52:9:2:24:18:0.28 0/0:130:1506.66:-153,-15,-2:52:0:52:0:51:0:23:3:0:24:1 1/0:200:0.00:-0,-54,-181:182:182:0:181:0:120:0:0:61:0:0 +1 24804398 1 T 2087.90 PASS SVTYPE=TRA;CIEND=0,0;CIPOS=0,0;END=43059290;CHR2=1 GT:GQ:SQ:GL:DP:RO:AO:QR:QA:RS:AS:ASC:RP:AP:AB 0/1:146:581.24:-64,-6,-51:109:77:31:76:30:52:9:2:24:18:0.28 0/0:130:1506.66:-153,-15,-2:52:0:52:0:51:0:23:3:0:24:1 1/0:200:0.00:-0,-54,-181:182:182:0:181:0:120:0:0:61:0:0 +1 24804398 1 T 2087.90 PASS SVTYPE=TRA;CIEND=0,0;CIPOS=0,0;END=99813787;CHR2=4 GT:GQ:SQ:GL:DP:RO:AO:QR:QA:RS:AS:ASC:RP:AP:AB 0/1:146:581.24:-64,-6,-51:109:77:31:76:30:52:9:2:24:18:0.28 0/0:130:1506.66:-153,-15,-2:52:0:52:0:51:0:23:3:0:24:1 1/0:200:0.00:-0,-54,-181:182:182:0:181:0:120:0:0:61:0:0 1 43059290 2 T 2087.90 PASS SVTYPE=DEL;CIEND=0,0;CIPOS=0,0;END=43059950; GT:GQ:SQ:GL:DP:RO:AO:QR:QA:RS:AS:ASC:RP:AP:AB 0/0:146:581.24:-64,-6,-51:109:77:31:76:30:52:9:2:24:18:0.28 0/0:130:1506.66:-153,-15,-2:52:0:52:0:51:0:23:3:0:24:1 0/0:200:0.00:-0,-54,-181:182:182:0:181:0:120:0:0:61:0:0 4 99813787 3 T 2087.90 PASS SVTYPE=DUP;CIEND=0,0;CIPOS=0,0;END=99817098; GT:GQ:SQ:GL:DP:RO:AO:QR:QA:RS:AS:ASC:RP:AP:AB 1/1:146:581.24:-64,-6,-51:109:77:31:76:30:52:9:2:24:18:0.28 1/1:130:1506.66:-153,-15,-2:52:0:52:0:51:0:23:3:0:24:1 1/1:200:0.00:-0,-54,-181:182:182:0:181:0:120:0:0:61:0:0 11 67974432 4 T 2087.90 PASS SVTYPE=DUP;CIEND=0,0;CIPOS=0,0;END=67975639; GT:GQ:SQ:GL:DP:RO:AO:QR:QA:RS:AS:ASC:RP:AP:AB 0/1:146:581.24:-64,-6,-51:109:77:31:76:30:52:9:2:24:18:0.28 0/1:130:1506.66:-153,-15,-2:52:0:52:0:51:0:23:3:0:24:1 0/0:200:0.00:-0,-54,-181:182:182:0:181:0:120:0:0:61:0:0