3 # Copyright (C) 2007-2013 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 # Read FASTQ entries from one or more files.
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
31 require 'maasha/biopieces'
32 require 'maasha/fastq'
36 allowed_enc = 'auto,base_33,base_64'
39 casts << {:long=>'data_in', :short=>'i', :type=>'files!', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
40 casts << {:long=>'data_in2', :short=>'j', :type=>'files!', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
41 casts << {:long=>'num', :short=>'n', :type=>'uint', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>'0'}
42 casts << {:long=>'encoding', :short=>'e', :type=>'string', :mandatory=>false, :default=>'auto', :allowed=>allowed_enc, :disallowed=>nil}
44 options = Biopieces.options_parse(ARGV, casts)
46 encoding = options[:encoding].to_sym
51 Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
52 unless options[:data_in] and options[:data_in].first == '-'
53 input.each_record do |record|
58 if options[:data_in] and options[:data_in2]
59 raise "data_in files differ" if options[:data_in].size != options[:data_in2].size
61 (0 ... options[:data_in].size).each do |i|
62 file1 = options[:data_in][i]
63 file2 = options[:data_in2][i]
65 io1 = Fastq.open(file1, 'r')
66 io2 = Fastq.open(file2, 'r')
68 while entry1 = io1.get_entry and entry2 = io2.get_entry
70 if entry1.qual_base33? or entry2.qual_base33?
72 elsif entry1.qual_base64? or entry2.qual_base64?
75 raise SeqError, "Could not auto-detect quality score encoding"
79 entry1.qual_convert!(encoding, :base_33)
80 entry2.qual_convert!(encoding, :base_33)
81 entry1.qual_coerce!(:base_33)
82 entry2.qual_coerce!(:base_33)
85 raise SeqError, "Quality score outside valid range" unless entry1.qual_valid?(:base_33)
86 raise SeqError, "Quality score outside valid range" unless entry2.qual_valid?(:base_33)
89 output.puts entry1.to_bp
90 output.puts entry2.to_bp
94 if options[:num] and num >= options[:num]
105 elsif options[:data_in]
106 options[:data_in].each do |file|
107 Fastq.open(file, 'r') do |fastq|
108 fastq.each do |entry|
110 if entry.qual_base33?
112 elsif entry.qual_base64?
115 raise SeqError, "Could not auto-detect quality score encoding"
119 entry.qual_convert!(encoding, :base_33)
120 entry.qual_coerce!(:base_33)
123 raise SeqError, "Quality score outside valid range" unless entry.qual_valid?(:base_33)
126 output.puts entry.to_bp
129 if options[:num] == num
142 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<