Class: BioDSL::Fasta
- Inherits:
-
Object
- Object
- BioDSL::Fasta
- Defined in:
- lib/BioDSL/fasta.rb
Defined Under Namespace
Classes: IO
Instance Attribute Summary collapse
-
#seq ⇒ Object
Returns the value of attribute seq.
-
#seq_name ⇒ Object
Returns the value of attribute seq_name.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(io) ⇒ Fasta
constructor
A new instance of Fasta.
-
#next_entry ⇒ Object
Method to get the next FASTA entry form an ios and return this as a Seq object.
- #puts(*args) ⇒ Object
Constructor Details
#initialize(io) ⇒ Fasta
Returns a new instance of Fasta.
60 61 62 63 64 65 66 |
# File 'lib/BioDSL/fasta.rb', line 60 def initialize(io) @io = io @seq_name = nil @seq = "" @got_first = nil @got_last = nil end |
Instance Attribute Details
#seq ⇒ Object
Returns the value of attribute seq.
58 59 60 |
# File 'lib/BioDSL/fasta.rb', line 58 def seq @seq end |
#seq_name ⇒ Object
Returns the value of attribute seq_name.
58 59 60 |
# File 'lib/BioDSL/fasta.rb', line 58 def seq_name @seq_name end |
Class Method Details
Instance Method Details
#each ⇒ Object
68 69 70 71 72 |
# File 'lib/BioDSL/fasta.rb', line 68 def each while entry = next_entry yield entry end end |
#next_entry ⇒ Object
Method to get the next FASTA entry form an ios and return this as a Seq object. If no entry is found or eof then nil is returned.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/BioDSL/fasta.rb', line 80 def next_entry @io.each do |line| line.chomp! next if line.empty? if line[0] == '>' if not @got_first and not @seq.empty? raise FastaError, "Bad FASTA format -> content before Fasta header: #{@seq}" unless @seq.empty? end @got_first = true if @seq_name entry = Seq.new(seq_name: @seq_name, seq: @seq) @seq_name = line[1 .. -1] @seq = "" raise FastaError, "Bad FASTA format -> truncated Fasta header: no content after '>'" if @seq_name.empty? return entry else @seq_name = line[1 .. -1] raise FastaError, "Bad FASTA format -> truncated Fasta header: no content after '>'" if @seq_name.empty? end else @seq << line end end if @seq_name @got_last = true entry = Seq.new(seq_name: @seq_name, seq: @seq) @seq_name = nil return entry end if not @got_last and not @seq.empty? raise FastaError, "Bad FASTA format -> content witout Fasta header: #{@seq}" end nil end |
#puts(*args) ⇒ Object
74 75 76 |
# File 'lib/BioDSL/fasta.rb', line 74 def puts(*args) @io.puts(*args) end |