Class: Bio::DB::Exonerate::Alignment
- Inherits:
-
Object
- Object
- Bio::DB::Exonerate::Alignment
- Defined in:
- lib/bio/db/exonerate.rb
Instance Attribute Summary collapse
-
#g ⇒ Object
Returns the value of attribute g.
-
#line ⇒ Object
Returns the value of attribute line.
-
#pi ⇒ Object
Returns the value of attribute pi.
-
#ql ⇒ Object
Returns the value of attribute ql.
-
#query_end ⇒ Object
Returns the value of attribute query_end.
-
#query_id ⇒ Object
Returns the value of attribute query_id.
-
#query_start ⇒ Object
Returns the value of attribute query_start.
-
#query_strand ⇒ Object
Returns the value of attribute query_strand.
-
#score ⇒ Object
Returns the value of attribute score.
-
#target_end ⇒ Object
Returns the value of attribute target_end.
-
#target_id ⇒ Object
Returns the value of attribute target_id.
-
#target_start ⇒ Object
Returns the value of attribute target_start.
-
#target_strand ⇒ Object
Returns the value of attribute target_strand.
-
#tl ⇒ Object
Returns the value of attribute tl.
-
#vulgar_block ⇒ Object
Returns the value of attribute vulgar_block.
Class Method Summary collapse
-
.parse_custom(line) ⇒ Object
This one day may grow to work with complex ryo.…
Instance Method Summary collapse
-
#exon_on_gene_position(position) ⇒ Object
This assumes that the gene is the query and the chromosome is the target.
- #identity ⇒ Object
- #parse_sugar(sugar_str) ⇒ Object
-
#parse_vulgar(vulgar_str) ⇒ Object
The vulgar has to be parsed AFTER the sugar, otherwise it is impossible to determine the orientations.
- #print_features ⇒ Object
- #query ⇒ Object
- #query_coverage ⇒ Object
- #query_length ⇒ Object
- #query_position_on_target(position, base: 0) ⇒ Object
- #target ⇒ Object
- #tarpostion_from_query_position(position) ⇒ Object
Instance Attribute Details
#g ⇒ Object
Returns the value of attribute g.
48 49 50 |
# File 'lib/bio/db/exonerate.rb', line 48 def g @g end |
#line ⇒ Object
Returns the value of attribute line.
49 50 51 |
# File 'lib/bio/db/exonerate.rb', line 49 def line @line end |
#pi ⇒ Object
Returns the value of attribute pi.
48 49 50 |
# File 'lib/bio/db/exonerate.rb', line 48 def pi @pi end |
#ql ⇒ Object
Returns the value of attribute ql.
48 49 50 |
# File 'lib/bio/db/exonerate.rb', line 48 def ql @ql end |
#query_end ⇒ Object
Returns the value of attribute query_end.
46 47 48 |
# File 'lib/bio/db/exonerate.rb', line 46 def query_end @query_end end |
#query_id ⇒ Object
Returns the value of attribute query_id.
46 47 48 |
# File 'lib/bio/db/exonerate.rb', line 46 def query_id @query_id end |
#query_start ⇒ Object
Returns the value of attribute query_start.
46 47 48 |
# File 'lib/bio/db/exonerate.rb', line 46 def query_start @query_start end |
#query_strand ⇒ Object
Returns the value of attribute query_strand.
46 47 48 |
# File 'lib/bio/db/exonerate.rb', line 46 def query_strand @query_strand end |
#score ⇒ Object
Returns the value of attribute score.
47 48 49 |
# File 'lib/bio/db/exonerate.rb', line 47 def score @score end |
#target_end ⇒ Object
Returns the value of attribute target_end.
47 48 49 |
# File 'lib/bio/db/exonerate.rb', line 47 def target_end @target_end end |
#target_id ⇒ Object
Returns the value of attribute target_id.
47 48 49 |
# File 'lib/bio/db/exonerate.rb', line 47 def target_id @target_id end |
#target_start ⇒ Object
Returns the value of attribute target_start.
47 48 49 |
# File 'lib/bio/db/exonerate.rb', line 47 def target_start @target_start end |
#target_strand ⇒ Object
Returns the value of attribute target_strand.
47 48 49 |
# File 'lib/bio/db/exonerate.rb', line 47 def target_strand @target_strand end |
#tl ⇒ Object
Returns the value of attribute tl.
48 49 50 |
# File 'lib/bio/db/exonerate.rb', line 48 def tl @tl end |
#vulgar_block ⇒ Object
Returns the value of attribute vulgar_block.
48 49 50 |
# File 'lib/bio/db/exonerate.rb', line 48 def vulgar_block @vulgar_block end |
Class Method Details
.parse_custom(line) ⇒ Object
This one day may grow to work with complex ryo.…
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bio/db/exonerate.rb', line 52 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
184 185 186 187 188 189 190 191 |
# File 'lib/bio/db/exonerate.rb', line 184 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 |
#identity ⇒ Object
100 101 102 |
# File 'lib/bio/db/exonerate.rb', line 100 def identity @pi end |
#parse_sugar(sugar_str) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/bio/db/exonerate.rb', line 119 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
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/bio/db/exonerate.rb', line 156 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 |
#print_features ⇒ Object
219 220 221 222 223 224 225 226 |
# File 'lib/bio/db/exonerate.rb', line 219 def print_features out = String.new @vulgar_block.each do | vulgar | out << vulgar.to_s << "\n" end out end |
#query ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bio/db/exonerate.rb', line 69 def query unless @query @query = Bio::DB::Fasta::Region.new() @query.entry = query_id @query.start = query_start + 1 @query.end = query_end @query.orientation = query_strand if @query.orientation == :reverse @query.end = query_start @query.start = query_end + 1 end @query end @query end |
#query_coverage ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bio/db/exonerate.rb', line 106 def query_coverage total_m = 0 vulgar_block.each do |v| #p v.label if v.label == :M total_m += v.query_length end end #puts "Total m #{total_m}" #puts "ql #{query_length}" return 100.00 * total_m.to_f / query_length.to_f end |
#query_length ⇒ Object
103 104 105 |
# File 'lib/bio/db/exonerate.rb', line 103 def query_length @ql end |
#query_position_on_target(position, base: 0) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/bio/db/exonerate.rb', line 193 def query_position_on_target(position, base:0) vulgar = exon_on_gene_position(position) qr = vulgar.query_region tr = vulgar.target_region offset = qr.orientation == :forward ? position - qr.start + 1 : qr.end - position #puts vulgar.to_s #puts "SNP position: #{position}" #puts vulgar.query_region #puts vulgar.query_region.orientation #puts "Offset query: #{offset}" #puts vulgar.target_region #puts vulgar.target_region.orientation new_pos = tr.orientation == :forward ? offset + tr.start - 1 : tr.end - offset + 1 return new_pos end |
#target ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bio/db/exonerate.rb', line 85 def target unless @target @target = Bio::DB::Fasta::Region.new() @target.entry = target_id @target.start = target_start + 1 @target.end = target_end @target.orientation = target_strand if @target.orientation == :reverse @target.end = target_start @target.start = target_end + 1 end end @target end |
#tarpostion_from_query_position(position) ⇒ Object
213 214 215 216 217 |
# File 'lib/bio/db/exonerate.rb', line 213 def tarpostion_from_query_position(position) ret = nil vulgar_block = exon_on_gene_position(position) ret end |