Class: Bio::DB::Exonerate::Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/db/exonerate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gObject

Returns the value of attribute g.



49
50
51
# File 'lib/bio/db/exonerate.rb', line 49

def g
  @g
end

#lineObject

Returns the value of attribute line.



50
51
52
# File 'lib/bio/db/exonerate.rb', line 50

def line
  @line
end

#piObject

Returns the value of attribute pi.



49
50
51
# File 'lib/bio/db/exonerate.rb', line 49

def pi
  @pi
end

#qlObject

Returns the value of attribute ql.



49
50
51
# File 'lib/bio/db/exonerate.rb', line 49

def ql
  @ql
end

#query_endObject

Returns the value of attribute query_end.



47
48
49
# File 'lib/bio/db/exonerate.rb', line 47

def query_end
  @query_end
end

#query_idObject

Returns the value of attribute query_id.



47
48
49
# File 'lib/bio/db/exonerate.rb', line 47

def query_id
  @query_id
end

#query_startObject

Returns the value of attribute query_start.



47
48
49
# File 'lib/bio/db/exonerate.rb', line 47

def query_start
  @query_start
end

#query_strandObject

Returns the value of attribute query_strand.



47
48
49
# File 'lib/bio/db/exonerate.rb', line 47

def query_strand
  @query_strand
end

#scoreObject

Returns the value of attribute score.



48
49
50
# File 'lib/bio/db/exonerate.rb', line 48

def score
  @score
end

#target_endObject

Returns the value of attribute target_end.



48
49
50
# File 'lib/bio/db/exonerate.rb', line 48

def target_end
  @target_end
end

#target_idObject

Returns the value of attribute target_id.



48
49
50
# File 'lib/bio/db/exonerate.rb', line 48

def target_id
  @target_id
end

#target_startObject

Returns the value of attribute target_start.



48
49
50
# File 'lib/bio/db/exonerate.rb', line 48

def target_start
  @target_start
end

#target_strandObject

Returns the value of attribute target_strand.



48
49
50
# File 'lib/bio/db/exonerate.rb', line 48

def target_strand
  @target_strand
end

#tlObject

Returns the value of attribute tl.



49
50
51
# File 'lib/bio/db/exonerate.rb', line 49

def tl
  @tl
end

#vulgar_blockObject

Returns the value of attribute vulgar_block.



49
50
51
# File 'lib/bio/db/exonerate.rb', line 49

def vulgar_block
  @vulgar_block
end

Class Method Details

.parse_custom(line) ⇒ Object

This one day may grow to work with complex ryo.…



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bio/db/exonerate.rb', line 53

def self.parse_custom(line)
  fields=line.split(/\t/)
  if fields[0] == "RESULT:"
    al = Bio::DB::Exonerate::Alignment.new()      
    al.parse_sugar(fields[1])
    al.pi = fields[2].to_f 
    al.ql = fields[3].to_i
    al.tl = fields[4].to_i
    al.g  = fields[5]
    al.parse_vulgar(fields[6])
    al.line = line
    return al
  else
    return nil
  end
end

Instance Method Details

#exon_on_gene_position(position) ⇒ Object

This assumes that the gene is the query and the chromosome is the target



139
140
141
142
143
144
145
146
# File 'lib/bio/db/exonerate.rb', line 139

def exon_on_gene_position(position)
  @vulgar_block.each do |vulgar|
    if position.between?(vulgar.query_start, vulgar.query_end)
      return vulgar
    end
  end
  nil
end

#identityObject



70
71
72
# File 'lib/bio/db/exonerate.rb', line 70

def identity
  @pi
end

#parse_sugar(sugar_str) ⇒ Object

Raises:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/bio/db/exonerate.rb', line 74

def parse_sugar(sugar_str)
  @query_id, @query_start, @query_end, @query_strand, @target_id, @target_start, @target_end, @target_strand, @score = sugar_str.split(/\s+/)

  @query_start  = @query_start.to_i
  @query_end = @query_end.to_i
  @target_start = @target_start.to_i
  @target_end = @target_end.to_i
  @score = @score.to_f

  if @target_strand == "+"
    @target_strand = :forward
  elsif @target_strand == "-"
    @target_strand = :reverse
  else
    raise  ExonerateException.new(), "Ivalid target orientation #{@target_strand} for line:\n#{sugar_str}"
  end


  if @query_strand == "+"
    @query_strand = :forward
  elsif @query_strand == "-"
    @query_strand = :reverse
  else
    raise  ExonerateException.new(), "Ivalid query orientation #{@query_strand} for line:\n#{sugar_str}"
  end

  raise  ExonerateException.new(), "Inconsistent orientation (forward, query)" if @query_strand == :forward and @query_start > @query_end
  raise  ExonerateException.new(), "Inconsistent orientation (reverse, query)" if @query_strand == :reverse and @query_start < @query_end
  raise  ExonerateException.new(), "Inconsistent orientation (forward, target)" if @target_strand == :forward and @target_start > @target_end
  raise  ExonerateException.new(), "Inconsistent orientation (reverse, target)" if @target_strand == :reverse and @target_start < @target_end


  self
end

#parse_vulgar(vulgar_str) ⇒ Object

The vulgar has to be parsed AFTER the sugar, otherwise it is impossible to determine the orientations



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/bio/db/exonerate.rb', line 111

def parse_vulgar(vulgar_str)

  tarcurrent = @target_start
  query_current = @query_start
  target_multiply = 1
  query_multiply = 1

  if @target_strand == :reverse
    target_multiply = -1
  end

  if @query_strand == :reverse
    query_multiply = -1
  end

  @vulgar_block = Array.new
  # p "VULGAR #{vulgar_str}"
  vulgar_str.split(/\s/).each_slice(3) do | block |
    #    p block
    vulgar = Vulgar.new(block[0].to_sym, block[1].to_i, block[2].to_i, tarcurrent, target_multiply, query_current, query_multiply, self)
    query_current = vulgar.query_end
    tarcurrent = vulgar.target_end
    vulgar_block << vulgar
  end
  self
end


154
155
156
157
158
159
160
161
# File 'lib/bio/db/exonerate.rb', line 154

def print_features
  out = String.new

  @vulgar_block.each do |  vulgar |
    out << vulgar.to_s << "\n"
  end
  out
end

#tarpostion_from_query_position(position) ⇒ Object



148
149
150
151
152
# File 'lib/bio/db/exonerate.rb', line 148

def tarpostion_from_query_position(position)
  ret = nil
  vulgar_block = exon_on_gene_position(position)
  ret
end