3 # Copyright (C) 2007-2011 Martin A. Hansen.
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
21 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23 # Plot a histogram of mean sequence quality scores.
25 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
32 terminals = "dumb,x11,aqua,post,pdf,png,svg"
33 title = "Mean Quality Scores"
34 xlabel = "Sequence position"
38 casts << {:long=>'no_stream', :short=>'x', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
39 casts << {:long=>'data_out', :short=>'o', :type=>'file', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
40 casts << {:long=>'terminal', :short=>'t', :type=>'string', :mandatory=>false, :default=>'dumb', :allowed=>terminals, :disallowed=>nil}
41 casts << {:long=>'title', :short=>'T', :type=>'string', :mandatory=>false, :default=>title, :allowed=>nil, :disallowed=>nil}
42 casts << {:long=>'xlabel', :short=>'X', :type=>'string', :mandatory=>false, :default=>xlabel, :allowed=>nil, :disallowed=>nil}
43 casts << {:long=>'ylabel', :short=>'Y', :type=>'string', :mandatory=>false, :default=>ylabel, :allowed=>nil, :disallowed=>nil}
47 options = bp.parse(ARGV, casts)
51 sum_hash = Hash.new(0)
52 count_hash = Hash.new(0)
54 bp.each_record do |record|
56 scores = record[:SCORES]
57 (0 ... scores.length).each do |i|
58 sum_hash[i] += (scores[i].ord - BASE_SOLEXA)
63 bp.puts record unless options[:no_stream]
69 (0 ... sum_hash.size).each do |i|
71 y << sum_hash[i].to_f / count_hash[i].to_f
75 Gnuplot::Plot.new(gp) do |plot|
76 plot.terminal options[:terminal]
77 plot.title options[:title]
78 plot.xlabel options[:xlabel]
79 plot.ylabel options[:ylabel]
80 plot.output options[:data_out] if options[:data_out]
81 plot.xrange "[#{x.min - 1}:#{x.max + 1}]"
83 plot.style "fill solid 0.5 border"
87 plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
95 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<