class Bio::Alignment::DEFAULT_PARSER

Data class for fasta-formatted multiple sequence alignment data, which is simply multiple entiries of fasta formatted sequences.

Constants

DELIMITER

delimiter for flatfile

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
46 def initialize(str)
47   ff = Bio::FlatFile.new(Bio::FastaFormat, StringIO.new(str))
48   @data = ff.to_a
49   @alignment = nil
50   @seq_method = nil
51 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
60 def alignment(method = nil)
61   m = determine_seq_method(@data, method)
62   if !@alignment or m != @seq_method then
63     @seq_method = m
64     @alignment = do_parse(@data, @seq_method)
65   end
66   @alignment
67 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
 78 def determine_seq_method(data, m = nil)
 79   case m
 80   when :aaseq
 81     :aaseq
 82   when :naseq
 83     :naseq
 84   when :seq
 85     :seq
 86   when nil
 87     # auto-detection
 88     score = 0
 89     data[0, 3].each do |e|
 90       k = e.to_seq.guess
 91       if k == Bio::Sequence::NA then
 92         score += 1
 93       elsif k == Bio::Sequence::AA then
 94         score -= 1
 95       end
 96     end
 97     if score > 0 then
 98       :naseq
 99     elsif score < 0 then
100       :aaseq
101     else
102       :seq
103     end
104   else
105     raise 'one of :naseq, :aaseq, :seq, or nil should be given'
106   end
107 end
do_parse(ary, seqmethod) click to toggle source

Parses a result.

    # File lib/bio/appl/mafft/report.rb
110 def do_parse(ary, seqmethod)
111   a = Bio::Alignment.new
112   a.add_sequences(ary) do |x|
113     [ x.__send__(seqmethod), x.definition ]
114   end
115   a
116 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
71 def entries
72   @data
73 end