/usr/share/perl5/SWISS/Stars.pm is in libswiss-perl 1.67-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 | package SWISS::Stars;
use vars qw($AUTOLOAD @ISA @EXPORT_OK %fields $defaultClass %month2number
$header $footer $mheader $mfooter $headerPattern $footerPattern);
use Exporter;
use Carp;
use strict;
use SWISS::Stars::default;
use SWISS::Stars::aa;
use SWISS::Stars::EV;
BEGIN {
@EXPORT_OK = qw();
@ISA = ( 'Exporter', 'SWISS::BaseClass');
%fields = (
);
# The default class which handles new tags in the PRELIMINARY SECTION
$defaultClass = "SWISS::Stars::default";
$header = "** ################# SOURCE SECTION ##################\n";
$footer = "** ################# INTERNAL SECTION ##################\n";
$mheader = quotemeta $header;
$mfooter = quotemeta $footer;
$headerPattern = '\*\* \#+\s+SOURCE SECTION\s+\#+\n';
$footerPattern = '\*\* \#+\s+INTERNAL SECTION\s+\#+\n';
%month2number =
('01'=>'JAN', '02'=>'FEB', '03'=>'MAR', '04'=>'APR',
'05'=>'MAY', '06'=>'JUN', '07'=>'JUL', '08'=>'AUG',
'09'=>'SEP', '10'=>'OCT', '11'=>'NOV', '12'=>'DEC');
}
sub new {
my $ref = shift;
my $class = ref($ref) || $ref;
my $self = new SWISS::BaseClass;
$self->rebless($class);
return $self;
}
sub initialize {
}
sub AUTOLOAD {
my $self = shift;
my $value;
my $type = ref($self) || carp "Ok, $self is not an object of mine!";
my $name = $AUTOLOAD;
my $fullname = $name;
# * Initialise
if (@_) {
$value = shift;
}
else {
undef $value;
}
# get only the bit we want
$name =~ /::DESTROY/ && return;
$name =~ s/.*://;
# If a value is passed, try to set it
# No type verification - use at your own risk!!!
if (defined $value) {
if ((exists $self->{$name})
||
# is it a permitted object?
(length ($name) == 2 && ref $value )) {
$self->{_dirty} = 1;
# if a subobject is set, it's dirty
if (defined $self->{$name}->{_dirty}) {
$self->{$name}->{_dirty} = 1;
};
return $self->{$name} = $value;
}
else {
confess "Can't set $name to $value. Probably passed a wrong variable name into " . ref($self);
}
}
else {
# * An object has been requested
# If the object exists, return it
if (defined $self->{$name}) {
return $self->{$name};
}
else {
# no object $name yet, create and return it
if (defined &{$fullname . "::fromText"}) {
return $self->{$name} = $fullname->fromText($self->{_textRef});
}
else {
# check if name is a valid object tag
if (length $name == 2) {
$self->{$name} = $defaultClass->fromText($self->{_textRef}, $name);
return $self->{$name};
}
else {
confess "Can't create $name. Probably passed a wrong variable name into " . ref($self);
};
}
}
}
}
sub fromText {
my $self = new(shift);
my $textRef = shift;
my $lines = '';
if ($$textRef =~ /$SWISS::TextFunc::linePattern{'St'}/m){
$lines = $&;
# remove header and footer lines
$lines =~ s/($headerPattern)|($footerPattern)//mg;
# Cleanup empty lines at the beginning of the block
$lines =~ s/\A\*\*\s*\*{0,2}\n//gm;
};
$self->{'_textRef'} = \$lines;
return $self;
};
sub toText {
my $self = shift;
my $textRef = shift;
my $subObject;
# Recursively call toText for the subobjects
foreach $subObject (grep {length $_ == 2}
sort keys %$self) {
if ($self->{$subObject}->{_dirty}) {
$self->{$subObject}->toText($self->{_textRef}, $subObject);
$self->{_dirty} = 1;
}
}
if ($self->{_dirty}) {
# add header, unless it's already there
unless ( ${$self->{_textRef}} =~ /$headerPattern/) {
if ($self->aa->size) {
${$self->{_textRef}} = $header . ${$self->{_textRef}};
}
# Add empty line at the beginning, unless it's already there
unless (${$self->{_textRef}} =~ /^\*\*\n/) {
${$self->{_textRef}} = "\*\*\n" . ${$self->{_textRef}};
}
}
# add footer, unless it's already there
unless ( ${$self->{_textRef}} =~ /$footerPattern/) {
if (${$self->{_textRef}} =~ /\n\*\*\S{2} .*/) {
${$self->{_textRef}} = $` . "\n" . $footer . substr($&, 1) . $';
} else {
${$self->{_textRef}} .= $footer;
};
}
SWISS::TextFunc->insertLineGroup($textRef, ${$self->{_textRef}},
$SWISS::TextFunc::linePattern{'St'});
$self->{_dirty} = 0;
return 1;
}
else {
return 1;
};
};
# Stars is a master object like entry. Therefore it has to update itself
# and its subobjects. The text representation has also to be updated.
sub update {
my $self = shift;
my $force = shift;
my $subObject;
my @subObjects;
# Make sure all subobjects are parsed if $force is set.
if ($force) {
@subObjects = ${$self->{'_textRef'}} =~ /\*\*(\w\w) .*/g;
@subObjects = SWISS::TextFunc->uniqueList(@subObjects);
} else {
@subObjects = grep {length $_ == 2} sort keys %$self;
}
# Recursively call the subobjects
foreach $subObject (@subObjects) {
$self->$subObject()->{_dirty} = 1;
$self->$subObject()->update();
}
$self->{_dirty} = 1;
return 1;
}
sub insertLineGroup {
my ($class, $textRef, $text, $tag) = @_;
my ($currentTag);
# remove old lines with the tag in question
$$textRef =~ s/^(\*\*$tag .*\n)//gm;
# find the insertion position
# [This should be optimised!]
while ($$textRef =~ /^\*\*(..).*/gm) {
if ($1 gt $tag) {
$$textRef = $` . $text . $& . $';
return 1;
}
};
$$textRef .= $text;
return 1;
};
# Function: transfer from the old into the new ** section format
# Args : $curatedBlock : if set, the function supposes that
# the curator's comments are in a block
# started by $curatedStart and
# terminated by $curatedStop
# Returns : true
sub translate {
my $self = shift;
my $curatedBlock = shift;
my ($tmp, $tmpText, @tmp);
# transfer
# ** XXXX_ARATH
if (@tmp = $self->aa->get('[A-Z0-9]{1,4}\_[A-Z0-9]{3,5}')){
$self->aa->del('[A-Z0-9]{1,4}\_[A-Z0-9]{3,5}');
# Remove duplicates
if ($#tmp > 0) {
$tmp = new SWISS::ListBase;
$tmp->add(@tmp);
$tmp->unique();
@tmp = $tmp->elements();
}
$self->ID->add(@tmp);
};
# Delete PFAM predictions, they will be redone.
$self->aa->del('.*PREDICTED BY PFAM.*');
# Delete DR PRINTS, they are now in the main section
$self->aa->del('DR PRINTS.*');
# Delete DR PROSITE
$self->aa->del('PROSITE.*');
# Delete ** PSnnnnn lines
$self->aa->del('PS\d{5}.*');
# Delete ** EMOTIF
$self->aa->del('EMOTIF.*');
# Delete ** MISSING lines
$self->aa->del('MISSING.*');
# Delete
# ** -!- SUBCELLULAR LOCATION: NUCLEAR (POTENTIAL;
# ** PREDICTED BY NNPSL; 57.9 ACCURACY).
$self->aa->del('.*SUBCELLULAR LOCATION:.*POTENTIAL.*');
$self->aa->del('.*PREDICTED BY NNPSL.*');
# transfer
# ** DR GENBANK JOURNAL-SCAN; G1754741.
if (@tmp = $self->aa->get('DR GENBANK JOURNAL-SCAN.*')){
$self->aa->del('DR GENBANK JOURNAL-SCAN.*');
$self->GP->add(@tmp);
};
# transfer
# ** TAX_ID; 4932; Saccharomyces cerevisiae.
my ($line) = $self->aa->get('TAX_ID; .*');
if ($line) {
$line =~ /^TAX_ID; (-*\d+);/;
$self->OX->add($1 . ";");
$self->aa->del('TAX_ID.*');
}
# transfer
# ** RULE RU000204.
# ** RULE RU000195; 1998-01-22.
# to
# **RU RU000201; 22-SEP-1999.
my ($rule, $rulenum, $year, $month, $day);
if (@tmp = $self->aa->get('RULE\s+RU\d{6}.*')){
foreach $rule (@tmp) {
($rulenum) = $rule =~ /RULE\s+(RU\d{6})/;
($year, $month, $day) = $rule =~ /(\d{4})-(\d{2})-(\d{2})/;
if ($year){
$month = $month2number{$month};
$self->RU->add("$rulenum; $day-$month-$year.");
} else {
$self->RU->add("$rulenum;");
}
};
$self->aa->del('RULE\s+RU\d{6}.*');
}
# transfer the curator's comments
my $curatedStart = '((CREATED AND FINISHED BY)|(ANNOT )).*';
my $curatedText = '((FINISHED BY )|(ANNOTATED BY )|(UPDATED BY )|(ANNOT BY )).*';
my $curatedStop = 'CURATED\.?';
if ($curatedBlock) {
# Parse a prestructured block of curator's comments
my $inBlock = 0;
foreach $line ($self->aa->elements) {
if ($line =~ /\A$curatedStart\Z/i) {
$inBlock = 1;
};
if ($inBlock) {
$self->aa->del(quotemeta $line);
$self->ZZ->add($line);
if ($line =~ /\A$curatedStop\Z/) {
$inBlock = 0;
};
}
}
} else {
# Transfer only well-defined lines of curator's comments
foreach $line ($self->aa->elements) {
if ($line =~/\A$curatedStart\Z/i
||
$line =~/\A$curatedText\Z/i
||
$line =~/\A$curatedStop\Z/
) {
$self->aa->del(quotemeta $line);
$self->ZZ->add($line);
}
}
}
$self->{_dirty} = 1;
return 1;
}
sub sort {
my $self = shift;
my $subObject;
# Recursively call sort for the subobjects
foreach $subObject (grep {length $_ == 2} keys %$self) {
$self->{$subObject}->sort;
};
return 1;
}
sub cleanUpReferences {
my $self = shift;
my @lines = @{$self->list()};
my ($start,$end,$dirty);
REFERENCE:
for ($start=0; $start <= $#lines; $start++){
# find a reference start
while ($start<=$#lines && $lines[$start] !~ /^\[\d+\]/){
$start++;
}
last if $start>$#lines;
$end=$start+1;
while ($end<=$#lines && $lines[$end] !~ /^\[\d+\]/){$end++;}
last if $end>$#lines;
# now look for similar references
my $length = $end - $start - 1;
my $next;
TRY:
for ($next=$end; $next<=$#lines; $next++){
next if $lines[$next] !~ /^\[(\d+)\]/;
my $j;
for ($j=1; $j<=$length; $j++){
next REFERENCE if $j>$#lines;
#printf "%03d<<<%-20.20s>>%-20.20s%03d\n"
# ,$start+$j,$lines[$start+$j],
# $lines[$next+$j],$next+$j;
next TRY
if ($lines[$start+$j] ne $lines[$next+$j]);
}
my @removed = splice(@lines, $next, $j);
$main::opt_debug > 2 && print "Stars::cleanUpReferences: Removed\n".
join("\n",@removed)."\n";
$dirty |= 1;
$next--;
}
$start++
}
if ($dirty){
@{$self->{'list'}} = @lines;
$self->_dirty(1);
}
return $dirty;
}
1;
__END__
=head1 NAME
B<SWISS::Stars.pm>
=head1 DESCRIPTION
B<SWISS::Stars> represents the ** lines within an SWISS-PROT + TrEMBL
entry. These are the lines with the line tag ** which are normally not
publicly visible.
B<SWISS::Stars> is a master object like SWISS::Entry. It contains subobjects which represent the different line types in the ** section. Each line type has a two letter tag in addition to the ** line tag. This module has been written to allow easy addition of new ** line types. To use a new ** line tag, just use the tag as an object dereference. Example:
$entry->Stars->XX->add("New XX tag line.","Second new XX tag line.");
If there is no class SWISS::Stars::XX, the class of the new object will be SWISS::Stars::default, which handles lines with the corresponding tag as an array of lines. If more specific handling is required, a new class SWISS::Stars::XX can be created following the template of SWISS::Stars::default. An example is SWISS::Stars::aa.
Subclass names and new line tags have to be two-letter-tags. B<No checks are made wheter the dereferenced tag is allowed.>
Access to the (old) unstructured ANNOTATOR'S SECTION is provided by the line tag 'aa'.
$entry->Stars->aa->add("Testline 1.","Second new test line.");
will add these two lines to the ANNOTATOR'S SECTION.
=head1 Inherits from
SWISS::BaseClass.pm
=head1 Attributes
=over
No public attributes apart from the subclasses.
=back
=head1 Methods
=head2 Standard methods
=over
=item new
=item fromText
=item toText
=item update
=back
|