1 #-----------------------------------------------------------------------------
2 # PACKAGE : Bio::SeqIO::tab
3 # AUTHOR : Philip Lijnzaad <p.lijnzaad@med.uu.nl>
6 # Copyright (c) This module is free software; you can redistribute it
7 # and/or modify it under the same terms as Perl itself.
11 # Ewan Birney <birney@ebi.ac.uk> developed the SeqIO
12 # schema and the first prototype modules.
14 # This code is based on his Bio::SeqIO::raw
16 # You may distribute this module under the same terms as perl itself
18 # POD documentation - main docs before the code
22 Bio::SeqIO::tab - nearly raw sequence file input/output
23 stream. Reads/writes id"\t"sequence"\n"
27 Do not use this module directly. Use it via the L<Bio::SeqIO> class.
31 This object can transform Bio::Seq objects to and from tabbed flat
34 It is very useful when doing large scale stuff using the Unix command
35 line utilities (grep, sort, awk, sed, split, you name it). Imagine
36 that you have a format converter 'seqconvert' along the following
39 my $in = Bio::SeqIO->newFh(-fh => \*STDIN , '-format' => $from);
40 my $out = Bio::SeqIO->newFh(-fh=> \*STDOUT, '-format' => $to);
41 print $out $_ while <$in>;
43 then you can very easily filter sequence files for duplicates as:
45 $ seqconvert < foo.fa -from fasta -to tab | sort -u |\
46 seqconvert -from tab -to fasta > foo-unique.fa
48 Or grep [-v] for certain sequences with:
50 $ seqconvert < foo.fa -from fasta -to tab | grep -v '^S[a-z]*control' |\
51 seqconvert -from tab -to fasta > foo-without-controls.fa
53 Or chop up a huge file with sequences into smaller chunks with:
55 $ seqconvert < all.fa -from fasta -to tab | split -l 10 - chunk-
56 $ for i in chunk-*; do seqconvert -from tab -to fasta < $i > $i.fa; done
57 # (this creates files chunk-aa.fa, chunk-ab.fa, ..., each containing 10
65 User feedback is an integral part of the evolution of this and other
66 Bioperl modules. Send your comments and suggestions preferably to one
67 of the Bioperl mailing lists. Your participation is much appreciated.
69 bioperl-l@bioperl.org - General discussion
70 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
74 Please direct usage questions or support issues to the mailing list:
76 I<bioperl-l@bioperl.org>
78 rather than to the module maintainer directly. Many experienced and
79 reponsive experts will be able look at the problem and quickly
80 address it. Please include a thorough description of the problem
81 with code and data examples if at all possible.
85 Report bugs to the Bioperl bug tracking system to help us keep track
86 the bugs and their resolution.
87 Bug reports can be submitted via the web:
89 https://github.com/bioperl/bioperl-live/issues
93 Philip Lijnzaad, p.lijnzaad@med.uu.nl
97 The rest of the documentation details each of the object methods.
98 Internal methods are usually preceded with a _
103 # Let the code begin...
105 package Bio
::SeqIO
::tab
;
110 use base
qw(Bio::SeqIO);
115 Usage : $seq = $stream->next_seq()
116 Function: returns the next sequence in the stream
117 Returns : Bio::Seq object
124 my ($self,@args) = @_;
125 ## When its 1 sequence per line with no formatting at all,
126 ## grabbing it should be easy :)
128 my $nextline = $self->_readline();
129 chomp($nextline) if defined $nextline;
130 return unless defined $nextline;
131 if ($nextline =~ /^([^\t]*)\t(.*)/) {
132 my ($id, $seq)=($1, uc($2));
134 return Bio
::Seq
->new(-display_id
=> $id, -seq
=> $seq);
136 $self->throw("Can't parse tabbed sequence entry:'$nextline' around line $.");
143 Usage : $stream->write_seq($seq)
144 Function: writes the $seq object into the stream
145 Returns : 1 for success and 0 for error
146 Args : Bio::Seq object
152 my ($self,@seq) = @_;
154 if ($_->display_id() =~ /\t/) {
155 $self->throw("display_id [".$_->display_id()."] contains TAB -- illegal in tab format");
157 $self->_print($_->display_id(), "\t",$_->seq, "\n") or return;
160 $self->flush if $self->_flush_on_write && defined $self->_fh;