3 # Copyright (C) 2012 Martin A. Hansen (mail@maasha.dk).
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
26 def parse_analysis(file)
29 File.open(file, 'r') do |ios|
31 key, val = line.chomp.split(' ')
32 data[key] = val.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
42 File.open(file, "r") do |ios|
46 "data:image/png;base64," + Base64.encode64(png)
50 $stderr.puts "Usage: QA_Illumina_report.rb <FASTQ file> > <HTML file>"
57 analyze_vals_file = File.join(tmpdir, 'analyze_vals.txt')
58 analyze_vals_trim_file = File.join(tmpdir, 'analyze_vals_trim_noadapt.txt')
59 analyze_vals_trim_noadapt_file = File.join(tmpdir, 'analyze_vals_trim.txt')
60 lendist_file = File.join(tmpdir, 'lendist.png')
61 scores_file = File.join(tmpdir, 'scores.png')
62 nucdist_file = File.join(tmpdir, 'nucdist.png')
63 lendist_bin_file = File.join(tmpdir, 'lendist_bin.png')
64 scores_bin_file = File.join(tmpdir, 'scores_bin.png')
66 STDERR.puts "Analyzing sequences ... "
69 "read_fastq -i #{seq_file} |
71 analyze_vals -k SEQ -o #{analyze_vals_file} |
73 grab -e 'SEQ_LEN > 0' |
74 analyze_vals -k SEQ -o #{analyze_vals_trim_file} |
75 find_adaptor -c 12 -l 6 -L 6 -f ACACGACGCTCTTCCGATCT -r AGATCGGAAGAGCACACGTC |
77 grab -e 'SEQ_LEN > 0' |
78 analyze_vals -k SEQ -o #{analyze_vals_trim_noadapt_file} |
79 plot_distribution -k SEQ_LEN -T 'Sequence length distribution' -X 'Sequence length' -t png -o #{lendist_file} |
80 plot_scores -c -t png -o #{scores_file} |
81 plot_nucleotide_distribution -c -t png -o #{nucdist_file} |
82 bin_vals -k SEQ_LEN -b 25 |
83 plot_distribution -T '25 bases bin sequence length distribution' -X 'Sequence length' -k SEQ_LEN_BIN -t png -o #{lendist_bin_file} |
85 bin_vals -k SCORES_MEAN -b 5 |
86 plot_distribution -k SCORES_MEAN_BIN -T '5 bin mean score distribution' -X 'Mean scores' -t png -o #{scores_bin_file} -x"
91 analysis1 = parse_analysis(analyze_vals_file)
92 analysis2 = parse_analysis(analyze_vals_trim_file)
93 analysis3 = parse_analysis(analyze_vals_trim_noadapt_file)
98 <title>QA Illumina Report</title>
101 <h1>QA Illumina Report</h1>
102 <p>Date: #{Time.now}</p>
103 <p>File: <%= seq_file %></p>
104 <h2>Sequence composition</h2>
106 <tr><td></td><td>Before trimming</td><td>After trimming</td><td>After adaptor removal</td></tr>
107 <tr><td>Number of sequences</td><td align='right'><%= analysis1['COUNT'] %></td><td align='right'><%= analysis2['COUNT'] %></td><td align='right'><%= analysis3['COUNT'] %></td></tr>
108 <tr><td>Number of bases</td><td align='right'><%= analysis1['SUM'] %></td><td align='right'><%= analysis2['SUM'] %></td><td align='right'><%= analysis3['SUM'] %></td></tr>
109 <tr><td>Min sequence length</td><td align='right'><%= analysis1['MIN'] %></td><td align='right'><%= analysis2['MIN'] %></td><td align='right'><%= analysis3['MIN'] %></td></tr>
110 <tr><td>Max sequence length</td><td align='right'><%= analysis1['MAX'] %></td><td align='right'><%= analysis2['MAX'] %></td><td align='right'><%= analysis3['MAX'] %></td></tr>
111 <tr><td>Mean sequence length</td><td align='right'><%= analysis1['MEAN'] %></td><td align='right'><%= analysis2['MEAN'] %></td><td align='right'><%= analysis3['MEAN'] %></td></tr>
113 <p>Sequence trimming was performed by removing from the ends all residues until 3 consecutive</p>
114 <p>residues with quality score larger than or equal to 25.</p>
115 <p>All plots are after sequence trimming and adaptor removal.</p>
116 <h2>Sequence length distribution</h2>
117 <p><img src="<%= png2base64(lendist_file) %>" width="600" /></p>
118 <p><img src="<%= png2base64(lendist_bin_file) %>" width="600" /></p>
119 <h2>Sequence quality scores</h2>
120 <p><img src="<%= png2base64(scores_file) %>" width="600" /></p>
121 <p><img src="<%= png2base64(scores_bin_file) %>" width="600" /></p>
122 <h2>Sequence nucleotide distribution</h2>
123 <p><img src="<%= png2base64(nucdist_file) %>" width="600" /></p>
128 html = ERB.new(template)
130 puts html.result(binding)