]> git.donarmstrong.com Git - biopieces.git/commitdiff
added relative count to plot_nucleotide_distribution
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 27 Nov 2012 07:03:54 +0000 (07:03 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 27 Nov 2012 07:03:54 +0000 (07:03 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2000 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/plot_nucleotide_distribution

index 39702991f1ee42f9ea0656a07dfd29361ed35f19..ea9b0db2513c9ca662788728ebbe60acbe6e9efa 100755 (executable)
@@ -30,6 +30,7 @@ require 'narray'
 require 'pp'
 
 VEC_MAX   = 10_000
+Y_MAX     = 100
 
 terminals = "dumb,x11,aqua,post,pdf,png,svg"
 title     = "Nucleotide Distribution"
@@ -38,6 +39,7 @@ ylabel    = "Nucleotide distribution (%)"
 
 casts = []
 casts << {:long=>'no_stream', :short=>'x', :type=>'flag',   :mandatory=>false, :default=>nil,    :allowed=>nil,       :disallowed=>nil}
+casts << {:long=>'count',     :short=>'c', :type=>'flag',   :mandatory=>false, :default=>nil,    :allowed=>nil,       :disallowed=>nil}
 casts << {:long=>'data_out',  :short=>'o', :type=>'file',   :mandatory=>false, :default=>nil,    :allowed=>nil,       :disallowed=>nil}
 casts << {:long=>'terminal',  :short=>'t', :type=>'string', :mandatory=>false, :default=>'dumb', :allowed=>terminals, :disallowed=>nil}
 casts << {:long=>'title',     :short=>'T', :type=>'string', :mandatory=>false, :default=>title,  :allowed=>nil,       :disallowed=>nil}
@@ -85,6 +87,9 @@ c = ((vec_c / vec_tot) * 100)[0 ... max_len].to_a
 g = ((vec_g / vec_tot) * 100)[0 ... max_len].to_a
 n = ((vec_n / vec_tot) * 100)[0 ... max_len].to_a
 
+vec_tot *= (Y_MAX / vec_tot.max(0).to_f)
+y = vec_tot.to_a
+
 a.unshift 0.0
 t.unshift 0.0
 c.unshift 0.0
@@ -100,7 +105,7 @@ Gnuplot.open do |gp|
     plot.output   options[:data_out] if options[:data_out]
     plot.ytics    "out"
     plot.xtics    "out"
-    plot.yrange   "[0:100]"
+    plot.yrange   "[0:#{Y_MAX}]"
     plot.xrange   "[0:#{max_len}]"
     plot.auto     "fix"
     plot.offsets  "1"
@@ -140,6 +145,13 @@ Gnuplot.open do |gp|
       ds.with  = "histogram lt rgb \"red\""
       ds.title = "A"
     end
+
+    if options[:count]
+      plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
+        ds.with  = "lines lt rgb \"black\""
+        ds.title = "relative count"
+      end
+    end
   end
 end