9
#define MAX_ORG_LIST 10
16
static TreePtr tax_tree= NULL;
18
static Int2 VRL_div= 0;
19
static Int2 PHG_div= 0;
21
static Int2 SpeciesRank= 26;
22
static Int2 SubspeciesRank= 27;
23
static Int2 GenusRank= 22;
24
static Int2 FamilyRank= 0;
25
static Int2 OrderRank= 0;
26
static Int2 ClassRank= 0;
27
static Int2 SYNONYM= 0;
28
static Int2 COMMON_NAME= 0;
29
static Int2 PREF_COMMON= 0;
31
static int my_timer= 0;
33
typedef struct t_nameList {
34
struct t_nameList* next;
36
} NameList, *NameListPtr;
38
static struct t_or_buff {
45
NameListPtr blast_name;
48
static CharPtr DB_PATH= "TAX_OS";
50
static Boolean we_want_synonyms= 0;
52
static OrgRefPtr getFromBuff(Int4 id, int* is_sp, int* is_uncult, NameListPtr* bnl);
53
static void loadInBuff(Int4 id);
54
static void bldOrgRefOut(OrgRefPtr dst, OrgRefPtr src, Int4 tax_id);
56
Boolean tax1_setSynonyms(Boolean on_off)
60
ret= we_want_synonyms;
61
we_want_synonyms= on_off;
66
static Boolean tc2_toNode(TreeCursorPtr cursor, Int4 tax_id)
68
if(!tax_ptree_toTaxId(cursor, tax_id, FALSE)) {
69
/* this node is not in our tree */
70
return (tax_ptree_addNode(tax_tree, tax_id)) ?
71
tax_ptree_toTaxId(cursor, tax_id, FALSE) : FALSE;
76
static void lockBuff(int mode)
81
static void unlockBuff(void)
85
static void initBuff(void)
91
for(i= 0; i < BUFF_SIZE; i++) {
93
or_buff[i].p_org_ref= NULL;
94
or_buff[i].blast_name= NULL;
98
static Int4 getLiveId(Int4 id)
100
TreeCursorPtr cursor= tree_openCursor(tax_tree, NULL, NULL);
104
if((cursor == NULL) || (!tc2_toNode(cursor, id))) return 0;
106
tnp= tree_getNodeData(cursor, &s);
107
tree_closeCursor(cursor);
108
return (tnp != NULL)? tnp->tax_id : 0;
112
/**************************************************************************
116
**************************************************************************/
122
if((tmp=getenv("TAXDBPATH")) != NULL) DB_PATH= tmp;
124
if(!txc_connect2Server(DB_PATH, "soussov", "vladimir", "tax2cl")) {
129
if((!txc_loadNameClasses()) || (!txc_loadRanks()) ||
130
(!txc_loadDivisions()) || (!txc_loadGCs())) {
136
SpeciesRank= tax_getRankId("species");
137
SubspeciesRank= tax_getRankId("subspecies");
138
GenusRank= tax_getRankId("genus");
139
FamilyRank= tax_getRankId("family");
140
OrderRank= tax_getRankId("order");
141
ClassRank= tax_getRankId("class");
144
VRL_div= tax_getDivisionId("VRL", NULL);
145
PHG_div= tax_getDivisionId("PHG", NULL);
147
SYNONYM= tax_getClass_cde("synonym");
148
COMMON_NAME= tax_getClass_cde("common name");
149
PREF_COMMON= tax_getClass_cde("preferred common name");
152
tax_tree= tax_ptree_new();
154
return (tax_tree == NULL)? 0 : 1;
157
/**************************************************************************
161
**************************************************************************/
163
static void free_blast_name(NameListPtr blast_name)
165
if(blast_name != NULL) {
181
if(tax_tree != NULL) {
182
tree_delete(tax_tree);
186
for(i= 0; i < BUFF_SIZE; i++) {
187
if(or_buff[i].p_org_ref != NULL) {
188
OrgRefFree(or_buff[i].p_org_ref);
189
if(or_buff[i].blast_name != NULL) {
190
free_blast_name(or_buff[i].blast_name);
198
Int4 tax1_getParent(Int4 id_tax)
200
TreeCursorPtr cursor;
203
if(tax_tree == NULL) return -1;
205
if(id_tax == 1) return 0;
207
cursor= tree_openCursor(tax_tree, NULL, NULL);
208
if(cursor == NULL) return -1;
210
if(tc2_toNode(cursor, id_tax)) {
215
tnp= tree_getNodeData(cursor, &s);
216
if(tnp != NULL) ret_id= tnp->tax_id;
219
tree_closeCursor(cursor);
223
Int4 tax1_getGenus(Int4 id_tax)
225
TreeCursorPtr cursor;
228
if(tax_tree == NULL) return -1;
230
if(id_tax == 1) return 0;
232
cursor= tree_openCursor(tax_tree, NULL, NULL);
233
if(cursor == NULL) return -1;
235
if(tc2_toNode(cursor, id_tax)) {
242
tnp= tree_getNodeData(cursor, &s);
248
rank= tnp->flags & 0xFF;
250
if(rank == GenusRank) break;
251
if((rank > 0) && (rank < GenusRank)) ret_id= -1;
256
tree_closeCursor(cursor);
257
return (ret_id > 1)? ret_id : -1;
260
int tax1_getChildren(Int4 id_tax, Int4** ids_out)
264
TreeCursorPtr cursor= tree_openCursor(tax_tree, NULL, NULL);
268
if(cursor == NULL) return 0;
270
if(tc2_toNode(cursor, id_tax)) {
271
if(tax_ptree_addChildren(cursor) && tree_child(cursor)) {
278
while(tree_sibling(cursor));
280
*ids_out= ids= MemNew(n*sizeof(Int4));
286
tnp= tree_getNodeData(cursor, &s);
287
if(tnp != NULL) ids[n++]= tnp->tax_id;
289
while(tree_sibling(cursor));
293
tree_closeCursor(cursor);
298
/* find last common ancestor for two nodes */
299
Int4 tax1_join(Int4 taxid1, Int4 taxid2)
303
TreeCursorPtr cursor1= tree_openCursor(tax_tree, NULL, NULL);
304
TreeCursorPtr cursor2= tree_openCursor(tax_tree, NULL, NULL);
306
if((cursor1 == NULL) || (cursor2 == NULL) ||
307
(!tc2_toNode(cursor1, taxid1)) || (!tc2_toNode(cursor2, taxid2))) {
308
if(cursor1 != NULL) tree_closeCursor(cursor1);
309
if(cursor2 != NULL) tree_closeCursor(cursor2);
313
nid= tree_getAncestor(cursor1, cursor2);
315
if(tree_toNode(cursor1, nid)) {
319
tnp= tree_getNodeData(cursor1, &s);
320
if(tnp != NULL) aid= tnp->tax_id;
323
tree_closeCursor(cursor1);
324
tree_closeCursor(cursor2);
329
/***************************************************
330
* Get tax_id by organism name
332
* tax_id if one node found
333
* 0 no organism found
334
* -tax_id if more than one node found
336
Int4 tax1_getTaxIdByName(CharPtr orgname)
338
return tax_getIdByName(orgname, NULL, 0);
341
/***************************************************
342
* Get all tax_id by organism name
344
* Number of tax ids found
346
Int4 tax1_getAllTaxIdByName(CharPtr orgname, Int4 **Ids_out)
351
int n= tax_findByName(orgname, TAX_NAME_SEARCH, &nameList);
355
*Ids_out= Ids= MemNew(n*sizeof(Int4));
357
for(i= 0; i < n; i++) {
358
Ids[i]= nameList[i].tax_id;
359
if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
360
if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
364
for(i= 0; i < n; i++) {
365
if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
366
if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
374
static Boolean goodOrgMode(Uint1 t)
376
return (t != 254) && (t != 20);
379
static Int4 getIdByOrgRef(CharPtr sname, OrgNamePtr orNm)
382
OrgModPtr o_mod= orNm->mod;
383
Boolean om_flag= FALSE;
385
CharPtr altname= NULL;
390
/* first try to search using search name */
391
for(;o_mod != NULL; o_mod= o_mod->next) {
392
if(o_mod->subtype == 254) {
394
altname= o_mod->subname;
396
else if(o_mod->subtype != 20) nof_mods++;
400
/* we have no modifiers */
401
if(altname != NULL) {
402
if((tax_id= tax_getIdByName(altname, NULL, 0)) > 0) return tax_id;
403
return tax_getIdByName(sname, altname, 254);
405
return tax_getIdByName(sname, NULL, 0);
409
/* we have one valuable modifier */
410
for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
411
if(goodOrgMode(o_mod->subtype)) {
412
if(altname != NULL) {
413
if((tax_id= tax_getIdByName(altname, o_mod->subname, o_mod->subtype)) > 0)
414
return tax_id; /* find by old name and modifier */
415
if((tax_id= tax_getIdByName(sname, o_mod->subname, o_mod->subtype)) > 0)
416
return tax_id; /* find by new name and modifier */
417
return tax_getIdByName(sname, altname, 254); /* find by new name and old name */
419
return tax_getIdByName(sname, o_mod->subname, o_mod->subtype);
425
/* we have more than one modifier */
426
/* first try to find organism using just names */
427
if(altname != NULL) {
428
if((tax_id= tax_getIdByName(altname, NULL, 0)) == 0) {
429
tax_id= tax_getIdByName(sname, altname, 254);
433
tax_id= tax_getIdByName(sname, NULL, 0);
436
if(tax_id == 0) return 0; /* we have no such names */
438
/* we have found just one node, check it against modifiers */
440
for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
441
if(o_mod->subtype != 20) {
442
src.stype= o_mod->subtype;
443
src.sname= o_mod->subname;
445
if((ss= tax_SSget(tax_id, &src)) != NULL) {
446
if(ss->rname != NULL) MemFree(ss->rname);
447
if((ss->r_id != 0) && (ss->r_id != tax_id)) {
448
if(id == 0) id= ss->r_id;
449
else if(id != ss->r_id) {
450
id= -id; /* conflict in mapping */
457
if(id == 0) return tax_id;
458
if(id < 0) return -tax_id; /* we have a mapping conflict */
460
/* we have a mapping without conflict, we try to make the best assumption */
465
/* more than one tax_id was found */
469
if(altname != NULL) {
470
n= tax1_getAllTaxIdByName(altname, &ids);
471
if(n < 1) n= tax1_getAllTaxIdByName(sname, &ids);
473
else n= tax1_getAllTaxIdByName(sname, &ids);
477
for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
478
if(goodOrgMode(o_mod->subtype)) {
479
src.stype= o_mod->subtype;
480
src.sname= o_mod->subname;
482
if((ss= tax_SSget(ids[n], &src)) != NULL) {
483
if(ss->rname != NULL) MemFree(ss->rname);
485
if(id == 0) id= ss->r_id;
486
else if(id != ss->r_id) id= -id;
492
if(ids != NULL) MemFree(ids);
493
if(id > 0) return id;
498
/* we have no modifiers */
499
return tax_getIdByName(sname, NULL, 0);
504
Int4 tax1_getTaxIdByOrgRef(OrgRefPtr orgRef)
507
return txc_getTaxIdByOrgRef(orgRef);
511
if(orgRef == NULL) return 0;
515
if((orgRef->taxname != NULL) &&
516
((tax_id= getIdByOrgRef(orgRef->taxname, orgRef->orgname)) > 0)) return tax_id;
518
if((orgRef->common != NULL) &&
519
((tax_id= getIdByOrgRef(orgRef->common, orgRef->orgname)) > 0)) return tax_id;
521
if(orgRef->syn != NULL) {
526
for(synonym= orgRef->syn; (synonym != NULL) && (id < 1); synonym= synonym->next) {
527
id= getIdByOrgRef(synonym->data.ptrvalue, orgRef->orgname);
531
return (id > 0)? id : tax_id;
535
/*******************************************************************
536
* Get tax_id by organism name (it could be "unique" variant of name)
538
* tax_id if one node found
539
* 0 no organism found
540
* -tax_id if more than one node found
542
Int4 tax1_findTaxIdByName(CharPtr orgname)
544
Int4 id= tax_getIdByName(orgname, NULL, 0);
547
Int4 idu= tax_uniqueName(orgname, 0);
555
/*************************************************************************
556
* Get all tax_id by organism name (it could be "unique" variant of name)
558
* Number of tax ids found
560
Int4 tax1_findAllTaxIdByName(CharPtr orgname, Int4 **Ids_out)
562
Int4 id= tax1_findTaxIdByName(orgname);
565
*Ids_out= MemNew(sizeof(Int4));
566
if(*Ids_out != NULL) {
574
return tax1_getAllTaxIdByName(orgname, Ids_out);
580
Int2 tax1_getAllNames(Int4 tax_id, CharPtr **out_names, Boolean unique)
583
Int2 n= tax_getOrgNames(tax_id, &nameList);
589
*out_names= names= MemNew(n*sizeof(CharPtr));
591
for(i= 0; i < n; i++) {
592
if(unique && (nameList[i].unique_name != NULL) && (nameList[i].unique_name[0] != '\0')) {
593
names[i]= nameList[i].unique_name;
594
nameList[i].unique_name= NULL;
597
names[i]= nameList[i].name_txt;
598
nameList[i].name_txt= NULL;
603
for(i= 0; i < n; i++) {
604
if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
605
if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
613
CharPtr tax1_getGCName(Int2 gc_id)
615
return tax_getGCName(gc_id);
618
static OrgRefPtr s_tax1_getOrgRef(Int4 tax_id, int* is_species, int* is_uncultured, NameListPtr* blast_name)
622
tax_id= getLiveId(tax_id);
623
if(tax_id == 0) return NULL;
625
if((orp= getFromBuff(tax_id, is_species, is_uncultured, blast_name)) != NULL) {
626
/* OrgRef is already in buffer */
634
return getFromBuff(tax_id, is_species, is_uncultured, blast_name);
637
OrgRefPtr tax1m_getOrgRef(Int4 tax_id, int* is_species, int* is_uncultured, CharPtr* blast_name)
639
NameListPtr blast_name_list= NULL;
640
OrgRefPtr orp= s_tax1_getOrgRef(tax_id, is_species, is_uncultured, &blast_name_list);
641
if((blast_name_list != NULL) && (blast_name != NULL)) {
642
*blast_name= StringSave(blast_name_list->name);
647
OrgRefPtr tax1_getOrgRef(Int4 tax_id, int* is_species, CharPtr div, CharPtr embl_cde)
649
OrgRefPtr orp= s_tax1_getOrgRef(tax_id, is_species, NULL, NULL);
650
if(embl_cde != NULL) *embl_cde= '\0';
651
if((div != NULL) && (orp != NULL) && (orp->orgname != NULL) && (orp->orgname->div != NULL)) {
652
StringCpy(div, orp->orgname->div);
658
static ValNodePtr make_blast_name(NameListPtr bl)
660
ValNodePtr list= NULL;
661
ValNodePtr header= NULL;
664
list= ValNodeNew(list);
665
list->data.ptrvalue= StringSave(bl->name);
666
if(header == NULL) header= list;
672
Taxon2DataPtr tax1m_getbyid(Int4 tax_id)
680
if(tax_id <= 0) return NULL;
681
db_orgRef= s_tax1_getOrgRef(tax_id, &is_species, &is_uncultured, &bl);
682
if(db_orgRef == NULL) return NULL; /* nothing found */
684
res= Taxon2DataNew();
685
/* make new orgref */
686
res->org= OrgRefNew();
688
res->org->orgname= NULL;
689
res->is_species_level= is_species;
690
res->is_uncultured= is_uncultured;
691
res->blast_name= make_blast_name(bl);
693
/* fill-up orgref based on db_orgRef */
694
bldOrgRefOut(res->org, db_orgRef, getLiveId(tax_id));
698
/* the old version of the same function */
699
Taxon1DataPtr tax1_getbyid(Int4 tax_id)
705
if(tax_id <= 0) return NULL;
706
db_orgRef= s_tax1_getOrgRef(tax_id, &is_species, NULL, NULL);
707
if(db_orgRef == NULL) return NULL; /* nothing found */
709
res= Taxon1DataNew();
710
/* make new orgref */
711
res->org= OrgRefNew();
713
res->org->orgname= NULL;
714
res->is_species_level= is_species;
715
res->embl_code= NULL;
716
res->div= (db_orgRef->orgname != NULL)? StringSave(db_orgRef->orgname->div) : NULL;
718
/* fill-up orgref based on db_orgRef */
719
bldOrgRefOut(res->org, db_orgRef, getLiveId(tax_id));
723
/*************************************************************************/
724
/* return pointer to first non-blank character in str1 after prefix str2 */
725
/* if str2 is not prefix for str1 then return str1 */
726
/*************************************************************************/
727
static CharPtr strTail(CharPtr str1, CharPtr str2)
731
if(StringStr(str1, str2) != str1) return str1;
733
c= str1 + StringLen(str2);
735
while((*c != '\0') && IS_WHITESP(*c)) c++;
742
static OrgModPtr bldOrgMod(TreeCursorPtr cursor)
744
TXC_TreeNodePtr parent= NULL;
746
TXC_TreeNodePtr me= tree_getNodeData(cursor, &s);
748
TreeNodeId nid= tree_getId(cursor);
750
OrgModPtr orgMdf= OrgModNew();
752
while(tree_parent(cursor)) {
753
if((tnp= tree_getNodeData(cursor, &s)) == NULL) continue;
754
prank= tnp->flags & 0xFF;
756
if((prank == SubspeciesRank) ||
757
(prank == SpeciesRank) ||
758
(prank == GenusRank)) {
763
tree_toNode(cursor, nid);
766
orgMdf->subname= StringSave(strTail(me->node_label, parent->node_label));
769
orgMdf->subname= StringSave(me->node_label);
772
rank= me->flags & 0xFF;
774
if(--rank == SubspeciesRank) {
775
orgMdf->subtype= 22; /* subspecies */
777
else if(rank == tax_getRankId("varietas")) {
778
orgMdf->subtype= 6; /* variety */
780
else if(rank == tax_getRankId("forma")) {
781
orgMdf->subtype= 2; /* strain */
783
else if((parent != NULL) && (prank == SubspeciesRank)) {
784
orgMdf->subtype= 2; /* strain */
787
orgMdf->subtype= 255; /* other */
790
orgMdf->attrib= NULL;
796
/***************************************************************/
797
/* if name is binomial name build the correspondent structures */
798
/* otherwise return 0 */
799
/***************************************************************/
800
static int binomialName(TreeCursorPtr cursor, OrgNamePtr onp)
802
TXC_TreeNodePtr spec= NULL;
803
TXC_TreeNodePtr subspec= NULL;
804
TXC_TreeNodePtr genus= NULL;
807
TreeNodeId nid= tree_getId(cursor);
809
BinomialOrgNamePtr bName;
812
tnp= tree_getNodeData(cursor, &s);
813
if(tnp == NULL) continue;
814
rank= tnp->flags & 0xFF;
815
if(--rank == SubspeciesRank) subspec= tnp;
816
else if(rank == SpeciesRank) spec= tnp;
817
else if(rank == GenusRank) {
822
while(tree_parent(cursor));
824
tree_toNode(cursor, nid);
827
/* try to find subgenus */
829
tnp= tree_getNodeData(cursor, &s);
830
if(tnp == NULL) continue;
831
rank= tnp->flags & 0xFF;
832
if(--rank == (GenusRank + 1)) {
837
while(tree_parent(cursor));
838
tree_toNode(cursor, nid);
841
if(genus == NULL) return 0; /* no genus - no binomial */
843
onp->choice= 1; /*binomial*/
845
onp->data= bName= BinomialOrgNameNew();
847
bName->genus= StringSave(genus->node_label);
851
/* we have a species in lineage */
852
bName->species= StringSave(strTail(spec->node_label, genus->node_label));
854
if(subspec != NULL) {
855
/* we also have a subspecies in lineage */
856
bName->subspecies= StringSave(strTail(subspec->node_label, spec->node_label));
859
bName->subspecies= NULL;
861
tnp= tree_getNodeData(cursor, &s);
863
onp->mod= (tnp == spec)? NULL : bldOrgMod(cursor);
867
/* no species in lineage */
869
if(subspec != NULL) {
870
/* we have no species but we have subspecies */
871
bName->species= NULL;
872
bName->subspecies= StringSave(strTail(subspec->node_label, genus->node_label));
873
onp->mod= bldOrgMod(cursor);
877
/* we have no species, no subspecies but we are under species level (varietas or forma) */
879
bName->species= NULL;
880
bName->subspecies= NULL;
881
onp->mod= bldOrgMod(cursor);
886
static void partialName(TreeCursorPtr cursor, OrgNamePtr onp)
888
TaxElementPtr taxElem;
890
TXC_TreeNodePtr tnp= tree_getNodeData(cursor, &s);
891
Int2 rank_id= tnp->flags & 0xFF;
893
onp->choice= 5; /* partial */
894
onp->data= taxElem= TaxElementNew();
896
if(--rank_id == FamilyRank) {
897
taxElem->fixed_level= 1; /* family */
898
taxElem->level= NULL;
900
else if(rank_id == OrderRank) {
901
taxElem->fixed_level= 2;
902
taxElem->level= NULL;
904
else if(rank_id == ClassRank) {
905
taxElem->fixed_level= 3;
906
taxElem->level= NULL;
909
taxElem->fixed_level= 0;
910
taxElem->level= StringSave(tax_getRank(rank_id));
913
taxElem->name= StringSave(tnp->node_label);
918
/*****************************************************************
919
* build synonyms valnodes
920
* this routine include in valnodes synonyms and common synonyms
922
static ValNodePtr bldSynValNodes(TaxNamePtr syn, Int2 n)
924
ValNodePtr list= NULL;
925
ValNodePtr header= NULL;
928
for(i= 1; i < n; i++) {
929
if((syn[i].class_cde == SYNONYM) || (syn[i].class_cde == COMMON_NAME)) {
930
list= ValNodeNew(list);
931
list->choice= (syn[i].class_cde == SYNONYM)? 1 : 0;
932
list->data.ptrvalue= syn[i].name_txt;
933
syn[i].name_txt= NULL;
934
if(header == NULL) header= list;
941
/**************************************************************************
945
**************************************************************************/
947
static CharPtr bldLineage(TreeCursorPtr cursor, int* is_uncultured, NameListPtr* blast_name)
951
TreeNodeId nid= tree_getId(cursor);
952
CharPtr lineage= NULL;
957
while(tree_parent(cursor)) {
958
if((tnp= tree_getNodeData(cursor, &s)) != NULL) {
959
if(tnp->tax_id < 2) break;
960
if(tnp->flags & TXC_UNCULTURED) *is_uncultured= 1;
961
if((tnp->flags & TXC_STHIDE) == 0) { /* we do have a blast name here */
962
NameListPtr node= MemNew(sizeof(NameList));
963
node->name= tnp->node_label + (StringLen(tnp->node_label) + 1);
966
blast_name= &(node->next);
968
rank= tnp->flags & 0xFF;
969
if(rank > SpeciesRank) {
970
if(lineage != NULL) {
971
lineage = MemFree(lineage);
976
if((tnp->flags & TXC_GBHIDE) == 0) {
977
s= StringLen(tnp->node_label);
978
if(lineage != NULL) {
979
s+= StringLen(lineage) + 2;
983
if(tmp == NULL) continue;
984
t= StringMove(tmp, tnp->node_label);
985
if(lineage != NULL) {
986
t= StringMove(t, "; ");
987
t= StringMove(t, lineage);
995
tree_toNode(cursor, nid);
1000
static ValNodePtr bldDBId(Int4 id)
1004
ObjectIdPtr object_id;
1006
/* populate tax_id */
1007
dbnode= ValNodeNew(NULL);
1008
dbnode->data.ptrvalue= dbtag= DbtagNew();
1009
dbtag->db = StringSave("taxon");
1010
dbtag->tag= object_id= ObjectIdNew();
1011
object_id->str= NULL;
1016
static OrgNamePtr bldOrgName(TreeCursorPtr cursor, int* is_species_out,
1017
int* is_uncultured, NameListPtr* blast_name)
1021
TXC_TreeNodePtr tnp= tree_getNodeData(cursor, &s);
1026
TreeNodeId nid= tree_getId(cursor);
1029
/*Int4 p_id, s_id;*/
1031
if(tnp == NULL) return NULL;
1033
*is_uncultured= ((tnp->flags & TXC_UNCULTURED) != 0)? 1 : 0;
1034
if((tnp->flags & TXC_STHIDE) == 0) { /* we do have a blast name here */
1035
NameListPtr node= MemNew(sizeof(NameList));
1036
node->name= tnp->node_label + (StringLen(tnp->node_label) + 1);
1039
blast_name= &(node->next);
1044
rank_id= tnp->flags & 0xFF;
1047
div_id= (tnp->flags >> 8) & 0x3F;
1048
onp->gcode= (tnp->flags >> (8+6)) & 0x3F;
1049
onp->mgcode= (tnp->flags >> (8+6+6)) & 0x3F;
1050
onp->lineage= bldLineage(cursor, is_uncultured, blast_name);
1052
is_species= (rank_id >= SpeciesRank)? 1 : 0;
1053
/* correct level by lineage if node has no rank */
1056
while(tree_parent(cursor)) {
1057
tnp= tree_getNodeData(cursor, &s);
1059
rank= tnp->flags & 0xFF;
1061
is_species= (rank >= SpeciesRank) ? 1 : 0;
1066
tree_toNode(cursor, nid);
1067
tnp= tree_getNodeData(cursor, &s);
1070
if(tax_getDivision(div_id, &div_abbr, NULL)) {
1071
onp->div= StringSave(div_abbr);
1072
/* StringCpy(div, div_abbr);*/
1074
*is_species_out= is_species;
1077
/* we are on species level or below */
1079
/* check for viruses */
1080
if((div_id == VRL_div) || (div_id == PHG_div)) {
1081
/* this is a virus */
1082
onp->choice= 2; /* virus */
1083
if(rank_id == SpeciesRank) {
1084
/* we are on species level */
1085
onp->data= StringSave(tnp->node_label);
1089
/* we are below species */
1090
/* first try to find species or min rank which below species but above us */
1094
while(tree_parent(cursor)) {
1095
tnp= tree_getNodeData(cursor, &s);
1097
rank= tnp->flags & 0xFF;
1098
if(--rank >= SpeciesRank) {
1099
s_id= tree_getId(cursor);
1100
if(rank == SpeciesRank) break;
1102
else if(rank >= 0) break;
1106
/* we have species or something above us */
1107
tree_toNode(cursor, s_id);
1110
/* no species above */
1111
tree_toNode(cursor, nid);
1114
tnp= tree_getNodeData(cursor, &s);
1115
onp->data= StringSave(tnp->node_label);
1117
tree_toNode(cursor, nid);
1120
onp->mod= bldOrgMod(cursor);
1123
else if(!binomialName(cursor, onp)) {
1124
/* name is not binomial: set partial */
1125
partialName(cursor, onp);
1130
partialName(cursor, onp);
1137
static Boolean bldOrgRef(Int4 id, OrgRefPtr orp, int* is_species, int* is_uncult, NameListPtr* bnl)
1139
TreeCursorPtr cursor= tree_openCursor(tax_tree, NULL, NULL);
1140
TaxNamePtr nameList;
1143
if((cursor == NULL) || (!tc2_toNode(cursor, id))) return FALSE;
1149
n= tax_getOrgNames(id, &nameList);
1152
tree_closeCursor(cursor);
1156
orp->taxname= nameList[0].name_txt;
1157
nameList[0].name_txt= NULL;
1160
/* fill-up preferred common name */
1162
for(i= 1; i < n; i++) {
1163
if(nameList[i].class_cde == PREF_COMMON) {
1164
orp->common= nameList[i].name_txt;
1165
nameList[i].name_txt= NULL;
1170
/* fill-up synonyms */
1171
orp->syn= bldSynValNodes(nameList, n);
1172
for(i= 0; i < n; i++) {
1173
if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
1174
if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
1180
orp->db= bldDBId(id);
1181
orp->orgname= bldOrgName(cursor, is_species, is_uncult, bnl);
1184
tree_closeCursor(cursor);
1189
static void loadInBuff(Int4 id)
1192
Int4 t= my_timer + 1;
1195
for(i= 0; i < BUFF_SIZE; i++) {
1196
if(or_buff[i].tax_id == 0) {
1200
if(or_buff[i].timer < t) {
1201
t= or_buff[i].timer;
1207
if(or_buff[k].p_org_ref != NULL) {
1208
OrgRefFree(or_buff[k].p_org_ref);
1209
free_blast_name(or_buff[k].blast_name);
1212
or_buff[k].tax_id= id;
1213
or_buff[k].p_org_ref= OrgRefNew();
1214
or_buff[k].timer= ++my_timer;
1215
or_buff[k].blast_name= NULL;
1216
if(!bldOrgRef(id, or_buff[k].p_org_ref, &or_buff[k].is_species,
1217
&or_buff[k].is_uncultured, &(or_buff[k].blast_name))) {
1218
OrgRefFree(or_buff[k].p_org_ref);
1219
or_buff[k].tax_id= 0;
1224
static OrgRefPtr getFromBuff(Int4 id, int* is_sp, int* is_uncult, NameListPtr* bnl)
1227
OrgRefPtr orp= NULL;
1231
for(i= 0; i < BUFF_SIZE; i++) {
1232
if(or_buff[i].tax_id == id) {
1233
or_buff[i].timer= ++my_timer;
1234
orp= or_buff[i].p_org_ref;
1235
if(is_sp != NULL) *is_sp= or_buff[i].is_species;
1236
if(is_uncult != NULL) *is_uncult= or_buff[i].is_uncultured;
1237
if(bnl != NULL) *bnl= or_buff[i].blast_name;
1245
static OrgModPtr fixModifier(Int4 tax_id, OrgModPtr omp)
1248
_subspecPtr ss= NULL;
1250
memset(&src_ss, 0, sizeof(_subspec));
1252
if(omp->subtype < 2) {
1259
if((omp->subname != NULL) && (omp->subtype != 0)) {
1260
src_ss.stype= omp->subtype;
1261
src_ss.sname= omp->subname;
1264
ss= tax_SSget(tax_id, &src_ss);
1267
if((ss != NULL) && (ss->r_id == tax_id) && (ss->stype == 0)) {
1269
if(ss->rname != NULL) MemFree(ss->rname);
1275
if((ss != NULL) && (ss->r_id == tax_id) && (ss->stype != 0)) {
1276
MemFree(omp->subname);
1277
omp->subname= src_ss.rname;
1278
omp->subtype= src_ss.rtype;
1282
if(src_ss.rname != NULL) MemFree(src_ss.rname);
1286
static void CleanOrgMod(Int4 tax_id, OrgNamePtr onp)
1288
OrgModPtr omp, omp_p, omp_n;
1290
for(omp_p= NULL, omp= onp->mod; omp != NULL; omp= omp_n) {
1292
if((omp= fixModifier(tax_id, omp)) == NULL) {
1293
/* exclude this modifier */
1297
else omp_p->next= omp_n;
1303
static void cleanOrgName(Int4 tax_id, OrgNamePtr onp)
1305
if(onp->lineage != NULL) MemFree(onp->lineage);
1306
if(onp->div != NULL) MemFree(onp->div);
1308
/* #if 0 means that we will trust to initial modifier */
1309
if(onp->mod != NULL) CleanOrgMod(tax_id, onp);
1311
if(onp->next != NULL) OrgNameSetFree(onp->next);
1312
if(onp->data != NULL) {
1313
switch(onp->choice) {
1314
case 1 : /* binomial name */
1315
BinomialOrgNameFree(onp->data);
1317
case 2 : /* virus name */
1320
case 5 : /* partial name */
1321
TaxElementSetFree(onp->data);
1328
static BinomialOrgNamePtr copyBinomial(BinomialOrgNamePtr src)
1330
BinomialOrgNamePtr dst;
1332
if(src == NULL) return NULL;
1334
dst= BinomialOrgNameNew();
1335
dst->genus= (src->genus != NULL)? StringSave(src->genus) : NULL;
1336
dst->species= (src->species != NULL)? StringSave(src->species) : NULL;
1337
dst->subspecies= (src->subspecies != NULL)? StringSave(src->subspecies) : NULL;
1342
static TaxElementPtr copyPartial(TaxElementPtr src)
1346
if(src == NULL) return NULL;
1348
dst= TaxElementNew();
1349
dst->fixed_level= src->fixed_level;
1350
dst->level= (src->level != NULL)? StringSave(src->level) : NULL;
1351
dst->name= (src->name != NULL)? StringSave(src->name) : NULL;
1352
dst->next= (src->next != NULL)? copyPartial(src->next) : NULL;
1356
static OrgModPtr copyOrgMod(OrgModPtr src)
1361
if(src == NULL) return NULL;
1364
dst->subtype= src->subtype;
1365
dst->subname= (src->subname != NULL)? StringSave(src->subname) : NULL;
1366
dst->attrib= (src->attrib != NULL)? StringSave(src->attrib) : NULL;
1367
dst->next= (src->next != NULL)? copyOrgMod(src->next) : NULL;
1374
static ValNodePtr removeDbtag(ValNodePtr vnp)
1376
ValNodePtr vnn, vnf, vnl= NULL;
1379
for(vnf= vnp; vnp != NULL; vnp= vnn) {
1380
dbtag= vnp->data.ptrvalue;
1382
if(dbtag == NULL) return NULL;
1383
if(StringCmp(dbtag->db, "taxon") == 0) {
1384
/* taxon tag, remove it */
1402
static void bldOrgRefOut(OrgRefPtr dst, OrgRefPtr src, Int4 tax_id)
1404
ValNodePtr vnp, vnl;
1406
ObjectIdPtr object_id;
1409
dst->taxname= StringSave(src->taxname);
1410
dst->common= (src->common != NULL)? StringSave(src->common) : NULL;
1412
/* populate tax_id */
1413
vnp= ValNodeNew(NULL);
1414
if (dst->db != NULL) {
1415
dst->db= removeDbtag(dst->db);
1419
vnp->data.ptrvalue= dbtag= DbtagNew();
1420
dbtag->db = StringSave("taxon");
1421
dbtag->tag= object_id= ObjectIdNew();
1422
object_id->str= NULL;
1423
object_id->id = getLiveId(tax_id);
1425
/* copy the synonym list */
1426
dst->syn= NULL; vnl= NULL;
1427
if(we_want_synonyms) {
1428
for(vnp= src->syn; vnp != NULL; vnp= vnp->next) {
1429
vnl= ValNodeNew(vnl);
1430
vnl->choice= vnp->choice;
1431
vnl->data.ptrvalue= StringSave(vnp->data.ptrvalue);
1432
if(dst->syn == NULL) dst->syn= vnl;
1437
if(dst->orgname == NULL) dst->orgname= onp= OrgNameNew();
1438
else onp= dst->orgname;
1440
onp->choice= src->orgname->choice;
1442
switch(src->orgname->choice) {
1443
case 1 : /*binomial*/
1444
onp->data= copyBinomial(src->orgname->data);
1446
case 2 : /* virus */
1447
onp->data= (src->orgname->data != NULL)? StringSave(src->orgname->data) : NULL;
1449
case 5 : /* partial */
1450
onp->data= copyPartial(src->orgname->data);
1452
default : /* can't handle */
1456
if(onp->mod == NULL) onp->mod= copyOrgMod(src->orgname->mod);
1457
onp->lineage= (src->orgname->lineage != NULL)? StringSave(src->orgname->lineage) : NULL;
1458
onp->gcode= src->orgname->gcode;
1459
onp->mgcode= src->orgname->mgcode;
1460
onp->div= StringSave(src->orgname->div);
1463
static void populateReplaced(OrgRefPtr orp, CharPtr oldName)
1468
if((orp->taxname != NULL) && (StringICmp(orp->taxname, oldName) == 0)) {
1473
if((orp->common != NULL) && (StringICmp(orp->common, oldName) == 0)) {
1478
/* organism name was changed */
1482
omp->next= onp->mod;
1484
omp->subname= oldName;
1492
Taxon2DataPtr tax1m_lookup(OrgRefPtr inp_orgRef, int merge)
1496
OrgRefPtr db_orgRef;
1500
Boolean need_search_name= TRUE;
1503
tax_id= tax1_getTaxIdByOrgRef(inp_orgRef);
1504
if(tax_id <= 0) return NULL;
1505
db_orgRef= s_tax1_getOrgRef(tax_id, &is_species, &is_uncultured, &bl);
1506
if(db_orgRef == NULL) return NULL;
1508
res= Taxon2DataNew();
1509
res->is_species_level= is_species;
1510
res->is_uncultured= is_uncultured;
1511
res->blast_name= make_blast_name(bl);
1513
/* populate search name if necessary */
1514
if(inp_orgRef->taxname != NULL) {
1515
if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->taxname) == 0)) {
1516
need_search_name= FALSE;
1518
else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->common) == 0)) {
1519
need_search_name= FALSE;
1523
if(need_search_name && (inp_orgRef->common != NULL)) {
1524
if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->taxname) == 0)) {
1525
need_search_name= FALSE;
1527
else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->common) == 0)) {
1528
need_search_name= FALSE;
1532
if(need_search_name && (inp_orgRef->orgname != NULL)) {
1533
/* check if search name already exists */
1536
for(omp= inp_orgRef->orgname->mod; omp != NULL; omp= omp->next) {
1537
if(omp->subtype == 254) {
1538
need_search_name= FALSE;
1545
if(need_search_name) {
1546
if((inp_orgRef->taxname != NULL) && (inp_orgRef->taxname[0] != '\0')) {
1547
hit_name= StringSave(inp_orgRef->taxname);
1549
else if((inp_orgRef->common != NULL) && (inp_orgRef->common[0] != '\0')) {
1550
hit_name= StringSave(inp_orgRef->common);
1555
/* we have to merge old orgref with the new one */
1556
res->org= inp_orgRef;
1557
/* clean-up old information */
1558
if(inp_orgRef->taxname != NULL) MemFree(inp_orgRef->taxname);
1559
if(inp_orgRef->common != NULL) MemFree(inp_orgRef->common);
1560
if(inp_orgRef->syn != NULL) ValNodeFreeData(inp_orgRef->syn);
1561
if(inp_orgRef->orgname != NULL) cleanOrgName(tax_id, inp_orgRef->orgname);
1564
/* make new orgref */
1565
res->org= OrgRefNew();
1567
res->org->orgname= NULL;
1569
/* fill-up orgref based on db_orgRef */
1570
bldOrgRefOut(res->org, db_orgRef, tax_id);
1571
if(need_search_name && (hit_name != NULL)) populateReplaced(res->org, hit_name);
1575
Taxon1DataPtr tax1_lookup(OrgRefPtr inp_orgRef, int merge)
1579
OrgRefPtr db_orgRef;
1581
Boolean need_search_name= TRUE;
1584
tax_id= tax1_getTaxIdByOrgRef(inp_orgRef);
1585
if(tax_id <= 0) return NULL;
1586
db_orgRef= s_tax1_getOrgRef(tax_id, &is_species, NULL, NULL);
1587
if(db_orgRef == NULL) return NULL;
1589
res= Taxon1DataNew();
1590
res->is_species_level= is_species;
1591
res->embl_code= NULL;
1592
res->div= (db_orgRef->orgname != NULL)? StringSave(db_orgRef->orgname->div) : NULL;
1594
/* populate search name if necessary */
1595
if(inp_orgRef->taxname != NULL) {
1596
if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->taxname) == 0)) {
1597
need_search_name= FALSE;
1599
else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->common) == 0)) {
1600
need_search_name= FALSE;
1604
if(need_search_name && (inp_orgRef->common != NULL)) {
1605
if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->taxname) == 0)) {
1606
need_search_name= FALSE;
1608
else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->common) == 0)) {
1609
need_search_name= FALSE;
1613
if(need_search_name && (inp_orgRef->orgname != NULL)) {
1614
/* check if search name already exists */
1617
for(omp= inp_orgRef->orgname->mod; omp != NULL; omp= omp->next) {
1618
if(omp->subtype == 254) {
1619
need_search_name= FALSE;
1626
if(need_search_name) {
1627
if((inp_orgRef->taxname != NULL) && (inp_orgRef->taxname[0] != '\0')) {
1628
hit_name= StringSave(inp_orgRef->taxname);
1630
else if((inp_orgRef->common != NULL) && (inp_orgRef->common[0] != '\0')) {
1631
hit_name= StringSave(inp_orgRef->common);
1636
/* we have to merge old orgref with the new one */
1637
res->org= inp_orgRef;
1638
/* clean-up old information */
1639
if(inp_orgRef->taxname != NULL) MemFree(inp_orgRef->taxname);
1640
if(inp_orgRef->common != NULL) MemFree(inp_orgRef->common);
1641
if(inp_orgRef->syn != NULL) ValNodeFreeData(inp_orgRef->syn);
1642
if(inp_orgRef->orgname != NULL) cleanOrgName(tax_id, inp_orgRef->orgname);
1645
/* make new orgref */
1646
res->org= OrgRefNew();
1648
res->org->orgname= NULL;
1650
/* fill-up orgref based on db_orgRef */
1651
bldOrgRefOut(res->org, db_orgRef, tax_id);
1652
if(need_search_name && (hit_name != NULL)) populateReplaced(res->org, hit_name);
1657
Boolean tax1_init(void)
1662
void tax1_fini(void)
1667
TreePtr tax1e_getTaxTreePtr(void)
1672
Boolean tax1e_invokeNode(Int4 tax_id)
1674
return tax_ptree_addNode(tax_tree, tax_id);
1677
Boolean tax1e_invokeChildren(Int4 tax_id)
1681
TreeCursorPtr cursor= tree_openCursor(tax_tree, NULL, NULL);
1687
if((cursor == NULL) || (!tc2_toNode(cursor, tax_id))) return FALSE;
1689
res= res? tax_ptree_addSubtree(cursor) : tax_ptree_addChildren(cursor);
1691
tree_closeCursor(cursor);
1695
Boolean tax1e_toNode(TreeCursorPtr cursor, Int4 tax_id)
1697
return tc2_toNode(cursor, tax_id);
1700
Int4 tax1e_getTaxId(TreeCursorPtr cursor)
1703
TXC_TreeNodePtr tnp;
1705
tnp= tree_getNodeData(cursor, &s);
1707
return (tnp != NULL)? tnp->tax_id : 0;
1710
CharPtr tax1e_getTaxName(TreeCursorPtr cursor)
1713
TXC_TreeNodePtr tnp;
1715
tnp= tree_getNodeData(cursor, &s);
1717
return (tnp != NULL)? StringSave(tnp->node_label) : NULL;
1720
Int4 tax1_getTaxId4Str(CharPtr str, CharPtr* substring, Int4Ptr *Ids_out)
1729
tax_id= tax1_getTaxIdByName(str);
1732
*Ids_out= MemNew(sizeof(Int4));
1734
*substring= StringSave(str);
1737
else if(tax_id < 0) {
1738
*substring= StringSave(str);
1739
return tax1_getAllTaxIdByName(str, Ids_out);
1742
/* whole string matches nothing */
1743
/* try the whole string inside first set of parenthesis */
1744
for(b= str; *b != '\0'; b++) {
1747
for(e= b+1; *e != '\0'; e++) {
1759
tax_id= tax1_getTaxIdByName(b+1);
1762
*substring= StringSave(b+1);
1764
*Ids_out= MemNew(sizeof(Int4));
1768
else if(tax_id < 0) {
1769
*substring= StringSave(b+1);
1771
return tax1_getAllTaxIdByName(*substring, Ids_out);
1774
/* whole string won't help lets try truncate it at first comma*/
1776
for(e= b+1; *e != '\0'; e++) {
1779
tax_id= tax1_getTaxIdByName(b+1);
1782
*substring= StringSave(b+1);
1784
*Ids_out= MemNew(sizeof(Int4));
1788
else if(tax_id < 0) {
1789
*substring= StringSave(b+1);
1791
return tax1_getAllTaxIdByName(*substring, Ids_out);
1804
/* we still have got nothing */
1805
/* try the substring before first '(' */
1808
/* we are staying on the first '(' */
1811
tax_id= tax1_getTaxIdByName(str);
1814
*Ids_out= MemNew(sizeof(Int4));
1816
*substring= StringSave(str);
1820
else if(tax_id < 0) {
1821
*substring= StringSave(str);
1823
return tax1_getAllTaxIdByName(*substring, Ids_out);
1828
b= StringStr(str, "Organism");
1829
if(b == NULL) b= StringStr(str, "organism");
1830
if(b == NULL) b= StringStr(str, "ORGANISM");
1833
e= StringChr(b, ':');
1836
tax_id= tax1_getTaxIdByName(b);
1839
*Ids_out= MemNew(sizeof(Int4));
1841
*substring= StringSave(b);
1844
else if(tax_id < 0) {
1845
*substring= StringSave(b);
1846
return tax1_getAllTaxIdByName(*substring, Ids_out);
1849
/* if multiple lines or ; , ( */
1850
for(++e; *e != '\0'; e++) {
1851
if((*e == '\n') || (*e == ';') || (*e == ',') || (*e == '(')) {
1854
tax_id= tax1_getTaxIdByName(b);
1857
*substring= StringSave(b);
1859
*Ids_out= MemNew(sizeof(Int4));
1863
else if(tax_id < 0) {
1864
*substring= StringSave(b);
1866
return tax1_getAllTaxIdByName(*substring, Ids_out);
1877
static int nameCmp(CharPtr s1, CharPtr s2)
1879
if((s1 == NULL) && (s2 == NULL)) return 0;
1880
if((s1 == NULL) || (s2 == NULL)) return 1;
1882
return strcmp(s1, s2);
1885
static Int4 storedTaxId(OrgRefPtr orp)
1889
ObjectIdPtr object_id;
1891
for(vnp= orp->db; vnp != NULL; vnp= vnp->next) {
1892
dbtag= vnp->data.ptrvalue;
1893
if((dbtag != NULL) && (StringCmp(dbtag->db, "taxon") == 0)) {
1894
ObjectIdPtr object_id= dbtag->tag;
1895
return object_id->id;
1902
static Int4 OrgModCmp(OrgModPtr omp1, OrgModPtr omp2)
1907
if(omp2 == NULL) return 0;
1908
if(omp1 == NULL) return 100;
1910
for(;omp2 != NULL; omp2= omp2->next) {
1912
for(omp= omp1; omp != NULL; omp= omp->next) {
1913
if((omp2->subtype == omp->subtype) &&
1914
(nameCmp(omp2->subname, omp->subname) == 0)) {
1919
if(!found) return 100;
1924
static Int4 OrgRefCmp(OrgRefPtr orp1, OrgRefPtr orp2)
1926
OrgNamePtr onp1= orp1->orgname;
1927
OrgNamePtr onp2= orp2->orgname;
1929
if(onp1 == NULL) return 4;
1930
if(onp2 == NULL) return -2;
1932
if(onp1->gcode != onp2->gcode) return 2;
1933
if(onp1->mgcode != onp2->mgcode) return 3;
1935
if(nameCmp(orp1->taxname, orp2->taxname) != 0) return 10;
1937
if(nameCmp(onp1->lineage, onp2->lineage) != 0) return 20;
1939
if(nameCmp(orp1->common, orp2->common) != 0) return 30;
1941
if(onp1->choice != onp2->choice) return 40;
1943
if(nameCmp(onp1->div, onp2->div) != 0) return 50;
1945
return OrgModCmp(onp1->mod, onp2->mod);
1949
Int4 tax1e_needUpdate(OrgRefPtr inp_orgRef)
1953
OrgRefPtr db_orgRef;
1955
Boolean need_search_name= TRUE;
1958
tax_id= tax1_getTaxIdByOrgRef(inp_orgRef);
1959
if(tax_id <= 0) return -1;
1961
if(tax_id != storedTaxId(inp_orgRef)) return 1;
1963
db_orgRef= s_tax1_getOrgRef(tax_id, NULL, NULL, NULL /*res->embl_code*/);
1964
if(db_orgRef == NULL) {
1968
return OrgRefCmp(inp_orgRef, db_orgRef);
1971
Boolean tax1_isAlive(void)
1973
return (tax1_getTaxIdByName("dog") > 1)? TRUE : FALSE;
1976
/***************************************************
1977
* Get tax_id for given gi
1980
* 0 if no data or error
1982
Int4 tax1_getTaxId4GI(Int4 gi)
1984
return tax_getTaxId4GI(gi);
1987
/***************************************************
1988
* Get pointer to "blast" name
1989
* Returns: the pointer on first blast name at or above this node in the lineage
1991
* This function does not make a copy of "blast" name, so, caller can not use
1992
* MemFree function for returned pointer.
1994
CharPtr tax1m_getBlastName(Int4 tax_id)
1997
TreeCursorPtr cursor= tree_openCursor(tax_tree, NULL, NULL);
1999
if(tc2_toNode(cursor, tax_id)) {
2000
TXC_TreeNodePtr tnp;
2003
tnp= tree_getNodeData(cursor, &s);
2004
if((tnp != NULL) && ((tnp->flags & TXC_STHIDE) == 0)) { /* we do have a blast name here */
2005
res= tnp->node_label + (StringLen(tnp->node_label) + 1);
2009
while(tree_parent(cursor));
2012
tree_closeCursor(cursor);