]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/lib/maasha/fastq.rb
added crufty puts method to fastq.rb
[biopieces.git] / code_ruby / lib / maasha / fastq.rb
1 # Copyright (C) 2007-2011 Martin A. Hansen.
2
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17 # http://www.gnu.org/copyleft/gpl.html
18
19 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
20
21 # This software is part of the Biopieces framework (www.biopieces.org).
22
23 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24
25 require 'maasha/seq'
26 require 'maasha/filesys'
27
28 # Error class for all exceptions to do with FASTQ.
29 class FastqError < StandardError; end
30
31 class Fastq < Filesys
32   # Method to get the next FASTQ entry form an ios and return this
33   # as a Seq object. If no entry is found or eof then nil is returned.
34   def get_entry
35     begin
36       seq_name       = @io.gets.chomp!
37       seq            = @io.gets.chomp!
38       qual_name      = @io.gets.chomp!
39       qual           = @io.gets.chomp!
40
41       entry          = Seq.new
42       entry.type     = @type.nil? ? nil : @type.downcase
43       entry.seq      = seq
44       entry.seq_name = seq_name[1 .. seq_name.length]
45       entry.qual     = qual
46
47       entry
48     rescue
49       nil
50     end
51   end
52
53   # TODO - this should be some custom to_s method instead.
54   def puts(record)
55     if record[:SEQ_NAME] and record[:SEQ] and record[:SCORES]
56       @io.print "@#{record[:SEQ_NAME]}\n"
57       @io.print "#{record[:SEQ]}\n"
58       @io.print "+\n"
59       @io.print "#{record[:SCORES]}\n"
60     end
61   end
62 end
63
64
65 __END__