Class: Bio::DB::Primer3::SNP

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSNP

Returns a new instance of SNP.



67
68
69
70
71
# File 'lib/bio/db/primer3.rb', line 67

def initialize
  @primers_line_1 = SortedSet.new
  @primers_line_2 = SortedSet.new
  @reguibs = SortedSet.new
end

Instance Attribute Details

#chromosomeObject

Returns the value of attribute chromosome.



55
56
57
# File 'lib/bio/db/primer3.rb', line 55

def chromosome
  @chromosome
end

#geneObject

Returns the value of attribute gene.



55
56
57
# File 'lib/bio/db/primer3.rb', line 55

def gene
  @gene
end

#line_1Object

Returns the value of attribute line_1.



55
56
57
# File 'lib/bio/db/primer3.rb', line 55

def line_1
  @line_1
end

#line_2Object

Returns the value of attribute line_2.



55
56
57
# File 'lib/bio/db/primer3.rb', line 55

def line_2
  @line_2
end

#originalObject

Returns the value of attribute original.



55
56
57
# File 'lib/bio/db/primer3.rb', line 55

def original
  @original
end

#positionObject

Returns the value of attribute position.



55
56
57
# File 'lib/bio/db/primer3.rb', line 55

def position
  @position
end

#primer3_errorsObject

Returns the value of attribute primer3_errors.



61
62
63
# File 'lib/bio/db/primer3.rb', line 61

def primer3_errors
  @primer3_errors
end

#primer3_line_1Object

Returns the value of attribute primer3_line_1.



56
57
58
# File 'lib/bio/db/primer3.rb', line 56

def primer3_line_1
  @primer3_line_1
end

#primer3_line_2Object

Returns the value of attribute primer3_line_2.



56
57
58
# File 'lib/bio/db/primer3.rb', line 56

def primer3_line_2
  @primer3_line_2
end

#primers_line_1Object

Returns the value of attribute primers_line_1.



57
58
59
# File 'lib/bio/db/primer3.rb', line 57

def primers_line_1
  @primers_line_1
end

#primers_line_2Object

Returns the value of attribute primers_line_2.



57
58
59
# File 'lib/bio/db/primer3.rb', line 57

def primers_line_2
  @primers_line_2
end

#regionsObject

Returns the value of attribute regions.



60
61
62
# File 'lib/bio/db/primer3.rb', line 60

def regions
  @regions
end

#snpObject

Returns the value of attribute snp.



55
56
57
# File 'lib/bio/db/primer3.rb', line 55

def snp
  @snp
end

#snp_fromObject

Returns the value of attribute snp_from.



59
60
61
# File 'lib/bio/db/primer3.rb', line 59

def snp_from
  @snp_from
end

#template_lengthObject

Returns the value of attribute template_length.



56
57
58
# File 'lib/bio/db/primer3.rb', line 56

def template_length
  @template_length
end

#used_contigsObject

Returns the value of attribute used_contigs.



58
59
60
# File 'lib/bio/db/primer3.rb', line 58

def used_contigs
  @used_contigs
end

Class Method Details

.parse(reg_str) ⇒ Object



248
249
250
251
252
253
254
255
256
# File 'lib/bio/db/primer3.rb', line 248

def self.parse(reg_str)
  reg_str.chomp!
  snp = SNP.new
  snp.gene, snp.original, snp.position, snp.snp = reg_str.split(",")
  snp.position = snp.position.to_i
  snp.original.upcase!
  snp.snp.upcase!  
  snp
end

.parse_file(filename) ⇒ Object



258
259
260
261
262
263
264
265
266
267
# File 'lib/bio/db/primer3.rb', line 258

def self.parse_file(filename)
  File.open(filename) do | f |
    f.each_line do | line |
      snp = SNP.parse(line)
      if snp.position > 0
        yield snp
      end
    end
  end
end

Instance Method Details

#add_record(primer3record) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/bio/db/primer3.rb', line 270

