]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/plot_scores
code update
[biopieces.git] / bp_bin / plot_scores
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2007-2011 Martin A. Hansen.
4
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.
9
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.
14
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.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
22
23 # Plot a histogram of mean sequence quality scores.
24
25 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
26
27
28 require 'biopieces'
29 require 'gnuplot'
30 require 'pp'
31
32 terminals = "dumb,x11,aqua,post,pdf,png,svg"
33
34 casts = []
35 casts << {:long=>'no_stream', :short=>'x', :type=>'flag',   :mandatory=>false, :default=>nil,    :allowed=>nil,       :disallowed=>nil}
36 casts << {:long=>'data_out',  :short=>'o', :type=>'file',   :mandatory=>false, :default=>nil,    :allowed=>nil,       :disallowed=>nil}
37 casts << {:long=>'terminal',  :short=>'t', :type=>'string', :mandatory=>false, :default=>'dumb', :allowed=>terminals, :disallowed=>nil}
38
39 bp = Biopieces.new
40
41 options = bp.parse(ARGV, casts)
42
43 BASE_SOLEXA = 64
44
45 sum_hash   = Hash.new(0)
46 count_hash = Hash.new(0)
47
48 bp.each_record do |record|
49   if record[:SCORES]
50     scores = record[:SCORES]
51     (0 ... scores.length).each do |i|
52       sum_hash[i]   += (scores[i].ord - BASE_SOLEXA)
53       count_hash[i] += 1
54     end
55   end
56
57   bp.puts record unless options[:no_stream]
58 end
59
60 x = []
61 y = []
62
63 (0 ... sum_hash.size).each do |i|
64   x << i
65   y << sum_hash[i].to_f / count_hash[i].to_f
66 end
67
68 Gnuplot.open do |gp|
69   Gnuplot::Plot.new(gp) do |plot|
70     plot.terminal options[:terminal]
71     plot.title    "Mean Quality Scores"
72     plot.ylabel   "Mean score"
73     plot.xlabel   "Sequence position"
74     plot.output   options[:data_out] if options[:data_out]
75     plot.xrange   "[#{x.min - 1}:#{x.max + 1}]"
76     plot.yrange   "[0:40]"
77     plot.style    "fill solid 0.5 border"
78     plot.xtics    "out"
79     plot.ytics    "out"
80     
81     plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
82       ds.with = "boxes"
83       ds.notitle
84     end
85   end
86 end
87
88
89 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
90
91
92 __END__