3 # Copyright (C) 2007-2011 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 # This program is part of the Biopieces framework (www.biopieces.org).
25 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27 # Trim sequence ends for residues with a low quality score.
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 require 'maasha/biopieces'
35 casts << {:long=>'min', :short=>'m', :type=>'uint', :mandatory=>true, :default=>15, :allowed=>nil, :disallowed=>'0'}
36 casts << {:long=>'trim', :short=>'t', :type=>'string', :mandatory=>true, :default=>'both', :allowed=>'left,right,both', :disallowed=>nil}
38 options = Biopieces.options_parse(ARGV, casts)
42 regex_left = Regexp.new("^[#{(ILLUMINA_BASE).chr}-#{(ILLUMINA_BASE + options[:min]).chr}]+")
43 regex_right = Regexp.new("[#{(ILLUMINA_BASE).chr}-#{(ILLUMINA_BASE + options[:min]).chr}]+$")
45 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
46 input.each_record do |record|
47 if record.has_key? :SEQ and record.has_key? :SCORES
50 record[:SCORES].match(regex_right) do |m|
51 record[:SEQ] = record[:SEQ][0 ... record[:SEQ].length - m.to_s.length]
53 record[:SEQ_LEN] = record[:SEQ].length
54 record[:TRIM_LEFT] = m.to_s.length
56 record[:SCORES].match(regex_left) do |m|
57 record[:SEQ] = record[:SEQ][m.to_s.length ... record[:SEQ].length]
59 record[:SEQ_LEN] = record[:SEQ].length
60 record[:TRIM_RIGHT] = $'.length - 1
63 record[:SCORES].match(regex_left) do |m|
64 record[:SEQ] = record[:SEQ][m.to_s.length ... record[:SEQ].length]
66 record[:SEQ_LEN] = record[:SEQ].length
67 record[:TRIM_LEFT] = m.to_s.length
70 record[:SCORES].match(regex_right) do |m|
71 record[:SEQ] = record[:SEQ][0 ... record[:SEQ].length - m.to_s.length]
73 record[:SEQ_LEN] = record[:SEQ].length
74 record[:TRIM_RIGHT] = $`.length - 1
84 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<