class Bio::Alignment::DEFAULT_PARSER
Data class for fasta-formatted multiple sequence alignment data, which is simply multiple entiries of fasta formatted sequences.
Private Class Methods
new(str)
click to toggle source
Creates a new data object. str
should be a (multi-)fasta
formatted string.
# File lib/bio/appl/mafft/report.rb, line 46 def initialize(str) ff = Bio::FlatFile.new(Bio::FastaFormat, StringIO.new(str)) @data = ff.to_a @alignment = nil @seq_method = nil end
Private Instance Methods
alignment(method = nil)
click to toggle source
Gets an multiple alignment. Returns a Bio::Alignment object. method
should be one of :naseq, :aaseq, :seq, or nil (default). nil means to
automatically determine nucleotide or amino acid.
This method returns previously parsed object if the same method is given (or guessed method is the same).
# File lib/bio/appl/mafft/report.rb, line 60 def alignment(method = nil) m = determine_seq_method(@data, method) if !@alignment or m != @seq_method then @seq_method = m @alignment = do_parse(@data, @seq_method) end @alignment end
determine_seq_method(data, m = nil)
click to toggle source
determines seqtype. if nil is given, try to guess DNA or protein.
# File lib/bio/appl/mafft/report.rb, line 78 def determine_seq_method(data, m = nil) case m when :aaseq :aaseq when :naseq :naseq when :seq :seq when nil # auto-detection score = 0 data[0, 3].each do |e| k = e.to_seq.guess if k == Bio::Sequence::NA then score += 1 elsif k == Bio::Sequence::AA then score -= 1 end end if score > 0 then :naseq elsif score < 0 then :aaseq else :seq end else raise 'one of :naseq, :aaseq, :seq, or nil should be given' end end
do_parse(ary, seqmethod)
click to toggle source
Parses a result.
# File lib/bio/appl/mafft/report.rb, line 110 def do_parse(ary, seqmethod) a = Bio::Alignment.new a.add_sequences(ary) do |x| [ x.__send__(seqmethod), x.definition ] end a end
entries()
click to toggle source
Gets an array of the fasta formatted sequence objects. Returns an array of Bio::FastaFormat objects.
# File lib/bio/appl/mafft/report.rb, line 71 def entries @data end