3 # Author: petr.danecek@sanger
10 my $opts = parse_params();
11 parse_bamcheck($opts);
12 plot_qualities($opts);
13 plot_acgt_cycles($opts);
18 plot_mismatches_per_cycle($opts);
19 plot_indel_dist($opts);
20 plot_indel_cycles($opts);
24 #--------------------------------
29 if ( scalar @msg ) { confess @msg; }
31 "Usage: plot-bamcheck [OPTIONS] file.bam.bc\n",
32 " plot-bamcheck -p outdir/ file.bam.bc\n",
34 " -k, --keep-files Do not remove temporary files.\n",
35 " -p, --prefix <path> The output files prefix, add a slash to create new directory.\n",
36 " -r, --ref-stats <file.fa.gc> Optional reference stats file with expected GC content (created with -s).\n",
37 " -s, --do-ref-stats <file.fa> Calculate reference sequence GC for later use with -r\n",
38 " -t, --targets <file.tab> Restrict -s to the listed regions (tab-delimited chr,from,to. 1-based, inclusive)\n",
39 " -h, -?, --help This help message.\n",
47 my $opts = { args=>join(' ',$0,@ARGV) };
48 while (defined(my $arg=shift(@ARGV)))
50 if ( $arg eq '-k' || $arg eq '--keep-files' ) { $$opts{keep_files}=1; next; }
51 if ( $arg eq '-r' || $arg eq '--ref-stats' ) { $$opts{ref_stats}=shift(@ARGV); next; }
52 if ( $arg eq '-s' || $arg eq '--do-ref-stats' ) { $$opts{do_ref_stats}=shift(@ARGV); next; }
53 if ( $arg eq '-t' || $arg eq '--targets' ) { $$opts{targets}=shift(@ARGV); next; }
54 if ( $arg eq '-p' || $arg eq '--prefix' ) { $$opts{prefix}=shift(@ARGV); next; }
55 if ( $arg eq '-?' || $arg eq '-h' || $arg eq '--help' ) { error(); }
56 if ( -e $arg ) { $$opts{bamcheck}=$arg; next; }
57 error("Unknown parameter or non-existent file \"$arg\". Run -h for help.\n");
59 if ( exists($$opts{do_ref_stats }) ) { do_ref_stats($opts); exit; }
60 if ( !exists($$opts{bamcheck}) ) { error("No bamcheck file?\n") }
61 if ( !exists($$opts{prefix}) ) { error("Expected -p parameter.\n") }
62 if ( $$opts{prefix}=~m{/$} ) { `mkdir -p $$opts{prefix}`; }
63 elsif ( !($$opts{prefix}=~/-$/) ) { $$opts{prefix} .= '-'; }
68 # Creates GC stats for either the whole reference or only on target regions for exome QC
75 if ( exists($$opts{targets}) )
77 my ($prev_chr,$prev_pos);
78 open(my $fh,'<',$$opts{targets}) or error("$$opts{targets}: $!");
79 while (my $line=<$fh>)
81 if ( $line=~/^#/ ) { next; }
82 my ($chr,$from,$to) = split(/\s+/,$line);
84 push @{$targets{$chr}}, $from,$to;
85 if ( !defined $prev_chr or $chr ne $prev_chr ) { $prev_chr=$chr; $prev_pos=$from }
86 if ( $prev_pos > $from ) { error("The file must be sorted: $$opts{targets}\n"); }
92 my $_len = 60; # for now do only standard fasta's with 60 bases per line
94 my ($skip_chr,$pos,$ireg,$regions);
95 open(my $fh,'<',$$opts{do_ref_stats}) or error("$$opts{do_ref_stats}: $!");
96 while (my $line=<$fh>)
100 if ( !scalar %targets ) { next; }
102 if ( !($line=~/>(\S+)/) ) { error("FIXME: could not determine chromosome name: $line"); }
103 if ( !exists($targets{$1}) ) { $skip_chr=$1; next; }
107 $regions = $targets{$1};
109 if ( defined $skip_chr ) { next; }
111 # Only $_len sized lines are considered and no chopping for target regions.
113 my $len = length($line);
114 if ( $len ne $_len ) { next; }
116 if ( scalar %targets )
118 while ( $ireg<@$regions && $$regions[$ireg+1]<=$pos ) { $ireg += 2; }
120 if ( $ireg==@$regions ) { next; }
121 if ( $pos < $$regions[$ireg] ) { next; }
125 for (my $i=0; $i<$len; $i++)
127 my $base = substr($line,$i,1);
128 if ( $base eq 'g' || $base eq 'G' || $base eq 'c' || $base eq 'C' ) { $gc_count++; }
130 $gc_counts{$gc_count}++;
133 print "# Generated by $$opts{args}\n";
134 print "# The columns are: GC content bin, normalized frequency\n";
136 for my $count (values %gc_counts)
138 if ( !defined $max or $count>$max ) { $max=$count; }
140 for my $gc (sort {$a<=>$b} keys %gc_counts)
142 if ( $gc==0 ) { next; }
143 printf "%f\t%f\n", $gc*100./$_len, $gc_counts{$gc}/$max;
150 my $cmd = "gnuplot $cmdfile";
152 if ( $? ) { error("The command exited with non-zero status $?:\n\t$cmd\n\n"); }
159 open(my $fh,'<',$$opts{bamcheck}) or error("$$opts{bamcheck}: $!");
161 if ( !($line=~/^# This file was produced by bamcheck (\S+)/) ) { error("Sanity check failed: was this file generated by bamcheck?"); }
162 $$opts{dat}{version} = $1;
165 if ( $line=~/^#/ ) { next; }
166 my @items = split(/\t/,$line);
168 if ( $items[0] eq 'SN' )
170 $$opts{dat}{$items[1]} = splice(@items,2);
173 push @{$$opts{dat}{$items[0]}}, [splice(@items,1)];
178 if ( !exists($$opts{dat}{'sequences:'}) or !$$opts{dat}{'sequences:'} )
180 error("Sanity check failed: no sequences found by bamcheck??\n");
186 my ($opts,$version) = @_;
187 my ($year,$month,$day) = split(/-/,$version);
188 $version = $$opts{dat}{version};
189 if ( !($version=~/\((\d+)-(\d+)-(\d+)\)$/) ) { return 1; }
190 if ( $1<$year ) { return 1; }
191 elsif ( $1>$year ) { return 0; }
192 if ( $2<$month ) { return 1; }
193 elsif ( $2>$month ) { return 0; }
194 if ( $3<$day ) { return 1; }
200 my ($opts,$img_fname,%args) = @_;
202 if ( !($img_fname=~/\.png$/i) ) { error("FIXME: currently only PNG supported. (Easy to extend.)\n"); }
204 # Determine the gnuplot script file name
205 my $gp_file = $img_fname;
206 $gp_file =~ s{\.[^.]+$}{.gp};
207 if ( !($gp_file=~/.gp$/) ) { $gp_file .= '.gp'; }
209 # Determine the default title:
210 # 5446_6/5446_6.bam.bc.gp -> 5446_6
211 # test.aaa.png -> test.aaa
212 if ( !($$opts{bamcheck}=~m{([^/]+?)(?:\.bam)?(?:\.bc)?$}i) ) { error("FIXME: Could not determine the title from [$img_fname]\n"); }
216 $dir =~ s{/[^/]+$}{};
217 if ( $dir && $dir ne $gp_file ) { `mkdir -p $dir`; }
219 my $wh = exists($args{wh}) ? $args{wh} : '600,400';
221 open(my $fh,'>',$gp_file) or error("$gp_file: $!");
227 terminal => qq[set terminal png size $wh truecolor],
228 grid => 'set grid xtics ytics y2tics back lc rgb "#cccccc"',
236 for my $val (@vals) { $N += $val; }
237 my $n = $p*($N+1)/100.;
240 if ( $k<=0 ) { return 0; }
241 if ( $k>=$N ) { return scalar @vals-1; }
243 for (my $i=0; $i<@vals; $i++)
246 if ( $cnt>=$k ) { return $i; }
248 error("FIXME: this should not happen [percentile]\n");
255 if ( !exists($$opts{dat}{FFQ}) or !@{$$opts{dat}{FFQ}} ) { return; }
257 my $yrange = @{$$opts{dat}{FFQ}[0]} > 50 ? @{$$opts{dat}{FFQ}[0]} : 50;
258 my $is_paired = $$opts{dat}{'is paired:'};
260 # Average quality per cycle, forward and reverse reads in one plot
261 my $args = get_defaults($opts,"$$opts{prefix}quals.png");
265 set output "$$args{img}"
267 set ylabel "Average Quality"
269 set yrange [0:$yrange]
270 set title "$$args{title}"
271 plot '-' using 1:2 with lines title 'Forward reads' ] . ($is_paired ? q[, '-' using 1:2 with lines title 'Reverse reads'] : '') . q[
273 my (@fp75,@fp50,@fmean);
274 my (@lp75,@lp50,@lmean);
275 my ($fmax,$fmax_qual,$fmax_cycle);
276 my ($lmax,$lmax_qual,$lmax_cycle);
277 for my $cycle (@{$$opts{dat}{FFQ}})
280 for (my $iqual=1; $iqual<@$cycle; $iqual++)
282 $sum += $$cycle[$iqual]*$iqual;
283 $n += $$cycle[$iqual];
284 if ( !defined $fmax or $fmax<$$cycle[$iqual] ) { $fmax=$$cycle[$iqual]; $fmax_qual=$iqual; $fmax_cycle=$$cycle[0]; }
286 my $p25 = percentile(25,(@$cycle)[1..$#$cycle]);
287 my $p50 = percentile(50,(@$cycle)[1..$#$cycle]);
288 my $p75 = percentile(75,(@$cycle)[1..$#$cycle]);
290 push @fp75, "$$cycle[0]\t$p25\t$p75\n";
291 push @fp50, "$$cycle[0]\t$p50\n";
292 push @fmean, sprintf "%d\t%.2f\n", $$cycle[0],$sum/$n;
293 printf $fh $fmean[-1];
298 for my $cycle (@{$$opts{dat}{LFQ}})
301 for (my $iqual=1; $iqual<@$cycle; $iqual++)
303 $sum += $$cycle[$iqual]*$iqual;
304 $n += $$cycle[$iqual];
305 if ( !defined $lmax or $lmax<$$cycle[$iqual] ) { $lmax=$$cycle[$iqual]; $lmax_qual=$iqual; $lmax_cycle=$$cycle[0]; }
307 my $p25 = percentile(25,(@$cycle)[1..$#$cycle]);
308 my $p50 = percentile(50,(@$cycle)[1..$#$cycle]);
309 my $p75 = percentile(75,(@$cycle)[1..$#$cycle]);
311 push @lp75, "$$cycle[0]\t$p25\t$p75\n";
312 push @lp50, "$$cycle[0]\t$p50\n";
313 push @lmean, sprintf "%d\t%.2f\n", $$cycle[0],$sum/$n;
314 printf $fh $lmean[-1];
323 # Average, mean and quality percentiles per cycle, forward and reverse reads in separate plots
324 $args = get_defaults($opts,"$$opts{prefix}quals2.png",wh=>'700,500');
328 set output "$$args{img}"
337 set yrange [0:$yrange]
339 set xlabel "Cycle (fwd reads)"
340 plot '-' using 1:2:3 with filledcurve lt 1 lc rgb "#cccccc" t '25-75th percentile' , '-' using 1:2 with lines lc rgb "#000000" t 'Median', '-' using 1:2 with lines lt 1 t 'Mean'
342 print $fh join('',@fp75),"end\n";
343 print $fh join('',@fp50),"end\n";
344 print $fh join('',@fmean),"end\n";
352 set yrange [0:$yrange]
354 set xlabel "Cycle (rev reads)"
355 set label "$$args{title}" at screen 0.5,0.95 center
356 plot '-' using 1:2:3 with filledcurve lt 1 lc rgb "#cccccc" t '25-75th percentile' , '-' using 1:2 with lines lc rgb "#000000" t 'Median', '-' using 1:2 with lines lt 2 t 'Mean'
358 print $fh join('',@lp75),"end\n";
359 print $fh join('',@lp50),"end\n";
360 print $fh join('',@lmean),"end\n";
367 # Quality distribution per cycle, the distribution is for each cycle plotted as a separate curve
368 $args = get_defaults($opts,"$$opts{prefix}quals3.png",wh=>'600,600');
370 my $nquals = @{$$opts{dat}{FFQ}[0]}-1;
371 my $ncycles = @{$$opts{dat}{FFQ}};
374 set output "$$args{img}"
383 set title "$$args{title}"
384 set ylabel "Frequency (fwd reads)"
385 set label "Cycle $fmax_cycle" at $fmax_qual+1,$fmax
387 set xrange [0:$nquals]
391 for (my $i=0; $i<$ncycles; $i++) { push @plots, q['-' using 1:2 with lines t ''] }
392 print $fh "plot ", join(",", @plots), "\n";
393 for my $cycle (@{$$opts{dat}{FFQ}})
395 for (my $iqual=1; $iqual<$nquals; $iqual++) { print $fh "$iqual\t$$cycle[$iqual]\n"; }
408 set label "Cycle $lmax_cycle" at $lmax_qual+1,$lmax
409 set ylabel "Frequency (rev reads)"
411 print $fh "plot ", join(",", @plots), "\n";
412 for my $cycle (@{$$opts{dat}{LFQ}})
414 for (my $iqual=1; $iqual<$nquals; $iqual++)
416 print $fh "$iqual\t$$cycle[$iqual]\n";
426 $args = get_defaults($opts,"$$opts{prefix}quals-hm.png", wh=>'600,500');
428 my $max = defined $lmax && $lmax > $fmax ? $lmax : $fmax;
430 for my $cycle (@{$$opts{dat}{FFQ}}) { if ( $$cycle[0]%10==0 ) { push @ytics,qq["$$cycle[0]" $$cycle[0]]; } }
431 my $ytics = join(',', @ytics);
434 set output "$$args{img}"
437 set palette defined (0 0 0 0, 1 0 0 1, 3 0 1 0, 4 1 0 0, 6 1 1 1)
439 set yrange [0:$ncycles]
440 set xrange [0:$nquals]
449 set obj 1 rectangle behind from first 0,0 to first $nquals,$ncycles
450 set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
451 set ylabel "Cycle (fwd reads)" offset character -1,0
455 set title "$$args{title}"
456 splot '-' matrix with image
458 for my $cycle (@{$$opts{dat}{FFQ}})
460 for (my $iqual=1; $iqual<@$cycle; $iqual++) { print $fh "\t$$cycle[$iqual]"; }
463 print $fh "end\nend\n";
465 for my $cycle (@{$$opts{dat}{LFQ}}) { if ( $$cycle[0]%10==0 ) { push @ytics,qq["$$cycle[0]" $$cycle[0]]; } }
466 $ytics = join(',', @ytics);
470 set ylabel "Cycle (rev reads)" offset character -1,0
471 set xlabel "Base Quality"
475 set xrange [0:$nquals]
477 set colorbox vertical user origin first ($nquals+1),0 size screen 0.025,0.812
478 set cblabel "Number of bases"
479 splot '-' matrix with image
481 for my $cycle (@{$$opts{dat}{LFQ}})
483 for (my $iqual=1; $iqual<@$cycle; $iqual++) { print $fh "\t$$cycle[$iqual]"; }
486 print $fh "end\nend\n";
496 if ( !exists($$opts{dat}{GCC}) or !@{$$opts{dat}{GCC}} ) { return; }
498 my $args = get_defaults($opts,"$$opts{prefix}acgt-cycles.png");
502 set output "$$args{img}"
504 set style line 1 linecolor rgb "green"
505 set style line 2 linecolor rgb "red"
506 set style line 3 linecolor rgb "black"
507 set style line 4 linecolor rgb "blue"
508 set style increment user
509 set ylabel "Base content [%]"
510 set xlabel "Read Cycle"
512 set title "$$args{title}"
513 plot '-' w l ti 'A', '-' w l ti 'C', '-' w l ti 'G', '-' w l ti 'T'
517 for my $cycle (@{$$opts{dat}{GCC}})
519 print $fh $$cycle[0]+1,"\t",$$cycle[$base],"\n";
532 my $is_paired = $$opts{dat}{'is paired:'};
533 my $args = get_defaults($opts,"$$opts{prefix}gc-content.png");
535 my ($gcl_max,$gcf_max,$lmax,$fmax);
536 for my $gc (@{$$opts{dat}{GCF}}) { if ( !defined $gcf_max or $gcf_max<$$gc[1] ) { $gcf_max=$$gc[1]; $fmax=$$gc[0]; } }
537 for my $gc (@{$$opts{dat}{GCL}}) { if ( !defined $gcl_max or $gcl_max<$$gc[1] ) { $gcl_max=$$gc[1]; $lmax=$$gc[0]; } }
538 my $gcmax = $is_paired && $gcl_max > $gcf_max ? $lmax : $fmax;
541 set output "$$args{img}"
543 set title "$$args{title}"
544 set ylabel "Normalized Frequency"
545 set xlabel "GC Content [%]"
547 set label sprintf("%.1f",$gcmax) at $gcmax,1 front offset 1,0
549 . (exists($$opts{ref_stats}) ? q['-' smooth csplines with lines lt 0 title 'Reference', ] : '')
550 . q['-' smooth csplines with lines lc 1 title 'First fragments' ]
551 . ($is_paired ? q[, '-' smooth csplines with lines lc 2 title 'Last fragments'] : '')
554 if ( exists($$opts{ref_stats}) )
556 open(my $ref,'<',$$opts{ref_stats}) or error("$$opts{ref_stats}: $!");
557 while (my $line=<$ref>) { print $fh $line }
561 for my $cycle (@{$$opts{dat}{GCF}}) { printf $fh "%d\t%f\n", $$cycle[0],$$cycle[1]/$gcf_max; }
565 for my $cycle (@{$$opts{dat}{GCL}}) { printf $fh "%d\t%f\n", $$cycle[0],$$cycle[1]/$gcl_max; }
577 if ( !exists($$opts{dat}{GCD}) or !@{$$opts{dat}{GCD}} ) { return; }
579 # Find unique sequence percentiles for 30,40, and 50% GC content, just to draw x2tics.
580 my @tics = ( {gc=>30},{gc=>40},{gc=>50} );
581 for my $gc (@{$$opts{dat}{GCD}})
585 my $diff = abs($$gc[0]-$$tic{gc});
586 if ( !exists($$tic{pr}) or $diff<$$tic{diff} ) { $$tic{pr}=$$gc[1]; $$tic{diff}=$diff; }
591 for my $tic (@tics) { push @x2tics, qq["$$tic{gc}" $$tic{pr}]; }
592 my $x2tics = join(',',@x2tics);
594 my $args = get_defaults($opts,"$$opts{prefix}gc-depth.png", wh=>'600,500');
598 set output "$$args{img}"
600 set ylabel "Mapped depth"
601 set xlabel "Percentile of mapped sequence ordered by GC content"
602 set x2label "GC Content [%]"
603 set title "$$args{title}"
606 set xrange [0.1:99.9]
608 plot '-' using 1:2:3 with filledcurve lt 1 lc rgb "#dedede" t '10-90th percentile' , \\
609 '-' using 1:2:3 with filledcurve lt 1 lc rgb "#bbdeff" t '25-75th percentile' , \\
610 '-' using 1:2 with lines lc rgb "#0084ff" t 'Median'
612 for my $gc (@{$$opts{dat}{GCD}}) { print $fh "$$gc[1]\t$$gc[2]\t$$gc[6]\n"; } print $fh "end\n";
613 for my $gc (@{$$opts{dat}{GCD}}) { print $fh "$$gc[1]\t$$gc[3]\t$$gc[5]\n"; } print $fh "end\n";
614 for my $gc (@{$$opts{dat}{GCD}}) { print $fh "$$gc[1]\t$$gc[4]\n"; } print $fh "end\n";
624 if ( !$$opts{dat}{'is paired:'} or !exists($$opts{dat}{IS}) or !@{$$opts{dat}{IS}} ) { return; }
626 my ($isize_max,$isize_cnt);
627 for my $isize (@{$$opts{dat}{IS}})
629 if ( !defined $isize_max or $isize_cnt<$$isize[1] ) { $isize_cnt=$$isize[1]; $isize_max=$$isize[0]; }
632 my $args = get_defaults($opts,"$$opts{prefix}insert-size.png");
636 set output "$$args{img}"
639 set label sprintf("%d",$isize_max) at $isize_max+10,$isize_cnt
640 set ylabel "Number of pairs"
641 set xlabel "Insert Size"
642 set title "$$args{title}"
644 '-' with lines lc rgb 'black' title 'All pairs', \\
645 '-' with lines title 'Inward', \\
646 '-' with lines title 'Outward', \\
647 '-' with lines title 'Other'
649 for my $isize (@{$$opts{dat}{IS}}) { print $fh "$$isize[0]\t$$isize[1]\n"; } print $fh "end\n";
650 for my $isize (@{$$opts{dat}{IS}}) { print $fh "$$isize[0]\t$$isize[2]\n"; } print $fh "end\n";
651 for my $isize (@{$$opts{dat}{IS}}) { print $fh "$$isize[0]\t$$isize[3]\n"; } print $fh "end\n";
652 for my $isize (@{$$opts{dat}{IS}}) { print $fh "$$isize[0]\t$$isize[4]\n"; } print $fh "end\n";
662 if ( !exists($$opts{dat}{COV}) or !@{$$opts{dat}{COV}} ) { return; }
665 for my $cov (@{$$opts{dat}{COV}}) { push @vals,$$cov[2]; }
666 my $i = percentile(99.8,@vals);
667 my $p99 = $$opts{dat}{COV}[$i][1];
669 my $args = get_defaults($opts,"$$opts{prefix}coverage.png");
673 set output "$$args{img}"
675 set ylabel "Number of mapped bases"
676 set xlabel "Coverage"
677 set style fill solid border -1
678 set title "$$args{title}"
680 plot '-' with lines notitle
682 for my $cov (@{$$opts{dat}{COV}})
684 if ( $$cov[2]==0 ) { next; }
685 print $fh "$$cov[1]\t$$cov[2]\n";
693 sub plot_mismatches_per_cycle
697 if ( !exists($$opts{dat}{MPC}) or !@{$$opts{dat}{MPC}} ) { return; }
698 if ( older_than($opts,'2012-02-06') ) { plot_mismatches_per_cycle_old($opts); }
700 my $nquals = @{$$opts{dat}{MPC}[0]} - 2;
701 my $ncycles = @{$$opts{dat}{MPC}};
703 if ( $ncycles>100 ) { $style = ''; $with = 'w l'; }
704 else { $style = 'set style data histogram; set style histogram rowstacked'; $with = ''; }
706 my $args = get_defaults($opts,"$$opts{prefix}mism-per-cycle.png");
710 set output "$$args{img}"
712 set style line 1 linecolor rgb "#e40000"
713 set style line 2 linecolor rgb "#ff9f00"
714 set style line 3 linecolor rgb "#eeee00"
715 set style line 4 linecolor rgb "#4ebd68"
716 set style line 5 linecolor rgb "#0061ff"
717 set style increment user
720 set ylabel "Number of mismatches"
721 set xlabel "Read Cycle"
722 set style fill solid border -1
723 set title "$$args{title}"
724 set xrange [-1:$ncycles]
725 plot '-' $with ti 'Base Quality>30', \\
726 '-' $with ti '30>=Q>20', \\
727 '-' $with ti '20>=Q>10', \\
728 '-' $with ti '10>=Q', \\
731 for my $cycle (@{$$opts{dat}{MPC}})
733 my $sum; for my $idx (31..$#$cycle) { $sum += $$cycle[$idx]; }
737 for my $cycle (@{$$opts{dat}{MPC}})
739 my $sum; for my $idx (22..31) { $sum += $$cycle[$idx]; }
743 for my $cycle (@{$$opts{dat}{MPC}})
745 my $sum; for my $idx (12..21) { $sum += $$cycle[$idx]; }
749 for my $cycle (@{$$opts{dat}{MPC}})
751 my $sum; for my $idx (2..11) { $sum += $$cycle[$idx]; }
755 for my $cycle (@{$$opts{dat}{MPC}}) { print $fh "$$cycle[1]\n"; }
765 if ( !exists($$opts{dat}{ID}) or !@{$$opts{dat}{ID}} ) { return; }
767 my $args = get_defaults($opts,"$$opts{prefix}indel-dist.png");
771 set output "$$args{img}"
773 set style line 1 linetype 1 linecolor rgb "red"
774 set style line 2 linetype 2 linecolor rgb "black"
775 set style line 3 linetype 3 linecolor rgb "green"
776 set style increment user
777 set ylabel "Indel count [log]"
778 set xlabel "Indel length"
779 set y2label "Insertions/Deletions ratio"
783 set title "$$args{title}"
784 plot '-' w l ti 'Insertions', '-' w l ti 'Deletions', '-' axes x1y2 w l ti "Ins/Dels ratio"
786 for my $len (@{$$opts{dat}{ID}}) { print $fh "$$len[0]\t$$len[1]\n"; } print $fh "end\n";
787 for my $len (@{$$opts{dat}{ID}}) { print $fh "$$len[0]\t$$len[2]\n"; } print $fh "end\n";
788 for my $len (@{$$opts{dat}{ID}}) { printf $fh "%d\t%f\n", $$len[0],$$len[2]?$$len[1]/$$len[2]:0; } print $fh "end\n";
793 sub plot_indel_cycles
797 if ( !exists($$opts{dat}{IC}) or !@{$$opts{dat}{IC}} ) { return; }
799 my $args = get_defaults($opts,"$$opts{prefix}indel-cycles.png");
803 set output "$$args{img}"
805 set style line 1 linetype 1 linecolor rgb "red"
806 set style line 2 linetype 2 linecolor rgb "black"
807 set style line 3 linetype 3 linecolor rgb "green"
808 set style line 4 linetype 4 linecolor rgb "blue"
809 set style increment user
810 set ylabel "Indel count"
811 set xlabel "Read Cycle"
812 set title "$$args{title}"
813 plot '-' w l ti 'Insertions (fwd)', '' w l ti 'Insertions (rev)', '' w l ti 'Deletions (fwd)', '' w l ti 'Deletions (rev)'
815 for my $len (@{$$opts{dat}{IC}}) { print $fh "$$len[0]\t$$len[1]\n"; } print $fh "end\n";
816 for my $len (@{$$opts{dat}{IC}}) { print $fh "$$len[0]\t$$len[2]\n"; } print $fh "end\n";
817 for my $len (@{$$opts{dat}{IC}}) { print $fh "$$len[0]\t$$len[3]\n"; } print $fh "end\n";
818 for my $len (@{$$opts{dat}{IC}}) { print $fh "$$len[0]\t$$len[4]\n"; } print $fh "end\n";
831 my ($opts,@tags) = @_;
834 my (@lines) = `cat $$opts{bamcheck} | grep ^$tag | wc -l`;
836 if ( $lines[0]<2 ) { return 0; }
841 sub plot_mismatches_per_cycle_old
845 my $args = get_defaults($opts,"$$opts{prefix}mism-per-cycle.png");
846 my ($nquals) = `grep ^MPC $$opts{bamcheck} | awk '\$2==1' | sed 's,\\t,\\n,g' | wc -l`;
847 my ($ncycles) = `grep ^MPC $$opts{bamcheck} | wc -l`;
852 my @gr0_15 = (2..17);
853 my @gr16_30 = (18..32);
854 my @gr31_n = (33..$nquals);
855 my $gr0_15 = '$'. join('+$',@gr0_15);
856 my $gr16_30 = '$'. join('+$',@gr16_30);
857 my $gr31_n = '$'. join('+$',@gr31_n);
859 open(my $fh,'>',$$args{gp}) or error("$$args{gp}: $!");
861 set terminal png size 600,400 truecolor font "DejaVuSansMono,9"
862 set output "] . $$args{img} . q["
865 set style data histogram
866 set style histogram rowstacked
868 set grid back lc rgb "#aaaaaa"
869 set ylabel "Number of mismatches"
870 set xlabel "Read Cycle"
871 set style fill solid border -1
872 set title "] . $$args{title} . qq["
873 set xrange [-1:$ncycles]
875 plot '< grep ^MPC $$opts{bamcheck} | cut -f 2-' using ($gr31_n) ti 'Base Quality>30', '' using ($gr16_30) ti '30>=Q>15', '' using ($gr0_15) ti '15>=Q'