You are still comparing the IDs twice (checking for key existence and then comparing if ( $bow1{$ID}[0] eq $bow2{$ID}[0] ){..., so you can streamline more there.
Also, you don't need to read in both files this way, but simply read in the first, then compare the ids and sequences of the second as you read them in, this will help you with memory issues is your files are huge.
Also, just as a bit of error checking, that you aren't overwriting any IDs, i would check for existence of the ID in the hash when you read in the file :
while (<$fh1>) { # Reading first hash
my ($id, undef, undef, undef, $seq) = split;
if ( exists $bow1{$ID} ){
warn "ID \'$id\' already exists for hash 1!\nThe current sequen
+ce value is \'$bow1{$id}\', which would be replaced with \'$seq\'.\n"
+;
.... handle the error better (maybe ignore if sequences are the
+ same?) ....
next; ## skip it
}
$bow1{$id} = $seq;
}
close $fh1 || die "Failed to close $file1 : $!";
Lastly, and this is just a matter of style, but this is important for writing code that will last and other people can read, in Perl variable names are usually all lower case, with words separated by an underscore ( <c>$this_that</\> ). All caps variables are reserved for global variables. This is just convention, but it makes your code easier to interpret, not just for others, but for yourself 6 months down the line...
Well done for working it out though, and thanks for posting it here!
Just a something something...
|