3
在Perl中,我們有IO::ScalarArray
用於處理數組的元素,如文件的行。在BioPerl中,我們有Bio::SeqIO
,它可以生成一個文件句柄,讀取和寫入Bio::Seq
對象,而不是表示文本行的字符串。我想做兩者的結合:我想獲得一個句柄,它從一組這樣的對象中讀取連續的Bio::Seq
對象。有沒有辦法做到這一點?對我來說,實現一個這樣做的模塊會是微不足道的嗎?對於Seq對象數組,有沒有Bio :: IO :: ScalarArray的等價物?
我想要這樣做的原因是我希望能夠編寫一個子程序,它接受Bio::SeqIO
句柄或Bio::Seq
對象的數組,並且我希望避免根據什麼類型的輸入來編寫單獨的循環我明白了。也許下面比編寫我自己的IO模塊更好?
sub process_sequences {
my $input = $_[0];
# read either from array of Bio::Seq or from Bio::SeqIO
my $nextseq;
if (ref $input eq 'ARRAY') {
my $pos = 0
$nextseq = sub { return $input->[$pos++] if $pos < @$input}; }
}
else {
$nextseq = sub { $input->getline(); }
}
while (my $seq = $nextseq->()) {
do_cool_stuff_with($seq)
}
}
感謝您讓我到HOP,這導致我[[Iterator :: Simple]](http://search.cpan.org/~rintaro/Iterator-Simple-0.05/lib/Iterator/Simple.pm) – 2010-04-26 04:56:28