Aliging sequences using BLAST is the most common task performed in bioinformatics. Here is how you can do it using BioPerl:
#!/usr/bin/perl
use strict;
use warnings;
use Bio::Perl;
# get sequence given an identifier or accession number
my $so = get_sequence('swiss',$ARGV[0]);
# get blast the sequence
my $blast_result = blast_sequence($so);
# write blast results into a file
write_blast(">$ARGV[1]",$blast_result);
usage:
$ chmod 755 blastseq.pl $ perl blastseq.pl PYGM_HUMAN pygm.blast
The above example retrieves a sequence from Swiss-Prot and then blasts the retrieved sequence against NCBI blast server. The following example blasts a given sequence against NCBI blast server.
#!/usr/bin/perl
use strict;
use warnings;
use Bio::Perl;
# get sequence
my $blast_result = blast_sequence('MFVEGGTFASEDDDSASAEDE');
# write output to file
write_blast(">$ARGV[0]",$blast_result);
usage:
$ chmod 755 blastseq2.pl $ perl blastseq2.pl test.blast
The next example takes a fasta file as input which is used to blast against NCBI blast server.
#!/usr/bin/perl
use strict;
use warnings;
use Bio::Perl;
use Bio::SeqIO;
# create sequence object from the fasta file
my $s = Bio::SeqIO->new(
-file => $ARGV[0],
-format => "fasta"
);
while (my $st = $s->next_seq)
{
# uncomment to print fasta sequence
# print $st->seq;
# blast against NCBI blast server
my $blast_result = blast_sequence($st->seq);
# write blast results to the specified file
write_blast(">$ARGV[1]",$blast_result);
}
usage:
$ chmod 755 blastseq3.pl $ perl blastseq3.pl pygm.fasta pygm.blast