annotate sum_fastqc.pl @ 3:8256c1d0d63b draft

Uploaded
author estrain
date Wed, 17 Oct 2018 11:10:03 -0400
parents
children d47775122e78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
1 #!/usr/bin/perl
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
2
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
3 ####################################################
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
4 ##
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
5 ## sum_fastqc.pl
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
6 ##
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
7 ## Errol Strain (estrain@gmail.com)
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
8 ##
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
9 ## Description: Takes raw FASTQC output and produces
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
10 ## simple table summary
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
11 ##
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
12 ####################################################
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
13
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
14 my($inname)=shift(@ARGV);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
15 my($qscore)=shift(@ARGV);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
16 $qscore=~s/\s+//g;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
17 my(@qlist)=split(/\,/,$qscore);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
18
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
19 print "Input\tFile\tFastQC\tPass-Fail\tReads\tPoor_Reads\tGC";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
20 foreach(@qlist) {
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
21 print "\tQ".$_;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
22 }
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
23 print "\n";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
24
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
25 foreach (@ARGV) {
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
26 print_stats($_);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
27 }
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
28
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
29 sub print_stats {
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
30 $infile = shift;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
31 # First 10 lines of raw FASTQC contain basic overview
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
32 @sumlines=`head -n 10 $infile`;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
33 chomp(@sumlines);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
34
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
35 # Sequence level Q scores are buried in the middle of the file
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
36 @qlines=`awk '/#Quality\tCount/,/>>END_MODULE/' $infile | head -n -1 | tail -n +2`;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
37 chomp(@qlines);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
38
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
39 @fastqc = split(/[\n\t]/,shift(@sumlines));
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
40 @pass = split(/\t/,shift(@sumlines));
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
41 shift(@sumlines);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
42 @fn = split(/\t/,shift(@sumlines));
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
43 shift(@sumlines);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
44 shift(@sumlines);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
45 @nreads = split(/\t/,shift(@sumlines));
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
46 @npoor = split(/\t/,shift(@sumlines));
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
47 shift(@sumlines);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
48 @gc = split(/\t/,shift(@sumlines));
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
49
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
50 print $inname."\t";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
51 print $fn[1]."\t";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
52 print $fastqc[1]."\t";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
53 print $pass[1]."\t";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
54 print $nreads[1]."\t";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
55 print $npoor[1]."\t";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
56 print $gc[1];
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
57 foreach $qs (@qlist) {
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
58 print "\t";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
59 print qcal($nreads[1],$qs,\@qlines);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
60 }
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
61 print "\n";
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
62 }
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
63
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
64 # Sum reads w/ Q scores > cutoff and divide by number of reads
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
65 sub qcal {
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
66 $nreads=shift(@_);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
67 $cutoff=shift(@_);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
68 @qarray=@{$_[0]};
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
69 $sum = 0;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
70
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
71 foreach $item (@qarray) {
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
72 my($qval,$q)=split(/\t/,$item);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
73 if($qval>=$cutoff) {
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
74 $sum += $q;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
75 }
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
76 }
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
77 $qmean = sprintf("%.2f", 100 * $sum / $nreads);
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
78 return $qmean;
8256c1d0d63b Uploaded
estrain
parents:
diff changeset
79 }