]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/plot_scores
ported plot_scores to ruby
[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 # This program is part of the Biopieces framework (www.biopieces.org).
24
25 use warnings;
26 use strict;
27 use Maasha::Biopieces;
28 use Maasha::Fastq;
29 use Maasha::Plot;
30
31 # Plot a histogram of mean sequence quality scores.
32
33 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
34
35
36 require 'biopieces'
37 require 'gnuplot'
38 require 'pp'
39
40 terminals = "dumb,x11,aqua,post,pdf,png,svg"
41
42 casts = []
43 casts << {:long=>'no_stream', :short=>'x', :type=>'flag',   :mandatory=>false, :default=>nil,    :allowed=>nil,       :disallowed=>nil}
44 casts << {:long=>'data_out',  :short=>'o', :type=>'file',   :mandatory=>false, :default=>nil,    :allowed=>nil,       :disallowed=>nil}
45 casts << {:long=>'terminal',  :short=>'t', :type=>'string', :mandatory=>false, :default=>'dumb', :allowed=>terminals, :disallowed=>nil}
46
47 bp = Biopieces.new
48
49 options = bp.parse(ARGV, casts)
50
51 BASE_SOLEXA = 64
52
53 sum_hash   = Hash.new(0)
54 count_hash = Hash.new(0)
55
56 bp.each_record do |record|
57   if record[:SCORES]
58     scores = record[:SCORES]
59     (0 ... scores.length).each do |i|
60       sum_hash[i]   += (scores[i].ord - BASE_SOLEXA)
61       count_hash[i] += 1
62     end
63   end
64
65   bp.puts record unless options[:no_stream]
66 end
67
68 x = []
69 y = []
70
71 (0 ... sum_hash.size).each do |i|
72   x << i
73   y << sum_hash[i].to_f / count_hash[i].to_f
74 end
75
76 Gnuplot.open do |gp|
77   Gnuplot::Plot.new(gp) do |plot|
78     plot.terminal options[:terminal]
79     plot.title    "Mean Quality Scores"
80     plot.ylabel   "Mean score"
81     plot.xlabel   "Sequence position"
82     plot.output   options[:data_out] if options[:data_out]
83     plot.xrange   "[#{x.min - 1}:#{x.max + 1}]"
84     plot.yrange   "[0:40]"
85     plot.style    "fill solid 0.5 border"
86     plot.xtics    "out"
87     plot.ytics    "out"
88     
89     plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
90       ds.with = "boxes"
91       ds.notitle
92     end
93   end
94 end
95
96
97 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
98
99
100 __END__