Skip to content

Commit

Permalink
bugfixes for errors in vcf with translocations and CIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelyeu committed Oct 20, 2020
1 parent b8e58fa commit 3501f14
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions samplot/samplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 10 additions & 7 deletions samplot/samplot_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions samplot/templates/samplot_vcf.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ <h5>SV Overlaps</h5>
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()
Expand Down
5 changes: 4 additions & 1 deletion test/data/test.vcf
Original file line number Diff line number Diff line change
@@ -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=<ID=CHR2,Number=1,Type=String,Description="Chromosome for END coordinate">
##INFO=<ID=TSD,Number=1,Type=String,Description="Precise Target Site Duplication for bases, if unknown, value will be NULL">
##INFO=<ID=SVTYPE,Number=1,Type=String,Description="Type of structural variant">
##INFO=<ID=MSTART,Number=1,Type=Integer,Description="Mitochondrial start coordinate of inserted sequence">
Expand Down Expand Up @@ -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 <DEL> 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 <DEL> 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 <DEL> 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 <DEL> 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 <DEL> 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 <DUP> 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 <DUP> 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
Expand Down

0 comments on commit 3501f14

Please sign in to comment.