Excellent use of Bio::SeqIO!
If I may make a few observations...
- Always
use strict; use warnings;. - This limits the OP to searching a single file at a time.
- You can match directly on
$seq->idand$seq->description. - It's best to
quotemetaon$string.
Given the above, consider the following:
use strict;
use warnings;
use Bio::SeqIO;
my $string = pop;
my $seqout = Bio::SeqIO->new( -format => 'Fasta', -fh => \*STDOUT );
for my $inFile (@ARGV) {
my $seqin = Bio::SeqIO->new( -format => 'Fasta', -file => $inFile );
while ( my $seq = $seqin->next_seq() ) {
if ( $seq->id =~ m/\Q$string\E/i
or $seq->description =~ m/\Q$string\E/i )
{
$seqout->write_seq($seq);
}
}
}
Since the search term is always the last item sent to the script, you can pop it off @ARGV (implied if no argument is passed to pop). File names are left in @ARGV, so the above iterates through each. Depending upon the file system, one could perl script.pl * oxidase on a dir of fasta files--or just write out the separate files.
What do you mean by "direct solution"? (and what formats keep changing?)
direct solution means that any script which takes wild card as input and provides output with sequences..
">testcomp2344c0seq1 BlastHit=ref|NP182170.1| inner membrane OXA1-like protein [Arabidopsis thaliana]sp|Q9SKD3.1|OXA1L_ARATH RecName: Full=Mitochondrial inner membrane protein OXA1-like; Flags: Precursorgb|AAD23047.1| putative cytochrome oxidase biogenesis protein "
That was one of the header i have but the script works with fasta id only which is "testcomp2344c0_seq1 " . so i have to perform preprocessing to remove rest of it.