[Bioperl-l] genbank to fasta conversion

Thomas Sharpton sharpton at berkeley.edu
Thu Aug 20 16:40:34 EDT 2009


This is a problem I think I can solve, so I'm chiming in for once.

Looks to me like you're trying to pass a file handle to the -file  
setting in your SeqIO object.  One of the excellent things about using  
SeqIO is that you don't need to worry about file handles; it's all  
taken care of under the hood.  Try the following adaptation of your  
script:

#!/usr/bin/perl -w
use strict;
use Bio::SeqIO;

my $inFile  = "C:/Documents and Settings/mydir/Desktop/TARGETING.gb";
my $outfile = "C:/Documents and Settings/mydir/Desktop/TARGET.fa";

#OPEN A SEQUENCE FILE OF INTEREST ($inFile) AND CREATE A SEQUENCE  
STREAM ($in)
my $in  = Bio::SeqIO->new(-file => "$inFile" , '-format' => 'GenBank');

#OPEN AN OUPUT FILE OF INTEREST ($outfile)AND CREATE AN OUTPUT  
SEQUENCE STREAM ($out)
#NOTICE HOW WE SET -file FOR OUTPUT WITH THE > SYMBOL HERE:
my $out = Bio::SeqIO->new(-file => ">$outfile" ,'-format' => 'Fasta');

#NOW LET'S DO THE CONVERSION AND DUMP THE OUTPUT
#INSTEAD OF DOING THIS
#print $out $_ while <$in>;
#TRY THIS
while(my $seq = $in->next_seq() ){
	$out->write_seq($seq)
}

The above is pretty much what you'll find here: http://www.bioperl.org/wiki/HOWTO:SeqIO 
   which you should definitely look over to better understand what's  
happening with SeqIO object.

Good luck!
Tom

On Aug 20, 2009, at 1:31 PM, Mgavi Brathwaite wrote:

> Hello,
>
> I have previously converted multiple genbank files to fasta. For  
> some reason
> I am having trouble with this simple script.
> #!/usr/bin/perl -w
> use strict;
> use Bio::SeqIO;
>
> open (my $inFile, "C:/Documents and Settings/mydir/Desktop/ 
> TARGETING.gb");
> open (my $outfile, ">C:/Documents and Settings/mydir/Desktop/ 
> TARGET.fa");
> my $in  = Bio::SeqIO->new('-file' => "$inFile" ,
>                           '-format' => 'GenBank');
> my $out = Bio::SeqIO->new('-file' => "$outfile" ,'-format' =>  
> 'Fasta');
> print $out $_ while <$in>;
>
> I keep getting the error:
> ------------- EXCEPTION: Bio::Root::Exception -------------
> MSG: Could not open GLOB(0x36a214): No such file or directory
> STACK: Error::throw
> STACK: Bio::Root::Root::throw C:/Perl/site/lib/Bio/Root/Root.pm:359
> STACK: Bio::Root::IO::_initialize_io C:/Perl/site/lib/Bio/Root/IO.pm: 
> 310
> STACK: Bio::SeqIO::_initialize C:/Perl/site/lib/Bio/SeqIO.pm:454
> STACK: Bio::SeqIO::genbank::_initialize C:/Perl/site/lib/Bio\SeqIO\
> genbank.pm:202
> STACK: Bio::SeqIO::new C:/Perl/site/lib/Bio/SeqIO.pm:351
> STACK: C:/Perl/site/lib/Bio/SeqIO.pm:377
> -----------------------------------------------------------
>
> I am probably missing something simple, but would appreciate any help.
>
> M
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l




More information about the Bioperl-l mailing list