/usr/share/perl5/Bio/SeqIO/embldriver.pm is in libbio-perl-perl 1.7.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | #
# BioPerl module for Bio::SeqIO::embldriver
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Ewan Birney <birney@ebi.ac.uk>
#
# Copyright Ewan Birney
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::SeqIO::embldriver - EMBL sequence input/output stream
=head1 SYNOPSIS
It is probably best not to use this object directly, but
rather go through the SeqIO handler system. Go:
$stream = Bio::SeqIO->new(-file => $filename, -format => 'embldriver');
while ( (my $seq = $stream->next_seq()) ) {
# do something with $seq
}
=head1 DESCRIPTION
This object can transform Bio::Seq objects to and from EMBL flat
file databases.
There is a lot of flexibility here about how to dump things which
should be documented more fully.
There should be a common object that this and Genbank share (probably
with Swissprot). Too much of the magic is identical.
=head2 Optional functions
=over 3
=item _show_dna()
(output only) shows the dna or not
=item _post_sort()
(output only) provides a sorting func which is applied to the FTHelpers
before printing
=item _id_generation_func()
This is function which is called as
print "ID ", $func($annseq), "\n";
To generate the ID line. If it is not there, it generates a sensible ID
line using a number of tools.
If you want to output annotations in EMBL format they need to be
stored in a Bio::Annotation::Collection object which is accessible
through the Bio::SeqI interface method L<annotation()|annotation>.
The following are the names of the keys which are polled from a
L<Bio::Annotation::Collection> object.
reference - Should contain Bio::Annotation::Reference objects
comment - Should contain Bio::Annotation::Comment objects
dblink - Should contain Bio::Annotation::DBLink objects
=back
=head1 FEEDBACK
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via
the web:
https://github.com/bioperl/bioperl-live/issues
=head1 AUTHOR - Ewan Birney
Email birney@ebi.ac.uk
=head1 APPENDIX
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _
=cut
# Let the code begin...
package Bio::SeqIO::embldriver;
use vars qw(%FTQUAL_NO_QUOTE);
use strict;
use Bio::SeqIO::Handler::GenericRichSeqHandler;
use Data::Dumper;
use base qw(Bio::SeqIO);
my %FTQUAL_NO_QUOTE = map {$_ => 1} qw(
anticodon citation
codon codon_start
cons_splice direction
evidence label
mod_base number
rpt_type rpt_unit
transl_except transl_table
usedin
LOCATION
);
my %DATA_KEY = (
ID => 'ID',
AC => 'ACCESSION',
DT => 'DATE',
DE => 'DESCRIPTION',
KW => 'KEYWORDS',
OS => 'SOURCE',
OC => 'CLASSIFICATION',
OG => 'ORGANELLE',
RN => 'REFERENCE',
RA => 'AUTHORS',
RC => 'COMMENT',
RG => 'CONSRTM',
RP => 'POSITION',
RX => 'CROSSREF',
RT => 'TITLE',
RL => 'LOCATION',
XX => 'SPACER',
FH => 'FEATHEADER',
FT => 'FEATURES',
AH => 'TPA_HEADER', # Third party annotation
AS => 'TPA_DATA', # Third party annotation
DR => 'DBLINK',
CC => 'COMMENT',
CO => 'CO',
CON => 'CON',
WGS => 'WGS',
ANN => 'ANN',
TPA => 'TPA',
SQ => 'SEQUENCE',
);
my %SEC = (
OC => 'CLASSIFICATION',
OH => 'HOST', # not currently handled, bundled with organism data for now
OG => 'ORGANELLE',
OX => 'CROSSREF',
RA => 'AUTHORS',
RC => 'COMMENT',
RG => 'CONSRTM',
RP => 'POSITION',
RX => 'CROSSREF',
RT => 'TITLE',
RL => 'JOURNAL',
AS => 'ASSEMBLYINFO', # Third party annotation
);
my %DELIM = (
#CC => "\n",
#DR => "\n",
#DT => "\n",
);
# signals to process what's in the hash prior to next round
# these should be changed to map secondary data
my %PRIMARY = map {$_ => 1} qw(ID AC DT DE SV KW OS RN AH DR FH CC SQ FT WGS CON ANN TPA //);
sub _initialize {
my($self,@args) = @_;
$self->SUPER::_initialize(@args);
my $handler = $self->_rearrange([qw(HANDLER)],@args);
# hash for functions for decoding keys.
$handler ? $self->seqhandler($handler) :
$self->seqhandler(Bio::SeqIO::Handler::GenericRichSeqHandler->new(
-format => 'embl',
-verbose => $self->verbose,
-builder => $self->sequence_builder
));
#
if( ! defined $self->sequence_factory ) {
$self->sequence_factory(Bio::Seq::SeqFactory->new
(-verbose => $self->verbose(),
-type => 'Bio::Seq::RichSeq'));
}
}
=head2 next_seq
Title : next_seq
Usage : $seq = $stream->next_seq()
Function: returns the next sequence in the stream
Returns : Bio::Seq object
Args :
=cut
sub next_seq {
my $self = shift;
my $hobj = $self->seqhandler;
local($/) = "\n";
my ($featkey, $qual, $annkey, $delim, $seqdata);
my $lastann = '';
my $ct = 0;
PARSER:
while(defined(my $line = $self->_readline)) {
next PARSER if $line =~ m{^\s*$};
chomp $line;
my ($ann,$data) = split m{\s{2,3}}, $line , 2;
next PARSER if ($ann eq 'XX' || $ann eq 'FH');
if ($ann) {
$data ||='';
if ($ann eq 'FT') {
# seqfeatures
if ($data =~ m{^(\S+)\s+([^\n]+)}) {
$hobj->data_handler($seqdata) if $seqdata;
$seqdata = ();
($seqdata->{FEATURE_KEY}, $data) = ($1, $2);
$seqdata->{NAME} = $ann;
$qual = 'LOCATION';
} elsif ($data =~ m{^\s+/([^=]+)=?(.+)?}) {
($qual, $data) = ($1, $2 ||'');
$ct = (exists $seqdata->{$qual}) ?
((ref($seqdata->{$qual})) ? scalar(@{ $seqdata->{$qual} }) : 1)
: 0 ;
}
$data =~ s{^\s+}{};
$data =~ tr{"}{}d; # we don't care about quotes yet...
my $delim = ($FTQUAL_NO_QUOTE{$qual}) ? '' : ' ';
if ($ct == 0) {
$seqdata->{$qual} .= ($seqdata->{$qual}) ?
$delim.$data :
$data;
} else {
if (!ref($seqdata->{$qual})) {
$seqdata->{$qual} = [$seqdata->{$qual}];
}
(exists $seqdata->{$qual}->[$ct]) ?
(($seqdata->{$qual}->[$ct]) .= $delim.$data) :
(($seqdata->{$qual}->[$ct]) .= $data);
}
} else {
# simple annotations
$data =~ s{;$}{};
last PARSER if $ann eq '//';
if ($ann ne $lastann) {
if (!$SEC{$ann} && $seqdata) {
$hobj->data_handler($seqdata);
# can't use undef here; it can lead to subtle mem leaks
$seqdata = ();
}
$annkey = (!$SEC{$ann}) ? 'DATA' : # primary data
$SEC{$ann};
$seqdata->{'NAME'} = $ann if !$SEC{$ann};
}
# toss the data for SQ lines; this needs to be done after the
# call to the data handler
next PARSER if $ann eq 'SQ';
my $delim = $DELIM{$ann} || ' ';
$seqdata->{$annkey} .= ($seqdata->{$annkey}) ?
$delim.$data : $data;
$lastann = $ann;
}
} else {
# this should only be sequence (fingers crossed!)
SEQUENCE:
while (defined ($line = $self->_readline)) {
if (index($line, '//') == 0) {
$data =~ tr{0-9 \n}{}d;
$seqdata->{DATA} = $data;
#$self->debug(Dumper($seqdata));
$hobj->data_handler($seqdata);
$seqdata = ();
last PARSER;
} else {
$data .= $line;
$line = undef;
}
}
}
}
$hobj->data_handler($seqdata) if $seqdata;
$seqdata = ();
return $hobj->build_sequence;
}
sub next_chunk {
my $self = shift;
my $ct = 0;
PARSER:
while(defined(my $line = $self->_readline)) {
next if $line =~ m{^\s*$};
chomp $line;
my ($ann,$data) = split m{\s{2,3}}, $line , 2;
$data ||= '';
$self->debug("Ann: [$ann]\n\tData: [$data]\n");
last PARSER if $ann =~ m{//};
}
}
=head2 write_seq
Title : write_seq
Usage : $stream->write_seq($seq)
Function: writes the $seq object (must be seq) to the stream
Returns : 1 for success and 0 for error
Args : array of 1 to n Bio::SeqI objects
=cut
sub write_seq {
shift->throw("Use Bio::SeqIO::embl for output");
# maybe make a Writer class as well????
}
=head2 seqhandler
Title : seqhandler
Usage : $stream->seqhandler($handler)
Function: Get/Set the Bio::Seq::HandlerBaseI object
Returns : Bio::Seq::HandlerBaseI
Args : Bio::Seq::HandlerBaseI
=cut
sub seqhandler {
my ($self, $handler) = @_;
if ($handler) {
$self->throw("Not a Bio::HandlerBaseI") unless
ref($handler) && $handler->isa("Bio::HandlerBaseI");
$self->{'_seqhandler'} = $handler;
}
return $self->{'_seqhandler'};
}
1;
__END__
|