Class: FastaWriter
- Inherits:
-
Object
- Object
- FastaWriter
- Defined in:
- lib/bigbio/db/fasta/fastawriter.rb
Overview
Fasta writer
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(fn) ⇒ FastaWriter
constructor
Open a FASTA stream for writing.
-
#write(id, seq = nil) ⇒ Object
write a FASTA item.
Constructor Details
#initialize(fn) ⇒ FastaWriter
Open a FASTA stream for writing
6 7 8 |
# File 'lib/bigbio/db/fasta/fastawriter.rb', line 6 def initialize fn @f = File.open(fn,"w") end |
Instance Method Details
#close ⇒ Object
27 28 29 |
# File 'lib/bigbio/db/fasta/fastawriter.rb', line 27 def close @f.close end |
#write(id, seq = nil) ⇒ Object
write a FASTA item. Normally write using id,seq. If only one item is passed in, the item should respond to descr and seq, or id and seq.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bigbio/db/fasta/fastawriter.rb', line 12 def write id, seq = nil if seq == nil item = id if item.respond_to?(:descr) @f.write ">"+item.descr+"\n" else @f.write ">"+item.id+"\n" end @f.write item.seq.to_s.strip+"\n" else @f.write ">"+id+"\n" @f.write seq.to_s.strip+"\n" end end |