def add_record(primer3record)
  @primer3_errors = Array.new unless @primer3_errors
  @template_length = primer3record.sequence_template.size
   if primer3record.primer_error != nil 
      primer3_errors << primer3record
      return
    end
  case
  when primer3record.line == @line_1

    @line_1_template = primer3record.sequence_template

  when primer3record.line == @line_2
    @line_2_template = primer3record.sequence_template
  else
    raise Primer3Exception.new "#{primer3record.line} is not recognized (#{line_1}, #{line_2})"
  end

  if  primer3record.primer_left_num_returned.to_i > 0 
    case
    when primer3record.line == @line_1
      primers_line_1 << primer3record
      #puts primer3record.inspect
      @primer3_line_1 = primer3record if not @primer3_line_1  or @primer3_line_1 > primer3record
    when primer3record.line == @line_2
      primers_line_2 << primer3record
      @primer3_line_2 = primer3record if not @primer3_line_2 or @primer3_line_2 > primer3record
    else
      raise Primer3Exception.new "#{primer3record.line} is not recognized (#{line_1}, #{line_2})"
    end
  end
end

#find_left_primer_temp(primer) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/bio/db/primer3.rb', line 81

def find_left_primer_temp(primer)
  primers_line_1.each do |pr|
    return pr.find_left_tm(primer) if pr.find_left_tm(primer)
  end
  primers_line_2.each do |pr|
    return pr.find_left_tm(primer) if pr.find_left_tm(primer)
  end
  return "NA"
end

#find_primer_pair_firstObject



92
93
94
95
96
97
98
# File 'lib/bio/db/primer3.rb', line 92

def find_primer_pair_first
  primers_line_1.each do |pr|
    primer = pr.left_primer_snp(self)
    return pr if find_left_primer_temp(primer) != "NA"
  end
  nil
end

#find_primer_pair_secondObject



100
101
102
103
104
105
106
# File 'lib/bio/db/primer3.rb', line 100

def find_primer_pair_second
  primers_line_2.each do |pr|
    primer = pr.left_primer_snp(self)
    return pr if find_left_primer_temp(primer) != "NA"
  end
  nil
end

#line_1_nameObject



63
64
65
# File 'lib/bio/db/primer3.rb', line 63

def line_1_name
  "#{gene}:#{position}#{original}>#{snp} #{line_1}}"
end

#line_2_nameObject



73
74
75
# File 'lib/bio/db/primer3.rb', line 73

def line_2_name
  "#{gene}:#{position}#{original}>#{snp} #{line_2}}"
end


109
110
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
137
138
139
140
141
142
143
144
145
146
147
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/bio/db/primer3.rb', line 109

def print_primers
#TODO: Retrieve error messages
  left_start = 0
  left_end = 0
  right_start = 0
  right_end = 0
 #     exons = snp_from.exon_list.values
  
#      puts "Exons: #{exon_list.size}"
  
