class Bio::ClustalW::DEFAULT_PARSER

CLUSTAL W result data (*.aln file) parser class.

Constants

DELIMITER

Delimiter of each entry. Bio::FlatFile uses it. In Bio::ClustalW::Report, it it nil (1 entry 1 file).

Attributes

raw[R]

string of whole result

seqclass[R]

sequence class (one of Bio::Sequence, Bio::Sequence::NA, Bio::Sequence::AA, …)

Public Class Methods

new(str, seqclass = nil) click to toggle source

Creates new instance. str should be a CLUSTAL format string. seqclass should on of following:

# File lib/bio/appl/clustalw/report.rb, line 45
def initialize(str, seqclass = nil)
  @raw = str
  @align = nil
  @match_line = nil
  @header = nil
  case seqclass
  when /PROTEIN/i
    @seqclass = Bio::Sequence::AA
  when /[DR]NA/i
    @seqclass = Bio::Sequence::NA
  else
    if seqclass.is_a?(Module) then
      @seqclass = seqclass
    else
      @seqclass = Bio::Sequence
    end
  end
end

Public Instance Methods

align() click to toggle source

This will be deprecated. Instead, please use alignment.

Gets an multiple alignment. Returns a Bio::Alignment object.

# File lib/bio/appl/clustalw/report.rb, line 111
def align
  warn "Bio::ClustalW#align will be deprecated. Please use \'alignment\'."
  alignment
end
alignment() click to toggle source

Gets an multiple alignment. Returns a Bio::Alignment object.

# File lib/bio/appl/clustalw/report.rb, line 102
def alignment
  do_parse() unless @align
  @align
end
get_sequence(row) click to toggle source

Returns the Bio::Sequence in the matrix at row 'row' as Bio::Sequence object. When row is out of range a nil is returned.


Arguments:

  • (required) row: Integer

Returns

Bio::Sequence

# File lib/bio/appl/clustalw/report.rb, line 83
def get_sequence(row)
  a = alignment
  return nil if row < 0 or row >= a.keys.size
  id  = a.keys[row]
  seq = a.to_hash[id]
  s = Bio::Sequence.new(seq.seq)
  s.definition = id
  s
end
header() click to toggle source

Shows first line of the result data, for example, 'CLUSTAL W (1.82) multiple sequence alignment'. Returns a string.

# File lib/bio/appl/clustalw/report.rb, line 73
def header
  @header or (do_parse or @header)
end
match_line() click to toggle source

Shows “match line” of CLUSTAL's alignment result, for example, ':* :* .* * .::. ** :* . * . '. Returns a string.

# File lib/bio/appl/clustalw/report.rb, line 96
def match_line
  @match_line or (do_parse or @match_line)
end
to_a() click to toggle source

Compatibility note: Behavior of the method will be changed in the future.

Gets an array of the sequences. Returns an array of Bio::FastaFormat objects.

# File lib/bio/appl/clustalw/report.rb, line 130
def to_a
  alignment.to_fastaformat_array
end
to_fasta(*arg) click to toggle source

This will be deprecated. Instead, please use alignment.output_fasta.

Gets an fasta-format string of the sequences. Returns a string.

# File lib/bio/appl/clustalw/report.rb, line 120
def to_fasta(*arg)
  warn "Bio::ClustalW::report#to_fasta is deprecated. Please use \'alignment.output_fasta\'"
  alignment.output_fasta(*arg)
end

Private Instance Methods

do_parse() click to toggle source

Parses Clustal W result text.

# File lib/bio/appl/clustalw/report.rb, line 136
def do_parse
  return nil if @align
  a = @raw.split(/\r?\n\r?\n/)
  @header = a.shift.to_s
  xalign = Bio::Alignment.new
  @match_line = ''
  if a.size > 0 then
    a[0].gsub!(/\A(\r?\n)+/, '')
    a.collect! { |x| x.split(/\r?\n/) }
    a.each { |x|
      x.each { |y| y.sub!(/ +\d+\s*$/, '') }} #for -SEQNOS=on option
    @tagsize = ( a[0][0].rindex(/\s/) or -1 ) + 1
    a.each do |x|
      @match_line << x.pop.to_s[@tagsize..-1]
    end
    a[0].each do |y|
      xalign.store(y[0, @tagsize].sub(/\s+\z/, ''), '')
    end
    a.each do |x|
      x.each do |y|
        name = y[0, @tagsize].sub(/\s+\z/, '')
        seq = y[@tagsize..-1]
        xalign[name] << seq
      end
    end
    xalign.collect! { |x| @seqclass.new(x) }
  end
  @align = xalign
  nil
end