]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/plot_scores
fixed x bug in compute
[biopieces.git] / bp_bin / plot_scores
index 337ce0af0b853ce63f6d7c687299fee7429b50eb..20d12e3dffab519884f4642224b78d0dade8ef70 100755 (executable)
@@ -25,7 +25,7 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
-require 'biopieces'
+require 'maasha/biopieces'
 require 'gnuplot'
 require 'pp'
 
@@ -42,32 +42,34 @@ casts << {:long=>'title',     :short=>'T', :type=>'string', :mandatory=>false, :
 casts << {:long=>'xlabel',    :short=>'X', :type=>'string', :mandatory=>false, :default=>xlabel, :allowed=>nil,       :disallowed=>nil}
 casts << {:long=>'ylabel',    :short=>'Y', :type=>'string', :mandatory=>false, :default=>ylabel, :allowed=>nil,       :disallowed=>nil}
 
-bp = Biopieces.new
+options = Biopieces.options_parse(ARGV, casts)
 
-options = bp.parse(ARGV, casts)
-
-BASE_SOLEXA = 64
+ILLUMINA_BASE = 64
+ILLUMINA_MIN  = 0
+ILLUMINA_MAX  = 40
 
 sum_hash   = Hash.new(0)
 count_hash = Hash.new(0)
 
-bp.each_record do |record|
-  if record[:SCORES]
-    scores = record[:SCORES]
-    (0 ... scores.length).each do |i|
-      sum_hash[i]   += (scores[i].ord - BASE_SOLEXA)
-      count_hash[i] += 1
+Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
+  input.each_record do |record|
+    if record[:SCORES]
+      scores = record[:SCORES]
+      (0 ... scores.length).each do |i|
+        sum_hash[i]   += (scores[i].ord - ILLUMINA_BASE)
+        count_hash[i] += 1
+      end
     end
-  end
 
-  bp.puts record unless options[:no_stream]
+    output.puts record unless options[:no_stream]
+  end
 end
 
 x = []
 y = []
 
 (0 ... sum_hash.size).each do |i|
-  x << i
+  x << i + 1
   y << sum_hash[i].to_f / count_hash[i].to_f
 end
 
@@ -79,7 +81,7 @@ Gnuplot.open do |gp|
     plot.ylabel   options[:ylabel]
     plot.output   options[:data_out] if options[:data_out]
     plot.xrange   "[#{x.min - 1}:#{x.max + 1}]"
-    plot.yrange   "[0:40]"
+    plot.yrange   "[#{ILLUMINA_MIN}:#{ILLUMINA_MAX}]"
     plot.style    "fill solid 0.5 border"
     plot.xtics    "out"
     plot.ytics    "out"