-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGO_Tools
executable file
·1753 lines (1451 loc) · 75 KB
/
GO_Tools
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
#$Id$
# Copyright © 2009, Stowers Institute for Medical Research. All rights reserved.
# c.f. attached LICENSE
## TO DO:
##
## Add term-tree intersection matrices: input list of N terms, get NxN matrix where cells indicate any of: { child progeny parent ancestor } overlap, or other-list-member-containment
##
## Fix --rootpaths; currently --flatmap IS --rootpaths
##
## WANT TO FIND A WAY TO FILTER OUT NON-SPECIES TERMS!!!!!!!!!!!!!!!
## -- except, it seems not even geneontology.org can do this completely.
## still, there at least must be a way to eliminate ectopic plant/fungal terms from vertebrate searches? hardcoded grep lists?
=pod
=head1 SYNOPSIS
GO_Tools is a set of high-level GO database queries on the command-line.
=head1 OPTIONS
=over
=item B<--showdbs [-h hostname] [-f output_file]>
Show a list of canonically-named GO databases (go_yyyymm) on the specified host (default = mysql-dev).
=item B<--showtaxa [-f output_file] [--sprintf]>
Show a list of the NCBI taxa ids for the most common model organisms.
=item B<--orgstats [-o Genus.species] [-d db_name] [-h host_name] [-f output_file] [--novirus]>
Input your genus and species separated by a period to see all NCBI taxa ids for that organism. Genus must be Capitalized. Use "Genus." to query all
species within a genus. This uses approximate species matching: string queried is "species*". Returned is a table with taxon ID, scientific name, and
three database parameters for the taxon id: gene count, gene label count, and GO term count. Use "--novirus" to block viral results, i.e. any taxa
containing the string "virus" (there can be lots...)
=item B<--showxrefs [-x taxon_id(s)] [-d db_name] [-h host_name] [-f output_file] [--noPDB] [--sprintf]>
Show all xref identifier databases for each org(s) and the first 5 IDs for each, as well as the number of IDs in each vs number of genes for org. "-x" can be one taxon ID, or a CSV list of them.
=item B<--getdbids [-x taxon_id] [-d db_name] [-h host_name] [-i id_list_file] [-f output_file] [--clean] [--long]>
Get a table of all mappable gene identifiers AND their mapped terms for a specified organism. Use "--clean" flag to discard all mappings to generic terms,
e.g. "biological process" or "biological process unknown". Use "--long" to output one line per term, instead of one line per gene. Use "-i <file>" to report results for only these identifiers (uses exact match against Symbol, Name, Xref).
=item B<--findterms [-a GO_accession_list] [-d db_name] [-h host_name] [-f output_file]>
Identify which GO DB a given accession (or file containing multiple accessions) came from. Returns 3 cols: 1=database, 2=accession, 3=name.
=item B<--termtable [-x taxon_id] [-d db_name] [-h host_name] [-f output_file] [-g grep] [--noimputed]>
In-depth reporting for each GO term for the specified organism, either annotated directly or imputed by hierarchical relationships. Includes accession,
name, level(s), numbers of parents, children, total downstream IDs, and annotated genes, etc. Use --noimputed to restrict terms to only those with direct
gene annotations (this will probably return an incomplete hierarchy). Use -g to restrict results based on a grep against term name.
=item B<--slimmap [-a slim_list] [-x taxon_id] [-d db_name] [-h host_name] [-f output_file] [--stats]>
Given a slim list (column 1 = GO accession(s); any other columns ignored), returns one of two things. If the --stats flag is used, returns mapping statistics: number of terms mapped to each slim term, number of overlaps between terms, parent/child relationships among slim terms, and number of terms which are unmappable to the slim list. If --stats is not used, then a 4-column slim map is returned: cols 1-2 = mapped acc, name; cols 3-4 = slim acc, name.
=item B<--slimtree [-a GO_accession(s)] [-x taxon_id] [-d db_name] [-h host_name] [-f output_file] [--genes]>
This option returns the downstream terms of a given GO accession (or CSV string of accessions), useful e.g. when using a slim list
and you want to know what terms map to a particular slim term. Using --genes adds, for each output term, the list of all genes mapping to that term.
=item B<--fulltree [-x taxon_id] [-d db_name] [-h host_name] [-f output_file]>
Designed for building custom MeV annotation files. This option gives a 5-column list (GO type, child acc, child name, parent acc, parent name) of all
terms with one degree of separation. Results are constrained to the given organism. The list contains the minimal information required to construct the
entire GO graph for that organism.
=item B<--children [-a GO_accession(s) or file] [-x taxon_id] [-d db_name] [-h host_name] [-f output_file]>
Finds the immediate child terms for a GO accession or list of accessions. List may be a file or a comma-delimited string of GO
accessions.
=item B<--parents [-a GO_accession(s) or file] [-x taxon_id] [-d db_name] [-h host_name] [-f output_file]>
Finds the immediate parent terms for a GO accession or list of accessions. List may be a file or a comma-delimited string of GO
accessions.
=item B<--allparents [-a GO_accession] [-x taxon_id] [-d db_name] [-h host_name] [-f output_file] [--genes]>
UNDER CONSTRUCTION. Sort of the opposite of --slimtree: this option returns all parents for the given term.
=item B<--rootpaths [-a GO_accession] [-x taxon_id] [-d db_name] [-h host_name] [-f output_file] [--genes]>
UNDER CONSTRUCTION. The ordered version of --allparents: all parents for a given term, organized into paths leading back to the root.
=item B<--nca [-a GO_accession(s) or file] [-x taxon_id] [-d db_name] [-h host_name] [-f output_file]>
Finds the nearest common ancestor term for a list of GO accessions. List may be a file or a comma-delimited string of GO accessions.
=item B<--cache [-d db_name]>
Create default GO_Tools / FatiClone cache files for a new GO database (only done once, at DB install time)
=item B<--help>
Display command line usage with options.
=item B<--man>
Display complete manual page and exit.
=item B<--version>
Display the scripts version number and exit.
=back
=head1 EXAMPLES
=over
=item C< GO_Tools --man >
print a manpage.
=item C< GO_Tools --showtaxa >
show the NCBI taxa numbers for the most common model organisms.
=item C< GO_Tools --orgstats Bacillus.subtilis -d go_201001>
show all NCBI taxa numbers associated with Bacillus subtilis* from database 'go_201001', and their associated DB statistics.
=item C< GO_Tools --showdbs -h rho >
show any GO databases (with name format go_yyyymm) on host rho.
=back
=head1 VERSION
$Revision: 1.0$
=head1 AUTHOR
Ariel Paulson ([email protected])
=head1 DEPENDENCIES
perl
=head1 AVAILABILITY
Download at will.
=cut
require '/home/apa/apa_routines.pm';
use DBI;
use Cwd;
use Storable (qw/ nstore retrieve /);
use File::Path;
use Data::Dumper;
use Getopt::Long;
use Pod::Usage;
use FindBin;
use strict;
no strict 'refs';
#use vars qw($VERSION $VC_DATE);
#BEGIN {
our $VERSION = qw$Revision: 1.0 $[-1];
our $VC_DATE = qw$Date: $[-2];
#}
###################################################################### ACTUAL CODE ######################################################################
###################################################################### ACTUAL CODE ######################################################################
###################################################################### ACTUAL CODE ######################################################################
###################################################################### ACTUAL CODE ######################################################################
###################################################################### ACTUAL CODE ######################################################################
### Setup
# script parameters
my ($taxon, $slimtree, $slimmap, $fulltree, $flatmap, $orgstats, $getdbids, $findterms, $termtable, $children, $parents, $allparents, $rootpaths, $nca, $genspec, $slimacc);
my ($cache, $showdbs, $showtaxa, $showxrefs, $help, $man, $ver, $GOdb, $clean, $genes, $novirus, $noimputed, $do_sprintf, $no_PDB, $idfile, $outfile, $grep, $stats, $long, $full);
my $dbhost = 'mysql-dev';
my $cachedir = "/home/apa/local/bin/GO_Tools_DBcache"; # DB cache directory
GetOptions(
"x=s" => \$taxon,
"d=s" => \$GOdb,
"h=s" => \$dbhost,
"o=s" => \$genspec,
"a=s" => \$slimacc,
"i=s" => \$idfile,
"f=s" => \$outfile,
"g=s" => \$grep,
"clean" => \$clean,
"long" => \$long,
"full" => \$full,
"genes" => \$genes,
"stats" => \$stats,
"novirus" => \$novirus,
"noimputed" => \$noimputed,
"noPDB" => \$no_PDB,
"sprintf" => \$do_sprintf,
"cache" => \$cache,
"showdbs" => \$showdbs,
"showtaxa" => \$showtaxa,
"showxrefs" => \$showxrefs,
"slimtree" => \$slimtree,
"slimmap" => \$slimmap,
"fulltree" => \$fulltree,
"flatmap" => \$flatmap,
"getdbids" => \$getdbids,
"findterms" => \$findterms,
"termtable" => \$termtable,
"orgstats" => \$orgstats,
"children" => \$children,
"parents" => \$parents,
"allparents" => \$allparents,
"rootpaths" => \$rootpaths,
"nca" => \$nca,
"help|?" => \$help,
"man!" => \$man,
"version!" => \$ver
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
if ($ver) {print "$FindBin::Script: $VERSION\n"; exit(0)};
# declare HERE
my (%four_names, %slimterms, %slimfound, %ignore, %termlevels, %idtable, %allterms, %inputids);
my (%accdata, %obsoletes, %levelmap, %relations, %idcounts, %idtrack, %output, %alliters, %write_termgene_already);
my ($dbh, $FH, $maxlevel, $universal, @reparent);
my $cachedir = "/home/apa/local/bin/GO_Tools_DBcache"; # DB cache directory
if ($idfile) {
if (open IN, $idfile) {
while (<IN>) {
$_ =~ s/[\n\r]+$//;
$inputids{$.} = [split /;/, $_]; # semicolon-delimited entries allowed, e.g. for microarray probes which target multiple genes. Downstream handling varies.
}
close IN;
} else {
die "$0: id file '$idfile' unreadable: $!\n";
}
}
if ($outfile) {
$FH = 'OUT';
open $FH, "> $outfile" or die "$0: Cannot open path '$outfile' for writing: $!\n";
} else {
$FH = 'STDOUT';
}
if ($showtaxa) {
# my @headers = ('Taxon ID', 'Scientific Name', 'Common Name');
# my $width0 = length($headers[0]);
# my $width1 = length($headers[1]);
# my $width2 = length($headers[2]);
# foreach my $id (keys %taxon_ids) {
# my ($sciname, $comname) = @{ $taxon_ids{$id} };
# $width0 = length($id) if length($id) > $width0;
# $width1 = length($sciname) if length($sciname) > $width1;
# $width2 = length($comname) if length($comname) > $width2;
# }
# my $format = "%${width0}s %-${width1}s %-${width2}s";
# my $header = sprintf($format, 'Taxon ID', 'Scientific Name', 'Common Name');
# my $commontaxa = join "\n", map { sprintf($format, $_, @{ $taxon_ids{$_} }) } (sort {$taxon_ids{$a}->[0] cmp $taxon_ids{$b}->[0]} keys %taxon_ids);
# print "\n\n" unless $outfile;
# print $FH "Some taxa and their numbers:\n\n$header\n$commontaxa\n";
# print "\n\n" unless $outfile;
my $cmd = '/home/apa/local/bin/showTaxa';
$cmd .= ' --no-sprintf' unless $do_sprintf;
system $cmd;
exit;
} elsif ($showdbs) {
my $dbh = DBI->connect("DBI:mysql:host=$dbhost",'anonymous','guy#fawkes',{RaiseError=>1}) or die "$0: Cannot connect to $dbhost: $DBI::err() $DBI::errstr()\n";
my $dbquery = $dbh->prepare("SHOW DATABASES");
$dbquery->execute();
my $ref = $dbquery->fetchall_arrayref();
$dbquery->finish();
print "\n" unless $outfile;
print $FH "GO databases on host $dbhost:\n";
foreach (reverse @$ref) {
print $FH "$$_[0]\n" if $$_[0] =~ /^go_\d{5,8}$/;
}
$dbh->disconnect();
print "\n" unless $outfile;
exit;
} elsif ($showxrefs) {
my $nIDs = 5; # show first 5 IDs per xref database
my @taxids;
if ($taxon) {
if ($taxon =~ /,/) {
@taxids = split /,/, $taxon;
} else {
@taxids = ($taxon);
}
} else {
open my $IN, '-|', '/home/apa/local/bin/showTaxa | grep . | tail -n +2 | head -n -1 | sed "s/^ *//" | cut -f1 -d" "';
chomp(@taxids = (<$IN>));
close $IN;
}
my $ntaxa = scalar @taxids;
$ntaxa = "ALL $ntaxa SIMR" unless $taxon;
print STDERR "\nSearching $ntaxa species in database $GOdb...\n";
my (%orgname, %xreftable, %symbols);
my ($genus, $species) = split /\./, $genspec;
my $dbhq = DBI->connect("DBI:mysql:database=$GOdb:host=$dbhost",'anonymous','guy#fawkes',{RaiseError=>1}) or die "$0: Cannot connect to $GOdb on $dbhost: $DBI::err() $DBI::errstr()\n";
my $taxidquery = $dbhq->prepare("SELECT id, genus, species FROM species WHERE ncbi_taxa_id = ?");
my $qPDB = $dbhq->quote('PDB');
my $xrefq1_string = "select distinct d.xref_dbname, g.symbol from dbxref d, gene_product g where d.id = g.dbxref_id";
$xrefq1_string .= " and d.xref_dbname != $qPDB" if $no_PDB;
$xrefq1_string .= " and g.species_id = ? order by g.symbol";
my $xrefquery1 = $dbhq->prepare($xrefq1_string);
my $xrefquery2 = $dbhq->prepare("SELECT d.xref_key FROM dbxref d, gene_product g WHERE d.id = g.dbxref_id AND g.species_id = ? AND d.xref_dbname = ? limit $nIDs");
foreach my $taxid (@taxids) {
$taxidquery->bind_param(1, $taxid);
$taxidquery->execute();
while ( my ($spid, $genus, $species) = $taxidquery->fetchrow_array() ) {
$orgname{$taxid} = "$genus $species";
$xrefquery1->bind_param(1, $spid);
$xrefquery1->execute();
my $prev_symb;
while ( my ($xrefdb, $symb) = $xrefquery1->fetchrow_array() ) {
next if $xrefdb eq 'PDB' && $no_PDB;
$symbols{$taxid}{$symb} = 1;
$xreftable{$taxid}{$xrefdb}{N}++ unless $symb eq $prev_symb;
$prev_symb = $symb;
}
$xrefquery1->finish();
warn "Error retrieving xrefquery1 data: $xrefquery1->errstr()\n" if $xrefquery1->err();
foreach my $xrefdb (keys %{ $xreftable{$taxid} }) {
next if $xrefdb eq 'PDB' && $no_PDB;
$xrefquery2->bind_param(1, $spid);
$xrefquery2->bind_param(2, $xrefdb);
$xrefquery2->execute();
while ( my ($xrefid) = $xrefquery2->fetchrow_array() ) {
push @{ $xreftable{$taxid}{$xrefdb}{I} }, $xrefid;
}
warn "Error retrieving xrefquery2 data: $xrefquery2->errstr()\n" if $xrefquery2->err();
$xrefquery2->finish();
}
}
$taxidquery->finish();
warn "Error retrieving taxidquery data: $taxidquery->errstr()\n" if $taxidquery->err();
}
my @OUT;
push @OUT, [qw/ Taxon Organism Org_Genes Xref_Genes Xref_Gene% Xref_DB Xref_IDs /];
foreach my $taxid (@taxids) {
my $org = $orgname{$taxid};
my $ngpids = scalar keys %{ $symbols{$taxid} };
foreach my $xrefdb (sort { $xreftable{$taxid}{$b}{N} <=> $xreftable{$taxid}{$a}{N} } keys %{ $xreftable{$taxid} }) {
my $xrefdbn = $xreftable{$taxid}{$xrefdb}{N};
my $xrefdbp = sprintf("%3.2f", 100*$xrefdbn/($ngpids||1));
my $xrefids = join ',', sort @{ $xreftable{$taxid}{$xrefdb}{I} };
push @OUT, [$taxid, $orgname{$taxid}, $ngpids, $xrefdbn, $xrefdbp, $xrefdb, $xrefids];
}
}
&print_table(\@OUT, $do_sprintf);
print "\n";
exit;
} elsif ($cache) {
die "\n$0: --cache flag MUST be accompanied by a database name, using -d !\n" unless $GOdb;
$dbh = DBI->connect("DBI:mysql:database=$GOdb:host=$dbhost",'anonymous','guy#fawkes',{RaiseError=>1}) or die "$0: Cannot connect to $GOdb on $dbhost: $DBI::err() $DBI::errstr()\n";
# $termsname = 'GO';
my ($maxlevel, %downstreams);
my $childquery = $dbh->prepare("SELECT DISTINCT term2_id, distance FROM graph_path WHERE term1_id = ?");
my $parentquery = $dbh->prepare("SELECT DISTINCT term1_id, distance FROM graph_path WHERE term2_id = ?");
&root_query($dbh);
&term_query('ALL', $dbh);
########## have a query to investigate gene_product_count table somewhere....
print STDERR "Mapping GO terms to levels...\n";
$childquery->bind_param(1, $four_names{all}->[0]);
$childquery->execute();
while ( my ($tid, $level) = $childquery->fetchrow_array() ) {
if ($allterms{I2A}{$tid}) { # no relationships or obsoletes
$termlevels{T2L}{$tid}{$level} = 1;
$termlevels{L2T}{$level}{$tid} = 1;
$maxlevel = $level if $level > $maxlevel;
}
}
warn "Error retrieving data: $childquery->errstr()\n" if $childquery->err();
$childquery->finish();
print STDERR "Mapping downstream GO terms to upper levels...\n";
foreach my $level (0..$maxlevel) {
my $at_this_level = scalar (keys %{ $termlevels{L2T}{$level} });
my %downstreams;
foreach my $tid (keys %{ $termlevels{L2T}{$level} }) { # all terms at level $level
$childquery->bind_param(1, $tid);
$childquery->execute();
while ( my ($tid2, $dist) = $childquery->fetchrow_array() ) {
if (exists $allterms{I2A}{$tid2}) { # no relationships or obsoletes
$levelmap{L}{$level}{$tid}{$tid2} = 1 if $dist > 0; # for each $tid at level $level, what are its downstream $tids? (NO SELF)
$levelmap{T}{$tid2}{$level}{$tid} = 1; # for each $tid2, what are its level-$level parental mappings? (NEED SELF)
#print "$tid child = $tid2 @ $dist\n" if $tid == 19;
$relations{P2C}{$tid}{$tid2}{$level} = 1 if $dist == 1; # $tid is parent, $tid2 is child
$downstreams{$tid2} = 1;
}
}
warn "Error retrieving data: $childquery->errstr()\n" if $childquery->err();
$childquery->finish();
$parentquery->bind_param(1, $tid);
$parentquery->execute();
while ( my ($tid2, $dist) = $parentquery->fetchrow_array() ) {
if (exists $allterms{I2A}{$tid2} && $tid2 != $tid) { # no relationships, obsoletes, or self-references
#print "$tid parent = $tid2 @ $dist\n" if $tid == 19;
$relations{C2P}{$tid}{$tid2}{$level} = 1 if $dist == 1; # $tid is child, $tid2 is parent
}
}
warn "Error retrieving data: $parentquery->errstr()\n" if $parentquery->err();
$parentquery->finish();
}
printf STDERR "Level %2d: %5d terms with %5d children.\n", $level, $at_this_level, scalar (keys %downstreams);
}
$dbh->disconnect();
print STDERR "Storing '$cachedir/${GOdb}_relations_dump.dat' for next time...\n";
nstore(\%relations,"$cachedir/${GOdb}_relations_dump.dat") or warn "Cannot store \%relations in file '$cachedir/${GOdb}_relations_dump.dat': $!";
print STDERR "Storing '$cachedir/${GOdb}_levelmap_dump.dat' for next time...\n";
nstore(\%levelmap,"$cachedir/${GOdb}_levelmap_dump.dat") or warn "Cannot store \%levelmap in file '$cachedir/${GOdb}_levelmap_dump.dat': $!";
## DB caching for Perl-based utilities (like this one) complete.
## Now, cache DB for R-based utilities
## STEPS:
## 1. write set of 3 tables to tmp dir
## 2. run small R script that converts tables into one RData object
my %Routput = (
'TERM' => ["Accession\tTerm\tType\tParent.Terms\tChild.Terms\tDownstream.Terms\tDirect.Genes\tDownstream.Genes"],
'GENE' => ["Gene\tDirect.BP\tDirect.CC\tDirect.MF\tTotal.BP\tTotal.CC\tTotal.MF"],
'T2G' => ["DB\tAccession\tGene\tDirect"]
);
## Termwise ops
foreach my $tid (keys %{ $allterms{I2A} }) {
my $gpids = scalar (keys %{ $allterms{I2G}{$taxon}{$tid} });
next if ($gpids == 0 && $noimputed);
my $acc = $allterms{I2A}{$tid};
$slimfound{$acc} = $acc if $slimterms{1}{$acc};
my $nametype = join "\t", reverse @{ $accdata{$acc} }[0,1];
my $alevels = join ',', (sort {$a <=> $b} keys %{ $termlevels{T2L}{$tid} });
my $parents = scalar (keys %{ $relations{C2P}{$tid} });
my $children = scalar (keys %{ $relations{P2C}{$tid} });
my %downstream; ################# MODIFY THIS FOR T2G TABLE BUILDING
foreach my $level (0..$maxlevel) {
if ($levelmap{L}{$level}{$tid}) {
foreach my $tid2 (keys %{ $levelmap{L}{$level}{$tid} }) {
$downstream{I}{$tid2} = 1;
$downstream{G}{$_} = 1 foreach (keys %{ $allterms{I2G}{$taxon}{$tid2} });
}
}
}
my $dsI = scalar (keys %{ $downstream{I} }); # ids
my $dsG = scalar (keys %{ $downstream{G} }); # gpids
next unless ($gpids || $dsG); # must have direct or downstream-associated products! Unfortunately, this is the only way to remove non-species junk from tree...
## acc, name, db, inferred, N parents, N children, N upstream, N downstream, N tot genes, N dir genes]
push @{ $Routput{TERM} }, "$acc\t$nametype\t$parents\t$children\t$dsI\t$gpids\t$dsG\n";
}
## Genewise ops
my @dbids;
foreach my $gpid (sort keys %{ $idtable{1}{$taxon} }) {
my (%realias, %accframe);
foreach my $alias (keys %{ $idtable{1}{$taxon}{$gpid} }) {
$realias{ $idtable{1}{$taxon}{$gpid}{$alias} }{$alias} = 1; # re-key by alias origin (name, symbol, xref)
}
foreach my $tid (keys %{ $allterms{G2I}{$taxon}{$gpid} }) {
next if $ignore{$tid}; # removes the generic / unknown GO terms
my $acc = $allterms{I2A}{$tid};
my $delim = $long ? "\t" : ' ';
$accframe{ $accdata{$acc}->[0] }{"$acc$delim$accdata{$acc}->[1]"} = 1;
}
my $outsymbol = join ' // ', (sort keys %{ $realias{S} });
my $outname = join ' // ', (sort keys %{ $realias{N} });
my $outxref = join ' // ', (sort keys %{ $realias{X} });
my $IDstring = "$outsymbol\t$outname\t$outxref";
if ($long) {
foreach my $branch (qw/ BP CC MF /) {
push @dbids, "$IDstring\t$branch\t$_\n" foreach sort keys %{ $accframe{$branch} };
}
} else {
my $outBP = join ' // ', sort keys %{ $accframe{BP} };
my $outCC = join ' // ', sort keys %{ $accframe{CC} };
my $outMF = join ' // ', sort keys %{ $accframe{MF} };
push @dbids, "$IDstring\t$outBP\t$outCC\t$outMF\n";
}
}
my $outheader = "Symbol\tName\tXref";
$outheader .= $long ? "\tDB\tTerm Acc\tTerm Name\n" : "\tBiological Process\tCellular Component\tMolecular Function\n";
## What are these lines doing here? Mis-pasted??
## ##### PRODUCES DIRECT TERMS ONLY #####
## print $FH $outheader,@dbids;
exit;
} elsif ($findterms) {
die "\n$0: --findterms flag MUST be accompanied by a GO accession or list file, using -a !\n" unless $slimacc;
die "\n$0: --findterms flag MUST be accompanied by a database name, using -d !\n" unless $GOdb;
&root_query;
&term_query;
print $FH "Database\tAccession\tName\n";
if ($slimacc =~ /^GO:\d+$/) { # single-acc input
my ($db, $name) = @{ $accdata{$slimacc} }[0,1];
print $FH "$db\t$slimacc\t$name\n";
} else { # list-file input
foreach my $acc (keys %{ read_list($slimacc) }) {
my ($db, $name) = @{ $accdata{$acc} }[0,1];
print $FH "$db\t$acc\t$name\n";
}
}
exit;
} elsif ($slimtree) {
die "\n$0: --slimtree flag MUST be accompanied by a GO accession, using -a !\n" unless $slimacc;
die "\n$0: --slimtree flag MUST be accompanied by a taxon id, using -x !\n" unless $taxon;
die "\n$0: --slimtree flag MUST be accompanied by a database name, using -d !\n" unless $GOdb;
&GO_queries($taxon);
&get_level_mappings;
$dbh->disconnect();
my (@slimtids, %toplevels, %parentaccs, %kids1, %parents1, %levels, @tree);
foreach my $acc (split /,/, $slimacc) {
my $tid;
if ($accdata{$acc}) {
$tid = $accdata{$acc}->[2];
} elsif ($obsoletes{A2T}{$acc}) {
$tid = $obsoletes{A2T}{$acc};
print STDERR "Warning: GO accession $acc is considered obsolete.\n";
} else {
die "$0: GO accession $acc not found for taxon $taxon!\n";
}
push @slimtids, $tid;
my %tidlevels = map {($_=>1)} keys %{ $termlevels{T2L}{$tid} }; # all levels this $tid may be found at
$toplevels{$tid} = (sort {$a <=> $b} keys %tidlevels)[0]; # take highest level (if multiple)
foreach my $tid2 (keys %{ $levelmap{L}{ $toplevels{$tid} }{$tid} }) { # child tids
$kids1{$tid2}{$tid} = $toplevels{$tid}; # input $tids will also be $tid2s
}
}
my %slimtids = map {($_=>1)} @slimtids;
my @ordkids = @slimtids; # init w/ queries: make sure query accessions are first!
foreach my $tid (sort keys %kids1) {
push @ordkids, $tid unless exists $slimtids{$tid};
}
foreach my $tid (@ordkids) {
my @templev;
my $parentmin = (sort {$a <=> $b} values %{ $kids1{$tid} })[0];
foreach my $lev (keys %{ $termlevels{T2L}{$tid} }) {
push @templev, $lev if $lev > $parentmin; # levels that child term may be found at; must be below parent (slim) term
}
my $minlev = (sort {$a <=> $b} @templev)[0]; # take highest level (if multiple)
$levels{$tid} = $minlev; # highest level that child may occur at BELOW the highest parent level (i.e. ignore higher levels coming from alternate parents)
foreach my $tid2 (keys %{ $relations{C2P}{$tid} }) {
next if $tid eq $tid2;
next unless exists $kids1{$tid2}; # parent must also be in under slim term
foreach my $level (keys %{ $relations{C2P}{$tid}{$tid2} }) {
$parents1{$tid}{$tid2} = 1 if $level >= $minlev; # so long as C->P relation exists when C is at or below level $minlev, then record parent
}
}
}
my %output;
sub output_parent_slim {
my ($LINE, $TID) = @_;
my @parents = sort map { $allterms{I2A}{$_} } keys %{ $parents1{$TID} };
@parents = ('NA') unless @parents;
my $parentstr = join(',', sort @parents);
if (exists $slimtids{$TID}) {
## query (parent) term
$output{"$LINE\t$allterms{I2A}{$TID}\t$parentstr\n"} = 1;
} else {
## obligate child term
$output{"$LINE\t$allterms{I2A}{$_}\t$parentstr\n"} = 1 foreach keys %{ $kids1{$TID} };
}
}
foreach my $tid (@ordkids) {
my $string;
if ($allterms{I2G}{$taxon}{$tid}) {
## term has mapped genes
foreach my $gpid (keys %{ $allterms{I2G}{$taxon}{$tid} }) {
my %idtemp;
$idtemp{ $idtable{1}{$taxon}{$gpid}{$_} }{$_} = 1 foreach keys %{ $idtable{1}{$taxon}{$gpid} };
my $symbs = join '; ', (sort keys %{ $idtemp{S} });
my $names = join '; ', (sort keys %{ $idtemp{N} });
my $xrefs = join '; ', (sort keys %{ $idtemp{X} });
$string = "$allterms{I2A}{$tid}\t$accdata{ $allterms{I2A}{$tid} }->[1]\t$levels{$tid}";
$string = $genes ? "$string\t$xrefs\t$symbs\t$names" : $string;
&output_parent_slim($string, $tid);
}
} else {
## term lacks mapped genes
$string = "$allterms{I2A}{$tid}\t$accdata{ $allterms{I2A}{$tid} }->[1]\t$levels{$tid}";
$string = $genes ? "$string\t\t\t" : $string;
&output_parent_slim($string, $tid);
}
}
my $header = $genes ? "Accession\tTerm\tLevel\tXrefs\tSymbols\tNames\tSlim\tParent(s)\n" : "Accession\tTerm\tLevel\tSlim\tParent(s)\n";
print $FH $header;
print $FH sort keys %output;
exit;
} elsif ($slimmap) {
die "\n$0: --slimmap flag MUST be accompanied by a GO slim map, using -a !\n" unless $slimacc;
die "\n$0: --slimmap flag MUST be accompanied by a taxon id, using -x !\n" unless $taxon;
die "\n$0: --slimmap flag MUST be accompanied by a database name, using -d !\n" unless $GOdb;
&GO_queries($taxon);
&get_level_mappings;
$dbh->disconnect();
my %data = %{ read_list($slimacc) };
print STDERR "Arranging slim map...\n";
my (@output, %DBN, %slimtids, %lostaccs, %slimmap, %slimcross, %slimstate, %slimtable, %slimhits);
## test GO DB presence; convert accs to tids
foreach my $acc (keys %data) {
my ($type, $tid) = @{ $accdata{$acc} }[0,2];
if ($tid) {
$slimtids{$type}{$tid} = 1;
} else {
print STDERR "$acc not found in GO database!\n";
$lostaccs{$type}{$acc} = 1;
}
}
## build %slimmap
foreach my $child (keys %{ $relations{C2P} }) { # all GO terms
my $type = $accdata{ $allterms{I2A}{$child} }->[0];
next unless $slimtids{$type}; # do not consider terms outside of the slim target DB
$DBN{$type}++; # count number of genes for each DB
$slimmap{$type}{A2S}{$child}{$child} = 1 if $slimtids{$type}{$child}; # map self
foreach my $level (keys %{ $levelmap{T}{$child} }) { # all levels above term
foreach my $parent (keys %{ $levelmap{T}{$child}{$level} }) { # parental mapping(s) for this level (incl. self)
next if $child == $parent; # no self (got it above)
next unless $slimtids{$type}{$parent}; # slim parents only
$slimmap{$type}{A2S}{$child}{$parent} = 1; # {A2S} maps ALL terms to appropriate slim parent(s) (if any)
$slimmap{$type}{S2A}{$parent}{$child} = 1; # {S2A} is reverse
next unless $slimtids{$type}{$child}; # now, slim children of slim parents only
$slimmap{$type}{P2C}{$parent}{$child} = 1; # {P2C} lists any slim child terms for each slim parent
$slimmap{$type}{C2P}{$child}{$parent} = 1; # {C2P} lists any slim parent terms for each slim child
}
}
}
foreach my $type (keys %slimmap) {
## initial mapped terms per slim
foreach my $tid (keys %{ $slimmap{$type}{A2S} }) {
$slimhits{$type}{$_}{I}++ foreach keys %{ $slimmap{$type}{A2S}{$tid} };
}
## remove any terms from slim parent that also map to slim children, if any (make parent the 'leftovers' term)
foreach my $parent (keys %{ $slimmap{$type}{P2C} }) {
next unless $slimmap{$type}{P2C}{$parent}; # no slim children
foreach my $child (keys %{ $slimmap{$type}{P2C}{$parent} }) {
foreach my $tid (keys %{ $slimmap{$type}{S2A}{$parent} }) {
if ($slimmap{$type}{A2S}{$tid}{$child}) {
$slimcross{$type}{$child}{I}{$parent}++; # initial crosstalk that will be removed
$slimcross{$type}{$parent}{I}{$child}++; # initial crosstalk that will be removed
delete $slimmap{$type}{A2S}{$tid}{$parent}; # keep lowest-level mapping
}
}
}
}
## final mapped terms per slim
foreach my $tid (keys %{ $slimmap{$type}{A2S} }) {
$slimhits{$type}{$_}{F}++ foreach keys %{ $slimmap{$type}{A2S}{$tid} };
}
## now, remove all mappings involving the root (cause problems for state assignment below)
foreach my $root (keys %ignore) {
delete $slimmap{$type}{P2C}{$root};
delete $slimmap{$type}{C2P}{$root}; # if possible??
}
foreach my $parent (keys %{ $slimmap{$type}{P2C} }) {
delete $slimmap{$type}{P2C}{$parent}{$_} foreach keys %ignore;
delete $slimmap{$type}{P2C}{$parent} unless scalar keys %{ $slimmap{$type}{P2C}{$parent} }; # remove if no further associations
}
foreach my $child (keys %{ $slimmap{$type}{C2P} }) {
delete $slimmap{$type}{C2P}{$child}{$_} foreach keys %ignore;
delete $slimmap{$type}{C2P}{$child} unless scalar keys %{ $slimmap{$type}{C2P}{$child} }; # remove if no further associations
}
}
if ($stats) {
print STDERR "Calculating slim statistics...\n";
my $header1 = "DB\tState\tN Terms\tState Description\n";
# my $header2 = "DB\tSlim Acc\tSlim Name\tState\tInitial Mappings\tFinal Mappings\tMapping Overlaps (Initial; Final)\n";
my $header2 = "DB\tSlim Acc\tSlim Name\tState\tInitial Mappings\tFinal Mappings\tCross-Mapping Terms\n";
my %statenames = (
1 => 'Singular slim term (no non-root parents or children)',
2 => 'Parent slim term (has children in the slim list; can\'t be root)',
3 => 'Child slim term (has parents in the slim list)',
4 => 'Parent+child slim term (has both parents and children in the slim list)',
5 => 'Non-slim term, is slim-mappable (the majority)',
6 => 'Non-slim term, root-mappable only, not traceable to any slim term (gaps in slim term coverage)',
7 => 'Non-slim term, root-mappable only, exists between slim terms and root',
8 => 'The root'
);
foreach my $type (keys %slimmap) {
## apply slim states 0/5
foreach my $tid (keys %{ $relations{C2P} }) { # all GO terms
next unless $type eq $accdata{ $allterms{I2A}{$tid} }->[0];
my %candidates = %{ $slimmap{$type}{A2S}{$tid} };
delete $candidates{$_} foreach keys %ignore; # remove root mappings
if (%candidates) {
$slimstate{$type}{$tid} = 5; # state 5: non-root-mappable (default; may get overwritten below)
} else {
$slimstate{$type}{$tid} = 6; # state 6: root-only mappable (trivial mapping; unmapped in slim list)
}
}
## apply slim states 1-4
foreach my $tid (keys %{ $slimtids{$type} }) { # all slim terms
next if $ignore{$tid}; # skip roots
if ($slimmap{$type}{P2C}{$tid}) { # slim parent
if ($slimmap{$type}{C2P}{$tid}) { # also mappable to parent
my @parents = keys %{ $slimmap{$type}{C2P}{$tid} };
$slimstate{$type}{$tid} = 4; # state 4: slim parent + slim child
} else {
$slimstate{$type}{$tid} = 2; # state 2: slim parent only
}
} elsif ($slimmap{$type}{C2P}{$tid}) {
$slimstate{$type}{$tid} = 3; # state 3: slim child of a slim parent
} else {
$slimstate{$type}{$tid} = 1; # state 1: 'singleton' slim term
}
}
## apply slim state 7
my %pre7;
foreach my $tid (keys %{ $slimtids{$type} }) {
## collect all ancestor terms for all slim terms
my %temp = %{ getmyancestors($tid) };
$pre7{$_} = 1 foreach keys %temp;
}
foreach my $tid (keys %pre7) {
## collect all ancestor terms for each %pre7 ancestor term
$pre7{$tid} = getmyancestors($tid); # replace '1' with hash
}
foreach my $tid (keys %pre7) {
## identify and remove any ancestors mappable to other slim terms
my $mappable;
foreach my $ancestor (keys %{ $pre7{$tid} }) {
next if $ignore{$ancestor}; # roots don't count
$mappable = 1 if $slimtids{$type}{$ancestor};
}
delete $pre7{$tid} if $mappable;
}
foreach my $tid (keys %pre7) {
next if $ignore{$tid} || $slimtids{$type}{$tid}; # don't count the roots, or the original inputs
$slimstate{$type}{$tid} = 7; # remainder are state 7: unmappable between slims and root
}
## apply slim state 8
foreach my $root (keys %ignore) {
$slimstate{$type}{$root} = 8 if $ignore{$root} eq $type; # state 8: the one and only (per db), the root
}
## summarize slim states, hits, etc.
$slimtable{$type}{$_} = 0 foreach keys %statenames; # ensure printable values
$slimtable{$type}{ $slimstate{$type}{$_} }++ foreach keys %{ $slimstate{$type} };
foreach my $tid (keys %{ $slimmap{$type}{A2S} }) {
my @mapto = keys %{ $slimmap{$type}{A2S}{$tid} };
if ($#mapto > 0) {
foreach my $par1 (@mapto) {
foreach my $par2 (@mapto) {
next if $par1 == $par2;
foreach my $xtype (qw/ I F /) { # these crosstalks are in both initial and final
$slimcross{$type}{$par1}{$xtype}{$par2}++;
$slimcross{$type}{$par2}{$xtype}{$par1}++;
}
}
}
}
}
my $N = $DBN{$type};
my $M = scalar keys %{ $slimstate{$type} };
my $lost = $N - $M;
my $Nmapped = scalar keys %{ $slimmap{$type}{A2S} };
my $Nslim = scalar keys %{ $slimmap{$type}{S2A} };
print STDERR "$type: $Nmapped/$N terms mapped to $Nslim slim terms | $M have states\n";
push @output, "\n$header1"; # "DB\tState\tN Terms\tState Description\n";
push @output, "$type\t$_\t$slimtable{$type}{$_}\t$statenames{$_}\n" foreach sort {$a <=> $b} keys %statenames;
push @output, "$type\tTOTAL\t$M\tTerms in $type: $N ($lost lost)\n";
push @output, "\n$header2"; # "DB\tSlim Acc\tSlim Name\tState\tInitial Mappings\tFinal Mappings\tCross-Mapping Terms\n";
my @termsort;
foreach (keys %{ $slimtids{$type} }) {
push @termsort, $_ if $ignore{$_}; # root goes first
}
foreach (sort namecmp keys %{ $slimtids{$type} }) {
push @termsort, $_ unless $ignore{$_}; # then everyone else
}
push @output, "\t\t\t\t\t";
push @output, "\t". $accdata{ $allterms{I2A}{$_} }->[1] foreach @termsort;
push @output, "\n";
foreach my $i (0..$#termsort) {
my $tid = $termsort[$i];
my ($acc, $name) = ($allterms{I2A}{$tid}, $accdata{ $allterms{I2A}{$tid} }->[1]);
# my $overi = join '; ', map { "$allterms{I2A}{$_}=$slimcross{$type}{$tid}{I}{$_}" } sort keys %{ $slimcross{$type}{$tid}{I} };
# my $overf = join '; ', map { "$allterms{I2A}{$_}=$slimcross{$type}{$tid}{F}{$_}" } sort keys %{ $slimcross{$type}{$tid}{F} };
push @output, "$type\t$acc\t$name\t$slimstate{$type}{$tid}\t$slimhits{$type}{$tid}{I}\t$slimhits{$type}{$tid}{F}";
foreach my $j (0..$#termsort) {
my $tid2 = $termsort[$j];
next if $i <= $j;
my $initial = $slimcross{$type}{$tid}{I}{$tid2} || 0;
my $final = $slimcross{$type}{$tid}{F}{$tid2} || 0;
# ($final || $initial) ? (push @output, "\t$initial; $final") : (push @output, "\t");
($final) ? (push @output, "\t$final") : (push @output, "\t");
}
push @output, "\n";
}
foreach my $acc (keys %{ $lostaccs{$type} }) {
my $name = $accdata{$acc}->[2];
push @output, "$type\t$acc\t$name\tNOT IN DB\t\t\t\n";
}
push @output, "\n";
}
print OUT @output;
} else {
foreach my $type (keys %slimmap) {
my $N = $DBN{$type};
my $Nmapped = scalar keys %{ $slimmap{$type}{A2S} };
my $Nslim = scalar keys %{ $slimmap{$type}{S2A} };
print STDERR "$type: $Nmapped/$N terms mapped to $Nslim slim terms\n";
foreach my $tid (keys %{ $slimmap{$type}{A2S} }) { # mapped terms
my ($acc, $name) = ($allterms{I2A}{$tid}, $accdata{ $allterms{I2A}{$tid} }->[1]);
foreach my $tid2 (keys %{ $slimmap{$type}{A2S}{$tid} }) { # slim terms
my ($pacc, $pname) = ($allterms{I2A}{$tid2}, $accdata{ $allterms{I2A}{$tid2} }->[1]);
push @output, "$type\t$acc\t$name\t$pacc\t$pname\n";
}
}
}
print OUT "DB\tAcc\tName\tSlim Acc\tSlim Name\n", @output;
}
} elsif ($fulltree || $flatmap) {
die "\n$0: --fulltree flag MUST be accompanied by a taxon id, using -x !\n" unless $taxon;
die "\n$0: --fulltree flag MUST be accompanied by a database name, using -d !\n" unless $GOdb;
&GO_queries($taxon);
&get_level_mappings;
$dbh->disconnect();
print "Imputing un-annotated parent terms...\n";
&impute_parents($_, 0, $fulltree) foreach (keys %{ $relations{C2P} });
if (@reparent) {
my $iters;
{
$iters++;
my @temp = @reparent;
@reparent = ();
&impute_parents($_, $iters, $fulltree) foreach @temp;
redo if @reparent; # found more new child terms with parents not annotated to $taxon; iterate again
}
}
if ($fulltree) {
#print "$_\t$alliters{$_}\n" foreach (sort {$a <=> $b} keys %alliters);
print $FH "Type\tChild Acc\tChild Term\tParent Acc\tParent Term\n";
print $FH keys %{ $output{$_} } foreach qw/ BP CC MF /;
} elsif ($flatmap) {
print "Writing complete gene->term mappings...\n";
print $FH "Type\tAccession\tName\tXref\tDirect\n";
foreach my $gpid (sort keys %{ $idtable{1}{$taxon} }) {
foreach my $type (qw/ BP CC MF /) { # output terms in this order
foreach my $tid (keys %{ $allterms{G2I}{$taxon}{$gpid} }) {
## Directly-annotated terms
&write_termgene($gpid, $tid, $type, 1);
## Now, trace all paths back to root
my %parents = map {($_=>1)} keys %{ $relations{C2P}{$tid} };
my %parents_already = ($tid,1);
{
my @temp = keys %parents;
%parents = ();
foreach my $ptid (@temp) {
&write_termgene($gpid, $ptid, $type);
$parents_already{$ptid} = 1;
foreach (keys %{ $relations{C2P}{$ptid} }) {
$parents{$_} = 1 unless $parents_already{$_};
}
}
redo if %parents; # keep going until all parents have been accounted for
}
}
}
%write_termgene_already = (); # zap after every gene, just to keep footprint down
}
}
exit;
} elsif ($getdbids) {
die "\n$0: --getdbids flag MUST be accompanied by a taxon id, using -x !\n" unless $taxon;
die "\n$0: --getdbids flag MUST be accompanied by a database name, using -d !\n" unless $GOdb;
&GO_queries($taxon);
my @dbids;
# if ($long) { ## && something else? This block of code originally intended for extracting "most-specific terms" per gene, given some way to subset the tree
#
#
#
# die "$0: --long not enabled for --getdbids yet!\n";
#
#
#
# foreach my $gpid (sort keys %{ $idtable{1}{$taxon} }) {
# my (%realias, %accframe, %allaccs, $is_parent);
# foreach my $alias (keys %{ $idtable{1}{$taxon}{$gpid} }) {
# $realias{ $idtable{1}{$taxon}{$gpid}{$alias} }{$alias} = 1; # re-key by alias origin (name, symbol, xref)
# }
# my $symb = join ' // ', (sort keys %{ $realias{S} }); # allows for > 1 mappable ID, although > 1 never observed.
# my $name = join ' // ', (sort keys %{ $realias{N} });
# my $xref = join ' // ', (sort keys %{ $realias{X} });
# foreach my $tid (keys %{ $allterms{G2I}{$taxon}{$gpid} }) {
# next if ($clean && $ignore{$tid}); # "clean" removes the generic / unknown GO terms
#
#
# #### PROBLEM: most-specific terms not usefully defined when dealing with entire tree! Need to subset the tree first.