Class: Bio::Phylip::PhylipFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/appl/phylip/alignment.rb

Overview

This is phylip multiple alignment format parser. The two formats, interleaved and non-interleaved, are automatically determined.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ PhylipFormat

create a new object from a string



26
27
28
29
30
31
# File 'lib/bio/appl/phylip/alignment.rb', line 26

def initialize(str)
  @data = str.strip.split(/(?:\r\n|\r|\n)/)
  @first_line = @data.shift
  @number_of_sequences, @alignment_length =
    @first_line.to_s.strip.split(/\s+/).collect { |x| x.to_i }
end

Instance Attribute Details

#alignment_lengthObject (readonly)

alignment length



37
38
39
# File 'lib/bio/appl/phylip/alignment.rb', line 37

def alignment_length
  @alignment_length
end

#number_of_sequencesObject (readonly)

number of sequences



34
35
36
# File 'lib/bio/appl/phylip/alignment.rb', line 34

def number_of_sequences
  @number_of_sequences
end

Instance Method Details

#alignmentObject

Gets the alignment. Returns a Bio::Alignment object.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bio/appl/phylip/alignment.rb', line 54

def alignment
  unless defined? @alignment then
    do_parse
    a = Bio::Alignment.new
    (0...@number_of_sequences).each do |i|
      a.add_seq(@sequences[i], @sequence_names[i])
    end
    @alignment = a
  end
  @alignment
end

#interleaved?Boolean

If the alignment format is “interleaved”, returns true. If not, returns false. It would mistake to determine if the alignment is very short.

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/bio/appl/phylip/alignment.rb', line 42

def interleaved?
  unless defined? @interleaved_flag then
    if /\A +/ =~ @data[1].to_s then
      @interleaved_flag = false
    else
      @interleaved_flag = true
    end
  end
  @interleaved_flag
end