1 # make as generic as possible (along with gbhandler, emblhandler)
3 # Let the code begin...
5 package Bio
::SeqIO
::swissdriver
;
6 use vars
qw(%FTQUAL_NO_QUOTE);
8 use Bio::SeqIO::Handler::GenericRichSeqHandler;
11 use base qw(Bio::SeqIO);
13 # signals to process what's in the hash prior to next round, maps ann => names
15 OC
=> 'CLASSIFICATION',
16 OH
=> 'HOST', # not currently handled, bundled with organism data for now
26 AS
=> 'ASSEMBLYINFO', # Third party annotation
30 # add specialized delimiters here for easier postprocessing
40 $self->SUPER::_initialize
(@args);
41 my $handler = $self->_rearrange([qw(HANDLER)],@args);
42 # hash for functions for decoding keys.
43 $handler ?
$self->seqhandler($handler) :
44 $self->seqhandler(Bio
::SeqIO
::Handler
::GenericRichSeqHandler
->new(
46 -verbose
=> $self->verbose,
47 -builder
=> $self->sequence_builder
49 if( ! defined $self->sequence_factory ) {
50 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
51 (-verbose
=> $self->verbose(),
52 -type
=> 'Bio::Seq::RichSeq'));
59 Usage : $seq = $stream->next_seq()
60 Function: returns the next sequence in the stream
61 Returns : Bio::Seq object
68 my $hobj = $self->seqhandler;
70 # these contain values that need to carry over each round
71 my ($featkey, $qual, $annkey, $seqdata, $location);
76 while(defined(my $line = $self->_readline)) {
78 my ($ann, $data) = split(m{\s+}, $line, 2);
82 if ($data =~ m{^(\w+)\s+([\d\?\<]+)\s+([\d\?\>]+)(?:\s+?(\S.*))?}ox) {
83 # has location data and desc
85 $hobj->data_handler($seqdata);
88 ($seqdata->{FEATURE_KEY
}, my $loc1, my $loc2, $data) = ($1, $2, $3, $4);
89 $qual = 'description';
90 $seqdata->{$qual} = $data;
91 $seqdata->{NAME
} = $ann;
92 $seqdata->{LOCATION
} = "$loc1..$loc2" if defined $loc1;
94 } elsif ($data =~ m{^\s+/([^=]+)(?:=(.+))?}ox) {
96 ($qual, $data) = ($1, $2 || '');
97 $ct = ($seqdata->{$qual}) ?
98 ((ref($seqdata->{$qual})) ?
scalar(@
{ $seqdata->{$qual} }) : 1)
103 $seqdata->{$qual} .= ($seqdata->{$qual}) ?
106 if (!ref($seqdata->{$qual})) {
107 $seqdata->{$qual} = [$seqdata->{$qual}];
109 ($seqdata->{$qual}->[$ct]) ?
110 ($seqdata->{$qual}->[$ct] .= ' '.$data) :
111 ($seqdata->{$qual}->[$ct] .= $data);
115 if ($ann ne $lastann) {
116 if (!$SEC{$ann} && $seqdata) {
117 $hobj->data_handler($seqdata);
118 # can't use undef here; it can lead to subtle mem leaks
121 $annkey = (!$SEC{$ann}) ?
'DATA' : # primary data
123 $seqdata->{'NAME'} = $ann if !$SEC{$ann};
125 last PARSER
if $ann eq '//';
126 next PARSER
if $ann eq 'SQ';
127 my $delim = $DELIM{$ann} || ' ';
128 $seqdata->{$annkey} .= ($seqdata->{$annkey}) ?
129 $delim.$data : $data;
133 # this should only be sequence (fingers crossed!)
135 while (defined ($line = $self->_readline)) {
136 if (index($line, '//') == 0) {
137 $data =~ tr{0-9 \n}{}d;
138 $seqdata->{DATA
} = $data;
139 #$self->debug(Dumper($seqdata));
140 $hobj->data_handler($seqdata);
150 # some files have no // for the last file; this catches the last bit o' data
151 $hobj->data_handler($seqdata) if $seqdata;
152 return $hobj->build_sequence;
158 Usage : $stream->write_seq($seq)
159 Function: writes the $seq object (must be seq) to the stream
160 Returns : 1 for success and 0 for error
161 Args : array of 1 to n Bio::SeqI objects
166 shift->throw("Use Bio::SeqIO::swiss write_seq() for output");
167 # maybe make a Writer class as well????
173 Usage : $stream->seqhandler($handler)
174 Function: Get/Set teh Bio::Seq::HandlerBaseI object
175 Returns : Bio::Seq::HandlerBaseI
176 Args : Bio::Seq::HandlerBaseI
181 my ($self, $handler) = @_;
183 $self->throw("Not a Bio::HandlerBaseI") unless
184 ref($handler) && $handler->isa("Bio::HandlerBaseI");
185 $self->{'_seqhandler'} = $handler;
187 return $self->{'_seqhandler'};