[BioLib-dev] About istream and ostream in script language.

Xin Shuai xshuai at umail.iu.edu
Mon Aug 3 22:54:16 UTC 2009


Thank you a lot for your information, Mark, though I cannot totally
understand your perl code.It seems that there's NO NEED  for the paired
read() and print() in libsequence dealing with iostream, to be mapped to
Python/Perl script. But I'm not sure about whether BioPython has the similar
classes to deal with FASTA streaming.

On Sun, Aug 2, 2009 at 1:54 PM, Mark A. Jensen <maj at fortinbras.us> wrote:

>  Hi David--
> It looks like these classes and methods provide streaming FASTA I/O. In
> BioPerl, there is a class called
> Bio::SeqIO that will do true FASTA streaming. In a Perl script, it would be
> used as follows
>
> for "read":
>
> use Bio::SeqIO;
> my $io = Bio::SeqIO->new(-format=>'fasta', -file => 'filename.fas');
> while ( my $seq = $io->next_seq ) {
>     # do stuff with $seq, which is-a Bio::Seq object
>  }
>
> for "print":
>
> use Bio::SeqIO;
> use Bio::Seq;
> my $io = Bio::SeqIO->new(-format=>'fasta', -file=>'>filename.fas');
> my $seq = Bio::Seq->new( -seq=>'ATACTA', -id=>'seq0' );
> $io->write_seq($seq);
>
> These require a considerable amount of BioPerl machinery, however. What may
> be better is to provide simple "native" Perl functions that accept or return
> a two-member hash
>
> %seq = ( 'id' => 'seq0, 'seq'=>'ATCTGA');
>
> or arrays of hashrefs:
>
> @seqs = ( {'id'=>'seq0', 'seq'=>'ATCTGA'}, {'id'=>'seq1', 'seq'=>'TTCGAT'},
> ... };
>
> and use these to read and write very simple fasta. Using the perl "open()"
> and "print()" functions will automatically generate streams (via C fopen,
> etc, I believe), so no special streaming code would need to be written.
> Maybe Chris has other thoughts as well-
> cheers,
> Mark
>
> ----- Original Message -----
> *From:* Xin Shuai <xshuai at umail.iu.edu>
> *To:* Pjotr Prins <pjotr2009 at thebird.nl> ; chris Fields<cjfields at illinois.edu>; Mark
> A. Jensen <maj at fortinbras.us>
> *Sent:* Saturday, August 01, 2009 5:45 PM
> *Subject:* About istream and ostream in script language.
>
> In libsequence, many classes or struct have the similar following paired
> member functions:
>
> std::istream &  read<http://molpopgen.org/software/libsequence/doc/html/classSequence_1_1Fasta.html#10d9c55ca6c9b8b58593cb4f7b359b02>(std::istream &s)
>
>
> std::ostream & print<http://molpopgen.org/software/libsequence/doc/html/classSequence_1_1Fasta.html#5e71e5adf3dad82a87e5f00ce074ab4a>(std::ostream &s) const
>
> I think the above two functions are used to for user
> to input/output related data. And I also know there's a <std_iostream.i>
> library in swig for Python. But there's no such library in Perl
>
>  I really have no idea of how these two functions can be used in script
> language and how to deal with istream/ostream object in script language.
>
> Thus I'm wondering: Do I need to wrap them into Python/Perl? Or is it
> better to manually write  similar replacing functions for Python/Perl?
> --
> Xin Shuai (David)
> PhD of Complex System in School of Informatics
> Indiana University Bloomington
> 812-606-8019
>
>


-- 
Xin Shuai (David)
PhD of Complex System in School of Informatics
Indiana University Bloomington
812-606-8019



More information about the BioLib-dev mailing list