]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/lib/maasha/seq.rb
changed Seq.new argument to hash
[biopieces.git] / code_ruby / lib / maasha / seq.rb
1 # Copyright (C) 2007-2012 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/bits'
26 require 'maasha/seq/digest'
27 require 'maasha/seq/trim'
28 require 'narray'
29
30 autoload :BackTrack,   'maasha/seq/backtrack'
31 autoload :Dynamic,     'maasha/seq/dynamic'
32 autoload :Homopolymer, 'maasha/seq/homopolymer'
33 autoload :Hamming,     'maasha/seq/hamming'
34 autoload :Levenshtein, 'maasha/seq/levenshtein'
35 autoload :Ambiguity,   'maasha/seq/ambiguity'
36
37 # Residue alphabets
38 DNA     = %w[a t c g]
39 RNA     = %w[a u c g]
40 PROTEIN = %w[f l s y c w p h q r i m t n k v a d e g]
41 INDELS  = %w[. - _ ~]
42
43 # Translation table 11
44 # (http://www.ncbi.nlm.nih.gov/Taxonomy/taxonomyhome.html/index.cgi?chapter=cgencodes#SG11)
45 #   AAs  = FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG
46 # Starts = ---M---------------M------------MMMM---------------M------------
47 # Base1  = TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG
48 # Base2  = TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG
49 # Base3  = TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG
50 TRANS_TAB11_START = {
51   "TTG" => "M", "CTG" => "M", "ATT" => "M", "ATC" => "M",
52   "ATA" => "M", "ATG" => "M", "GTG" => "M"
53 }
54
55 TRANS_TAB11 = {
56   "TTT" => "F", "TCT" => "S", "TAT" => "Y", "TGT" => "C",
57   "TTC" => "F", "TCC" => "S", "TAC" => "Y", "TGC" => "C",
58   "TTA" => "L", "TCA" => "S", "TAA" => "*", "TGA" => "*",
59   "TTG" => "L", "TCG" => "S", "TAG" => "*", "TGG" => "W",
60   "CTT" => "L", "CCT" => "P", "CAT" => "H", "CGT" => "R",
61   "CTC" => "L", "CCC" => "P", "CAC" => "H", "CGC" => "R",
62   "CTA" => "L", "CCA" => "P", "CAA" => "Q", "CGA" => "R",
63   "CTG" => "L", "CCG" => "P", "CAG" => "Q", "CGG" => "R",
64   "ATT" => "I", "ACT" => "T", "AAT" => "N", "AGT" => "S",
65   "ATC" => "I", "ACC" => "T", "AAC" => "N", "AGC" => "S",
66   "ATA" => "I", "ACA" => "T", "AAA" => "K", "AGA" => "R",
67   "ATG" => "M", "ACG" => "T", "AAG" => "K", "AGG" => "R",
68   "GTT" => "V", "GCT" => "A", "GAT" => "D", "GGT" => "G",
69   "GTC" => "V", "GCC" => "A", "GAC" => "D", "GGC" => "G",
70   "GTA" => "V", "GCA" => "A", "GAA" => "E", "GGA" => "G",
71   "GTG" => "V", "GCG" => "A", "GAG" => "E", "GGG" => "G"
72 }
73
74 # Error class for all exceptions to do with Seq.
75 class SeqError < StandardError; end
76
77 class Seq
78   # Quality scores bases
79   SCORE_BASE = 33
80   SCORE_MIN  = 0
81   SCORE_MAX  = 40
82
83   include Digest
84   include Trim
85
86   attr_accessor :seq_name, :seq, :type, :qual
87
88   # Class method to instantiate a new Sequence object given
89   # a Biopiece record.
90   def self.new_bp(record)
91     seq_name = record[:SEQ_NAME]
92     seq      = record[:SEQ]
93     type     = record[:SEQ_TYPE].to_sym if record[:SEQ_TYPE]
94     qual     = record[:SCORES]
95
96     self.new(seq_name: seq_name, seq: seq, type: type, qual: qual)
97   end
98
99   # Class method that generates all possible oligos of a specifed length and type.
100   def self.generate_oligos(length, type)
101     raise SeqError, "Cannot generate negative oligo length: #{length}" if length <= 0
102
103     case type.downcase
104     when :dna     then alph = DNA
105     when :rna     then alph = RNA
106     when :protein then alph = PROTEIN
107     else
108       raise SeqError, "Unknown sequence type: #{type}"
109     end
110
111     oligos = [""]
112
113     (1 .. length).each do
114       list = []
115
116       oligos.each do |oligo|
117         alph.each do |char|
118           list << oligo + char
119         end
120       end
121
122       oligos = list
123     end
124
125     oligos
126   end
127
128   # Initialize a sequence object with the following options:
129   # - :seq_name   Name of the sequence.
130   # - :seq        The sequence.
131   # - :type       The sequence type - DNA, RNA, or protein
132   # - :qual       An Illumina type quality scores string.
133   def initialize(options = {})
134     @seq_name = options[:seq_name]
135     @seq      = options[:seq]
136     @type     = options[:type]
137     @qual     = options[:qual]
138
139     if @qual and @seq.length != @qual.length
140       raise SeqError, "Sequence length and score length mismatch: #{@seq.length} != #{@qual.length}"
141     end
142   end
143
144   # Method that guesses and returns the sequence type
145   # by inspecting the first 100 residues.
146   def type_guess
147     raise SeqError, "Guess failed: sequence is nil" if self.seq.nil?
148
149     case self.seq[0 ... 100].downcase
150     when /[flpqie]/ then return :protein
151     when /[u]/      then return :rna
152     else                 return :dna
153     end
154   end
155
156   # Method that guesses and sets the sequence type
157   # by inspecting the first 100 residues.
158   def type_guess!
159     self.type = self.type_guess
160     self
161   end
162
163   # Returns the length of a sequence.
164   def length
165     self.seq.nil? ? 0 : self.seq.length
166   end
167
168   alias :len :length
169
170   # Return the number indels in a sequence.
171   def indels
172     regex = Regexp.new(/[#{Regexp.escape(INDELS.join(""))}]/)
173     self.seq.scan(regex).size
174   end
175
176   # Method to remove indels from seq and qual if qual.
177   def indels_remove
178     if self.qual.nil?
179       self.seq.delete!(Regexp.escape(INDELS.join('')))
180     else
181       na_seq  = NArray.to_na(self.seq, "byte")
182       na_qual = NArray.to_na(self.qual, "byte")
183       mask    = NArray.byte(self.length)
184
185       INDELS.each do |c|
186         mask += na_seq.eq(c.ord)
187       end
188
189       mask = mask.eq(0)
190
191       self.seq  = na_seq[mask].to_s
192       self.qual = na_qual[mask].to_s
193     end
194
195     self
196   end
197
198   # Method that returns true is a given sequence type is DNA.
199   def is_dna?
200     self.type == :dna
201   end
202
203   # Method that returns true is a given sequence type is RNA.
204   def is_rna?
205     self.type == :rna
206   end
207
208   # Method that returns true is a given sequence type is protein.
209   def is_protein?
210     self.type == :protein
211   end
212
213   # Method to transcribe DNA to RNA.
214   def to_rna
215     raise SeqError, "Cannot transcribe 0 length sequence" if self.length == 0
216     raise SeqError, "Cannot transcribe sequence type: #{self.type}" unless self.is_dna?
217     self.type = :rna
218     self.seq.tr!('Tt','Uu')
219   end
220
221   # Method to reverse-transcribe RNA to DNA.
222   def to_dna
223     raise SeqError, "Cannot reverse-transcribe 0 length sequence" if self.length == 0
224     raise SeqError, "Cannot reverse-transcribe sequence type: #{self.type}" unless self.is_rna?
225     self.type = :dna
226     self.seq.tr!('Uu','Tt')
227   end
228
229   # Method to translate a DNA sequence to protein.
230   def translate!(trans_tab = 11)
231     raise SeqError, "Sequence type must be 'dna' - not #{self.type}" unless self.type == :dna
232     raise SeqError, "Sequence length must be a multiplum of 3 - was: #{self.length}" unless (self.length % 3) == 0
233
234     case trans_tab
235     when 11
236       codon_start_hash = TRANS_TAB11_START
237       codon_hash       = TRANS_TAB11
238     else
239       raise SeqError, "Unknown translation table: #{trans_tab}"
240     end
241
242     codon  = self.seq[0 ... 3].upcase
243
244     aa = codon_start_hash[codon]
245
246     raise SeqError, "Unknown start codon: #{codon}" if aa.nil?
247
248     protein = aa
249
250     i = 3
251
252     while i < self.length
253       codon = self.seq[i ... i + 3].upcase
254
255       aa = codon_hash[codon]
256
257       raise SeqError, "Unknown codon: #{codon}" if aa.nil?
258
259       protein << aa
260
261       i += 3
262     end
263
264     self.seq  = protein
265     self.qual = nil
266     self.type = :protein
267
268     self
269   end
270
271   alias :to_protein! :translate!
272
273   def translate(trans_tab = 11)
274     self.dup.translate!(trans_tab)
275   end
276
277   alias :to_protein :translate
278
279   # Method that given a Seq entry returns a Biopieces record (a hash).
280   def to_bp
281     raise SeqError, "Missing seq_name" if self.seq_name.nil?
282     raise SeqError, "Missing seq"      if self.seq.nil?
283
284     record             = {}
285     record[:SEQ_NAME] = self.seq_name
286     record[:SEQ]      = self.seq
287     record[:SEQ_LEN]  = self.length
288     record[:SCORES]   = self.qual if self.qual
289     record
290   end
291
292   # Method that given a Seq entry returns a FASTA entry (a string).
293   def to_fasta(wrap = nil)
294     raise SeqError, "Missing seq_name" if self.seq_name.nil? or self.seq_name == ''
295     raise SeqError, "Missing seq"      if self.seq.nil?      or self.seq.empty?
296
297     seq_name = self.seq_name.to_s
298     seq      = self.seq.to_s
299
300     unless wrap.nil?
301       seq.gsub!(/(.{#{wrap}})/) do |match|
302         match << $/
303       end
304
305       seq.chomp!
306     end
307
308     ">" + seq_name + $/ + seq + $/
309   end
310
311   # Method that given a Seq entry returns a FASTQ entry (a string).
312   def to_fastq
313     raise SeqError, "Missing seq_name" if self.seq_name.nil?
314     raise SeqError, "Missing seq"      if self.seq.nil?
315     raise SeqError, "Missing qual"     if self.qual.nil?
316
317     seq_name = self.seq_name.to_s
318     seq      = self.seq.to_s
319     qual     = self.qual.to_s
320
321     "@" + seq_name + $/ + seq + $/ + "+" + $/ + qual + $/
322   end
323
324   # Method that generates a unique key for a
325   # DNA sequence and return this key as a Fixnum.
326   def to_key
327     key = 0
328     
329     self.seq.upcase.each_char do |char|
330       key <<= 2
331       
332       case char
333       when 'A' then key |= 0
334       when 'C' then key |= 1
335       when 'G' then key |= 2
336       when 'T' then key |= 3
337       else raise SeqError, "Bad residue: #{char}"
338       end
339     end
340     
341     key
342   end
343
344   # Method to reverse the sequence.
345   def reverse
346     Seq.new(
347       seq_name: self.seq_name,
348       seq:      self.seq.reverse,
349       type:     self.type,
350       qual:     (self.qual ? self.qual.reverse : self.qual)
351     )
352   end
353
354   # Method to reverse the sequence.
355   def reverse!
356     self.seq.reverse!
357     self.qual.reverse! if self.qual
358     self
359   end
360
361   # Method that complements sequence including ambiguity codes.
362   def complement
363     raise SeqError, "Cannot complement 0 length sequence" if self.length == 0
364
365     entry = Seq.new(
366       seq_name: self.seq_name,
367       type:     self.type,
368       qual:     self.qual
369     )
370
371     if self.is_dna?
372       entry.seq = self.seq.tr('AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'TCGAAYRWSKMDHBVNtcgaayrwskmdhbvn')
373     elsif self.is_rna?
374       entry.seq = self.seq.tr('AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'UCGAAYRWSKMDHBVNucgaayrwskmdhbvn')
375     else
376       raise SeqError, "Cannot complement sequence type: #{self.type}"
377     end
378
379     entry
380   end
381
382   # Method that complements sequence including ambiguity codes.
383   def complement!
384     raise SeqError, "Cannot complement 0 length sequence" if self.length == 0
385
386     if self.is_dna?
387       self.seq.tr!('AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'TCGAAYRWSKMDHBVNtcgaayrwskmdhbvn')
388     elsif self.is_rna?
389       self.seq.tr!('AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'UCGAAYRWSKMDHBVNucgaayrwskmdhbvn')
390     else
391       raise SeqError, "Cannot complement sequence type: #{self.type}"
392     end
393
394     self
395   end
396
397   # Method to determine the Hamming Distance between
398   # two Sequence objects (case insensitive).
399   def hamming_distance(entry, options = nil)
400     if options and options[:ambiguity]
401       Hamming.distance(self.seq, entry.seq)
402     else
403       self.seq.upcase.hamming_distance(entry.seq.upcase)
404     end
405   end
406
407   # Method to determine the Edit Distance between
408   # two Sequence objects (case insensitive).
409   def edit_distance(entry)
410     Levenshtein.distance(self.seq, entry.seq)
411   end
412
413   # Method that generates a random sequence of a given length and type.
414   def generate(length, type)
415     raise SeqError, "Cannot generate sequence length < 1: #{length}" if length <= 0
416
417     case type
418     when :dna     then alph = DNA
419     when :rna     then alph = RNA
420     when :protein then alph = PROTEIN
421     else
422       raise SeqError, "Unknown sequence type: #{type}"
423     end
424
425     seq_new   = Array.new(length) { alph[rand(alph.size)] }.join("")
426     self.seq  = seq_new
427     self.type = type
428     seq_new
429   end
430
431   # Method to return a new Seq object with shuffled sequence.
432   def shuffle
433     Seq.new(
434       seq_name: self.seq_name,
435       seq:      self.seq.split('').shuffle!.join,
436       type:     self.type,
437       qual:     self.qual
438     )
439   end
440
441   # Method to shuffle a sequence randomly inline.
442   def shuffle!
443     self.seq = self.seq.split('').shuffle!.join
444     self
445   end
446
447   # Method to add two Seq objects.
448   def +(entry)
449     new_entry = Seq.new()
450     new_entry.seq  = self.seq  + entry.seq
451     new_entry.type = self.type              if self.type == entry.type
452     new_entry.qual = self.qual + entry.qual if self.qual and entry.qual
453     new_entry
454   end
455
456   # Method to concatenate sequence entries.
457   def <<(entry)
458     raise SeqError, "sequences of different types" unless self.type == entry.type
459     raise SeqError, "qual is missing in one entry" unless self.qual.class == entry.qual.class
460
461     self.seq  << entry.seq
462     self.qual << entry.qual unless entry.qual.nil?
463
464     self
465   end
466
467   # Index method for Seq objects.
468   def [](*args)
469     entry = Seq.new
470     entry.seq_name = self.seq_name
471     entry.seq      = self.seq[*args]
472     entry.type     = self.type
473     entry.qual     = self.qual[*args] unless self.qual.nil?
474
475     entry
476   end
477
478   # Index assignment method for Seq objects.
479   def []=(*args, entry)
480     self.seq[*args]  = entry.seq[*args]
481     self.qual[*args] = entry.qual[*args] unless self.qual.nil?
482
483     self
484   end
485
486   # Method that returns a subsequence of from a given start position
487   # and of a given length.
488   def subseq(start, length = self.length - start)
489     raise SeqError, "subsequence start: #{start} < 0"                                                if start  < 0
490     raise SeqError, "subsequence length: #{length} < 0"                                              if length < 0
491     raise SeqError, "subsequence start + length > Seq.length: #{start} + #{length} > #{self.length}" if start + length > self.length
492
493     if length == 0
494       seq  = ""
495       qual = "" unless self.qual.nil?
496     else
497       stop = start + length - 1
498
499       seq  = self.seq[start .. stop]
500       qual = self.qual[start .. stop] unless self.qual.nil?
501     end
502
503     seq_name = self.seq_name.nil? ? nil : self.seq_name.dup
504
505     Seq.new(seq_name: seq_name, seq: seq, type: self.type, qual: qual)
506   end
507
508   # Method that replaces a sequence with a subsequence from a given start position
509   # and of a given length.
510   def subseq!(start, length = self.length - start)
511     s = subseq(start, length)
512
513     self.seq_name = s.seq_name
514     self.seq      = s.seq
515     self.type     = s.type
516     self.qual     = s.qual
517
518     self
519   end
520
521   # Method that returns a subsequence of a given length
522   # beginning at a random position.
523   def subseq_rand(length)
524     if self.length - length + 1 == 0
525       start = 0
526     else
527       start = rand(self.length - length + 1)
528     end
529
530     self.subseq(start, length)
531   end
532
533   # Method that returns the residue compositions of a sequence in
534   # a hash where the key is the residue and the value is the residue
535   # count.
536   def composition
537     comp = Hash.new(0);
538
539     self.seq.upcase.each_char do |char|
540       comp[char] += 1
541     end
542
543     comp
544   end
545
546   # Method that returns the percentage of hard masked residues
547   # or N's in a sequence.
548   def hard_mask
549     ((self.seq.upcase.scan("N").size.to_f / (self.len - self.indels).to_f) * 100).round(2)
550   end
551
552   # Method that returns the percentage of soft masked residues
553   # or lower cased residues in a sequence.
554   def soft_mask
555     ((self.seq.scan(/[a-z]/).size.to_f / (self.len - self.indels).to_f) * 100).round(2)
556   end
557
558   # Hard masks sequence residues where the corresponding quality score
559   # is below a given cutoff.
560   def mask_seq_hard!(cutoff)
561     raise SeqError, "seq is nil"  if self.seq.nil?
562     raise SeqError, "qual is nil" if self.qual.nil?
563     raise SeqError, "cufoff value: #{cutoff} out of range #{SCORE_MIN} .. #{SCORE_MAX}" unless (SCORE_MIN .. SCORE_MAX).include? cutoff
564
565     na_seq  = NArray.to_na(self.seq, "byte")
566     na_qual = NArray.to_na(self.qual, "byte")
567     mask    = (na_qual - SCORE_BASE) < cutoff
568     mask   *= na_seq.ne("-".ord)
569
570     na_seq[mask] = 'N'.ord
571
572     self.seq = na_seq.to_s
573
574     self
575   end
576
577   # Soft masks sequence residues where the corresponding quality score
578   # is below a given cutoff.
579   def mask_seq_soft!(cutoff)
580     raise SeqError, "seq is nil"  if self.seq.nil?
581     raise SeqError, "qual is nil" if self.qual.nil?
582     raise SeqError, "cufoff value: #{cutoff} out of range #{SCORE_MIN} .. #{SCORE_MAX}" unless (SCORE_MIN .. SCORE_MAX).include? cutoff
583
584     na_seq  = NArray.to_na(self.seq, "byte")
585     na_qual = NArray.to_na(self.qual, "byte")
586     mask    = (na_qual - SCORE_BASE) < cutoff
587     mask   *= na_seq.ne("-".ord)
588
589     na_seq[mask] ^= ' '.ord
590
591     self.seq = na_seq.to_s
592
593     self
594   end
595
596   # Method that determines if a quality score string can be
597   # absolutely identified as base 33.
598   def qual_base33?
599     self.qual.match(/[!-:]/) ? true : false
600   end
601  
602   # Method that determines if a quality score string may be base 64.
603   def qual_base64?
604     self.qual.match(/[K-h]/) ? true : false
605   end
606
607   # Method to determine if a quality score is valid accepting only 0-40 range.
608   def qual_valid?(encoding)
609     raise SeqError, "Missing qual" if self.qual.nil?
610
611     case encoding
612     when :base_33 then return true if self.qual.match(/^[!-I]*$/)
613     when :base_64 then return true if self.qual.match(/^[@-h]*$/)
614     else raise SeqError, "unknown quality score encoding: #{encoding}"
615     end
616
617     false
618   end
619
620   # Method to coerce quality scores to be within the 0-40 range.
621   def qual_coerce!(encoding)
622     raise SeqError, "Missing qual" if self.qual.nil?
623
624     case encoding
625     when :base_33 then self.qual.tr!("[J-~]", "I")
626     when :base_64 then self.qual.tr!("[i-~]", "h")
627     else raise SeqError, "unknown quality score encoding: #{encoding}"
628     end 
629
630     self
631   end
632
633   # Method to convert quality scores.
634   def qual_convert!(from, to)
635     raise SeqError, "unknown quality score encoding: #{from}" unless from == :base_33 or from == :base_64
636     raise SeqError, "unknown quality score encoding: #{to}"   unless to   == :base_33 or to   == :base_64
637
638     if from == :base_33 and to == :base_64
639       na_qual   = NArray.to_na(self.qual, "byte")
640       na_qual  += 64 - 33
641       self.qual = na_qual.to_s
642     elsif from == :base_64 and to == :base_33
643       self.qual.tr!("[;-?]", "@")  # Handle negative Solexa values from -5 to -1 (set these to 0).
644       na_qual   = NArray.to_na(self.qual, "byte")
645       na_qual  -= 64 - 33
646       self.qual = na_qual.to_s
647     end
648
649     self
650   end
651
652   # Method to calculate and return the mean quality score.
653   def scores_mean
654     raise SeqError, "Missing qual in entry" if self.qual.nil?
655
656     na_qual = NArray.to_na(self.qual, "byte")
657     na_qual -= SCORE_BASE
658
659     na_qual.mean
660   end
661
662   # Method to find open reading frames (ORFs).
663   def each_orf(size_min, size_max, start_codons, stop_codons, pick_longest = false)
664     orfs    = []
665     pos_beg = 0
666
667     regex_start = Regexp.new(start_codons.join('|'), true)
668     regex_stop  = Regexp.new(stop_codons.join('|'), true)
669
670     while pos_beg and pos_beg < self.length - size_min
671       if pos_beg = self.seq.index(regex_start, pos_beg)
672         if pos_end = self.seq.index(regex_stop, pos_beg)
673           length = (pos_end - pos_beg) + 3
674
675           if (length % 3) == 0
676             if size_min <= length and length <= size_max
677               subseq = self.subseq(pos_beg, length)
678
679               orfs << [subseq, pos_beg, pos_end + 3]
680             end
681           end
682         end
683
684         pos_beg += 1
685       end
686     end
687
688     if pick_longest
689       orf_hash = {}
690
691       orfs.each { |orf| orf_hash[orf.last] = orf unless orf_hash[orf.last] }
692
693       orfs = orf_hash.values
694     end
695
696     if block_given?
697       orfs.each { |orf| yield orf }
698     else
699       return orfs
700     end
701   end
702 end
703
704 __END__