#      puts "It has the following exons: #{snp_in.exon_list.to_s}"
  values = Array.new
  #values << "#{gene},,#{template_length},"
  values << gene
  values << "#{original}#{position}#{snp}"
  values << template_length
  values << snp_from.chromosome
  values << regions.size
  values << regions.join("|")
  if primer3_line_1 and primer3_line_2
    values <<  primer3_line_1.polymorphism

    #Block that searches both if both pairs have a TM
    primer_2 = primer3_line_2.left_primer_with_coordinates(primer3_line_1.left_coordinates, primer3_line_1.orientation)
    primer_2_tm = find_left_primer_temp(primer_2)
    primer_1 = primer3_line_1.left_primer_with_coordinates(primer3_line_2.left_coordinates, primer3_line_2.orientation) 
    primer_1_tm = find_left_primer_temp(primer_1)
    #  $stderr.puts primer_1
    #  $stderr.puts primer_2
    if primer3_line_1 < primer3_line_2 and primer_2_tm != "NA"
      values << primer3_line_1.left_primer
      values << primer_2
      values << primer3_line_1.right_primer 
      values << primer3_line_1.type.to_s 
      values << primer3_line_1.orientation.to_s 
      values << primer3_line_1.best_pair.left.tm 
      values << primer_2_tm
      values << primer3_line_1.best_pair.right.tm
      values << "first" 
      values << primer3_line_1.best_pair.product_size
    elsif  primer_1_tm != "NA"
      values << primer_1
      values << primer3_line_2.left_primer
      values << primer3_line_2.right_primer
      values << primer3_line_2.type.to_s
      values << primer3_line_2.orientation.to_s
      values << primer_1_tm
      values << primer3_line_2.best_pair.left.tm
      values << primer3_line_2.best_pair.right.tm
      values << "second"
      values << primer3_line_2.best_pair.product_size
    else

      first_candidate = find_primer_pair_first
      second_candidate = find_primer_pair_second

      if first_candidate
        primer_2 = primer3_line_2.left_primer_with_coordinates(first_candidate.left_coordinates, first_candidate.orientation)
        primer_2_tm = find_left_primer_temp(primer_2)
      end
      if second_candidate
        #puts "input to search #{first_candidate.left_coordinates}"
        primer_1 = primer3_line_1.left_primer_with_coordinates(second_candidate.left_coordinates, second_candidate.orientation) 
        primer_1_tm = find_left_primer_temp(primer_1)
        #puts "In the other funky if #{primer_2}"
      end

      if first_candidate and second_candidate and first_candidate < second_candidate 
        #puts "A"
        values << first_candidate.left_primer
        values << primer_2
        values << first_candidate.right_primer 
        values << first_candidate.type.to_s 
        values << first_candidate.orientation.to_s 
        values << first_candidate.best_pair.left.tm 
        values << primer_2_tm
        values << first_candidate.best_pair.right.tm
        values << "first" 
        values << first_candidate.best_pair.product_size
      elsif  second_candidate 
        #puts "B"
        values << primer_1
        values << second_candidate.left_primer
        values << second_candidate.right_primer
        values << second_candidate.type.to_s
        values << second_candidate.orientation.to_s
        values << primer_1_tm
        values << second_candidate.best_pair.left.tm
        values << second_candidate.best_pair.right.tm
        values << "second"
        values << second_candidate.best_pair.product_size
      elsif  first_candidate 
        #puts "C"
        values << first_candidate.left_primer
        values << primer_2
        values << first_candidate.right_primer
        values << first_candidate.type.to_s
        values << first_candidate.orientation.to_s
        values << primer_2_tm
        values << first_candidate.best_pair.left.tm
        values << first_candidate.best_pair.right.tm
        values << "first"
        values << first_candidate.best_pair.product_size
#          else
#            values << "" 
      end

    end

  elsif primer3_line_1 
    values << primer3_line_1.polymorphism
    values << primer3_line_1.left_primer
    values << primer3_line_1.left_primer_snp(self) 
    values << primer3_line_1.right_primer 
    values << primer3_line_1.type.to_s 
    values << primer3_line_1.orientation.to_s      
    values << primer3_line_1.best_pair.left.tm 
    values << "NA"
    values << primer3_line_1.best_pair.right.tm

    values << "first+"
    values << primer3_line_1.best_pair.product_size
  elsif primer3_line_2 
    values << primer3_line_2.polymorphism
    values << primer3_line_2.left_primer_snp(self) 
    values << primer3_line_2.left_primer
    values << primer3_line_2.right_primer
    values << primer3_line_2.type.to_s
    values << primer3_line_2.orientation.to_s
    values << "NA"
    values << primer3_line_2.best_pair.left.tm
    values << primer3_line_2.best_pair.right.tm
    values << "second+"
    values << primer3_line_2.best_pair.product_size

  end 
  values.join(",")
end

#to_sObject



77
78
79
# File 'lib/bio/db/primer3.rb', line 77

def to_s
  "#{gene}:#{original}#{position}#{snp}:#{snp_from.chromosome}"
end