Saturday, 7 September 2013

compare two string in perl to find mismatches

compare two string in perl to find mismatches

I am a beginner in Perl. I have a file two column. I want to compare first
column (as reference) with second column (test):
pppqqrrsttqrstrr pppqrrrsttqrstrr
if p in ref =~ p in test print p
if q in ref =~ q in test print q
if r in ref =~ r in test print r
if s in ref =~ s in test print s
if t in ref =~ t in test print W
if q in ref =~ r in test print w
so output : pppqwrrsWWqrsWrr
I tried:
#!/usr/bin/perl
use warnings;
use strict;
open my $F1, '>', 'match' or die $!;
while(<>){
chomp($_);
my @file = split ("\t| ",$_);
my @ref = split (//, $file[0]);
my @test = split (//, $file[1]);
for my $i (0 .. @ref -1) {
if(($ref[$i] =~ /Pp/) && ($test[$i] =~ /Pp/)){
print $F1 ("$ref[$i]");
}
elsif(($ref[$i] =~ /Qq/) && ($test[$i] =~ /Qq/)){
print $F1 ("$ref[$i]");
}
elsif(($ref[$i] =~ /Rr/) && ($test[$i] =~ /Rr/)){
print $F1 ("$ref[$i]");
}
elsif(($ref[$i] =~ /Ss/) && ($test[$i] =~ /Ss/)){
print $F1 ("$ref[$i]");
}
elsif(($ref[$i] =~ /Tt/) && ($test[$i] =~ /Tt/)){
print $F1 ("W");
}
elsif(($ref[$i] =~ m/Qq/) && ($test[$i] =~ m/Rr/)){
print $F1 ("w");
}
$i++;
}print $F1 ("\n");}
close $F1;
but I don't get anything!!!
thank you

No comments:

Post a Comment