Calculating primer melting temperatures

From BioPerl
Jump to: navigation, search

These code snippets demonstrate a way to calculate the melting temperature (Tm) of PCR primers (or other DNA). This code is designed to be called from an external package.

To calculate the Tm of degenerate primers, you can use this code in conjunction with the degenerate primers code. First get the constituent sequences of the degenerate primer, the pass them through these subroutines and take the mean of the returned temperatures.

The first subroutine takes a sequence string and passes it to the second or third subroutines as appropriate, depending on the length of the sequence.

The second subroutine calculates the Tm of short sequences by running the oligotm program, which is part of the Primer 3 package. This subroutine relies on IPC::Open3 so it isn't Windows friendly.

The third subroutine calculates the Tm of longer sequences using a method derived from one of the test scripts in the Primer 3 package.

package Primer;
use IPC::Open3;
 
sub calc_oligo_tm
{
	my ($class, $sequence) = @_;
 
	my ($tm, $errors);
	if (length($sequence) >= 32) { ($tm, $errors) = $class->_calc_long_oligo_tm ($sequence); }
	else { ($tm, $errors) = $class->_run_oligotm ($sequence); }
	return ($tm, $errors);
}
 
sub _run_oligotm
{
	my ($class, $sequence) = @_;
 
	my $command = "oligotm -tp 1 -sc 1 $sequence";
	my $pid = open3(\*WTRFH, \*RDRFH, \*ERRFH, $command);
	close (WTRFH);
 
	my ($tm, $errors);
	while (<RDRFH>) { $tm .= $_;}
	while (<ERRFH>) { $errors .= $_;}
	chomp $tm;
	return ($tm, $errors);
}
 
sub _calc_long_oligo_tm
{
	my ($class, $sequence) = @_;
	# This code based on Test script from primer3
 
	my $GC_count = $sequence =~ tr/gGcC/gGcC/;
	my $len = length $sequence;
 
	my $salt=50;
	my $divalent=0;
	my $dntp=0;
 
	$salt = $salt + 120*sqrt(($divalent-$dntp));
	my $r = log($salt/1000.0)/log(10);
	my $tm = 81.5 + 16.6*$r + 41*$GC_count/$len - 600./$len;
	my $errors = "hopefully none";
 
	return ($tm, $errors);
}

Primer 3 can be obtained here. If you are running a Debian based Linux distribution such as Ubuntu you can install it by typing:

sudo apt-get install primer3

--Giles.weaver 19:14, 14 April 2010 (UTC)

Personal tools
Namespaces
Variants
Actions
Main Links
documentation
community
development
Toolbox