Hi,
I have issues designing a code that scans 2 DNA sequences (taken as input from user, of same length) and then compares the two sequences, nucleotide by nucleotide (e.g. compare nt 1 from sequence 1, with nt 1 from sequence 2 etc).
I'm new to perl, I've tried several different ways but I don't seem to get anything working.
With the code that I've tried, nothing is printed out at all, so the nested foreach loops seem to get stuck somewhere.
I would be greatful for some help/advice.
PS I know I should use script, I deleted all that to simplify my problem and will add all that later on once I figured out this problem.
Code:
#!/usr/bin/perl
use warnings;
print("Please enter the first DNA sequence: ");
$DNAsequence1 = <STDIN>;
chomp($DNAsequence1);
+
$DNAsequence1=uc($DNAsequence1);
$lengthDNA1=length $DNAsequence1;
print("\nPlease enter the second DNA sequenc (of same length as the fi
+rst): ");
$DNAsequence2 = <STDIN>;
chomp($DNAsequence2);
+
$DNAsequence2=uc($DNAsequence2);
$lengthDNA2=length $DNAsequence2;
#print "The length of DNA sequence 2 is $lengthDNA2";
if ($lengthDNA1==$lengthDNA2){
print "DNA sequence 1: $DNAsequence1\nDNA sequence 2: $DNAsequence2\n"
+;
} else {
print "\nThe DNA sequences are not of same lenght, please try aga
+in!";
}
@DNAsequence1=split(//,$DNAsequence1);
@DNAsequence2=split(//,$DNAsequence2);
$score=0;
foreach $base1 (@$DNAsequence1)
print $score;
{
foreach $base2(@$DNAsequence2)
{
if($base1->[0] eq $base2->[0])
{
$score += 3;
print $score;
} else
{
$score=$score+1;
}
}
}
print $score;