@@ -440,30 +440,56 @@ def vcf(parser):
440440
441441 out_file = open (args .command_file , "w" )
442442
443- for variant in vcf :
443+ for var_count ,variant in enumerate (vcf ):
444+ try :
445+ translocation_chrom = variant .info .get ("CHR2" )
446+ except :
447+ translocation_chrom = None
444448 svtype = variant .info .get ("SVTYPE" , "SV" )
445449 if args .important_regions :
446450 if not var_in_important_regions (
447451 important_regions , variant .chrom , variant .start , variant .stop
448452 ):
453+ if args .debug :
454+ print ("Skipping {} at {}:{}-{}, outside important_regions coordinates" .format (
455+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
449456 continue
450457
451458 if svtype in ("INS" ):
459+ if args .debug :
460+ print ("Skipping {} at {}:{}-{}, INS type not supported" .format (
461+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
452462 continue
453- if variant .stop - variant .start > args .max_mb * 1000000 :
463+ if args .max_mb and (variant .stop - variant .start > args .max_mb * 1000000 ):
464+ if args .debug :
465+ print ("Skipping {} at {}:{}-{}, variant length greater than max_mb" .format (
466+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
454467 continue
455- if variant .stop - variant .start < args .min_bp :
468+
469+ if (variant .stop - variant .start < args .min_bp ) and translocation_chrom is None :
470+ if args .debug :
471+ print ("Skipping {} at {}:{}-{}, variant length shorter than min_bp" .format (
472+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
456473 continue
457474
458475 gts = [s .get ("GT" , (None , None )) for s in variant .samples .values ()]
459476
460477 if sum (None in g for g in gts ) >= args .min_call_rate * len (vcf_samples ):
478+ if args .debug :
479+ print ("Skipping {} at {}:{}-{}, call rate of variant below min_call_rate" .format (
480+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
461481 continue
462482 if args .max_hets :
463483 # requisite hets/hom-alts
464484 if sum (sum (x ) >= 1 for x in gts if not None in x ) > args .max_hets :
485+ if args .debug :
486+ print ("Skipping {} at {}:{}-{}, more than max_hets heterozygotes" .format (
487+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
465488 continue
466489 if not any (sum (x ) > 0 for x in gts if not None in x ):
490+ if args .debug :
491+ print ("Skipping {} at {}:{}-{}, no samples have non-ref genotypes" .format (
492+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
467493 continue
468494
469495 test_idxs = [i for i , gt in enumerate (gts ) if not None in gt and sum (gt ) > 0 ]
@@ -493,7 +519,10 @@ def vcf(parser):
493519 for i in idxs :
494520 if vcf_samples [i ] in names_to_bams :
495521 variant_samples .append (vcf_samples [i ])
496- if len (variant_samples ) <= 0 :
522+ if len (variant_samples ) == 0 :
523+ if args .debug :
524+ print ("Skipping {} at {}:{}-{}, no samples with matched alignment files have variant" .format (
525+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
497526 continue
498527
499528 bams = [names_to_bams [s ] for s in variant_samples ]
@@ -510,6 +539,9 @@ def vcf(parser):
510539 is_dn .append (sample .id )
511540
512541 if len (is_dn ) <= 0 and args .dn_only :
542+ if args .debug :
543+ print ("Skipping {} at {}:{}-{}, dn_only selected and no de novos found" .format (
544+ svtype , variant .chrom , variant .start , variant .stop ),file = sys .stderr )
513545 continue
514546
515547 # save these for the html.
@@ -581,6 +613,7 @@ def vcf(parser):
581613
582614 data_dict = {
583615 "chrom" : variant .chrom ,
616+ "chrom2" : translocation_chrom ,
584617 "start" : variant .start ,
585618 "end" : variant .stop ,
586619 "svtype" : svtype ,
@@ -590,15 +623,17 @@ def vcf(parser):
590623 }
591624 if annotations :
592625 data_dict ["overlaps" ] = get_overlap (
593- annotations , variant .chrom , variant .start , variant .stop
626+ annotations , variant .chrom , variant .start , variant .stop , translocation_chrom
594627 )
595628 if dn_row != "" :
596629 data_dict ["dn" ] = "," .join (is_dn )
630+ if translocation_chrom is None :
631+ template = "{svtype}_{chrom}_{start}_{end}.{itype}"
632+ else :
633+ template = "{svtype}_{chrom}_{start}_{chrom2}_{end}.{itype}"
597634 fig_path = os .path .join (
598635 args .out_dir ,
599- "{svtype}_{chrom}_{start}_{end}.{itype}" .format (
600- itype = args .output_type , ** data_dict
601- ),
636+ template .format (itype = args .output_type , ** data_dict ),
602637 )
603638 tabledata .append (data_dict )
604639
@@ -633,8 +668,22 @@ def vcf(parser):
633668 else :
634669 title_list .append (variant_sample )
635670
671+ template = ("samplot plot {extra_args} -z {z} -n {titles}"
672+ + "{cipos} {ciend} {svtype} -c {chrom} -s {start} "
673+ + "-e {end} -o {fig_path} -d {downsample} -b {bams}" )
674+ start = variant .start
675+ stop = variant .stop
676+ start2 = None
677+ stop2 = None
678+ if translocation_chrom is not None :
679+ template += " -c {chrom2} -s {start2} -e {end2}"
680+ start2 = stop
681+ stop2 = start2 + 1
682+ stop = start + 1
683+ template += "\n "
684+
636685 out_file .write (
637- "samplot plot {extra_args} -z {z} -n {titles} {cipos} {ciend} {svtype} -c {chrom} -s {start} -e {end} -o {fig_path} -d {downsample} -b {bams} \n " .format (
686+ template .format (
638687 extra_args = " " .join (pass_through_args ),
639688 bams = " " .join (bams ),
640689 titles = " " .join (title_list ),
@@ -644,11 +693,16 @@ def vcf(parser):
644693 svtype = "-t " + svtype if svtype != "SV" else "" ,
645694 fig_path = fig_path ,
646695 chrom = variant .chrom ,
647- start = variant . start ,
648- end = variant . stop ,
696+ start = start ,
697+ end = stop ,
649698 downsample = args .downsample ,
699+ chrom2 = translocation_chrom ,
700+ start2 = start2 ,
701+ end2 = stop2 ,
650702 )
651703 )
704+ if args .debug :
705+ print ("VCF entry count:" ,var_count + 1 ,file = sys .stderr )
652706
653707 if args .command_file :
654708 out_file .close ()
@@ -750,7 +804,6 @@ def add_vcf(parent_parser):
750804 "--max_mb" ,
751805 type = int ,
752806 help = "skip variants longer than this many megabases" ,
753- default = 1 ,
754807 )
755808 parser .add_argument (
756809 "--min_bp" ,
@@ -802,7 +855,12 @@ def add_vcf(parent_parser):
802855 default = False ,
803856 action = "store_true" ,
804857 )
805-
858+ parser .add_argument (
859+ "--debug" ,
860+ help = "prints out the reason each skipped variant entry is skipped" ,
861+ default = False ,
862+ action = "store_true" ,
863+ )
806864 parser .set_defaults (func = vcf )
807865
808866
0 commit comments