Class: Bio::DB::Primer3::Primer3Record

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrimer3Record

Returns a new instance of Primer3Record.



533
534
535
536
537
538
539
540
541
# File 'lib/bio/db/primer3.rb', line 533

def initialize
  @properties = Hash.new
  @scores = Hash.new
  @scores[:chromosome_specific] = 1000
  @scores[:chromosome_semispecific] = 100
  @scores[:chromosome_nonspecific] = 0
  @scores[:exon] = 50

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Raises:

  • (NoMethodError)


421
422
423
424
425
426
427
# File 'lib/bio/db/primer3.rb', line 421

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

Instance Attribute Details

#polymorphismObject

Returns the value of attribute polymorphism.



401
402
403
# File 'lib/bio/db/primer3.rb', line 401

def polymorphism
  @polymorphism
end

#propertiesObject

Returns the value of attribute properties.



401
402
403
# File 'lib/bio/db/primer3.rb', line 401

def properties
  @properties
end

#scoresObject

Returns the value of attribute scores.



402
403
404
# File 'lib/bio/db/primer3.rb', line 402

def scores
  @scores
end

Class Method Details

.parse_file(filename, scores: nil) ⇒ Object



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/bio/db/primer3.rb', line 629

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) ⇒ Object



514
515
516
517
# File 'lib/bio/db/primer3.rb', line 514

def self.reverse_complement_string(sequenc_str)
  complement = sequenc_str.tr('atgcrymkdhvbswnATGCRYMKDHVBSWN', 'tacgyrkmhdbvswnTACGYRKMHDBVSWN')
  complement.reverse!
end

Instance Method Details

#<=>(anOther) ⇒ Object



450
451
452
# File 'lib/bio/db/primer3.rb', line 450

def <=>(anOther)
  return  anOther.score <=> score
end

#best_pairObject



405
406
407
408
409
410
411
412
413
414
# File 'lib/bio/db/primer3.rb', line 405

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

#chromosomeObject



586
587
588
589
590
# File 'lib/bio/db/primer3.rb', line 586

def chromosome
  return @chromosome if @parsed
  parse_header
  @chromosome
end

#exon?Boolean

Returns:

  • (Boolean)


604
605
606
607
608
# File 'lib/bio/db/primer3.rb', line 604

def exon?
  return @exon if @parsed
  parse_header
  @exon
end

#find_left_tm(primer) ⇒ Object



429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/bio/db/primer3.rb', line 429

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?Boolean

Returns:

  • (Boolean)


592
593
594
595
596
# File 'lib/bio/db/primer3.rb', line 592

def homoeologous?
  return @homoeologous if @parsed
  parse_header
  @homoeologous
end

#left_coordinatesObject



462
463
464
465
466
# File 'lib/bio/db/primer3.rb', line 462

def left_coordinates
  #@left_coordinates = parse_coordinates(self.primer_left_0) unless @left_coordinates 
  @left_coordinates = best_pair.left.coordinates
  @left_coordinates 
end

#left_primerObject



476
477
478
479
480
# File 'lib/bio/db/primer3.rb', line 476

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) ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/bio/db/primer3.rb', line 482

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) ⇒ Object



507
508
509
510
511
512
# File 'lib/bio/db/primer3.rb', line 507

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

#lineObject



610
611
612
613
614
# File 'lib/bio/db/primer3.rb', line 610

def line
  return @line if @parsed
  parse_header
  @line
end

#orientationObject



580
581
582
583
584
# File 'lib/bio/db/primer3.rb', line 580

def orientation
  return @orientation if @parsed
  parse_header
  @orientation
end

#parse_blocksObject



620
621
622
623
624
625
626
627
# File 'lib/bio/db/primer3.rb', line 620

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) ⇒ Object



454
455
456
457
458
459
# File 'lib/bio/db/primer3.rb', line 454

def parse_coordinates(str)
  coords = str.split(',')
  coords[0] = coords[0].to_i
  coords[1] = coords[1].to_i
  coords
end

#parse_headerObject

CL3339Contig1:T509C AvocetS chromosome_specific exon 4D forward



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/bio/db/primer3.rb', line 550

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_errorObject



416
417
418
419
# File 'lib/bio/db/primer3.rb', line 416

def primer_error
  return @properties[:primer_error] if @properties[:primer_error]
  return nil
end

#product_lengthObject



529
530
531
# File 'lib/bio/db/primer3.rb', line 529

def product_length
  return best_pair.size
end

#right_coordinatesObject



468
469
470
471
472
473
474
# File 'lib/bio/db/primer3.rb', line 468

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_primerObject



525
526
527
# File 'lib/bio/db/primer3.rb', line 525

def right_primer
  return best_pair.right.sequence
end

#right_primer_deleteObject



519
520
521
522
523
# File 'lib/bio/db/primer3.rb', line 519

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

#scoreObject



442
443
444
445
446
447
448
# File 'lib/bio/db/primer3.rb', line 442

def score
  ret = 0
  ret += @scores[type]
  ret += @scores[:exon] if exon?
  ret -= product_length
  ret
end

#sizeObject



616
617
618
# File 'lib/bio/db/primer3.rb', line 616

def size
  @properties[:primer_pair_num_returned].to_i
end

#snpObject



543
544
545
546
547
# File 'lib/bio/db/primer3.rb', line 543

def snp
  return @snp if @snp
  parse_header
  @snp
end

#typeObject



598
599
600
601
602
# File 'lib/bio/db/primer3.rb', line 598

def type
  return @type if @parsed
  parse_header
  @type
end