class Bio::DB::Primer3::Primer3Record
Attributes
polymorphism[RW]
properties[RW]
scores[RW]
Public Class Methods
new()
click to toggle source
# File lib/bio/db/primer3.rb, line 536 def initialize @properties = Hash.new @scores = Hash.new @scores[:chromosome_specific] = 1000 @scores[:chromosome_semispecific] = 100 @scores[:chromosome_nonspecific] = 0 @scores[:exon] = 50 end
parse_file(filename, scores: nil) { |record| ... }
click to toggle source
# File lib/bio/db/primer3.rb, line 632 def self.parse_file(filename, scores: nil) File.open(filename) do | f | record = Primer3Record.new record.scores = scores if scores f.each_line do | line | line.chomp! if line == "=" record.parse_blocks yield record record = Primer3Record.new record.scores = scores if scores else tokens = line.split("=") i = 0 reg = "" #TODO: Look if there is a join function or something similar to go around this... tokens.each do |tok| if i > 0 if i > 1 reg << "=" end reg << tok end i+=1 end record.properties[tokens[0].downcase.to_sym] = reg end end end end
reverse_complement_string(sequenc_str)
click to toggle source
# File lib/bio/db/primer3.rb, line 517 def self.reverse_complement_string(sequenc_str) complement = sequenc_str.tr('atgcrymkdhvbswnATGCRYMKDHVBSWN', 'tacgyrkmhdbvswnTACGYRKMHDBVSWN') complement.reverse! end
Public Instance Methods
<=>(anOther)
click to toggle source
# File lib/bio/db/primer3.rb, line 453 def <=>(anOther) return anOther.score <=> score end
best_pair()
click to toggle source
# File lib/bio/db/primer3.rb, line 408 def best_pair return @best_pair if @best_pair @best_pair = nil @primerPairs.each do | primer | @best_pair = primer if @best_pair.nil? @best_pair = primer if primer.size < @best_pair.size end #@best_pair = @primerPairs.min @best_pair end
chromosome()
click to toggle source
# File lib/bio/db/primer3.rb, line 589 def chromosome return @chromosome if @parsed parse_header @chromosome end
exon?()
click to toggle source
# File lib/bio/db/primer3.rb, line 607 def exon? return @exon if @parsed parse_header @exon end
find_left_tm(primer)
click to toggle source
# File lib/bio/db/primer3.rb, line 432 def find_left_tm(primer) last = size - 1 (0..last).each do | i | seq_prop = "primer_left_#{i}_sequence".to_sym # $stderr.puts seq_prop temp_property = "primer_left_#{i}_tm".to_sym # $stderr.puts "comparing #{@properties[seq_prop] } == #{primer}" return @properties[temp_property] if @properties[seq_prop] == primer end return nil end
homoeologous?()
click to toggle source
# File lib/bio/db/primer3.rb, line 595 def homoeologous? return @homoeologous if @parsed parse_header @homoeologous end
left_coordinates()
click to toggle source
# File lib/bio/db/primer3.rb, line 465 def left_coordinates #@left_coordinates = parse_coordinates(self.primer_left_0) unless @left_coordinates @left_coordinates = best_pair.left.coordinates @left_coordinates end
left_primer()
click to toggle source
# File lib/bio/db/primer3.rb, line 479 def left_primer #@left_primer = self.sequence_template[left_coordinates[0],left_coordinates[1]] unless @left_primer @left_primer = best_pair.left.sequence @left_primer end
left_primer_snp(snp)
click to toggle source
# File lib/bio/db/primer3.rb, line 485 def left_primer_snp(snp) tmp_primer = String.new(left_primer) if self.orientation == :forward base_original = snp.original base_snp = snp.snp elsif self.orientation == :reverse #puts self.inspect base_original =Primer3Record.reverse_complement_string(snp.original ) base_snp = Primer3Record.reverse_complement_string(snp.snp) else raise Primer3Exception.new "#{self.orientation} is not a valid orientation" end #puts "#{snp.to_s} #{self.orientation} #{tmp_primer[-1] } #{base_original} #{base_snp}" if tmp_primer[-1] == base_original tmp_primer[-1] = base_snp elsif tmp_primer[-1] == base_snp tmp_primer[-1] = base_original else raise Primer3Exception.new "#{tmp_primer} doesnt end in a base in the SNP #{snp.to_s}" end #puts "tmp_primer: #{tmp_primer}" return tmp_primer end
left_primer_with_coordinates(coordinates, other_orientation)
click to toggle source
# File lib/bio/db/primer3.rb, line 510 def left_primer_with_coordinates(coordinates, other_orientation) seq = self.sequence_template seq = Primer3Record.reverse_complement_string(seq) if self.orientation != other_orientation seq[coordinates[0],coordinates[1]] end
line()
click to toggle source
# File lib/bio/db/primer3.rb, line 613 def line return @line if @parsed parse_header @line end
method_missing(method_name, *args)
click to toggle source
# File lib/bio/db/primer3.rb, line 424 def method_missing(method_name, *args) return @properties[method_name] if @properties[method_name] $stderr.puts "Missing #{method_name}" $stderr.puts @properties.inspect return "" #if a property is missing, return blank. raise NoMethodError.new() end
orientation()
click to toggle source
# File lib/bio/db/primer3.rb, line 583 def orientation return @orientation if @parsed parse_header @orientation end
parse_blocks()
click to toggle source
# File lib/bio/db/primer3.rb, line 623 def parse_blocks total_blocks = size - 1 @primerPairs = Array.new for i in 0..total_blocks @primerPairs << PrimerPair.new(self, i) end end
parse_coordinates(str)
click to toggle source
# File lib/bio/db/primer3.rb, line 457 def parse_coordinates(str) coords = str.split(',') coords[0] = coords[0].to_i coords[1] = coords[1].to_i coords end
parse_header()
click to toggle source
CL3339Contig1:T509C AvocetS chromosome_specific exon 4D forward
# File lib/bio/db/primer3.rb, line 553 def parse_header #puts "Parsing header: '#{self.sequence_id}'" arr = self.sequence_id.split(" ") #if arr.size == 7 This validation can be useful to get the best primers regardless of the chromosome, #But it is commented as it will require further testing. @snp, @line, @type, @in, @polymorphism, @chromosome, @orientation = arr #else # if arr.size == 6 # @snp, @line, @type, @in, @polymorphism, @orientation = arr # @chromosome = "" # end #end @type = @type.to_sym if @in @in = @in.to_sym == :exon else @exon = false end if @polymorphism.to_sym == :homoeologous @homoeologous = true else @homoeologous = false end @parsed = true @orientation = @orientation.to_sym end
primer_error()
click to toggle source
# File lib/bio/db/primer3.rb, line 419 def primer_error return @properties[:primer_error] if @properties[:primer_error] return nil end
product_length()
click to toggle source
# File lib/bio/db/primer3.rb, line 532 def product_length return best_pair.size end
right_coordinates()
click to toggle source
# File lib/bio/db/primer3.rb, line 471 def right_coordinates unless @right_coordinates @right_coordinates = best_pair.right.coordinates @right_coordinates[0] = @right_coordinates[0] - @right_coordinates[1] + 1 end @right_coordinates end
right_primer()
click to toggle source
# File lib/bio/db/primer3.rb, line 528 def right_primer return best_pair.right.sequence end
right_primer_delete()
click to toggle source
# File lib/bio/db/primer3.rb, line 522 def right_primer_delete @right_primer = self.sequence_template[right_coordinates[0],right_coordinates[1]] unless @right_primer @right_primer = Primer3Record.reverse_complement_string(@right_primer) @right_primer end
score()
click to toggle source
# File lib/bio/db/primer3.rb, line 445 def score ret = 0 ret += @scores[type] ret += @scores[:exon] if exon? ret -= product_length ret end
size()
click to toggle source
# File lib/bio/db/primer3.rb, line 619 def size @properties[:primer_pair_num_returned].to_i end
snp()
click to toggle source
# File lib/bio/db/primer3.rb, line 546 def snp return @snp if @snp parse_header @snp end
type()
click to toggle source
# File lib/bio/db/primer3.rb, line 601 def type return @type if @parsed parse_header @type end