3 # Copyright (C) 2007-2013 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 the nucleotide distribution in percent of sequences in the stream.
25 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27 require 'maasha/biopieces'
31 terminals = "dumb,x11,aqua,post,pdf,png,svg"
32 title = "Stacked Histogram"
35 casts << {:long=>'no_stream', :short=>'x', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
36 casts << {:long=>'cols', :short=>'c', :type=>'string', :mandatory=>true, :default=>nil, :allowed=>nil, :disallowed=>nil}
37 casts << {:long=>'rows', :short=>'r', :type=>'string', :mandatory=>true, :default=>nil, :allowed=>nil, :disallowed=>nil}
38 casts << {:long=>'data_out', :short=>'o', :type=>'file', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
39 casts << {:long=>'terminal', :short=>'t', :type=>'string', :mandatory=>false, :default=>'dumb', :allowed=>terminals, :disallowed=>nil}
40 casts << {:long=>'title', :short=>'T', :type=>'string', :mandatory=>false, :default=>title, :allowed=>nil, :disallowed=>nil}
41 casts << {:long=>'xlabel', :short=>'X', :type=>'string', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
42 casts << {:long=>'ylabel', :short=>'Y', :type=>'string', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
44 options = Biopieces.options_parse(ARGV, casts)
45 options[:xlabel] ||= options[:cols].capitalize
46 options[:ylabel] ||= options[:rows].capitalize
52 @data = Hash.new { |h, k| h[k] = Hash.new(0) }
60 @seen_cols[col] = true
61 @seen_rows[row] = true
65 tabulize() if @table.empty?
79 @seen_cols.keys.each_with_index do |col, i|
80 titles << %{"#{col}" #{i}}
83 "(" + titles.join(", ") + ")"
89 @seen_rows.size.times { @table << Array.new(@seen_cols.size, 0) } # table init
93 @seen_cols.each_key do |col|
96 @seen_rows.each_key do |row|
97 @table[j][i] = @data[col][row]
109 data = PlotData.new()
111 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
112 input.each_record do |record|
113 cols = record[options[:cols].to_sym]
114 rows = record[options[:rows].to_sym]
120 output.puts record unless options[:no_stream]
125 Gnuplot::Plot.new(gp) do |plot|
126 plot.terminal options[:terminal]
127 plot.title options[:title]
128 plot.xlabel options[:xlabel]
129 plot.ylabel options[:ylabel]
130 plot.output options[:data_out] if options[:data_out]
133 plot.key "outside right top vertical Left reverse enhanced autotitles columnhead nobox"
134 plot.key "invert samplen 4 spacing 1 width 0 height 0"
135 plot.style "fill solid 0.5 border"
136 plot.style "histogram rowstacked"
137 plot.style "data histograms"
138 plot.boxwidth "0.75 absolute"
140 plot.xtics "norangelimit"
141 plot.xtics data.col_titles
143 data.each_with_index do |row, i|
144 plot.data << Gnuplot::DataSet.new(row.unshift(0)) do |ds|
145 ds.using = "1:xtic(2)"
146 ds.title = data.row_titles(i)
152 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<