There are many problems with your script.
When you read the lines in from the file
while($_ = <FILENAME>){
They have newlines attached to their ends. And when you store the sequence ID in teh key of the hash:
$accession{$seq} .= $_;
You have not removed it. But when you read the accession iD from the user:
print "Please enter in the accession_ID: "; chomp($accession_id = <STDIN>);
You did remove the newline. So when you try to compare those two:
if ($accession{$g} =~ m/$accession_id/i){
They will not match.
BUT ... when you are trying to compare the id entered by the user with the one read from the file, instead of comparing it with the key (ID) of the hash element:
if( $g =~ m/$accession_id/i){
You are comparing it with the sequence (value) of that hash entry:
if ($accession{$g} =~ m/$accession_id/i){
Which obviously wouldn't work, even if you had removed the newlines from both.
But then, even if you corrected all those problems, there are many other problems with your program.
First you read all the sequences into the hash -- despite that you know you are only looking for one and could stop reading as soon as you've seen that one.
And then you iterate over the hash checking if each of them matches the ID the user entered -- but the whole point of a hash is that you do not need to iterate over it. You can simply look up whether the key you need exists.
Finally, you should take more care over how you format your code. Think of your code as your workbench. If you keep it neat and tidy, you'll find it a lot easier to find what you are looking for.
Also, if you are intending using Perl to do work, rather than as a hobby, I strongly recommend that you take a basic programmers course, or at least work your way through one of the Learning Perl type books available. It would pay you dividends over and over in the long term.
In reply to Re: fasta file
by BrowserUk
in thread fasta file
by PrincePerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |