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 not io1.eof? and not io2.eof?
69 entry1 = io1.get_entry
70 entry2 = io2.get_entry
73 if entry1.qual_base33? or entry2.qual_base33?
75 elsif entry1.qual_base64? or entry2.qual_base64?
78 raise SeqError, "Could not auto-detect quality score encoding"
82 entry1.qual_convert!(encoding, :base_33)
83 entry2.qual_convert!(encoding, :base_33)
84 entry1.qual_coerce!(:base_33)
85 entry2.qual_coerce!(:base_33)
88 raise SeqError, "Quality score outside valid range" unless entry1.qual_valid?(:base_33)
89 raise SeqError, "Quality score outside valid range" unless entry2.qual_valid?(:base_33)
92 output.puts entry1.to_bp
93 output.puts entry2.to_bp
97 if options[:num] and num >= options[:num]
108 elsif options[:data_in]
109 options[:data_in].each do |file|
110 Fastq.open(file, 'r') do |fastq|
111 fastq.each do |entry|
113 if entry.qual_base33?
115 elsif entry.qual_base64?
118 raise SeqError, "Could not auto-detect quality score encoding"
122 entry.qual_convert!(encoding, :base_33)
123 entry.qual_coerce!(:base_33)
126 raise SeqError, "Quality score outside valid range" unless entry.qual_valid?(:base_33)
129 output.puts entry.to_bp
132 if options[:num] == num
145 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<