lib/bio/db/primer3.rb in bio-polyploid-tools-0.4.4 vs lib/bio/db/primer3.rb in bio-polyploid-tools-0.4.5

- old
+ new

@@ -139,76 +139,78 @@ 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.shortest_pair.left.tm + values << primer3_line_1.best_pair.left.tm values << primer_2_tm - values << primer3_line_1.shortest_pair.right.tm + values << primer3_line_1.best_pair.right.tm values << "first" - values << primer3_line_1.shortest_pair.product_size + 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.shortest_pair.left.tm - values << primer3_line_2.shortest_pair.right.tm + values << primer3_line_2.best_pair.left.tm + values << primer3_line_2.best_pair.right.tm values << "second" - values << primer3_line_2.shortest_pair.product_size + values << primer3_line_2.best_pair.product_size else first_candidate = find_primer_pair_first second_candidate = find_primer_pair_second if first_candidate - - #puts "input to search #{first_candidate.left_coordinates}" 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) - #puts "In the funky if #{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.shortest_pair.left.tm + values << first_candidate.best_pair.left.tm values << primer_2_tm - values << first_candidate.shortest_pair.right.tm + values << first_candidate.best_pair.right.tm values << "first" - values << first_candidate.shortest_pair.product_size + 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.shortest_pair.left.tm - values << second_candidate.shortest_pair.right.tm + values << second_candidate.best_pair.left.tm + values << second_candidate.best_pair.right.tm values << "second" - values << second_candidate.shortest_pair.product_size + values << second_candidate.best_pair.product_size elsif first_candidate - values << primer_2 + #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.shortest_pair.left.tm - values << first_candidate.shortest_pair.right.tm + values << first_candidate.best_pair.left.tm + values << first_candidate.best_pair.right.tm values << "first" - values << first_candidate.shortest_pair.product_size + values << first_candidate.best_pair.product_size # else # values << "" end end @@ -218,28 +220,28 @@ 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.shortest_pair.left.tm + values << primer3_line_1.best_pair.left.tm values << "NA" - values << primer3_line_1.shortest_pair.right.tm + values << primer3_line_1.best_pair.right.tm values << "first+" - values << primer3_line_1.shortest_pair.product_size + 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.shortest_pair.left.tm - values << primer3_line_2.shortest_pair.right.tm + values << primer3_line_2.best_pair.left.tm + values << primer3_line_2.best_pair.right.tm values << "second+" - values << primer3_line_2.shortest_pair.product_size + values << primer3_line_2.best_pair.product_size end values.join(",") end @@ -272,23 +274,26 @@ 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 + when primer3record.line == @line_2 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 + when primer3record.line == @line_1 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 @@ -297,19 +302,22 @@ end class Primer3Record include Comparable attr_accessor :properties, :polymorphism + attr_accessor :socres - def shortest_pair - return @shortest_pair if @shortest_pair - @shortest_pair = nil - @primerPairs.each do | primer | - @shortest_pair = primer if @shortest_pair == nil - @shortest_pair = primer if primer.size < @shortest_pair.size - end - @shortest_pair + + 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.first + @best_pair end def primer_error return @properties[:primer_error] if @properties[:primer_error] return nil @@ -333,48 +341,20 @@ end return nil end - def <=>(anOther) - ret = snp <=> anOther.snp - return ret if ret != 0 + def score + ret = 0 + ret += @scores[type] + ret += @scores[:exon] if exon? + ret -= product_length + ret + end - - #Sorting by the types. - if type == :chromosome_specific - if anOther.type != :chromosome_specific - return -1 - end - elsif type == :chromosome_semispecific - if anOther.type == :chromosome_specific - return 1 - else anOther.type == :chromosome_nonspecific - return -1 - end - elsif type == :chromosome_nonspecific - if anOther.type != :chromosome_nonspecific - return 1 - end - end - - #Sorting if it is in intron or not This will give priority - #to the cases when we know for sure the sequence from the line - #and reduce the chances of getting messed with a short indel - if self.exon? - unless anOther.exon? - return -1 - end - else - if anOther.exon? - return 1 - end - end - - #Sorting for how long the product is, the shorter, the better - return product_length <=> anOther.product_length - + def <=>(anOther) + return anOther.score <=> score end def parse_coordinates(str) coords = str.split(',') coords[0] = coords[0].to_i @@ -383,25 +363,25 @@ end def left_coordinates #@left_coordinates = parse_coordinates(self.primer_left_0) unless @left_coordinates - @left_coordinates = shortest_pair.left.coordinates + @left_coordinates = best_pair.left.coordinates @left_coordinates end def right_coordinates unless @right_coordinates - @right_coordinates = shortest_pair.right.coordinates + @right_coordinates = best_pair.right.coordinates @right_coordinates[0] = @right_coordinates[0] - @right_coordinates[1] + 1 end @right_coordinates end def left_primer #@left_primer = self.sequence_template[left_coordinates[0],left_coordinates[1]] unless @left_primer - @left_primer = shortest_pair.left.sequence + @left_primer = best_pair.left.sequence @left_primer end def left_primer_snp(snp) tmp_primer = String.new(left_primer) @@ -446,19 +426,25 @@ @right_primer = reverse_complement_string(@right_primer) @right_primer end def right_primer - return shortest_pair.right.sequence + return best_pair.right.sequence end def product_length - return shortest_pair.size + return best_pair.size end def initialize @properties = Hash.new + @scores = Hash.new + @scores[:chromosome_specific] = 1000 + @scores[:chromosome_semispecific] = 100 + @scores[:chromosome_nonspecific] = 0 + @scores[:exon] = 50 + end def snp return @snp if @snp parse_header @@ -585,11 +571,11 @@ end class PrimerPair - + include Comparable attr_reader :record attr_reader :left, :right def parse_coordinates(str) coords = str.split(',') @@ -598,9 +584,13 @@ coords end def size return product_size.to_i + end + + def <=>(anOther) + penalty.to_f <=> anOther.penalty.to_f end def initialize(record, index) raise Primer3Exception.new(), "Index #{index} is greater than the number of records" unless index < record.size @record = record