Thank You everyone for your replies....:-)
In the meantime I've found out where the problem was, but i will post the code, and an example of input data, nevertheless. Please note that the purpose of this code is to test an algorithm, and it's not a final version of the program i have in mind.
system "clear";
print "Palindrome - gamma version\n";
print "--------------------------\n\n";
print "Please enter DNA filename: ";
$filename=<STDIN>;
chomp $filename;
unless (-e $filename) {
print "No such file...exiting\n\n";
exit;
}
unless (open(DNASEQ, $filename)) {
print "Cannot open file...exiting\n\n";
exit;
}
@dna=<DNASEQ>;
$dna=join('', @dna);
$dna=~ s/\s//g;
$count_of_2=0;
for ($lb=0; $lb<length $dna; ++$lb) {
$lba=substr ($dna, $lb, 1);
$rba=substr ($dna, $lb+1, 1);
$rba=~ tr/atgc/tacg/;
if ($lba eq $rba) {
++$count_of_2;
}
else {
}
}
print "Number of 2bp palindromes: ", $count_of_2, "\n";
exit;
Input data are files that contain DNA sequences arranged in the following format:
CGACAGCTACGATCGTAC
CAGTATCATCACTACGTA
CACGAGAGTACGATCGAC
......etc.........
The program should work with both lower- and uppercase
sequences, but i forgot to add something like
$dna=~ tr/ATGC/atgc/;
so when i loaded uppercase
DNA sequence it just didn' do the job right. Now the two programs give the same results, i've tested them with sequences containing up to 29160000 characters.
|