Class: Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/rocker/alignment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAlignment

Returns a new instance of Alignment.



13
14
15
# File 'lib/rocker/alignment.rb', line 13

def initialize
   @seqs = {}
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



12
13
14
# File 'lib/rocker/alignment.rb', line 12

def cols
  @cols
end

#seqsObject (readonly)

Returns the value of attribute seqs.



12
13
14
# File 'lib/rocker/alignment.rb', line 12

def seqs
  @seqs
end

Instance Method Details

#<<(seq) ⇒ Object



38
39
40
41
42
# File 'lib/rocker/alignment.rb', line 38

def <<(seq)
   @seqs[seq.id] = seq
   @cols = seq.cols if self.cols.nil?
   raise "Aligned sequence #{seq.id} has a different length (#{seq.cols} vs #{self.cols})" unless seq.cols == self.cols
end

#get_idsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rocker/alignment.rb', line 43

def get_ids
   regexps = [/^[A-Za-z]+\|([A-Za-z0-9_]+)\|/, /^([A-Za-z0-9_]+)$/, /^([A-Za-z0-9_]+) /]
   prot_ids = []
   self.seqs.keys.each do |id|
	 prot_id = nil
	 regexps.each do |regexp|
  unless regexp.match(id).nil?
     prot_id = $1
     break
  end
	 end
	 prot_ids << prot_id unless prot_id.nil?
   end
   prot_ids
end

#read_fasta(file) ⇒ Object



16
# File 'lib/rocker/alignment.rb', line 16

def read_fasta(file) self.read_file(file, false) end

#read_file(file, is_rocker) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rocker/alignment.rb', line 18

def read_file(file, is_rocker)
   f = File.open(file, 'r')
   id = nil
   sq = ""
   while ln = f.gets
	 if is_rocker
  next if /^#:(.*)/.match(ln).nil?
  ln = $1
	 end
	 m = /^>(\S+)/.match(ln)
	 if m.nil?
  sq += ln
	 else
  self << Sequence.new(id, sq) unless id.nil?
  id = m[1]
  sq = ""
	 end
   end
   self << Sequence.new(id, sq) unless id.nil?
end

#read_rocker(file) ⇒ Object



17
# File 'lib/rocker/alignment.rb', line 17

def read_rocker(file) self.read_file(file, true) end

#seq(id) ⇒ Object



58
# File 'lib/rocker/alignment.rb', line 58

def seq(id) @seqs[id] end

#sizeObject



59
# File 'lib/rocker/alignment.rb', line 59

def size() self.seqs.size end

#to_sObject



61
# File 'lib/rocker/alignment.rb', line 61

def to_s() self.seqs.values.map{|s| s.to_s}.join + "\n" end

#to_seq_sObject



60
# File 'lib/rocker/alignment.rb', line 60

def to_seq_s() self.seqs.values.map{|s| s.to_seq_s}.join + "\n" end