lib/bio/db/primer3.rb in bio-polyploid-tools-0.7.3 vs lib/bio/db/primer3.rb in bio-polyploid-tools-0.8.0
- old
+ new
@@ -259,15 +259,80 @@
def second_primer
return self.values[8] if self.values[8] && self.values[8] != nil
return ""
end
- def common_primer
- return self.values[9] if self.values[9]&& self.values[9] != nil
+ def common_primer
+ return self.values[9] if self.values[9] && self.values[9] != nil
return ""
end
+ def product_size
+ return self.values[16].to_i if self.values[16]&& self.values[16] != nil
+ return 0
+ end
+
+ def orientation
+ puts "insideOrientation: #{self.values[11]}"
+ return self.values[11] if self.values[11]&& self.values[11] != nil
+ return 'unknown'
+ end
+
+
+ def first_product
+ left = first_primer
+ right = common_primer
+ nlen = product_size - left.size - right.size
+ product = left + ('n' * nlen) + Primer3Record.reverse_complement_string(right)
+ #puts "orientation: #{orientation}"
+
+ product = Primer3Record.reverse_complement_string(product) if orientation == 'reverse'
+
+ product
+ end
+
+ def second_product
+ left = second_primer
+ right = common_primer
+ nlen = product_size - left.size - right.size
+ product = left + ('n' * nlen) + Primer3Record.reverse_complement_string(right)
+ product = Primer3Record.reverse_complement_string(product) if orientation == 'reverse'
+
+
+ product
+ end
+
+
+ def realigned_primers_fasta
+ ret_str = ""
+ realigned_primers.each_pair do |name, seq|
+ ret_str << ">#{self.to_s}-#{name}\n#{seq}\n"
+ end
+ ret_str
+ end
+
+
+ def realigned_primers
+
+ return @realigned_primers if @realigned_primers
+ sequences_to_align = Hash.new
+ sequences_to_align["first_product"] = first_product
+ sequences_to_align["second_product"] = second_product
+ sequences_to_align.merge!(snp_from.surrounding_exon_sequences)
+ if sequences_to_align.size == 1
+ @realigned_primers = sequences_to_align
+ return @realigned_primers
+ end
+ options = ['--maxiterate', '1000', '--localpair', '--quiet']
+ mafft = Bio::MAFFT.new( "mafft" , options)
+ #puts "Before MAFT:#{sequences_to_align.inspect}"
+ report = mafft.query_align(sequences_to_align)
+ @realigned_primers = report.alignment
+ #puts "MAFFT: #{report.alignment.inspect}"
+ @realigned_primers
+ end
+
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
@@ -328,18 +393,18 @@
end
class Primer3Record
include Comparable
attr_accessor :properties, :polymorphism
- attr_accessor :socres
+ attr_accessor :scores
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 @best_pair.nil?
@best_pair = primer if primer.size < @best_pair.size
end
#@best_pair = @primerPairs.min
@best_pair
end
@@ -352,11 +417,11 @@
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()
+ raise NoMethodError.new()
end
def find_left_tm(primer)
last = size - 1
(0..last).each do | i |
@@ -414,17 +479,18 @@
tmp_primer = String.new(left_primer)
if self.orientation == :forward
base_original = snp.original
base_snp = snp.snp
elsif self.orientation == :reverse
- base_original = reverse_complement_string(snp.original )
- base_snp = reverse_complement_string(snp.snp)
+ #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}"
+ #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
@@ -436,23 +502,23 @@
def left_primer_with_coordinates(coordinates, other_orientation)
seq = self.sequence_template
#puts "Left coordinates: #{seq}"
- seq = reverse_complement_string(seq) if self.orientation != other_orientation
+ seq = Primer3Record.reverse_complement_string(seq) if self.orientation != other_orientation
seq[coordinates[0],coordinates[1]]
end
- def reverse_complement_string(sequenc_str)
+ def self.reverse_complement_string(sequenc_str)
complement = sequenc_str.tr('atgcrymkdhvbswnATGCRYMKDHVBSWN', 'tacgyrkmhdbvswnTACGYRKMHDBVSWN')
complement.reverse!
end
def right_primer_delete
@right_primer = self.sequence_template[right_coordinates[0],right_coordinates[1]] unless @right_primer
- @right_primer = reverse_complement_string(@right_primer)
+ @right_primer = Primer3Record.reverse_complement_string(@right_primer)
@right_primer
end
def right_primer
return best_pair.right.sequence
@@ -545,20 +611,22 @@
@primerPairs << PrimerPair.new(self, i)
end
end
- def self.parse_file(filename)
+ 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...
@@ -670,12 +738,12 @@
class KASPContainer
attr_accessor :line_1, :line_2
attr_accessor :snp_hash
+ attr_accessor :scores
-
def add_snp_file(filename)
@snp_hash=Hash.new unless @snp_hash
SNP.parse_file(filename) do |snp|
@snp_hash[snp.to_s] = snp
snp.line_1 = @line_1
@@ -699,10 +767,11 @@
@snp_hash[snp.to_s] = snp
snp
end
def add_primers_file(filename)
- Primer3Record.parse_file(filename) do | primer3record |
+ #primer3record.scores = @scores if @scores
+ Primer3Record.parse_file(filename, scores: @scores) do | primer3record |
current_snp = @snp_hash["#{primer3record.snp.to_s}:#{primer3record.chromosome}"]
current_snp.add_record(primer3record)
end
end