This file is indexed.

/usr/share/perl5/SWISS/OCs/Oracle.pm is in libswiss-perl 1.67-1.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
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
package SWISS::OCs::Oracle;

use DBI;
use DBD::Oracle; 
use Exporter;
use Carp;
use SWISS::TextFunc;
use SWISS::OCs;
use Utils qw(_print_args);

my $connection=undef;
my $CACHING=1;

my %SWISSID2TAXID=();
my %TAXID2OC=();
my $TAXID2OC_counter=0;

BEGIN {
  #print STDERR "Loading package SWISS::OCs::Oracle.pm\n";
}

sub _connect {
  carp "Connecting..." if $main::opt_debug;
  $connection = DBI->connect('dbi:Oracle:','/@PRDB1','', 
			     {PrintError => 1, RaiseError => 1})
    || die "Cannot connect to server: $DBI::errstr\n";
}

sub _disconnect {
  if ($connection){
    carp "Disconnecting..." if $main::opt_debug;
    $connection->disconnect;
    undef $connection;
  }
}


sub fetch_by_swiss_id {
  my $self = shift;
  my $oscode = shift;
  my $tax_id = oscode2tax_id($swiss_id);
  if ($tax_id){
    return $self->fetch_by_tax_id($tax_id);
  } else {
    carp "swiss_id '$swiss_id' not found" if $main::opt_warn;
  }
  return undef;
}

sub fetch_by_emblacs {
  &_print_args;
  my $self = shift;
  my @emblacs = @_;
  my $tax_id = emblacs2tax_id(@emblacs);
  if ($tax_id){
    return $self->fetch_by_tax_id($tax_id);
  }
  return undef;
}

sub fetch_by_species {
  &_print_args;
  my $self = shift;
  my $species = shift;
  return undef;
} 

sub ncbi_scientific2tax_id {
  &_print_args;
  my $species = shift;
  _connect() unless $connection;
  unless ($FETCH_NCBISCI2TAXID){
    $FETCH_NCBISCI2TAXID = $connection->prepare(q{
       select tax_id
         from datalib.ntx_synonym
        where upper_name_txt = ?
          and name_class = 'scientific name'
    }) || die "$DBI:errstr";
  }

  if ($FETCH_NCBISCI2TAXID->execute(uc($species))){
    my ($tax_id) = $FETCH_NCBISCI2TAXID->fetchrow_array;
    return $tax_id;
  } else {
    return undef;
  }
}

sub ncbi_synonym2tax_id {
  &_print_args;
  my $species = shift;
  _connect() unless $connection;
  unless ($FETCH_NCBISYN2TAXID){
    $FETCH_NCBISYN2TAXID = $connection->prepare(q{
       select tax_id
         from datalib.ntx_synonym
        where upper_name_txt = ?
    }) || die "$DBI:errstr";
  }

  if ($FETCH_NCBISYN2TAXID->execute(uc($species))){
    my ($tax_id) = $FETCH_NCBISYN2TAXID->fetchrow_array;
    return $tax_id;
  } else {
    return undef;
  }
}

sub ncbi_fullos2tax_id {
  &_print_args;
  my $species = shift;

  unless ($FETCH_NCBIFULL2TAXID){
    _connect() unless $connection;
    $FETCH_NCBIFULL2TAXID = $connection->prepare(q{
       select tax_id, fullname
         from opd$wfl.v_ntx_fullname
        where fulluppername = ?
    }) || die "$DBI:errstr";
  }

  if ($FETCH_NCBIFULL2TAXID->execute(uc($species))){
    my ($tax_id) = $FETCH_NCBIFULL2TAXID->fetchrow_array;
    return $tax_id;
  } else {
    return undef;
  }
}

sub ncbi_fullos2tax_id_bulk {
  &_print_args;
  my $species = shift;

  unless ($FETCH_NCBIFULL2TAXIDBULK){
    _connect() unless $connection;
    $FETCH_NCBIFULL2TAXIDBULK = $connection->prepare(q{
       select tax_id, fullname
         from ops$wfl.tmp_ntx_fullname
        where fulluppername = ?
    }) || die "$DBI:errstr";
  }
  if ($FETCH_NCBIFULL2TAXIDBULK->execute(uc($species))){
    my ($tax_id) = $FETCH_NCBIFULL2TAXIDBULK->fetchrow_array;
    return $tax_id;
  } else {
    return undef;
  }
}

