#!/usr/bin/env ruby # Copyright (C) 2007-2011 Martin A. Hansen. # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # http://www.gnu.org/copyleft/gpl.html # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< # This program is part of the Biopieces framework (www.biopieces.org). use warnings; use strict; use Maasha::Biopieces; use Maasha::Fastq; use Maasha::Plot; # Plot a histogram of mean sequence quality scores. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< require 'biopieces' require 'gnuplot' require 'pp' terminals = "dumb,x11,aqua,post,pdf,png,svg" casts = [] casts << {:long=>'no_stream', :short=>'x', :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} bp = Biopieces.new options = bp.parse(ARGV, casts) BASE_SOLEXA = 64 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 end end bp.puts record unless options[:no_stream] end x = [] y = [] (0 ... sum_hash.size).each do |i| x << i y << sum_hash[i].to_f / count_hash[i].to_f end Gnuplot.open do |gp| Gnuplot::Plot.new(gp) do |plot| plot.terminal options[:terminal] plot.title "Mean Quality Scores" plot.ylabel "Mean score" plot.xlabel "Sequence position" plot.output options[:data_out] if options[:data_out] plot.xrange "[#{x.min - 1}:#{x.max + 1}]" plot.yrange "[0:40]" plot.style "fill solid 0.5 border" plot.xtics "out" plot.ytics "out" plot.data << Gnuplot::DataSet.new([x, y]) do |ds| ds.with = "boxes" ds.notitle end end end # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< __END__