BioPerl (Perl syntax/programming using Bio::Perl) Write a program that takes the
ID: 3860447 • Letter: B
Question
BioPerl (Perl syntax/programming using Bio::Perl)
Write a program that takes the name of a FASTA file as its argument. The program should parse the FASTA file and present a list of the sequences the file contains, then allow the user of the program to select one or more sequences to BLAST against the appropriate database. The blast_sequence() method in Bio::Perl, contrary to what the documentation says, always runs BLASTP. Consequently, you will need to translate the nucleotide sequences before BLASTing them.
Explanation / Answer
use Bio::AlignIO;
$inputfilename = "testaln.fasta";
$in = Bio::AlignIO->new(-file => $inputfilename ,
-format => 'fasta');
$out = Bio::AlignIO->new(-file => ">out.aln.pfam" ,
-format => 'pfam');
while ( my $aln = $in->next_aln() ) {
$out->write_aln($aln);
}
# OR
use Bio::AlignIO;
open MYIN, '<', 'testaln.fasta' or die "Could not read file 'testaln.fasta': $! ";
$in = Bio::AlignIO->newFh(-fh => *MYIN,
-format => 'fasta');
open my $MYOUT, '>', 'testaln.pfam' or die "Could not write file 'testaln.pfam': $! ";
$out = Bio::AlignIO->newFh(-fh => $MYOUT,
-format => 'pfam');
# World's smallest Fasta<->pfam format converter:
print $out $_ while <$in>;
DESCRIPTION
AlignIO is a handler module for the formats in the AlignIO set, for example, Bio::AlignIO::fasta. It is the officially sanctioned way of getting at the alignment objects. The resulting alignment is a Bio::Align::AlignI-compliant object.
The idea is that you request an object for a particular format. All the objects have a notion of an internal file that is read from or written to. A particular AlignIO object instance is configured for either input or output, you can think of it as a stream object.
Each object has functions:
$stream->next_aln();
And:
$stream->write_aln($aln);
Also:
$stream->type() # returns 'INPUT' or 'OUTPUT'
As an added bonus, you can recover a filehandle that is tied to the AlignIO object, allowing you to use the standard <> and print operations to read and write alignment objects:
use Bio::AlignIO;
# read from standard input
$stream = Bio::AlignIO->newFh(-format => 'Fasta');
while ( $aln = <$stream> ) {
# do something with $aln
}
And:
print $stream $aln; # when stream is in output mode
Bio::AlignIO is patterned on the Bio::SeqIO module and shares most of its features. One significant difference is that Bio::AlignIO usually handles IO for only a single alignment at a time, whereas Bio::SeqIO handles IO for multiple sequences in a single stream. The principal reason for this is that whereas simultaneously handling multiple sequences is a common requirement, simultaneous handling of multiple alignments is not.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.