[Bioperl-l] Writing embl entry to string

Bernhard Schmalhofer Bernhard.Schmalhofer at biomax.de
Tue Sep 21 09:45:36 EDT 2004


Peter van Heusden wrote:
> TAPO (Thomas Agersten Poulsen) wrote:
> 
>> Dear List,
>>
>>     I am writing a small script to split embl-files into smaller file 
>> of a given maximum file size.
>> To this end, I would like to get the output from Bio::SeqIO->write_seq 
>> into a string (so I can evaluate length() on it). Would anybody out 
>> there know if this is posible????
>>
>>  
>>
> There's an example describing how to do this in the SeqIO howto at 
> http://bioperl.org/HOWTOs/SeqIO/string.html:
> 
>       use IO::String;
>       use Bio::SeqIO;
>             my $str;
>       my $io = IO::String->new(\$str);
>       my $seqOut = Bio::SeqIO->new(-format => 'swiss', 
>                                    -fh     => $io );
>       $seqOut->write_seq($seq_obj);
>       print $str;
> 

As of Perl 5.6.0 following is also possible, and maybe nicer:

        use Bio::SeqIO;
        my $str;
        open( my $str_fh, '>', \$str );
        my $seq_out = Bio::SeqIO->new( -format => 'swiss',
                                       -fh     => $str_fh ); 

        $seq_out->write_seq( $seq_obj );
        print $str;

CU, Bernhard

-- 
**************************************************
Dipl.-Physiker Bernhard Schmalhofer
Senior Developer
Biomax Informatics AG
Lochhamer Str. 11
82152 Martinsried, Germany
Tel: +49 89 895574-839
Fax: +49 89 895574-825
eMail: Bernhard.Schmalhofer at biomax.com
Website: www.biomax.com
**************************************************



More information about the Bioperl-l mailing list