CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Compare two sequences from one file

 



frenchcookie
New User

Dec 15, 2012, 11:14 AM

Post #1 of 2 (758 views)
Compare two sequences from one file Can't Post

Hello,
I have to compare two sequences form one file. I have to compare by the bases position. ( First base from seq A with first base from seq B, second base from seq A with second base from seq B etc. )

I have something like this, but it's not working properly. Could you give my any idea how to do it effectually?


Code
 my $end = $#a1 < $#a2 ? $#a1 : $#a2; 
my $result = 0;
for (my $l=0; $l<=$end; $l++) {
$result++ if $a1[$l] eq $a2[$l];
}

my $A = (2 * $result) / ($#a1 + $#a2 + 2);
my $B = $result / ($end+1);
print "Similar = $result, A = $A, B = $B\n";
}


my $file = 'seqs.txt';
open I, '<', $file
or die "Can't open '$file' for reading: $!\n";

chop (%hash = map { split /\s*,\s*/,$_,2 } grep (!/^$/,<I>));



print "$_$hash{$_}\n" for keys %hash;
open
open (IN, $ARGV[0]) || die "File not found $ARGV[0]: $!\n";
chomp(my @in = <IN>);


map {
s/[^agtc]//ig;
} @in;


my $dna1 = read_file($ARGV[0]);
my $dna2 = read_file($ARGV[1]);
compare ($dna1, $dna2);

compare($in[0], $in[1]);
compare($in[1], $in[2]);
compare($in[2], $in[3]);

close (IN);



Laurent_R
Veteran / Moderator

Dec 15, 2012, 1:59 PM

Post #2 of 2 (750 views)
Re: [frenchcookie] Compare two sequences from one file [In reply to] Can't Post

Hi,

I do not think that this syntax "grep (!/^$/,<I>)" will work (although I can't try it right now).

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives