/usr/share/perl5/Bio/SeqIO/locuslink.pm is in libbio-perl-perl 1.6.923-1.
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 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | #
# BioPerl module for Bio::SeqIO::locuslink
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Keith Ching <kching at gnf.org>
#
# Copyright Keith Ching
#
# You may distribute this module under the same terms as perl itself
#
# (c) Keith Ching, kching at gnf.org, 2002.
# (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
#
# You may distribute this module under the same terms as perl itself.
# Refer to the Perl Artistic License (see the license accompanying this
# software package, or see http://www.perl.com/language/misc/Artistic.html)
# for the terms under which you may use, modify, and redistribute this module.
#
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# POD documentation - main docs before the code
=head1 NAME
Bio::SeqIO::locuslink - LocusLink input/output stream
=head1 SYNOPSIS
# don't instantiate directly - instead do
my $seqio = Bio::SeqIO->new(-format => "locuslink", -file => \STDIN);
=head1 DESCRIPTION
This module parses LocusLink into Bio::SeqI objects with rich
annotation, but no sequence.
The input file has to be in the LL_tmpl format - the tabular format
will not work.
The way the current implementation populates the object is rather a
draft work than a finished work of art. Note that at this stage the
LocusLink entries cannot be round-tripped, because the parser loses
certain information. For instance, most of the alternative transcript
descriptions are not retained. The parser also misses any element
that deals with visual representation (e.g., 'button') except for the
URLs. Almost all of the pieces of the annotation are kept in a
Bio::Annotation::Collection object, see L<Bio::Annotation::Collection>
for more information.
=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
the Bioperl mailing list. 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
of the bugs and their resolution. Bug reports can be submitted via
the web:
https://redmine.open-bio.org/projects/bioperl/
=head1 AUTHOR - Keith Ching
Email kching at gnf.org
=head1 CONTRIBUTORS
Hilmar Lapp, hlapp at gmx.net
=head1 APPENDIX
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
=cut
package Bio::SeqIO::locuslink;
use strict;
use Bio::Seq::SeqFactory;
use Bio::Species;
use Bio::Annotation::DBLink;
#use Bio::Annotation::Reference;
use Bio::Annotation::Comment;
use Bio::Annotation::SimpleValue;
use Bio::Annotation::OntologyTerm;
use Bio::Annotation::Collection;
use base qw(Bio::SeqIO);
# list of all the field names in locuslink
my @locuslink_keys = qw(
ACCNUM
ALIAS_PROT
ALIAS_SYMBOL
ASSEMBLY
BUTTON
CDD
CHR
COMP
CONTIG
CURRENT_LOCUSID
DB_DESCR
DB_LINK
ECNUM
EVID
EXTANNOT
GO
GRIF
LINK
LOCUSID
LOCUS_CONFIRMED
LOCUS_TYPE
MAP
MAPLINK
NC
NG
NM
NP
NR
OFFICIAL_GENE_NAME
OFFICIAL_SYMBOL
OMIM
ORGANISM
PHENOTYPE
PHENOTYPE_ID
PMID
PREFERRED_GENE_NAME
PREFERRED_PRODUCT
PREFERRED_SYMBOL
PRODUCT
PROT
RELL
STATUS
STS
SUMFUNC
SUMMARY
TRANSVAR
TYPE
UNIGENE
XG
XM
XP
XR
);
# list of fields to make simple annotations from
# fields not listed here or as a key in feature hash are ignored (lost).
my %anntype_map = (
SimpleValue => [qw(
ALIAS_PROT
ALIAS_SYMBOL
CDD
CHR
CURRENT_LOCUSID
ECNUM
EXTANNOT
MAP
NC
NR
OFFICIAL_GENE_NAME
OFFICIAL_SYMBOL
PHENOTYPE
PREFERRED_GENE_NAME
PREFERRED_PRODUCT
PREFERRED_SYMBOL
PRODUCT
RELL
SUMFUNC
)
],
Comment => [qw(
SUMMARY
)
],
);
# certain fields are not named the same as the symgene database list
my %dbname_map = (
pfam => 'Pfam',
smart => 'SMART',
NM => 'RefSeq',
NP => 'RefSeq',
XP => 'RefSeq',
XM => 'RefSeq',
NG => 'RefSeq',
XG => 'RefSeq',
XR => 'RefSeq',
PROT => 'GenBank',
ACCNUM => 'GenBank',
CONTIG => 'GenBank',
# certain fields are not named the same as the symgene
# database list: rename the fields the symgene database name
# key = field name in locuslink
# value = database name in sym
#GO => 'GO',
OMIM => 'MIM',
GRIF => 'GRIF',
STS => 'STS',
UNIGENE => 'UniGene',
);
# certain CDD entries use the wrong prefix for the accession number
# cddprefix will replace the key w/ the value for these entries
my %cddprefix = (
pfam => 'PF',
smart => 'SM',
);
# alternate mappings if one field does not exist
my %alternate_map = (
OFFICIAL_GENE_NAME => 'PREFERRED_GENE_NAME',
OFFICIAL_SYMBOL => 'PREFERRED_SYMBOL',
);
# for these field names, we only care about the first value X in value X|Y|Z
my @ll_firstelements = qw(
NM
NP
NG
XG
XM
XP
XR
PROT
STS
ACCNUM
CONTIG
GRIF
);
# these fields need to be flattened into a single string, using the given
# join string
my %flatten_tags = (
ASSEMBLY => ',',
ORGANISM => '', # this should occur only once
OFFICIAL_SYMBOL => '', # this should occur only once
OFFICIAL_GENE_NAME => '', # this should occur only once
LOCUSID => '', # this should occur only once
PMID => ',',
PREFERRED_SYMBOL => ', ',
PREFERRED_GENE_NAME => ', '
);
# set the default search pattern for all the field names
my %feature_pat_map = map { ($_ , "^$_: (.+)\n"); } @locuslink_keys;
sub _initialize {
my($self,@args) = @_;
$self->SUPER::_initialize(@args);
# overwrite the search pattern w/ the first value pattern
foreach my $key(@ll_firstelements){
$feature_pat_map{$key}="^$key: ([^|]+)";
}
# special search pattern for cdd entries
foreach my $key(keys %cddprefix) {
$feature_pat_map{$key}='^CDD: .+\|'.$key.'(\d+)';
}
# special patterns for specific fields
$feature_pat_map{MAP} = '^MAP: (.+?)\|';
$feature_pat_map{MAPHTML} = '^MAP: .+\|(<.+>)\|';
$feature_pat_map{GO} = '^GO: .+\|.+\|\w+\|(GO:\d+)\|';
$feature_pat_map{GO_DESC} = '^GO: .+\|(.+)\|\w+\|GO:\d+\|';
$feature_pat_map{GO_CAT} = '^GO: (.+)\|.+\|\w+\|GO:\d+\|';
$feature_pat_map{EXTANNOT} = '^EXTANNOT: (.+)\|(.+)\|\w+\|.+\|\d+';
# set the sequence factory of none has been set already
if(! $self->sequence_factory()) {
$self->sequence_factory(Bio::Seq::SeqFactory->new(
-type => 'Bio::Seq::RichSeq'));
}
}
#########################
#
sub search_pattern{
#
#########################
my ($self,
$entry, #text to search
$searchconfirm, #to make sure you got the right thing
$searchpattern,
$searchtype) = @_;
my @query = $entry=~/$searchpattern/gm;
if ($searchconfirm ne "FALSE"){
$self->warn("No $searchtype found\n$entry\n") unless @query;
foreach (@query){
if (!($_=~/$searchconfirm/)){
$self->throw("error\n$entry\n$searchtype parse $_ does not match $searchconfirm\n");
}
}#endforeach
}#endsearchconfirm
return(@query);
}#endsub
############
#
sub read_species{
#
############
my ($spline)=@_;
my $species;
my $genus;
($genus,$species)=$spline=~/([^ ]+) ([^ ]+)/;
my $make = Bio::Species->new();
$make->classification( ($species,$genus) );
return $make;
}
################
#
sub read_dblink{
#
################
my ($ann,$db,$ref)=@_;
my @results=$ref ? @$ref : ();
foreach my $id(@results){
if($id){
$ann->add_Annotation('dblink',
Bio::Annotation::DBLink->new(
-database =>$db ,
-primary_id =>$id));
}
}
return($ann);
}
################
#
sub read_reference{
#
################
my ($ann,$db,$results)=@_;
if($results){
chomp($results);
my @ids=split(/,/,$results);
$ann = read_dblink($ann,$db,\@ids) if @ids;
}
return $ann;
}#endsub
################
#
sub add_annotation{
#
################
my ($ac,$type,$text,$anntype)=@_;
my @args;
$anntype = 'SimpleValue' unless $anntype;
SWITCH : {
$anntype eq 'SimpleValue' && do {
push(@args, -value => $text, -tagname => $type);
last SWITCH;
};
$anntype eq 'Comment' && do {
push(@args, -text => $text, -tagname => 'comment');
last SWITCH;
};
}
$ac->add_Annotation("Bio::Annotation::$anntype"->new(@args));
return($ac);
}#endsub
################
#
sub add_annotation_ref{
#
################
my ($ann,$type,$textref)=@_;
my @text=$textref ? @$textref : ();
foreach my $text(@text){
$ann->add_Annotation($type,Bio::Annotation::SimpleValue->new(-value => $text));
}
return($ann);
}#endsub
################
#
sub make_unique{
#
##############
my ($ann,$key) = @_;
my %seen = ();
foreach my $dbl ($ann->remove_Annotations($key)) {
if(!exists($seen{$dbl->as_text()})) {
$seen{$dbl->as_text()} = 1;
$ann->add_Annotation($dbl);
}
}
return $ann;
}
################
#
sub next_seq{
#
##############
my ($self, @args)=@_;
my (@results,$search,$ref,$cddref);
# LOCUSLINK entries begin w/ >>
local $/="\n>>";
# slurp in a whole entry and return if no more entries
return unless my $entry = $self->_readline;
# strip the leading '>>' if it's the first entry
if (index($entry,'>>') == 0) { #first entry
$entry = substr($entry,2);
}
# we aren't interested in obsoleted entries, so we need to loop
# and skip those until we've found the next not obsoleted
my %record = ();
while($entry && ($entry =~ /\w/)) {
if (!($entry=~/LOCUSID/)){
$self->throw("No LOCUSID in first line of record. ".
"Not LocusLink in my book.");
}
# see whether it's an obsoleted entry, and if so jump to the next
# one entry right away
if($entry =~ /^CURRENT_LOCUSID:/m) {
# read next entry and continue
$entry = $self->_readline;
%record = ();
next;
}
# loop through list of features and get field values
# place into record hash as array refs
foreach my $key (keys %feature_pat_map){
$search=$feature_pat_map{$key};
@results=$self->search_pattern($entry,'FALSE',$search,$search);
$record{$key} = @results ? [@results] : undef;
}#endfor
# terminate loop as this one hasn't been obsoleted
last;
}
# we have reached the end-of-file ...
return unless %record;
# special processing for CDD entries like pfam and smart
my ($PRESENT,@keep);
foreach my $key(keys %cddprefix){
#print "check CDD $key\n";
if($record{$key}) {
@keep=();
foreach my $list (@{$record{$key}}) {
# replace AC with correct AC number
push(@keep,$cddprefix{$key}.$list);
}
# replace CDD ref with correctly prefixed AC number
$record{$key} = [@keep];
}
}
# modify CDD references @=();
if($record{CDD}) {
@keep=();
foreach my $cdd (@{$record{CDD}}) {
$PRESENT = undef;
foreach my $key (keys %cddprefix) {
if ($cdd=~/$key/){
$PRESENT = 1;
last;
}
}
push(@keep,$cdd) if(! $PRESENT);
}
$record{CDD} = [@keep];
}
# create annotation collection - we'll need it now
my $ann = Bio::Annotation::Collection->new();
foreach my $field(keys %dbname_map){
$ann=read_dblink($ann,$dbname_map{$field},$record{$field});
}
# add GO link as an OntologyTerm annotation
if($record{GO}) {
for(my $j = 0; $j < @{$record{GO}}; $j++) {
my $goann = Bio::Annotation::OntologyTerm->new(
-identifier => $record{GO}->[$j],
-name => $record{GO_DESC}->[$j],
-ontology => $record{GO_CAT}->[$j]);
$ann->add_Annotation($goann);
}
}
$ann=add_annotation_ref($ann,'URL',$record{LINK});
$ann=add_annotation_ref($ann,'URL',$record{DB_LINK});
# everything else gets a simple tag or comment value annotation
foreach my $anntype (keys %anntype_map) {
foreach my $key (@{$anntype_map{$anntype}}){
if($record{$key}){
foreach (@{$record{$key}}){
#print "$key\t\t$_\n";
$ann=add_annotation($ann,$key,$_,$anntype);
}
}
}
}
# flatten designated attributes into a scalar value
foreach my $field (keys %flatten_tags) {
if($record{$field}) {
$record{$field} = join($flatten_tags{$field},
@{$record{$field}});
}
}
# annotation that expects the array flattened out
$ann=read_reference($ann,'PUBMED',$record{PMID});
if($record{ASSEMBLY}) {
my @assembly=split(/,/,$record{ASSEMBLY});
$ann=read_dblink($ann,'GenBank',\@assembly);
}
# replace fields w/ alternate if original does not exist
foreach my $fieldval (keys %alternate_map){
if((! $record{$fieldval}) && ($record{$alternate_map{$fieldval}})){
$record{$fieldval}=$record{$alternate_map{$fieldval}};
}
}
# presently we can't store types or context of dblinks - therefore
# we need to remove duplicates that only differ in context
make_unique($ann,'dblink');
# create sequence object (i.e., let seq.factory create one)
my $seq = $self->sequence_factory->create(
-verbose => $self->verbose(),
-accession_number => $record{LOCUSID},
-desc => $record{OFFICIAL_GENE_NAME},
-display_id => $record{OFFICIAL_SYMBOL},
-species => read_species($record{ORGANISM}),
-annotation => $ann);
# dump out object contents
# show_obj([$seq]);
return($seq);
}
################
#
sub show_obj{
#
################
my ($seqlistref)=@_;
my @list=@$seqlistref;
my $out = Bio::SeqIO->new('-fh' => \*STDOUT, -format => 'genbank' );
my ($ann,@values,$val);
foreach my $seq(@list){
$out->write_seq($seq);
$ann=$seq->annotation;
foreach my $key ( $ann->get_all_annotation_keys() ) {
@values = $ann->get_Annotations($key);
foreach my $value ( @values ) {
# value is an Bio::AnnotationI, and defines a "as_text" method
$val=$value->as_text;
print "Annotation ",$key,"\t\t",$val,"\n";
}
}
}
}#endsub
1;
|