#!perl -w
use strict;
# Open the file
my $data_file = shift || die("usage: $0 seq_file\n");
open(DAT, $data_file) || die("Unable to open file: $!\n");
my @lines = ;
my $dna = join("", @lines);
print "The sequence read from the $data_file is \n";
print @lines, "\n";
print "Melting Temperature: ", calc_temp (base_count (\$dna)), " degreesC\n\n";
# my @counts = count( \$sequence );
# from count.pl example
sub base_count {
my ($dna) = @_;
# Initialize the counts.
my ($a, $c, $g, $t, $e) = (0, 0, 0, 0, 0);
# Use a regular expression "trick", while loops,
# to find the counts of the four bases plus errors
while($$dna =~ /a/ig){++$a;}
while($$dna =~ /c/ig){++$c;}
while($$dna =~ /g/ig){++$g;}
while($$dna =~ /t/ig){++$t;}
while($$dna =~ /[^acgt\s]/ig){++$e;}
return ($a, $g, $c, $t, $e);
}
# foreach my $line (@lines) { print "$line \n"; }
# calc_temp( $a_count, $g_count, $c_count, $t_count);
# Return the calculated melting temperature of the DNA sequence
# Bases A and T have a melting temperature of 2 degrees C
# Bases G and C have a melting temperature of 4 degrees C
sub calc_temp {
my ($a, $g, $c, $t) = @_;
return 2 * ($a + $t) + 4 * ($g + $c);
}
exit(0);