sub swiss_scientific2tax_id {
  &_print_args;
  my $species = shift;
  my $tax_id;
  _connect() unless $connection;
  unless ($FETCH_SWISSSCI2TAXID){
    $FETCH_SWISSSCI2TAXID = $connection->prepare(q{
       select tax_id
         from OPS$WFL.Swiss_synonym
        where upper_name_txt = ?
          and name_class = 'scientific name'
    }) || die "$DBI:errstr";
  }

  if ($FETCH_SWISSSCI2TAXID->execute(uc($species))){
    ($tax_id) = $FETCH_SWISSSCI2TAXID->fetchrow_array;
    return $tax_id;
  } else {
    return undef;
  }
}
sub swiss_synonym2tax_id {
  &_print_args;
  my $species = shift;
  my $tax_id;
  _connect() unless $connection;
  unless ($FETCH_SWISSSYN2TAXID){
    $FETCH_SWISSSYN2TAXID = $connection->prepare(q{
       select tax_id
         from OPS$WFL.Swiss_synonym
        where upper_name_txt = ?
          and name_class = 'synonym'
    }) || die "$DBI:errstr";
  }

  if ($FETCH_SWISSSYN2TAXID->execute(uc($species))){
    ($tax_id) = $FETCH_SWISSSYN2TAXID->fetchrow_array;
    return $tax_id;
  } else {
    return undef;
  }
}

sub swiss_fullos2tax_id {
  &_print_args;
  my $species = shift;
  my $tax_id  = $SWISSFULL2TAXID{$species};
  return $tax_id if $tax_id;

  unless (%SWISSFULL2TAXID){
    _connect() unless $connection;
    carp "Loading swissfull->tax_id cache\n" if $main::opt_debug;
    my $sth = $connection->prepare
      (q{
	 select tax_id, fulluppername
           from OPS$WFL.V_swiss_fullname
	  where tax_id is not null
	}) || die "$DBI:errstr";
    $sth->execute || die "$DBI:errstr";
    while (my ($tax_id,$full_os) = $sth->fetchrow_array){
      printf "got :%7d, %s\n",$tax_id,$full_os
	if $main::opt_debug>4;
      $SWISSFULL2TAXID{$full_os}=$tax_id;
    }
    $sth->finish();
  }
  return $SWISSFULL2TAXID{uc($species)};
}

sub taxid2swissosline {
  &_print_args;
  my $tax_id = shift;
  my $osline;
  unless ($FETCH_TAXID2SWISSOSLINEBULK){
    _connect() unless $connection;
    $FETCH_TAXID2SWISSOSLINEBULK = $connection->prepare
      (q{
	       select fullname
           from OPS$WFL.Tmp_swiss_fullname
	        where tax_id = ?
	}) || die "$DBI:errstr";
  }
  if ($FETCH_TAXID2SWISSOSLINEBULK->execute($tax_id)){
    ($osline) = $FETCH_TAXID2SWISSOSLINEBULK->fetchrow_array;
    return $osline;
  } else {
    return undef;
  }
}

sub taxid2ncbiosline {
  &_print_args;
  my $tax_id = shift;
  my $osline;

  unless ($FETCH_TAXID2NCBIOSLINEBULK){
    _connect() unless $connection;
    $FETCH_TAXID2NCBIOSLINEBULK = $connection->prepare
      (q{
      	 select fullname
           from OPS$WFL.Tmp_ntx_fullname
          where tax_id = ?
	}) || die "$DBI:errstr";
  }
  if ($FETCH_TAXID2NCBIOSLINEBULK->execute($tax_id)){
    ($osline) = $FETCH_TAXID2NCBIOSLINEBULK->fetchrow_array;
    return $osline;
  } else {
    return undef;
  }
}

sub taxid2osline {
  &_print_args;
  my $tax_id = shift;
  return taxid2swissosline($tax_id) || taxid2ncbiosline($tax_id);
}


