Class: Hit

Inherits:
Object
  • Object
show all
Defined in:
lib/gene_assembler/hit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hit_name, s_length, q_frame, type) ⇒ Hit

Returns a new instance of Hit.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gene_assembler/hit.rb', line 4

def initialize (hit_name, s_length, q_frame, type)
  @name=hit_name #Nombre tomado del subject_id

  #@s_seq=s_seq #Secuencia del subject

  #@q_seq=q_seq #Secuencia del query

  @s_length=s_length # Longitud total del subject

  @hsps=[]
  if q_frame>0
    @reversed=FALSE
  else
    @reversed=TRUE
  end
  @type=type
  @source=nil
  @description=nil
  @e_value=nil
  @q_p_ident=nil
  @q_p_conserved=nil
  
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def description
  @description
end

#e_valueObject

Returns the value of attribute e_value.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def e_value
  @e_value
end

#hspsObject

Returns the value of attribute hsps.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def hsps
  @hsps
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def name
  @name
end

#q_p_conservedObject

Returns the value of attribute q_p_conserved.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def q_p_conserved
  @q_p_conserved
end

#q_p_identObject

Returns the value of attribute q_p_ident.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def q_p_ident
  @q_p_ident
end

#reversedObject

Returns the value of attribute reversed.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def reversed
  @reversed
end

#s_lengthObject

Returns the value of attribute s_length.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def s_length
  @s_length
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def source
  @source
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/gene_assembler/hit.rb', line 3

def type
  @type
end

Instance Method Details

#add_hsp(q_beg, q_end, s_beg, s_end, align_len, score, ident, gaps) ⇒ Object



24
25
26
27
28
# File 'lib/gene_assembler/hit.rb', line 24

def add_hsp(q_beg, q_end, s_beg, s_end, align_len, score, ident, gaps)
  hsp= Hsp.new(q_beg, q_end, s_beg, s_end, align_len, score, ident, gaps)
  @hsps << hsp
  return hsp
end

#correct_hsps(blast_coor_type) ⇒ Object

‘s’ => subject, ‘q’ => query



148
149
150
151
152
153
154
155
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
182
183
184
185
186
# File 'lib/gene_assembler/hit.rb', line 148

def correct_hsps(blast_coor_type)# 's' => subject, 'q' => query 

#   puts self.inspect

   if hsp_count>1
    delete_hsps=[]
    each_hsp_with_index{|hsp,i|
      each_hsp_with_index{|hsp_second,j|
        if i==j
          next
        end
#         puts hsp.compare(hsp_second)

         compare=nil
         if blast_coor_type == 's'
           compare = hsp.compare(hsp_second)
         else
           compare = hsp.compare_q(hsp_second)
         end
        if compare >= 0.9
          if hsp.score == hsp_second.score # En caso de hsps con scores iguales, nos quedamos con el mas pequeño

            if hsp.align_len == hsp_second.align_len # Si dos hsps son exactamente iguales eliminamos el segundo

              delete_hsps << j
            elsif hsp.align_len < hsp_second.align_len
              delete_hsps << j
            else
              delete_hsps << i
            end           
          elsif hsp.score > hsp_second.score
            delete_hsps << j
          else
            delete_hsps << i
          end
        end
      }
    }
    delete_hsps.uniq!
    delete_hsps.reverse_each do |hsp|
      drop_hsp(hsp)
    end
  end
end

#drop_hsp(position) ⇒ Object



188
189
190
# File 'lib/gene_assembler/hit.rb', line 188

def drop_hsp(position)
  hsps.delete_at(position)
end

#each_hspObject



30
31
32
33
34
# File 'lib/gene_assembler/hit.rb', line 30

def each_hsp
  @hsps.each do |hsp|
    yield hsp
  end
end

#each_hsp_with_indexObject



47
48
49
50
51
# File 'lib/gene_assembler/hit.rb', line 47

def each_hsp_with_index
  @hsps.each_with_index do |hsp,i|
    yield hsp,i
  end
end

#first_hspObject



65
66
67
68
69
70
71
72
# File 'lib/gene_assembler/hit.rb', line 65

def first_hsp
  h=nil
  each_hsp{|hit|
     h=hit
     break
  }
  return h
end

#hsp_at(n) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/gene_assembler/hit.rb', line 36

def hsp_at(n)
  hsp_at=nil
  each_hsp_with_index{|hsp,i|
    if n==i
      hsp_at=hsp
      break
    end
  }
  return hsp_at
end

#hsp_countObject



57
58
59
60
61
62
63
# File 'lib/gene_assembler/hit.rb', line 57

def hsp_count
  n=0
  each_hsp{|hsp|
    n+=1
  }
  return n
end

#hsp_minor_than?(hsp_length) ⇒ Boolean

En nt

Returns:

  • (Boolean)


137
138
139
140
141
142
143
144
145
146
# File 'lib/gene_assembler/hit.rb', line 137

def hsp_minor_than?(hsp_length)# En nt

  minor=FALSE
  each_hsp {|hsp|
    if hsp.length_q < hsp_length
      minor=TRUE
      break
    end 
  }
  return minor
end

#hsp_overlapObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gene_assembler/hit.rb', line 111

def hsp_overlap
  overlap=[]
  last_hsp=nil
  each_hsp_with_index{|hsp,i|
    if i>0
      diference=hsp.overlap_with(last_hsp)
      if diference<0
        overlap << diference
      end
    end
    last_hsp=hsp
   }
   return overlap
end

#hsps_correlative?Boolean

Ver si los hsps del hit son contiguos en la query

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/gene_assembler/hit.rb', line 82

def hsps_correlative?  # Ver si los hsps del hit son contiguos en la query

  is_correlative=FALSE
  ends=0
  each_hsp_with_index{|hsp,i|
    if i==0
      ends=hsp.q_end
      next
    end
    if (ends-hsp.q_beg).abs>3
      is_correlative=TRUE
      break
    end
    ends=hsp.q_end
  }
  return is_correlative
end

#hsps_sort!Object

Se ordenan los hsps en base a posicion en el subject



53
54
55
# File 'lib/gene_assembler/hit.rb', line 53

def hsps_sort! # Se ordenan los hsps en base a posicion en el subject

  @hsps.sort!{|e1,e2| e1.s_beg<=>e2.s_beg}
end

#last_hspObject



74
75
76
77
78
79
80
# File 'lib/gene_assembler/hit.rb', line 74

def last_hsp
  h=nil
  each_hsp{|hit|
     h=hit
  }
  return h
end

#modified_coordenates(add) ⇒ Object



99
100
101
102
103
# File 'lib/gene_assembler/hit.rb', line 99

def modified_coordenates(add)
  each_hsp{|hsp|
    hsp.modified_coordenates(add)
  }
end

#overlap_with(last_hit) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# File 'lib/gene_assembler/hit.rb', line 126

def overlap_with(last_hit)
  overlap=0
  if self.name==last_hit.name
    diference=self.first_hsp.overlap_with(last_hit.last_hsp)
    if diference<0
      overlap=diference
    end
  end
  return overlap
end

#rev_coord(contig_length) ⇒ Object



105
106
107
108
109
# File 'lib/gene_assembler/hit.rb', line 105

def rev_coord(contig_length)
  each_hsp{|hsp|
    hsp.rev_coord(contig_length)
  }
end