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.



536
537
538
539
540
541
542
543
544
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Raises:

  • (NoMethodError)


424
425
426
427
428
429
430
# 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

Instance Attribute Details

#polymorphismObject

Returns the value of attribute polymorphism.



404
405
406
# File 'lib/bio/db/primer3.rb', line 404

def polymorphism
  @polymorphism
end

#propertiesObject

Returns the value of attribute properties.



404
405
406
# File 'lib/bio/db/primer3.rb', line 404

def properties
  @properties
end

#scoresObject

Returns the value of attribute scores.



405
406
407
# File 'lib/bio/db/primer3.rb', line 405

def scores
  @scores
end

Class Method Details

.parse_file(filename, scores: nil) ⇒ Object



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
660
661
662
# 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) ⇒ Object



517
518
519
520
# File 'lib/bio/db/primer3.rb', line 517

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

Instance Method Details

#<=>(anOther) ⇒ Object



453
454
455
# File 'lib/bio/db/primer3.rb', line 453

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

#best_pairObject



408
409
410
411
412
413
414
415
416
417
# 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

#chromosomeObject



589
590
591
592
593
# File 'lib/bio/db/primer3.rb', line 589

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

#exon?Boolean

Returns:

  • (Boolean)


607
608
609
610
611
# File 'lib/bio/db/primer3.rb', line 607

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

#find_left_tm(primer) ⇒ Object



432
433
434
435
436
437
438
439
440
441
442
443
# 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?Boolean

Returns:

  • (Boolean)


595
596
597
598
599
# File 'lib/bio/db/primer3.rb', line 595

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

#left_coordinatesObject



465
466
467
468
469
# 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_primerObject



479
480
481
482
483
# 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) ⇒ Object



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# 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) ⇒ Object



510
511
512
513
514
515
# 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

#lineObject



613
614
615
616
617
# File 'lib/bio/db/primer3.rb', line 613

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

#orientationObject



583
584
585
586
587
# File 'lib/bio/db/primer3.rb', line 583

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

#parse_blocksObject



623
624
625
626
627
628
629
630
# 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) ⇒ Object



457
458
459
460
461
462
# 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_headerObject

CL3339Contig1:T509C AvocetS chromosome_specific exon 4D forward



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
579
580
581
# 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_errorObject



419
420
421
422
# File 'lib/bio/db/primer3.rb', line 419

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

#product_lengthObject



532
533
534
# File 'lib/bio/db/primer3.rb', line 532

def product_length
  return best_pair.size
end

#right_coordinatesObject



471
472
473
474
475
476
477
# 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_primerObject



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

def right_primer
  return best_pair.right.sequence
end

#right_primer_deleteObject



522
523
524
525
526
# 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

#scoreObject



445
446
447
448
449
450
451
# 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

#sizeObject



619
620
621
# File 'lib/bio/db/primer3.rb', line 619

def size
  @properties[:primer_pair_num_returned].to_i
end

#snpObject



546
547
548
549
550
# File 'lib/bio/db/primer3.rb', line 546

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

#typeObject



601
602
603
604
605
# File 'lib/bio/db/primer3.rb', line 601

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