sub swiss_fullos2tax_idbulk {
  &_print_args;
  my $os = shift;
  my $tax_id;

  unless ($FETCH_SWISSFULL2OSLINE){
    _connect() unless $connection;
    $FETCH_SWISSFULL2OSLINE = $connection->prepare
      (q{
	       select tax_id
           from OPS$WFL.Tmp_swiss_fullname
	        where fulluppername = (?)
	}) || die "$DBI:errstr";
  }
  
  if ($FETCH_SWISSFULL2OSLINE->execute(uc($os))){
    ($tax_id) = $FETCH_SWISSFULL2OSLINE->fetchrow_array;
    return $tax_id;
  } else {
    return undef;
  }
}

sub swiss_fullos2osline {
  &_print_args;
  my $os = shift;
  my $osline;

  unless ($FETCH_SWISSFULL2OSLINE){
    _connect() unless $connection;
    $FETCH_SWISSFULL2OSLINE = $connection->prepare
      (q{
         select fullname
           from OPS$WFL.Tmp_swiss_fullname
          where fulluppername = ?
	    }) || die "$DBI:errstr";
  }
  
  if ($FETCH_SWISSFULL2OSLINE->execute(uc($os))){
    ($osline) = $FETCH_SWISSFULL2OSLINE->fetchrow_array;
    return $osline;
  } else {
    return undef;
  }
}

sub ncbi_fullos2osline {
  &_print_args;
  my $os = shift;
  my $osline;

  unless ($FETCH_NCBIFULL2OSLINE){
    _connect() unless $connection;
    $FETCH_NCBIFULL2OSLINE = $connection->prepare
      (q{
         select fullname
           from OPS$WFL.Tmp_ntx_fullname
          where fulluppername = upper(?)
      }) || die "$DBI:errstr";
  }
  
  if ($FETCH_NCBIFULL2OSLINE->execute(uc($os))){
    ($osline) = $FETCH_NCBIFULL2OSLINE->fetchrow_array;
    return $osline;
  } else {
    return undef;
  }
}

sub fetch_by_tax_id {
  &_print_args;
  my $self = shift;
  my $tax_id = shift;

  my $longline;  # taxnodes as returned from oracle
  my @nodes;     # array of taxnodes
  my $result;    # result: either undef or SWISS::OCs object

  if ($CACHING && ($result=$TAXID2OC{$tax_id})){
    return $result;
  }
  
  unless ($FETCH_OC){
    _connect() unless $connection;
    $FETCH_OC = $connection->prepare
      (q{
	 select swiss_ocline(?) from dual
	}) || die "$DBI:errstr";
  }
  $FETCH_OC->execute($tax_id);
  ($longline) = $FETCH_OC->fetchrow_array;
  return undef unless $longline;

  @nodes = SWISS::TextFunc->listFromText($longline, ';\s*', '.\s*');
  if (@nodes){
    $result = new SWISS::OCs();
    $result->add(@nodes);
    if ($CACHING){
      %TAXID2OC=() if $TAXID2OC_counter++ > 1000;
      $TAXID2OC{$tax_id}=$result;
    }
    return $result;
  }
  return undef;
}

sub fetch_by_tax_id_do_not_use_this_anymore {
  &_print_args;
  my $self = shift;
  my $tax_id = shift;

  my $result;
  

  if ($CACHING && ($result=$TAXID2OC{$tax_id})){
    return $result;
  }

  unless ($FETCH_TAXANDPARENT){
   _connect() unless $connection;
   $FETCH_TAXANDPARENT = $connection->prepare(q{
       select tax_id, rank
         from datalib.ntx_tax_node
        where hidden = 0 
          and not rank in ('species','subspecies','varietas','forma')
        start with tax_id = ?	
      connect by tax_id = prior parent_id		 
    }) || die "$DBI:errstr";
  }

  my @nodes=();
  $FETCH_TAXANDPARENT->execute($tax_id);
  while(my ($id,$rank)=$FETCH_TAXANDPARENT->fetchrow_array){
    my $name = tax_id2scientific_name($id);
    unshift @nodes,$name;
  }
  
  if (@nodes){
    $result = new SWISS::OCs();
    $result->add(@nodes);
    if ($CACHING){
      %TAXID2OC=() if $TAXID2OC_counter++ > 1000;
      $TAXID2OC{$tax_id}=$result;
    }
    return $result;
  }
  return undef;
}

