# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-require 'biopieces'
+require 'maasha/biopieces'
require 'gnuplot'
require 'pp'
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
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"