script, , , , .
script , FASTA , ( = > ), , . , , , . , Perl, , , .
use strict;
use warnings;
print STDOUT "Enter the motif: ";
my $motif = <STDIN>;
chomp $motif;
my %seqs = %{ read_fasta_as_hash( 'data.fa' ) };
foreach my $id ( keys %seqs ) {
if ( $seqs{$id} =~ /$motif/ ) {
print $id, "\n";
print $seqs{$id}, "\n";
}
}
sub read_fasta_as_hash {
my $fn = shift;
my $current_id = '';
my %seqs;
open FILE, "<$fn" or die $!;
while ( my $line = <FILE> ) {
chomp $line;
if ( $line =~ /^(>.*)$/ ) {
$current_id = $1;
} elsif ( $line !~ /^\s*$/ ) {
$seqs{$current_id} .= $line
}
}
close FILE or die $!;
return \%seqs;
}