sub oscode2tax_id {
  &_print_args;
  my $oscode = shift;
  
  unless (%SWISSID2TAXID){
    _connect() unless $connection;
    carp "Loading oscode->tax_id cache\n" if $main::opt_debug;
    my $sth = $connection->prepare(q{
       select distinct oscode, tax_id
         from ops$wfl.Swiss_synonym
        where tax_id is not null
    }) || die "$DBI:errstr";
    $sth->execute || die "$DBI:errstr";
    while (my ($sid,$tid) = $sth->fetchrow_array){
     $SWISSID2TAXID{$sid}=$tid;
    }
    $sth->finish();
  }
  return $SWISSID2TAXID{$oscode};
}


sub tax_id2swiss_scientific {
  &_print_args;
  my $tax_id = shift;

  unless ($FETCH_SWISS_SCI){
    _connect() unless $connection;
    $FETCH_SWISS_NAME = $connection->prepare
      (q{
	       select name_txt
           from ops$wfl.swiss_synonym
	        where tax_id = ?
	          and name_class = 'scientific name'
	});
  }

  if ($FETCH_SWISS_NAME->execute($tax_id)){
    my ($sci_name) = $FETCH_SWISS_NAME->fetchrow_array;
    return $sci_name;
  } else {
    return tax_id2ncbi_scientific($tax_id);
  }
}

sub tax_id2ncbi_scientific {
  &_print_args;
  my $tax_id = shift;

  unless ($FETCH_SCI_NAME){
    _connect() unless $connection;
    $FETCH_SCI_NAME = $connection->prepare(q{
       select name_txt
         from ops$wfl.v_ntx_synonym
        where tax_id = ?
          and name_class = 'scientific name'
    }) || die "$DBI:errstr";
  }

  if ($FETCH_SCI_NAME->execute($tax_id)){
    my ($sci_name) = $FETCH_SCI_NAME->fetchrow_array;
    return $sci_name;
  } else {
    return undef;
  }
}

sub tax_id2scientific_name {
  &_print_args;
  my $tax_id = shift;
  return tax_id2swiss_scientific($tax_id) 
    || tax_id2ncbi_scientific($tax_id);
}


sub tax_id2superregnum {
  &_print_args;
  my $tax_id = shift;

  unless ($FETCH_SUPERREGNUM){
    _connect() unless $connection;
    $FETCH_SUPERREGNUM = $connection->prepare
      (q{select sr.superregnum
	   from ops$wfl.Swiss_superregnum sr
	  where sr.tax_id in
                (select n.tax_id
                   from DATALIB.Ntx_tax_node n
                  start with n.tax_id = ?
                connect by n.tax_id = prior n.parent_id)
    }) || die "$DBI:errstr";
  }

  if ($FETCH_SUPERREGNUM->execute($tax_id)){
    my ($superregnum) = $FETCH_SUPERREGNUM->fetchrow_array;
    return $superregnum;
  } else {
    return undef;
  }
}

sub emblacs2tax_id {
  &_print_args;
  my @emblacs = @_;

  unless ($FETCH_TAXID_BY_EMBLAC){
    _connect() unless $connection;
    $FETCH_TAXID_BY_EMBLAC = $connection->prepare(
       'select organism as taxid '.
       '  from datalib.sourcefeature,datalib.seqfeature,datalib.dbentry '.
       ' where sourcefeature.featid = seqfeature.featid '.
       '   and seqfeature.bioseqid  = dbentry.bioseqid '.
       '   and dbentry.primaryacc# = ?'
    ) || die "$DBI:errstr";
  }

  my %tax_ids = ();
  foreach $emblac (@emblacs) {
    $FETCH_TAXID_BY_EMBLAC->execute($emblac) || die "$DBI:errstr";
    if ($FETCH_TAXID_BY_EMBLAC->rows()){
      while (($tax_id) = $FETCH_TAXID_BY_EMBLAC->fetchrow_array){
	$tax_ids{$tax_id}++;
      }
    } else {
      #print STDERR "!!!!DEAD primary emblac $emblac\n" if $main::opt_warn;
    }
  }

  return keys %tax_ids;
}


DESTROY {
 _disconnect() if $dbh;
}

1;