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)
50 @data = Hash.new { |h, k| h[k] = Hash.new(0) }
58 @seen_cols[col] = true
59 @seen_rows[row] = true
63 tabulize() if @table.empty?
77 @seen_cols.keys.each_with_index do |col, i|
78 titles << %{"#{col}" #{i}}
81 "(" + titles.join(", ") + ")"
87 @seen_rows.size.times { @table << Array.new(@seen_cols.size, 0) } # table init
91 @seen_cols.each_key do |col|
94 @seen_rows.each_key do |row|
95 @table[j][i] = @data[col][row]
107 data = PlotData.new()
109 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
110 input.each_record do |record|
111 cols = record[options[:cols].to_sym]
112 rows = record[options[:rows].to_sym]
118 output.puts record unless options[:no_stream]
123 Gnuplot::Plot.new(gp) do |plot|
124 plot.terminal options[:terminal]
125 plot.title options[:title]
126 plot.xlabel options[:xlabel]
127 plot.ylabel options[:ylabel]
128 plot.output options[:data_out] if options[:data_out]
130 # plot.yrange "[0:100]"
131 # plot.xrange "[0:#{max_len}]"
134 plot.key "outside right top vertical Left reverse enhanced autotitles columnhead nobox"
135 plot.key "invert samplen 4 spacing 1 width 0 height 0"
136 plot.style "fill solid 0.5 border"
137 plot.style "histogram rowstacked"
138 plot.style "data histograms"
139 plot.boxwidth "0.75 absolute"
141 plot.xtics "norangelimit"
142 plot.xtics data.col_titles
144 data.each_with_index do |row, i|
145 plot.data << Gnuplot::DataSet.new(row.unshift(0)) do |ds|
146 ds.using = "1:xtic(2)"
147 ds.title = data.row_titles(i)
153 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<