summaryrefslogtreecommitdiff
path: root/network/taxon1/taxon2/tc2proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'network/taxon1/taxon2/tc2proc.c')
-rw-r--r--network/taxon1/taxon2/tc2proc.c1836
1 files changed, 1011 insertions, 825 deletions
diff --git a/network/taxon1/taxon2/tc2proc.c b/network/taxon1/taxon2/tc2proc.c
index ceb6bf00..c11b1b01 100644
--- a/network/taxon1/taxon2/tc2proc.c
+++ b/network/taxon1/taxon2/tc2proc.c
@@ -12,6 +12,10 @@
#define TAX_READ 0
#define TAX_WRITE 1
+#define ORGMOD_gb_acronym 32
+#define ORGMOD_gb_anamorph 33
+#define ORGMOD_gb_synonym 34
+
static TreePtr tax_tree= NULL;
@@ -26,7 +30,10 @@ static Int2 OrderRank= 0;
static Int2 ClassRank= 0;
static Int2 SYNONYM= 0;
static Int2 COMMON_NAME= 0;
-static Int2 PREF_COMMON= 0;
+static Int2 GB_COMMON= 0;
+static Int2 GB_ACRONYM= 0;
+static Int2 GB_SYNONYM= 0;
+static Int2 GB_ANAMORPH= 0;
static int my_timer= 0;
@@ -56,7 +63,7 @@ static void bldOrgRefOut(OrgRefPtr dst, OrgRefPtr src, Int4 tax_id);
Boolean tax1_setSynonyms(Boolean on_off)
{
Boolean ret;
-
+
ret= we_want_synonyms;
we_want_synonyms= on_off;
return ret;
@@ -66,9 +73,9 @@ Boolean tax1_setSynonyms(Boolean on_off)
static Boolean tc2_toNode(TreeCursorPtr cursor, Int4 tax_id)
{
if(!tax_ptree_toTaxId(cursor, tax_id, FALSE)) {
- /* this node is not in our tree */
- return (tax_ptree_addNode(tax_tree, tax_id)) ?
- tax_ptree_toTaxId(cursor, tax_id, FALSE) : FALSE;
+ /* this node is not in our tree */
+ return (tax_ptree_addNode(tax_tree, tax_id)) ?
+ tax_ptree_toTaxId(cursor, tax_id, FALSE) : FALSE;
}
return TRUE;
}
@@ -89,9 +96,9 @@ static void initBuff(void)
my_timer= 0;
for(i= 0; i < BUFF_SIZE; i++) {
- or_buff[i].tax_id= 0;
- or_buff[i].p_org_ref= NULL;
- or_buff[i].blast_name= NULL;
+ or_buff[i].tax_id= 0;
+ or_buff[i].p_org_ref= NULL;
+ or_buff[i].blast_name= NULL;
}
}
@@ -122,16 +129,16 @@ int InitTaxDB(void)
if((tmp=getenv("TAXDBPATH")) != NULL) DB_PATH= tmp;
if(!txc_connect2Server(DB_PATH, "soussov", "vladimir", "tax2cl")) {
-
- return 0;
+
+ return 0;
}
-
+
if((!txc_loadNameClasses()) || (!txc_loadRanks()) ||
(!txc_loadDivisions()) || (!txc_loadGCs())) {
-
- return 0;
+
+ return 0;
}
-
+
SpeciesRank= tax_getRankId("species");
SubspeciesRank= tax_getRankId("subspecies");
@@ -146,7 +153,10 @@ int InitTaxDB(void)
SYNONYM= tax_getClass_cde("synonym");
COMMON_NAME= tax_getClass_cde("common name");
- PREF_COMMON= tax_getClass_cde("preferred common name");
+ GB_COMMON= tax_getClass_cde("genbank common name");
+ GB_ACRONYM= tax_getClass_cde("genbank acronym");
+ GB_SYNONYM= tax_getClass_cde("genbank synonym");
+ GB_ANAMORPH= tax_getClass_cde("genbank anamorph");
initBuff();
tax_tree= tax_ptree_new();
@@ -163,14 +173,14 @@ int InitTaxDB(void)
static void free_blast_name(NameListPtr blast_name)
{
if(blast_name != NULL) {
- NameListPtr t;
-
- do {
- t= blast_name->next;
- MemFree(blast_name);
- blast_name= t;
- }
- while(blast_name);
+ NameListPtr t;
+
+ do {
+ t= blast_name->next;
+ MemFree(blast_name);
+ blast_name= t;
+ }
+ while(blast_name);
}
}
@@ -179,18 +189,18 @@ int CloseTaxDB(void)
int i;
if(tax_tree != NULL) {
- tree_delete(tax_tree);
-
- txc_close();
-
- for(i= 0; i < BUFF_SIZE; i++) {
- if(or_buff[i].p_org_ref != NULL) {
- OrgRefFree(or_buff[i].p_org_ref);
- if(or_buff[i].blast_name != NULL) {
- free_blast_name(or_buff[i].blast_name);
- }
- }
- }
+ tree_delete(tax_tree);
+
+ txc_close();
+
+ for(i= 0; i < BUFF_SIZE; i++) {
+ if(or_buff[i].p_org_ref != NULL) {
+ OrgRefFree(or_buff[i].p_org_ref);
+ if(or_buff[i].blast_name != NULL) {
+ free_blast_name(or_buff[i].blast_name);
+ }
+ }
+ }
}
return 1;
}
@@ -199,21 +209,21 @@ Int4 tax1_getParent(Int4 id_tax)
{
TreeCursorPtr cursor;
Int4 ret_id= -1;
-
+
if(tax_tree == NULL) return -1;
-
+
if(id_tax == 1) return 0;
-
+
cursor= tree_openCursor(tax_tree, NULL, NULL);
if(cursor == NULL) return -1;
-
+
if(tc2_toNode(cursor, id_tax)) {
- TXC_TreeNodePtr tnp;
- Uint2 s;
-
- tree_parent(cursor);
- tnp= tree_getNodeData(cursor, &s);
- if(tnp != NULL) ret_id= tnp->tax_id;
+ TXC_TreeNodePtr tnp;
+ Uint2 s;
+
+ tree_parent(cursor);
+ tnp= tree_getNodeData(cursor, &s);
+ if(tnp != NULL) ret_id= tnp->tax_id;
}
tree_closeCursor(cursor);
@@ -224,33 +234,33 @@ Int4 tax1_getGenus(Int4 id_tax)
{
TreeCursorPtr cursor;
Int4 ret_id= -1;
-
+
if(tax_tree == NULL) return -1;
-
+
if(id_tax == 1) return 0;
-
+
cursor= tree_openCursor(tax_tree, NULL, NULL);
if(cursor == NULL) return -1;
-
+
if(tc2_toNode(cursor, id_tax)) {
- TXC_TreeNodePtr tnp;
- Uint2 s;
- Int2 rank;
-
- do {
- tree_parent(cursor);
- tnp= tree_getNodeData(cursor, &s);
- if(tnp == NULL) {
- ret_id= -1;
- break;
- }
- ret_id= tnp->tax_id;
- rank= tnp->flags & 0xFF;
- --rank;
- if(rank == GenusRank) break;
- if((rank > 0) && (rank < GenusRank)) ret_id= -1;
- }
- while(ret_id > 1);
+ TXC_TreeNodePtr tnp;
+ Uint2 s;
+ Int2 rank;
+
+ do {
+ tree_parent(cursor);
+ tnp= tree_getNodeData(cursor, &s);
+ if(tnp == NULL) {
+ ret_id= -1;
+ break;
+ }
+ ret_id= tnp->tax_id;
+ rank= tnp->flags & 0xFF;
+ --rank;
+ if(rank == GenusRank) break;
+ if((rank > 0) && (rank < GenusRank)) ret_id= -1;
+ }
+ while(ret_id > 1);
}
tree_closeCursor(cursor);
@@ -268,32 +278,32 @@ int tax1_getChildren(Int4 id_tax, Int4** ids_out)
if(cursor == NULL) return 0;
if(tc2_toNode(cursor, id_tax)) {
- if(tax_ptree_addChildren(cursor) && tree_child(cursor)) {
- TXC_TreeNodePtr tnp;
- Uint2 s;
-
- do {
- n++;
- }
- while(tree_sibling(cursor));
-
- *ids_out= ids= MemNew(n*sizeof(Int4));
-
- tree_parent(cursor);
- tree_child(cursor);
- n= 0;
- do {
- tnp= tree_getNodeData(cursor, &s);
- if(tnp != NULL) ids[n++]= tnp->tax_id;
- }
- while(tree_sibling(cursor));
- }
+ if(tax_ptree_addChildren(cursor) && tree_child(cursor)) {
+ TXC_TreeNodePtr tnp;
+ Uint2 s;
+
+ do {
+ n++;
+ }
+ while(tree_sibling(cursor));
+
+ *ids_out= ids= MemNew(n*sizeof(Int4));
+
+ tree_parent(cursor);
+ tree_child(cursor);
+ n= 0;
+ do {
+ tnp= tree_getNodeData(cursor, &s);
+ if(tnp != NULL) ids[n++]= tnp->tax_id;
+ }
+ while(tree_sibling(cursor));
+ }
}
-
+
tree_closeCursor(cursor);
return n;
}
-
+
/* find last common ancestor for two nodes */
Int4 tax1_join(Int4 taxid1, Int4 taxid2)
@@ -302,24 +312,24 @@ Int4 tax1_join(Int4 taxid1, Int4 taxid2)
Int4 aid= 0;
TreeCursorPtr cursor1= tree_openCursor(tax_tree, NULL, NULL);
TreeCursorPtr cursor2= tree_openCursor(tax_tree, NULL, NULL);
-
+
if((cursor1 == NULL) || (cursor2 == NULL) ||
(!tc2_toNode(cursor1, taxid1)) || (!tc2_toNode(cursor2, taxid2))) {
- if(cursor1 != NULL) tree_closeCursor(cursor1);
- if(cursor2 != NULL) tree_closeCursor(cursor2);
- return -1;
+ if(cursor1 != NULL) tree_closeCursor(cursor1);
+ if(cursor2 != NULL) tree_closeCursor(cursor2);
+ return -1;
}
-
+
nid= tree_getAncestor(cursor1, cursor2);
-
+
if(tree_toNode(cursor1, nid)) {
- TXC_TreeNodePtr tnp;
- Uint2 s;
-
- tnp= tree_getNodeData(cursor1, &s);
- if(tnp != NULL) aid= tnp->tax_id;
+ TXC_TreeNodePtr tnp;
+ Uint2 s;
+
+ tnp= tree_getNodeData(cursor1, &s);
+ if(tnp != NULL) aid= tnp->tax_id;
}
-
+
tree_closeCursor(cursor1);
tree_closeCursor(cursor2);
return aid;
@@ -354,18 +364,18 @@ Int4 tax1_getAllTaxIdByName(CharPtr orgname, Int4 **Ids_out)
*Ids_out= Ids= MemNew(n*sizeof(Int4));
if(Ids != NULL) {
- for(i= 0; i < n; i++) {
- Ids[i]= nameList[i].tax_id;
- if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
- if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
- }
+ for(i= 0; i < n; i++) {
+ Ids[i]= nameList[i].tax_id;
+ if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
+ if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
+ }
}
else {
- for(i= 0; i < n; i++) {
- if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
- if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
- }
- n= 0;
+ for(i= 0; i < n; i++) {
+ if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
+ if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
+ }
+ n= 0;
}
MemFree(nameList);
return n;
@@ -379,126 +389,126 @@ static Boolean goodOrgMode(Uint1 t)
static Int4 getIdByOrgRef(CharPtr sname, OrgNamePtr orNm)
{
if(orNm != NULL) {
- OrgModPtr o_mod= orNm->mod;
- Boolean om_flag= FALSE;
- Int4 tax_id, id;
- CharPtr altname= NULL;
- int nof_mods= 0;
- _subspecPtr ss;
- _subspec src;
-
- /* first try to search using search name */
- for(;o_mod != NULL; o_mod= o_mod->next) {
- if(o_mod->subtype == 254) {
- /* search name */
- altname= o_mod->subname;
- }
- else if(o_mod->subtype != 20) nof_mods++;
- }
-
- if(nof_mods == 0) {
- /* we have no modifiers */
- if(altname != NULL) {
- if((tax_id= tax_getIdByName(altname, NULL, 0)) > 0) return tax_id;
- return tax_getIdByName(sname, altname, 254);
- }
- return tax_getIdByName(sname, NULL, 0);
- }
-
- if(nof_mods == 1) {
- /* we have one valuable modifier */
- for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
- if(goodOrgMode(o_mod->subtype)) {
- if(altname != NULL) {
- if((tax_id= tax_getIdByName(altname, o_mod->subname, o_mod->subtype)) > 0)
- return tax_id; /* find by old name and modifier */
- if((tax_id= tax_getIdByName(sname, o_mod->subname, o_mod->subtype)) > 0)
- return tax_id; /* find by new name and modifier */
- return tax_getIdByName(sname, altname, 254); /* find by new name and old name */
- }
- return tax_getIdByName(sname, o_mod->subname, o_mod->subtype);
- }
- }
- return 0;
- }
-
- /* we have more than one modifier */
- /* first try to find organism using just names */
- if(altname != NULL) {
- if((tax_id= tax_getIdByName(altname, NULL, 0)) == 0) {
- tax_id= tax_getIdByName(sname, altname, 254);
- }
- }
- else {
- tax_id= tax_getIdByName(sname, NULL, 0);
- }
-
- if(tax_id == 0) return 0; /* we have no such names */
- if(tax_id > 0) {
- /* we have found just one node, check it against modifiers */
- id= 0;
- for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
- if(o_mod->subtype != 20) {
- src.stype= o_mod->subtype;
- src.sname= o_mod->subname;
- src.rname= NULL;
- if((ss= tax_SSget(tax_id, &src)) != NULL) {
- if(ss->rname != NULL) MemFree(ss->rname);
- if((ss->r_id != 0) && (ss->r_id != tax_id)) {
- if(id == 0) id= ss->r_id;
- else if(id != ss->r_id) {
- id= -id; /* conflict in mapping */
- break;
- }
- }
- }
- }
- }
- if(id == 0) return tax_id;
- if(id < 0) return -tax_id; /* we have a mapping conflict */
-
- /* we have a mapping without conflict, we try to make the best assumption */
- return id;
- }
-
- if(tax_id < 0) {
- /* more than one tax_id was found */
- Int4Ptr ids;
- Int4 n;
-
- if(altname != NULL) {
- n= tax1_getAllTaxIdByName(altname, &ids);
- if(n < 1) n= tax1_getAllTaxIdByName(sname, &ids);
- }
- else n= tax1_getAllTaxIdByName(sname, &ids);
-
- id= 0;
- while(n-- > 0) {
- for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
- if(goodOrgMode(o_mod->subtype)) {
- src.stype= o_mod->subtype;
- src.sname= o_mod->subname;
- src.rname= NULL;
- if((ss= tax_SSget(ids[n], &src)) != NULL) {
- if(ss->rname != NULL) MemFree(ss->rname);
- if(ss->r_id != 0) {
- if(id == 0) id= ss->r_id;
- else if(id != ss->r_id) id= -id;
- }
- }
- }
- }
- }
- if(ids != NULL) MemFree(ids);
- if(id > 0) return id;
- }
- return tax_id;
+ OrgModPtr o_mod= orNm->mod;
+ Boolean om_flag= FALSE;
+ Int4 tax_id, id;
+ CharPtr altname= NULL;
+ int nof_mods= 0;
+ _subspecPtr ss;
+ _subspec src;
+
+ /* first try to search using search name */
+ for(;o_mod != NULL; o_mod= o_mod->next) {
+ if(o_mod->subtype == 254) {
+ /* search name */
+ altname= o_mod->subname;
+ }
+ else if(o_mod->subtype != 20) nof_mods++;
+ }
+
+ if(nof_mods == 0) {
+ /* we have no modifiers */
+ if(altname != NULL) {
+ if((tax_id= tax_getIdByName(altname, NULL, 0)) > 0) return tax_id;
+ return tax_getIdByName(sname, altname, 254);
+ }
+ return tax_getIdByName(sname, NULL, 0);
+ }
+
+ if(nof_mods == 1) {
+ /* we have one valuable modifier */
+ for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
+ if(goodOrgMode(o_mod->subtype)) {
+ if(altname != NULL) {
+ if((tax_id= tax_getIdByName(altname, o_mod->subname, o_mod->subtype)) > 0)
+ return tax_id; /* find by old name and modifier */
+ if((tax_id= tax_getIdByName(sname, o_mod->subname, o_mod->subtype)) > 0)
+ return tax_id; /* find by new name and modifier */
+ return tax_getIdByName(sname, altname, 254); /* find by new name and old name */
+ }
+ return tax_getIdByName(sname, o_mod->subname, o_mod->subtype);
+ }
+ }
+ return 0;
+ }
+
+ /* we have more than one modifier */
+ /* first try to find organism using just names */
+ if(altname != NULL) {
+ if((tax_id= tax_getIdByName(altname, NULL, 0)) == 0) {
+ tax_id= tax_getIdByName(sname, altname, 254);
+ }
+ }
+ else {
+ tax_id= tax_getIdByName(sname, NULL, 0);
+ }
+
+ if(tax_id == 0) return 0; /* we have no such names */
+ if(tax_id > 0) {
+ /* we have found just one node, check it against modifiers */
+ id= 0;
+ for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
+ if(o_mod->subtype != 20) {
+ src.stype= o_mod->subtype;
+ src.sname= o_mod->subname;
+ src.rname= NULL;
+ if((ss= tax_SSget(tax_id, &src)) != NULL) {
+ if(ss->rname != NULL) MemFree(ss->rname);
+ if((ss->r_id != 0) && (ss->r_id != tax_id)) {
+ if(id == 0) id= ss->r_id;
+ else if(id != ss->r_id) {
+ id= -id; /* conflict in mapping */
+ break;
+ }
+ }
+ }
+ }
+ }
+ if(id == 0) return tax_id;
+ if(id < 0) return -tax_id; /* we have a mapping conflict */
+
+ /* we have a mapping without conflict, we try to make the best assumption */
+ return id;
+ }
+
+ if(tax_id < 0) {
+ /* more than one tax_id was found */
+ Int4Ptr ids;
+ Int4 n;
+
+ if(altname != NULL) {
+ n= tax1_getAllTaxIdByName(altname, &ids);
+ if(n < 1) n= tax1_getAllTaxIdByName(sname, &ids);
+ }
+ else n= tax1_getAllTaxIdByName(sname, &ids);
+
+ id= 0;
+ while(n-- > 0) {
+ for(o_mod= orNm->mod; o_mod != NULL; o_mod= o_mod->next) {
+ if(goodOrgMode(o_mod->subtype)) {
+ src.stype= o_mod->subtype;
+ src.sname= o_mod->subname;
+ src.rname= NULL;
+ if((ss= tax_SSget(ids[n], &src)) != NULL) {
+ if(ss->rname != NULL) MemFree(ss->rname);
+ if(ss->r_id != 0) {
+ if(id == 0) id= ss->r_id;
+ else if(id != ss->r_id) id= -id;
+ }
+ }
+ }
+ }
+ }
+ if(ids != NULL) MemFree(ids);
+ if(id > 0) return id;
+ }
+ return tax_id;
}
else {
- /* we have no modifiers */
- return tax_getIdByName(sname, NULL, 0);
+ /* we have no modifiers */
+ return tax_getIdByName(sname, NULL, 0);
}
-
+
}
Int4 tax1_getTaxIdByOrgRef(OrgRefPtr orgRef)
@@ -507,27 +517,27 @@ Int4 tax1_getTaxIdByOrgRef(OrgRefPtr orgRef)
return txc_getTaxIdByOrgRef(orgRef);
#else
Int4 tax_id, id;
-
+
if(orgRef == NULL) return 0;
-
+
tax_id= 0;
-
+
if((orgRef->taxname != NULL) &&
((tax_id= getIdByOrgRef(orgRef->taxname, orgRef->orgname)) > 0)) return tax_id;
-
+
if((orgRef->common != NULL) &&
((tax_id= getIdByOrgRef(orgRef->common, orgRef->orgname)) > 0)) return tax_id;
-
+
if(orgRef->syn != NULL) {
- ValNodePtr synonym;
-
- id= 0;
-
- for(synonym= orgRef->syn; (synonym != NULL) && (id < 1); synonym= synonym->next) {
- id= getIdByOrgRef(synonym->data.ptrvalue, orgRef->orgname);
- }
+ ValNodePtr synonym;
+
+ id= 0;
+
+ for(synonym= orgRef->syn; (synonym != NULL) && (id < 1); synonym= synonym->next) {
+ id= getIdByOrgRef(synonym->data.ptrvalue, orgRef->orgname);
+ }
}
-
+
return (id > 0)? id : tax_id;
#endif
}
@@ -544,9 +554,9 @@ Int4 tax1_findTaxIdByName(CharPtr orgname)
Int4 id= tax_getIdByName(orgname, NULL, 0);
if(id < 1) {
- Int4 idu= tax_uniqueName(orgname, 0);
-
- if(idu > 0) id= idu;
+ Int4 idu= tax_uniqueName(orgname, 0);
+
+ if(idu > 0) id= idu;
}
return id;
}
@@ -562,18 +572,18 @@ Int4 tax1_findAllTaxIdByName(CharPtr orgname, Int4 **Ids_out)
Int4 id= tax1_findTaxIdByName(orgname);
if(id > 0) {
- *Ids_out= MemNew(sizeof(Int4));
- if(*Ids_out != NULL) {
- **Ids_out= id;
- return 1;
- }
- else return 0;
+ *Ids_out= MemNew(sizeof(Int4));
+ if(*Ids_out != NULL) {
+ **Ids_out= id;
+ return 1;
+ }
+ else return 0;
}
if(id < 0) {
- return tax1_getAllTaxIdByName(orgname, Ids_out);
+ return tax1_getAllTaxIdByName(orgname, Ids_out);
}
-
+
return 0;
}
@@ -589,20 +599,20 @@ Int2 tax1_getAllNames(Int4 tax_id, CharPtr **out_names, Boolean unique)
*out_names= names= MemNew(n*sizeof(CharPtr));
if(names != NULL) {
for(i= 0; i < n; i++) {
- if(unique && (nameList[i].unique_name != NULL) && (nameList[i].unique_name[0] != '\0')) {
- names[i]= nameList[i].unique_name;
- nameList[i].unique_name= NULL;
- }
- else {
- names[i]= nameList[i].name_txt;
- nameList[i].name_txt= NULL;
- }
- }
+ if(unique && (nameList[i].unique_name != NULL) && (nameList[i].unique_name[0] != '\0')) {
+ names[i]= nameList[i].unique_name;
+ nameList[i].unique_name= NULL;
+ }
+ else {
+ names[i]= nameList[i].name_txt;
+ nameList[i].name_txt= NULL;
+ }
+ }
}
-
+
for(i= 0; i < n; i++) {
- if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
- if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
+ if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
+ if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
}
MemFree(nameList);
@@ -621,16 +631,16 @@ static OrgRefPtr s_tax1_getOrgRef(Int4 tax_id, int* is_species, int* is_uncultur
tax_id= getLiveId(tax_id);
if(tax_id == 0) return NULL;
-
+
if((orp= getFromBuff(tax_id, is_species, is_uncultured, blast_name)) != NULL) {
- /* OrgRef is already in buffer */
- return orp;
+ /* OrgRef is already in buffer */
+ return orp;
}
-
+
lockBuff(TAX_WRITE);
loadInBuff(tax_id);
unlockBuff();
-
+
return getFromBuff(tax_id, is_species, is_uncultured, blast_name);
}
@@ -639,7 +649,7 @@ OrgRefPtr tax1m_getOrgRef(Int4 tax_id, int* is_species, int* is_uncultured, Char
NameListPtr blast_name_list= NULL;
OrgRefPtr orp= s_tax1_getOrgRef(tax_id, is_species, is_uncultured, &blast_name_list);
if((blast_name_list != NULL) && (blast_name != NULL)) {
- *blast_name= StringSave(blast_name_list->name);
+ *blast_name= StringSave(blast_name_list->name);
}
return orp;
}
@@ -649,7 +659,7 @@ OrgRefPtr tax1_getOrgRef(Int4 tax_id, int* is_species, CharPtr div, CharPtr embl
OrgRefPtr orp= s_tax1_getOrgRef(tax_id, is_species, NULL, NULL);
if(embl_cde != NULL) *embl_cde= '\0';
if((div != NULL) && (orp != NULL) && (orp->orgname != NULL) && (orp->orgname->div != NULL)) {
- StringCpy(div, orp->orgname->div);
+ StringCpy(div, orp->orgname->div);
}
return orp;
@@ -659,12 +669,12 @@ static ValNodePtr make_blast_name(NameListPtr bl)
{
ValNodePtr list= NULL;
ValNodePtr header= NULL;
-
+
while(bl != NULL) {
- list= ValNodeNew(list);
- list->data.ptrvalue= StringSave(bl->name);
- if(header == NULL) header= list;
- bl= bl->next;
+ list= ValNodeNew(list);
+ list->data.ptrvalue= StringSave(bl->name);
+ if(header == NULL) header= list;
+ bl= bl->next;
}
return header;
}
@@ -737,7 +747,96 @@ static CharPtr strTail(CharPtr str1, CharPtr str2)
return c;
}
+static void rmWord(CharPtr str, CharPtr wrd, int wlen)
+{
+ if((str == wrd) || isspace(*(wrd-1))) {
+ while((*(wrd+wlen) != '\0') && isspace(*(wrd+wlen))) wlen++;
+ }
+
+ for(;;) {
+ *wrd= *(wrd + wlen);
+ if(*wrd == '\0') break;
+ ++wrd;
+ }
+}
+static Int2 getSubtypeFromName(CharPtr name)
+{
+ CharPtr c;
+ if(strchr(name, '.') == NULL) return 0;
+ /* check for subsp */
+ c= StringStr(name, "subsp.");
+ if(c) {
+ rmWord(name, c, 6);
+ return 22;
+ }
+ c= StringStr(name, "ssp.");
+ if(c) {
+ rmWord(name, c, 4);
+ return 22;
+ }
+ c= StringStr(name, "f. sp.");
+ if(c) {
+ rmWord(name, c, 6);
+ return 26;
+ }
+ c= StringStr(name, "f.sp.");
+ if(c) {
+ rmWord(name, c, 5);
+ return 26;
+ }
+ c= StringStr(name, "str.");
+ if(c) {
+ rmWord(name, c, 4);
+ return 2;
+ }
+ c= StringStr(name, "substr.");
+ if(c) {
+ rmWord(name, c, 7);
+ return 3;
+ }
+ c= StringStr(name, "var.");
+ if(c) {
+ rmWord(name, c, 4);
+ return 6;
+ }
+ c= StringStr(name, "sv.");
+ if(c) {
+ rmWord(name, c, 3);
+ return 9;
+ }
+ c= StringStr(name, "cv.");
+ if(c) {
+ rmWord(name, c, 3);
+ return 10;
+ }
+ c= StringStr(name, "pv.");
+ if(c) {
+ rmWord(name, c, 3);
+ return 11;
+ }
+ c= StringStr(name, "bv.");
+ if(c) {
+ rmWord(name, c, 3);
+ return 13;
+ }
+ c= StringStr(name, "f.");
+ if(c) {
+ rmWord(name, c, 2);
+ return 25;
+ }
+ c= StringStr(name, "fo.");
+ if(c) {
+ rmWord(name, c, 3);
+ return 25;
+ }
+ c= StringStr(name, "grp.");
+ if(c) {
+ rmWord(name, c, 4);
+ return 15;
+ }
+ return 0;
+}
static OrgModPtr bldOrgMod(TreeCursorPtr cursor)
{
@@ -750,45 +849,48 @@ static OrgModPtr bldOrgMod(TreeCursorPtr cursor)
OrgModPtr orgMdf= OrgModNew();
while(tree_parent(cursor)) {
- if((tnp= tree_getNodeData(cursor, &s)) == NULL) continue;
- prank= tnp->flags & 0xFF;
- --prank;
- if((prank == SubspeciesRank) ||
- (prank == SpeciesRank) ||
- (prank == GenusRank)) {
- parent= tnp;
- break;
- }
+ if((tnp= tree_getNodeData(cursor, &s)) == NULL) continue;
+ prank= tnp->flags & 0xFF;
+ --prank;
+ if((prank == SubspeciesRank) ||
+ (prank == SpeciesRank) ||
+ (prank == GenusRank)) {
+ parent= tnp;
+ break;
+ }
}
tree_toNode(cursor, nid);
-
+
if(parent != NULL) {
- orgMdf->subname= StringSave(strTail(me->node_label, parent->node_label));
+ orgMdf->subname= StringSave(strTail(me->node_label, parent->node_label));
}
else {
- orgMdf->subname= StringSave(me->node_label);
+ orgMdf->subname= StringSave(me->node_label);
}
-
+
rank= me->flags & 0xFF;
- if(--rank == SubspeciesRank) {
- orgMdf->subtype= 22; /* subspecies */
- }
- else if(rank == tax_getRankId("varietas")) {
- orgMdf->subtype= 6; /* variety */
- }
- else if(rank == tax_getRankId("forma")) {
- orgMdf->subtype= 2; /* strain */
- }
- else if((parent != NULL) && (prank == SubspeciesRank)) {
- orgMdf->subtype= 2; /* strain */
+ orgMdf->subtype= getSubtypeFromName(orgMdf->subname);
+
+ if(orgMdf->subtype <= 0) {
+ if(--rank == SubspeciesRank) {
+ orgMdf->subtype= 22; /* subspecies */
+ }
+ else if(rank == tax_getRankId("varietas")) {
+ orgMdf->subtype= 6; /* variety */
+ }
+ else if(rank == tax_getRankId("forma")) {
+ orgMdf->subtype= 25; /* forma */
+ }
+ else if((parent != NULL) && (prank == SubspeciesRank)) {
+ orgMdf->subtype= 2; /* strain */
+ }
+ else {
+ orgMdf->subtype= 255; /* other */
+ }
}
- else {
- orgMdf->subtype= 255; /* other */
- }
-
orgMdf->attrib= NULL;
-
+
return orgMdf;
}
@@ -809,73 +911,73 @@ static int binomialName(TreeCursorPtr cursor, OrgNamePtr onp)
BinomialOrgNamePtr bName;
do {
- tnp= tree_getNodeData(cursor, &s);
- if(tnp == NULL) continue;
- rank= tnp->flags & 0xFF;
- if(--rank == SubspeciesRank) subspec= tnp;
- else if(rank == SpeciesRank) spec= tnp;
- else if(rank == GenusRank) {
- genus= tnp;
- break;
- }
+ tnp= tree_getNodeData(cursor, &s);
+ if(tnp == NULL) continue;
+ rank= tnp->flags & 0xFF;
+ if(--rank == SubspeciesRank) subspec= tnp;
+ else if(rank == SpeciesRank) spec= tnp;
+ else if(rank == GenusRank) {
+ genus= tnp;
+ break;
+ }
}
while(tree_parent(cursor));
-
+
tree_toNode(cursor, nid);
-
+
if(genus == NULL) {
- /* try to find subgenus */
- do {
- tnp= tree_getNodeData(cursor, &s);
- if(tnp == NULL) continue;
- rank= tnp->flags & 0xFF;
- if(--rank == (GenusRank + 1)) {
- genus= tnp;
- break;
- }
- }
- while(tree_parent(cursor));
- tree_toNode(cursor, nid);
+ /* try to find subgenus */
+ do {
+ tnp= tree_getNodeData(cursor, &s);
+ if(tnp == NULL) continue;
+ rank= tnp->flags & 0xFF;
+ if(--rank == (GenusRank + 1)) {
+ genus= tnp;
+ break;
+ }
+ }
+ while(tree_parent(cursor));
+ tree_toNode(cursor, nid);
}
-
+
if(genus == NULL) return 0; /* no genus - no binomial */
-
+
onp->choice= 1; /*binomial*/
-
+
onp->data= bName= BinomialOrgNameNew();
-
+
bName->genus= StringSave(genus->node_label);
-
+
if(spec != NULL) {
- /* we have a species in lineage */
- bName->species= StringSave(strTail(spec->node_label, genus->node_label));
-
- if(subspec != NULL) {
- /* we also have a subspecies in lineage */
- bName->subspecies= StringSave(strTail(subspec->node_label, spec->node_label));
- }
- else {
- bName->subspecies= NULL;
- }
- tnp= tree_getNodeData(cursor, &s);
-
- onp->mod= (tnp == spec)? NULL : bldOrgMod(cursor);
- return 1;
+ /* we have a species in lineage */
+ bName->species= StringSave(strTail(spec->node_label, genus->node_label));
+
+ if(subspec != NULL) {
+ /* we also have a subspecies in lineage */
+ bName->subspecies= StringSave(strTail(subspec->node_label, spec->node_label));
+ }
+ else {
+ bName->subspecies= NULL;
+ }
+ tnp= tree_getNodeData(cursor, &s);
+
+ onp->mod= (tnp == spec)? NULL : bldOrgMod(cursor);
+ return 1;
}
-
+
/* no species in lineage */
-
+
if(subspec != NULL) {
- /* we have no species but we have subspecies */
- bName->species= NULL;
- bName->subspecies= StringSave(strTail(subspec->node_label, genus->node_label));
- onp->mod= bldOrgMod(cursor);
- return 1;
+ /* we have no species but we have subspecies */
+ bName->species= NULL;
+ bName->subspecies= StringSave(strTail(subspec->node_label, genus->node_label));
+ onp->mod= bldOrgMod(cursor);
+ return 1;
}
-
+
/* we have no species, no subspecies but we are under species level (varietas or forma) */
-
+
bName->species= NULL;
bName->subspecies= NULL;
onp->mod= bldOrgMod(cursor);
@@ -889,32 +991,32 @@ static void partialName(TreeCursorPtr cursor, OrgNamePtr onp)
Uint2 s;
TXC_TreeNodePtr tnp= tree_getNodeData(cursor, &s);
Int2 rank_id= tnp->flags & 0xFF;
-
+
onp->choice= 5; /* partial */
onp->data= taxElem= TaxElementNew();
-
+
if(--rank_id == FamilyRank) {
- taxElem->fixed_level= 1; /* family */
- taxElem->level= NULL;
+ taxElem->fixed_level= 1; /* family */
+ taxElem->level= NULL;
}
else if(rank_id == OrderRank) {
- taxElem->fixed_level= 2;
- taxElem->level= NULL;
+ taxElem->fixed_level= 2;
+ taxElem->level= NULL;
}
else if(rank_id == ClassRank) {
- taxElem->fixed_level= 3;
- taxElem->level= NULL;
+ taxElem->fixed_level= 3;
+ taxElem->level= NULL;
}
else {
- taxElem->fixed_level= 0;
- taxElem->level= StringSave(tax_getRank(rank_id));
+ taxElem->fixed_level= 0;
+ taxElem->level= StringSave(tax_getRank(rank_id));
}
-
+
taxElem->name= StringSave(tnp->node_label);
taxElem->next= NULL;
}
-
+
/*****************************************************************
* build synonyms valnodes
* this routine include in valnodes synonyms and common synonyms
@@ -924,15 +1026,15 @@ static ValNodePtr bldSynValNodes(TaxNamePtr syn, Int2 n)
ValNodePtr list= NULL;
ValNodePtr header= NULL;
Int2 i;
-
+
for(i= 1; i < n; i++) {
- if((syn[i].class_cde == SYNONYM) || (syn[i].class_cde == COMMON_NAME)) {
- list= ValNodeNew(list);
- list->choice= (syn[i].class_cde == SYNONYM)? 1 : 0;
- list->data.ptrvalue= syn[i].name_txt;
- syn[i].name_txt= NULL;
- if(header == NULL) header= list;
- }
+ if((syn[i].class_cde == SYNONYM) || (syn[i].class_cde == COMMON_NAME)) {
+ list= ValNodeNew(list);
+ list->choice= (syn[i].class_cde == SYNONYM)? 1 : 0;
+ list->data.ptrvalue= syn[i].name_txt;
+ syn[i].name_txt= NULL;
+ if(header == NULL) header= list;
+ }
}
return header;
}
@@ -953,45 +1055,45 @@ static CharPtr bldLineage(TreeCursorPtr cursor, int* is_uncultured, NameListPtr*
CharPtr tmp, t;
Int2 rank= 0;
-
+
while(tree_parent(cursor)) {
- if((tnp= tree_getNodeData(cursor, &s)) != NULL) {
- if(tnp->tax_id < 2) break;
- if(tnp->flags & TXC_UNCULTURED) *is_uncultured= 1;
- if((tnp->flags & TXC_STHIDE) == 0) { /* we do have a blast name here */
- NameListPtr node= MemNew(sizeof(NameList));
- node->name= tnp->node_label + (StringLen(tnp->node_label) + 1);
- node->next= NULL;
- *blast_name= node;
- blast_name= &(node->next);
- }
- rank= tnp->flags & 0xFF;
- if(rank > SpeciesRank) {
- if(lineage != NULL) {
- lineage = MemFree(lineage);
- }
- continue;
- }
-
- if((tnp->flags & TXC_GBHIDE) == 0) {
- s= StringLen(tnp->node_label);
- if(lineage != NULL) {
- s+= StringLen(lineage) + 2;
- }
-
- tmp= MemNew(s+2);
- if(tmp == NULL) continue;
- t= StringMove(tmp, tnp->node_label);
- if(lineage != NULL) {
- t= StringMove(t, "; ");
- t= StringMove(t, lineage);
- MemFree(lineage);
- }
- lineage= tmp;
- }
- }
+ if((tnp= tree_getNodeData(cursor, &s)) != NULL) {
+ if(tnp->tax_id < 2) break;
+ if(tnp->flags & TXC_UNCULTURED) *is_uncultured= 1;
+ if((tnp->flags & TXC_STHIDE) == 0) { /* we do have a blast name here */
+ NameListPtr node= MemNew(sizeof(NameList));
+ node->name= tnp->node_label + (StringLen(tnp->node_label) + 1);
+ node->next= NULL;
+ *blast_name= node;
+ blast_name= &(node->next);
+ }
+ rank= tnp->flags & 0xFF;
+ if(rank > SpeciesRank) {
+ if(lineage != NULL) {
+ lineage = MemFree(lineage);
+ }
+ continue;
+ }
+
+ if((tnp->flags & TXC_GBHIDE) == 0) {
+ s= StringLen(tnp->node_label);
+ if(lineage != NULL) {
+ s+= StringLen(lineage) + 2;
+ }
+
+ tmp= MemNew(s+2);
+ if(tmp == NULL) continue;
+ t= StringMove(tmp, tnp->node_label);
+ if(lineage != NULL) {
+ t= StringMove(t, "; ");
+ t= StringMove(t, lineage);
+ MemFree(lineage);
+ }
+ lineage= tmp;
+ }
+ }
}
-
+
tree_toNode(cursor, nid);
return lineage;
@@ -1014,7 +1116,7 @@ static ValNodePtr bldDBId(Int4 id)
}
static OrgNamePtr bldOrgName(TreeCursorPtr cursor, int* is_species_out,
- int* is_uncultured, NameListPtr* blast_name)
+ int* is_uncultured, NameListPtr* blast_name)
{
OrgNamePtr onp;
Uint2 s;
@@ -1032,11 +1134,11 @@ static OrgNamePtr bldOrgName(TreeCursorPtr cursor, int* is_species_out,
*is_uncultured= ((tnp->flags & TXC_UNCULTURED) != 0)? 1 : 0;
if((tnp->flags & TXC_STHIDE) == 0) { /* we do have a blast name here */
- NameListPtr node= MemNew(sizeof(NameList));
- node->name= tnp->node_label + (StringLen(tnp->node_label) + 1);
- node->next= NULL;
- *blast_name= node;
- blast_name= &(node->next);
+ NameListPtr node= MemNew(sizeof(NameList));
+ node->name= tnp->node_label + (StringLen(tnp->node_label) + 1);
+ node->next= NULL;
+ *blast_name= node;
+ blast_name= &(node->next);
}
onp= OrgNameNew();
@@ -1053,84 +1155,84 @@ static OrgNamePtr bldOrgName(TreeCursorPtr cursor, int* is_species_out,
/* correct level by lineage if node has no rank */
if(rank_id < 0) {
- while(tree_parent(cursor)) {
- tnp= tree_getNodeData(cursor, &s);
- if(tnp != NULL) {
- rank= tnp->flags & 0xFF;
- if(rank != 0) {
- is_species= (rank >= SpeciesRank) ? 1 : 0;
- break;
- }
- }
- }
- tree_toNode(cursor, nid);
- tnp= tree_getNodeData(cursor, &s);
+ while(tree_parent(cursor)) {
+ tnp= tree_getNodeData(cursor, &s);
+ if(tnp != NULL) {
+ rank= tnp->flags & 0xFF;
+ if(rank != 0) {
+ is_species= (rank >= SpeciesRank) ? 1 : 0;
+ break;
+ }
+ }
+ }
+ tree_toNode(cursor, nid);
+ tnp= tree_getNodeData(cursor, &s);
}
if(tax_getDivision(div_id, &div_abbr, NULL)) {
- onp->div= StringSave(div_abbr);
- /* StringCpy(div, div_abbr);*/
+ onp->div= StringSave(div_abbr);
+ /* StringCpy(div, div_abbr);*/
}
*is_species_out= is_species;
if(is_species) {
- /* we are on species level or below */
+ /* we are on species level or below */
- /* check for viruses */
- if((div_id == VRL_div) || (div_id == PHG_div)) {
- /* this is a virus */
- onp->choice= 2; /* virus */
- if(rank_id == SpeciesRank) {
- /* we are on species level */
- onp->data= StringSave(tnp->node_label);
- onp->mod= NULL;
- }
- else {
- /* we are below species */
- /* first try to find species or min rank which below species but above us */
- TreeNodeId s_id;
+ /* check for viruses */
+ if((div_id == VRL_div) || (div_id == PHG_div)) {
+ /* this is a virus */
+ onp->choice= 2; /* virus */
+ if(rank_id == SpeciesRank) {
+ /* we are on species level */
+ onp->data= StringSave(tnp->node_label);
+ onp->mod= NULL;
+ }
+ else {
+ /* we are below species */
+ /* first try to find species or min rank which below species but above us */
+ TreeNodeId s_id;
- s_id.idi= 0;
- while(tree_parent(cursor)) {
- tnp= tree_getNodeData(cursor, &s);
- if(tnp != NULL) {
- rank= tnp->flags & 0xFF;
- if(--rank >= SpeciesRank) {
- s_id= tree_getId(cursor);
- if(rank == SpeciesRank) break;
- }
- else if(rank >= 0) break;
- }
- }
- if(s_id.idi != 0) {
- /* we have species or something above us */
- tree_toNode(cursor, s_id);
- }
- else {
- /* no species above */
- tree_toNode(cursor, nid);
- }
+ s_id.idi= 0;
+ while(tree_parent(cursor)) {
+ tnp= tree_getNodeData(cursor, &s);
+ if(tnp != NULL) {
+ rank= tnp->flags & 0xFF;
+ if(--rank >= SpeciesRank) {
+ s_id= tree_getId(cursor);
+ if(rank == SpeciesRank) break;
+ }
+ else if(rank >= 0) break;
+ }
+ }
+ if(s_id.idi != 0) {
+ /* we have species or something above us */
+ tree_toNode(cursor, s_id);
+ }
+ else {
+ /* no species above */
+ tree_toNode(cursor, nid);
+ }
- tnp= tree_getNodeData(cursor, &s);
- onp->data= StringSave(tnp->node_label);
- if(s_id.idi != 0) {
- tree_toNode(cursor, nid);
- }
-
- onp->mod= bldOrgMod(cursor);
- }
- }
- else if(!binomialName(cursor, onp)) {
- /* name is not binomial: set partial */
- partialName(cursor, onp);
- }
+ tnp= tree_getNodeData(cursor, &s);
+ onp->data= StringSave(tnp->node_label);
+ if(s_id.idi != 0) {
+ tree_toNode(cursor, nid);
+ }
+
+ onp->mod= bldOrgMod(cursor);
+ }
+ }
+ else if(!binomialName(cursor, onp)) {
+ /* name is not binomial: set partial */
+ partialName(cursor, onp);
+ }
}
else {
- /* above species */
- partialName(cursor, onp);
+ /* above species */
+ partialName(cursor, onp);
}
- return onp;
+ return onp;
}
@@ -1149,8 +1251,8 @@ static Boolean bldOrgRef(Int4 id, OrgRefPtr orp, int* is_species, int* is_uncult
n= tax_getOrgNames(id, &nameList);
if(n < 1) {
- tree_closeCursor(cursor);
- return FALSE;
+ tree_closeCursor(cursor);
+ return FALSE;
}
orp->taxname= nameList[0].name_txt;
@@ -1160,26 +1262,60 @@ static Boolean bldOrgRef(Int4 id, OrgRefPtr orp, int* is_species, int* is_uncult
/* fill-up preferred common name */
orp->common= NULL;
for(i= 1; i < n; i++) {
- if(nameList[i].class_cde == PREF_COMMON) {
- orp->common= nameList[i].name_txt;
- nameList[i].name_txt= NULL;
- break;
- }
+ if(nameList[i].class_cde == GB_COMMON) {
+ orp->common= nameList[i].name_txt;
+ nameList[i].name_txt= NULL;
+ break;
+ }
}
/* fill-up synonyms */
orp->syn= bldSynValNodes(nameList, n);
- for(i= 0; i < n; i++) {
- if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
- if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
- }
-
- MemFree(nameList);
orp->mod= NULL;
orp->db= bldDBId(id);
orp->orgname= bldOrgName(cursor, is_species, is_uncult, bnl);
+ /*
+ ORGMOD_gb_acronym 32
+ ORGMOD_gb_anamorph 33
+ ORGMOD_gb_synonym 34
+ */
+ /* add some of the nametypes as OrgMods */
+ if(orp->orgname) { // OrgName is not empty
+ for(i= 1; i < n; i++) {
+ if(nameList[i].class_cde == GB_ACRONYM) {
+ OrgModPtr acr= OrgModNew();
+ acr->subtype= ORGMOD_gb_acronym;
+ acr->subname= nameList[i].name_txt;
+ nameList[i].name_txt= NULL;
+ acr->next= orp->orgname->mod;
+ orp->orgname->mod= acr;
+ }
+ else if(nameList[i].class_cde == GB_ANAMORPH) {
+ OrgModPtr anm= OrgModNew();
+ anm->subtype= ORGMOD_gb_anamorph;
+ anm->subname= nameList[i].name_txt;
+ nameList[i].name_txt= NULL;
+ anm->next= orp->orgname->mod;
+ orp->orgname->mod= anm;
+ }
+ else if(nameList[i].class_cde == GB_SYNONYM) {
+ OrgModPtr snm= OrgModNew();
+ snm->subtype= ORGMOD_gb_synonym;
+ snm->subname= nameList[i].name_txt;
+ nameList[i].name_txt= NULL;
+ snm->next= orp->orgname->mod;
+ orp->orgname->mod= snm;
+ }
+ }
+ }
+
+ for(i= 0; i < n; i++) {
+ if(nameList[i].name_txt != NULL) MemFree(nameList[i].name_txt);
+ if(nameList[i].unique_name != NULL) MemFree(nameList[i].unique_name);
+ }
+ MemFree(nameList);
tree_closeCursor(cursor);
return TRUE;
@@ -1193,31 +1329,31 @@ static void loadInBuff(Int4 id)
/*Int4 bt;*/
for(i= 0; i < BUFF_SIZE; i++) {
- if(or_buff[i].tax_id == 0) {
- k= i;
- break;
- }
- if(or_buff[i].timer < t) {
- t= or_buff[i].timer;
- k= i;
- }
+ if(or_buff[i].tax_id == 0) {
+ k= i;
+ break;
+ }
+ if(or_buff[i].timer < t) {
+ t= or_buff[i].timer;
+ k= i;
+ }
}
if(k >= 0) {
- if(or_buff[k].p_org_ref != NULL) {
- OrgRefFree(or_buff[k].p_org_ref);
- free_blast_name(or_buff[k].blast_name);
- }
+ if(or_buff[k].p_org_ref != NULL) {
+ OrgRefFree(or_buff[k].p_org_ref);
+ free_blast_name(or_buff[k].blast_name);
+ }
- or_buff[k].tax_id= id;
- or_buff[k].p_org_ref= OrgRefNew();
- or_buff[k].timer= ++my_timer;
- or_buff[k].blast_name= NULL;
- if(!bldOrgRef(id, or_buff[k].p_org_ref, &or_buff[k].is_species,
- &or_buff[k].is_uncultured, &(or_buff[k].blast_name))) {
- OrgRefFree(or_buff[k].p_org_ref);
- or_buff[k].tax_id= 0;
- }
+ or_buff[k].tax_id= id;
+ or_buff[k].p_org_ref= OrgRefNew();
+ or_buff[k].timer= ++my_timer;
+ or_buff[k].blast_name= NULL;
+ if(!bldOrgRef(id, or_buff[k].p_org_ref, &or_buff[k].is_species,
+ &or_buff[k].is_uncultured, &(or_buff[k].blast_name))) {
+ OrgRefFree(or_buff[k].p_org_ref);
+ or_buff[k].tax_id= 0;
+ }
}
}
@@ -1229,14 +1365,14 @@ static OrgRefPtr getFromBuff(Int4 id, int* is_sp, int* is_uncult, NameListPtr* b
lockBuff(TAX_READ);
for(i= 0; i < BUFF_SIZE; i++) {
- if(or_buff[i].tax_id == id) {
- or_buff[i].timer= ++my_timer;
- orp= or_buff[i].p_org_ref;
- if(is_sp != NULL) *is_sp= or_buff[i].is_species;
- if(is_uncult != NULL) *is_uncult= or_buff[i].is_uncultured;
- if(bnl != NULL) *bnl= or_buff[i].blast_name;
- break;
- }
+ if(or_buff[i].tax_id == id) {
+ or_buff[i].timer= ++my_timer;
+ orp= or_buff[i].p_org_ref;
+ if(is_sp != NULL) *is_sp= or_buff[i].is_species;
+ if(is_uncult != NULL) *is_uncult= or_buff[i].is_uncultured;
+ if(bnl != NULL) *bnl= or_buff[i].blast_name;
+ break;
+ }
}
unlockBuff();
return orp;
@@ -1249,34 +1385,37 @@ static OrgModPtr fixModifier(Int4 tax_id, OrgModPtr omp)
memset(&src_ss, 0, sizeof(_subspec));
- if(omp->subtype < 2) {
- omp->next= NULL;
- OrgModFree(omp);
- return NULL;
+ if((omp->subtype < 2) ||
+ (omp->subtype == ORGMOD_gb_acronym) ||
+ (omp->subtype == ORGMOD_gb_anamorph) ||
+ (omp->subtype == ORGMOD_gb_synonym)) {
+ omp->next= NULL;
+ OrgModFree(omp);
+ return NULL;
}
if((omp->subname != NULL) && (omp->subtype != 0)) {
- src_ss.stype= omp->subtype;
- src_ss.sname= omp->subname;
- src_ss.rname= NULL;
+ src_ss.stype= omp->subtype;
+ src_ss.sname= omp->subname;
+ src_ss.rname= NULL;
- ss= tax_SSget(tax_id, &src_ss);
+ ss= tax_SSget(tax_id, &src_ss);
}
if((ss != NULL) && (ss->r_id == tax_id) && (ss->stype == 0)) {
- /* remove it */
- if(ss->rname != NULL) MemFree(ss->rname);
- omp->next= NULL;
- OrgModFree(omp);
- return NULL;
+ /* remove it */
+ if(ss->rname != NULL) MemFree(ss->rname);
+ omp->next= NULL;
+ OrgModFree(omp);
+ return NULL;
}
if((ss != NULL) && (ss->r_id == tax_id) && (ss->stype != 0)) {
- MemFree(omp->subname);
- omp->subname= src_ss.rname;
- omp->subtype= src_ss.rtype;
- return omp;
+ MemFree(omp->subname);
+ omp->subname= src_ss.rname;
+ omp->subtype= src_ss.rtype;
+ return omp;
}
if(src_ss.rname != NULL) MemFree(src_ss.rname);
@@ -1288,15 +1427,15 @@ static void CleanOrgMod(Int4 tax_id, OrgNamePtr onp)
OrgModPtr omp, omp_p, omp_n;
for(omp_p= NULL, omp= onp->mod; omp != NULL; omp= omp_n) {
- omp_n= omp->next;
- if((omp= fixModifier(tax_id, omp)) == NULL) {
- /* exclude this modifier */
- if(omp_p == NULL) {
- onp->mod= omp_n;
- }
- else omp_p->next= omp_n;
- }
- else omp_p= omp;
+ omp_n= omp->next;
+ if((omp= fixModifier(tax_id, omp)) == NULL) {
+ /* exclude this modifier */
+ if(omp_p == NULL) {
+ onp->mod= omp_n;
+ }
+ else omp_p->next= omp_n;
+ }
+ else omp_p= omp;
}
}
@@ -1310,17 +1449,17 @@ static void cleanOrgName(Int4 tax_id, OrgNamePtr onp)
#endif
if(onp->next != NULL) OrgNameSetFree(onp->next);
if(onp->data != NULL) {
- switch(onp->choice) {
- case 1 : /* binomial name */
- BinomialOrgNameFree(onp->data);
- break;
- case 2 : /* virus name */
- MemFree(onp->data);
- break;
- case 5 : /* partial name */
- TaxElementSetFree(onp->data);
- break;
- }
+ switch(onp->choice) {
+ case 1 : /* binomial name */
+ BinomialOrgNameFree(onp->data);
+ break;
+ case 2 : /* virus name */
+ MemFree(onp->data);
+ break;
+ case 5 : /* partial name */
+ TaxElementSetFree(onp->data);
+ break;
+ }
}
}
@@ -1355,10 +1494,12 @@ static TaxElementPtr copyPartial(TaxElementPtr src)
static OrgModPtr copyOrgMod(OrgModPtr src)
{
-#if 0
+#if 1
OrgModPtr dst;
if(src == NULL) return NULL;
+ if(src->subtype == 255)
+ return (src->next != NULL)? copyOrgMod(src->next) : NULL;
dst= OrgModNew();
dst->subtype= src->subtype;
@@ -1367,8 +1508,50 @@ static OrgModPtr copyOrgMod(OrgModPtr src)
dst->next= (src->next != NULL)? copyOrgMod(src->next) : NULL;
return dst;
-#endif
+#else
return NULL;
+#endif
+}
+
+static int subtypeConflict(Int2 t1, Int2 t2)
+{
+ if(t1 == t2) return 1;
+ switch(t2) {
+ case 2:
+ case 6:
+ case 22:
+ if((t1 >= 2 && t1 <= 17) || (t1 == 22)) return 1;
+ break;
+ case 255:
+ return 1;
+ default:
+ break;
+ }
+ return 0;
+}
+
+static void mergeOrgMod(OrgModPtr omp, OrgModPtr src)
+{
+ if(src == NULL) return;
+ else {
+ OrgModPtr dst, lst;
+ for(dst= omp; dst != NULL; dst= dst->next) {
+ lst= dst;
+ if(subtypeConflict((Int2)dst->subtype, (Int2)src->subtype)) {
+ mergeOrgMod(omp, src->next);
+ return;
+ }
+ }
+
+ lst->next= dst= OrgModNew();
+ dst->subtype= src->subtype;
+ dst->subname= (src->subname != NULL)? StringSave(src->subname) : NULL;
+ dst->attrib= (src->attrib != NULL)? StringSave(src->attrib) : NULL;
+ dst->next= NULL;
+
+ mergeOrgMod(omp, src->next);
+ }
+
}
static ValNodePtr removeDbtag(ValNodePtr vnp)
@@ -1377,23 +1560,23 @@ static ValNodePtr removeDbtag(ValNodePtr vnp)
DbtagPtr dbtag;
for(vnf= vnp; vnp != NULL; vnp= vnn) {
- dbtag= vnp->data.ptrvalue;
- vnn= vnp->next;
- if(dbtag == NULL) return NULL;
- if(StringCmp(dbtag->db, "taxon") == 0) {
- /* taxon tag, remove it */
- if(vnl == NULL) {
- vnf= vnn;
- }
- else {
- vnl->next= vnn;
- }
- DbtagFree(dbtag);
- MemFree(vnp);
- }
- else {
- vnl= vnp;
- }
+ dbtag= vnp->data.ptrvalue;
+ vnn= vnp->next;
+ if(dbtag == NULL) return NULL;
+ if(StringCmp(dbtag->db, "taxon") == 0) {
+ /* taxon tag, remove it */
+ if(vnl == NULL) {
+ vnf= vnn;
+ }
+ else {
+ vnl->next= vnn;
+ }
+ DbtagFree(dbtag);
+ MemFree(vnp);
+ }
+ else {
+ vnl= vnp;
+ }
}
return vnf;
}
@@ -1412,7 +1595,7 @@ static void bldOrgRefOut(OrgRefPtr dst, OrgRefPtr src, Int4 tax_id)
/* populate tax_id */
vnp= ValNodeNew(NULL);
if (dst->db != NULL) {
- dst->db= removeDbtag(dst->db);
+ dst->db= removeDbtag(dst->db);
}
vnp->next= dst->db;
dst->db= vnp;
@@ -1425,12 +1608,12 @@ static void bldOrgRefOut(OrgRefPtr dst, OrgRefPtr src, Int4 tax_id)
/* copy the synonym list */
dst->syn= NULL; vnl= NULL;
if(we_want_synonyms) {
- for(vnp= src->syn; vnp != NULL; vnp= vnp->next) {
- vnl= ValNodeNew(vnl);
- vnl->choice= vnp->choice;
- vnl->data.ptrvalue= StringSave(vnp->data.ptrvalue);
- if(dst->syn == NULL) dst->syn= vnl;
- }
+ for(vnp= src->syn; vnp != NULL; vnp= vnp->next) {
+ vnl= ValNodeNew(vnl);
+ vnl->choice= vnp->choice;
+ vnl->data.ptrvalue= StringSave(vnp->data.ptrvalue);
+ if(dst->syn == NULL) dst->syn= vnl;
+ }
}
/* copy orgname */
@@ -1441,19 +1624,22 @@ static void bldOrgRefOut(OrgRefPtr dst, OrgRefPtr src, Int4 tax_id)
switch(src->orgname->choice) {
case 1 : /*binomial*/
- onp->data= copyBinomial(src->orgname->data);
- break;
+ onp->data= copyBinomial(src->orgname->data);
+ break;
case 2 : /* virus */
- onp->data= (src->orgname->data != NULL)? StringSave(src->orgname->data) : NULL;
- break;
+ onp->data= (src->orgname->data != NULL)? StringSave(src->orgname->data) : NULL;
+ break;
case 5 : /* partial */
- onp->data= copyPartial(src->orgname->data);
- break;
+ onp->data= copyPartial(src->orgname->data);
+ break;
default : /* can't handle */
- onp->data= NULL;
+ onp->data= NULL;
}
if(onp->mod == NULL) onp->mod= copyOrgMod(src->orgname->mod);
+ else {
+ mergeOrgMod(onp->mod, src->orgname->mod);
+ }
onp->lineage= (src->orgname->lineage != NULL)? StringSave(src->orgname->lineage) : NULL;
onp->gcode= src->orgname->gcode;
onp->mgcode= src->orgname->mgcode;
@@ -1466,26 +1652,26 @@ static void populateReplaced(OrgRefPtr orp, CharPtr oldName)
OrgModPtr omp;
if((orp->taxname != NULL) && (StringICmp(orp->taxname, oldName) == 0)) {
- MemFree(oldName);
- return;
+ MemFree(oldName);
+ return;
}
if((orp->common != NULL) && (StringICmp(orp->common, oldName) == 0)) {
- MemFree(oldName);
- return;
+ MemFree(oldName);
+ return;
}
/* organism name was changed */
onp= orp->orgname;
if(onp != NULL) {
- omp= OrgModNew();
- omp->next= onp->mod;
- omp->subtype= 254;
- omp->subname= oldName;
- onp->mod= omp;
+ omp= OrgModNew();
+ omp->next= onp->mod;
+ omp->subtype= 254;
+ omp->subname= oldName;
+ onp->mod= omp;
}
else {
- MemFree(oldName);
+ MemFree(oldName);
}
}
@@ -1512,59 +1698,59 @@ Taxon2DataPtr tax1m_lookup(OrgRefPtr inp_orgRef, int merge)
/* populate search name if necessary */
if(inp_orgRef->taxname != NULL) {
- if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->taxname) == 0)) {
- need_search_name= FALSE;
- }
- else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->common) == 0)) {
- need_search_name= FALSE;
- }
+ if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->taxname) == 0)) {
+ need_search_name= FALSE;
+ }
+ else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->common) == 0)) {
+ need_search_name= FALSE;
+ }
}
if(need_search_name && (inp_orgRef->common != NULL)) {
- if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->taxname) == 0)) {
- need_search_name= FALSE;
- }
- else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->common) == 0)) {
- need_search_name= FALSE;
- }
+ if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->taxname) == 0)) {
+ need_search_name= FALSE;
+ }
+ else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->common) == 0)) {
+ need_search_name= FALSE;
+ }
}
if(need_search_name && (inp_orgRef->orgname != NULL)) {
- /* check if search name already exists */
- OrgModPtr omp;
+ /* check if search name already exists */
+ OrgModPtr omp;
- for(omp= inp_orgRef->orgname->mod; omp != NULL; omp= omp->next) {
- if(omp->subtype == 254) {
- need_search_name= FALSE;
- break;
- }
- }
+ for(omp= inp_orgRef->orgname->mod; omp != NULL; omp= omp->next) {
+ if(omp->subtype == 254) {
+ need_search_name= FALSE;
+ break;
+ }
+ }
}
hit_name= NULL;
if(need_search_name) {
- if((inp_orgRef->taxname != NULL) && (inp_orgRef->taxname[0] != '\0')) {
- hit_name= StringSave(inp_orgRef->taxname);
- }
- else if((inp_orgRef->common != NULL) && (inp_orgRef->common[0] != '\0')) {
- hit_name= StringSave(inp_orgRef->common);
- }
+ if((inp_orgRef->taxname != NULL) && (inp_orgRef->taxname[0] != '\0')) {
+ hit_name= StringSave(inp_orgRef->taxname);
+ }
+ else if((inp_orgRef->common != NULL) && (inp_orgRef->common[0] != '\0')) {
+ hit_name= StringSave(inp_orgRef->common);
+ }
}
if(merge) {
- /* we have to merge old orgref with the new one */
- res->org= inp_orgRef;
- /* clean-up old information */
- if(inp_orgRef->taxname != NULL) MemFree(inp_orgRef->taxname);
- if(inp_orgRef->common != NULL) MemFree(inp_orgRef->common);
- if(inp_orgRef->syn != NULL) ValNodeFreeData(inp_orgRef->syn);
- if(inp_orgRef->orgname != NULL) cleanOrgName(tax_id, inp_orgRef->orgname);
+ /* we have to merge old orgref with the new one */
+ res->org= inp_orgRef;
+ /* clean-up old information */
+ if(inp_orgRef->taxname != NULL) MemFree(inp_orgRef->taxname);
+ if(inp_orgRef->common != NULL) MemFree(inp_orgRef->common);
+ if(inp_orgRef->syn != NULL) ValNodeFreeData(inp_orgRef->syn);
+ if(inp_orgRef->orgname != NULL) cleanOrgName(tax_id, inp_orgRef->orgname);
}
else {
- /* make new orgref */
- res->org= OrgRefNew();
- res->org->db= NULL;
- res->org->orgname= NULL;
+ /* make new orgref */
+ res->org= OrgRefNew();
+ res->org->db= NULL;
+ res->org->orgname= NULL;
}
/* fill-up orgref based on db_orgRef */
bldOrgRefOut(res->org, db_orgRef, tax_id);
@@ -1593,59 +1779,59 @@ Taxon1DataPtr tax1_lookup(OrgRefPtr inp_orgRef, int merge)
/* populate search name if necessary */
if(inp_orgRef->taxname != NULL) {
- if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->taxname) == 0)) {
- need_search_name= FALSE;
- }
- else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->common) == 0)) {
- need_search_name= FALSE;
- }
+ if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->taxname) == 0)) {
+ need_search_name= FALSE;
+ }
+ else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->taxname, db_orgRef->common) == 0)) {
+ need_search_name= FALSE;
+ }
}
if(need_search_name && (inp_orgRef->common != NULL)) {
- if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->taxname) == 0)) {
- need_search_name= FALSE;
- }
- else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->common) == 0)) {
- need_search_name= FALSE;
- }
+ if((db_orgRef->taxname != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->taxname) == 0)) {
+ need_search_name= FALSE;
+ }
+ else if((db_orgRef->common != NULL) && (StringICmp(inp_orgRef->common, db_orgRef->common) == 0)) {
+ need_search_name= FALSE;
+ }
}
if(need_search_name && (inp_orgRef->orgname != NULL)) {
- /* check if search name already exists */
- OrgModPtr omp;
+ /* check if search name already exists */
+ OrgModPtr omp;
- for(omp= inp_orgRef->orgname->mod; omp != NULL; omp= omp->next) {
- if(omp->subtype == 254) {
- need_search_name= FALSE;
- break;
- }
- }
+ for(omp= inp_orgRef->orgname->mod; omp != NULL; omp= omp->next) {
+ if(omp->subtype == 254) {
+ need_search_name= FALSE;
+ break;
+ }
+ }
}
hit_name= NULL;
if(need_search_name) {
- if((inp_orgRef->taxname != NULL) && (inp_orgRef->taxname[0] != '\0')) {
- hit_name= StringSave(inp_orgRef->taxname);
- }
- else if((inp_orgRef->common != NULL) && (inp_orgRef->common[0] != '\0')) {
- hit_name= StringSave(inp_orgRef->common);
- }
+ if((inp_orgRef->taxname != NULL) && (inp_orgRef->taxname[0] != '\0')) {
+ hit_name= StringSave(inp_orgRef->taxname);
+ }
+ else if((inp_orgRef->common != NULL) && (inp_orgRef->common[0] != '\0')) {
+ hit_name= StringSave(inp_orgRef->common);
+ }
}
if(merge) {
- /* we have to merge old orgref with the new one */
- res->org= inp_orgRef;
- /* clean-up old information */
- if(inp_orgRef->taxname != NULL) MemFree(inp_orgRef->taxname);
- if(inp_orgRef->common != NULL) MemFree(inp_orgRef->common);
- if(inp_orgRef->syn != NULL) ValNodeFreeData(inp_orgRef->syn);
- if(inp_orgRef->orgname != NULL) cleanOrgName(tax_id, inp_orgRef->orgname);
+ /* we have to merge old orgref with the new one */
+ res->org= inp_orgRef;
+ /* clean-up old information */
+ if(inp_orgRef->taxname != NULL) MemFree(inp_orgRef->taxname);
+ if(inp_orgRef->common != NULL) MemFree(inp_orgRef->common);
+ if(inp_orgRef->syn != NULL) ValNodeFreeData(inp_orgRef->syn);
+ if(inp_orgRef->orgname != NULL) cleanOrgName(tax_id, inp_orgRef->orgname);
}
else {
- /* make new orgref */
- res->org= OrgRefNew();
- res->org->db= NULL;
- res->org->orgname= NULL;
+ /* make new orgref */
+ res->org= OrgRefNew();
+ res->org->db= NULL;
+ res->org->orgname= NULL;
}
/* fill-up orgref based on db_orgRef */
bldOrgRefOut(res->org, db_orgRef, tax_id);
@@ -1680,8 +1866,8 @@ Boolean tax1e_invokeChildren(Int4 tax_id)
TreeCursorPtr cursor= tree_openCursor(tax_tree, NULL, NULL);
if(tax_id < 0) {
- res= TRUE;
- tax_id= -tax_id;
+ res= TRUE;
+ tax_id= -tax_id;
}
if((cursor == NULL) || (!tc2_toNode(cursor, tax_id))) return FALSE;
@@ -1729,100 +1915,100 @@ Int4 tax1_getTaxId4Str(CharPtr str, CharPtr* substring, Int4Ptr *Ids_out)
tax_id= tax1_getTaxIdByName(str);
if(tax_id > 1) {
- *Ids_out= MemNew(sizeof(Int4));
- **Ids_out= tax_id;
- *substring= StringSave(str);
- return 1;
+ *Ids_out= MemNew(sizeof(Int4));
+ **Ids_out= tax_id;
+ *substring= StringSave(str);
+ return 1;
}
else if(tax_id < 0) {
- *substring= StringSave(str);
- return tax1_getAllTaxIdByName(str, Ids_out);
+ *substring= StringSave(str);
+ return tax1_getAllTaxIdByName(str, Ids_out);
}
/* whole string matches nothing */
/* try the whole string inside first set of parenthesis */
for(b= str; *b != '\0'; b++) {
- if(*b == '(') {
- k= 0;
- for(e= b+1; *e != '\0'; e++) {
- if(*e == '(') {
- k++;
- continue;
- }
- if(*e == ')') {
- if(k > 0) {
- k--;
- continue;
- }
-
- *e= '\0';
- tax_id= tax1_getTaxIdByName(b+1);
-
- if(tax_id > 1) {
- *substring= StringSave(b+1);
- *e= ')';
- *Ids_out= MemNew(sizeof(Int4));
- **Ids_out= tax_id;
- return 1;
- }
- else if(tax_id < 0) {
- *substring= StringSave(b+1);
- *e= ')';
- return tax1_getAllTaxIdByName(*substring, Ids_out);
- }
-
- /* whole string won't help lets try truncate it at first comma*/
- *e= ')';
- for(e= b+1; *e != '\0'; e++) {
- if(*e == ',') {
- *e= '\0';
- tax_id= tax1_getTaxIdByName(b+1);
-
- if(tax_id > 1) {
- *substring= StringSave(b+1);
- *e= ',';
- *Ids_out= MemNew(sizeof(Int4));
- **Ids_out= tax_id;
- return 1;
- }
- else if(tax_id < 0) {
- *substring= StringSave(b+1);
- *e= ',';
- return tax1_getAllTaxIdByName(*substring, Ids_out);
- }
- *e= ',';
- break;
- }
- }
- break;
- }
- }
- break;
- }
+ if(*b == '(') {
+ k= 0;
+ for(e= b+1; *e != '\0'; e++) {
+ if(*e == '(') {
+ k++;
+ continue;
+ }
+ if(*e == ')') {
+ if(k > 0) {
+ k--;
+ continue;
+ }
+
+ *e= '\0';
+ tax_id= tax1_getTaxIdByName(b+1);
+
+ if(tax_id > 1) {
+ *substring= StringSave(b+1);
+ *e= ')';
+ *Ids_out= MemNew(sizeof(Int4));
+ **Ids_out= tax_id;
+ return 1;
+ }
+ else if(tax_id < 0) {
+ *substring= StringSave(b+1);
+ *e= ')';
+ return tax1_getAllTaxIdByName(*substring, Ids_out);
+ }
+
+ /* whole string won't help lets try truncate it at first comma*/
+ *e= ')';
+ for(e= b+1; *e != '\0'; e++) {
+ if(*e == ',') {
+ *e= '\0';
+ tax_id= tax1_getTaxIdByName(b+1);
+
+ if(tax_id > 1) {
+ *substring= StringSave(b+1);
+ *e= ',';
+ *Ids_out= MemNew(sizeof(Int4));
+ **Ids_out= tax_id;
+ return 1;
+ }
+ else if(tax_id < 0) {
+ *substring= StringSave(b+1);
+ *e= ',';
+ return tax1_getAllTaxIdByName(*substring, Ids_out);
+ }
+ *e= ',';
+ break;
+ }
+ }
+ break;
+ }
+ }
+ break;
+ }
}
/* we still have got nothing */
/* try the substring before first '(' */
if(*b == '(') {
- /* we are staying on the first '(' */
- *b= '\0';
+ /* we are staying on the first '(' */
+ *b= '\0';
- tax_id= tax1_getTaxIdByName(str);
-
- if(tax_id > 1) {
- *Ids_out= MemNew(sizeof(Int4));
- **Ids_out= tax_id;
- *substring= StringSave(str);
- *b= '(';
- return 1;
- }
- else if(tax_id < 0) {
- *substring= StringSave(str);
- *b= '(';
- return tax1_getAllTaxIdByName(*substring, Ids_out);
- }
- *b= '(';
+ tax_id= tax1_getTaxIdByName(str);
+
+ if(tax_id > 1) {
+ *Ids_out= MemNew(sizeof(Int4));
+ **Ids_out= tax_id;
+ *substring= StringSave(str);
+ *b= '(';
+ return 1;
+ }
+ else if(tax_id < 0) {
+ *substring= StringSave(str);
+ *b= '(';
+ return tax1_getAllTaxIdByName(*substring, Ids_out);
+ }
+ *b= '(';
}
b= StringStr(str, "Organism");
@@ -1830,46 +2016,46 @@ Int4 tax1_getTaxId4Str(CharPtr str, CharPtr* substring, Int4Ptr *Ids_out)
if(b == NULL) b= StringStr(str, "ORGANISM");
if(b != NULL) {
- e= StringChr(b, ':');
- if(e != NULL) {
- b= e+1;
- tax_id= tax1_getTaxIdByName(b);
-
- if(tax_id > 1) {
- *Ids_out= MemNew(sizeof(Int4));
- **Ids_out= tax_id;
- *substring= StringSave(b);
- return 1;
- }
- else if(tax_id < 0) {
- *substring= StringSave(b);
- return tax1_getAllTaxIdByName(*substring, Ids_out);
- }
+ e= StringChr(b, ':');
+ if(e != NULL) {
+ b= e+1;
+ tax_id= tax1_getTaxIdByName(b);
+
+ if(tax_id > 1) {
+ *Ids_out= MemNew(sizeof(Int4));
+ **Ids_out= tax_id;
+ *substring= StringSave(b);
+ return 1;
+ }
+ else if(tax_id < 0) {
+ *substring= StringSave(b);
+ return tax1_getAllTaxIdByName(*substring, Ids_out);
+ }
- /* if multiple lines or ; , ( */
- for(++e; *e != '\0'; e++) {
- if((*e == '\n') || (*e == ';') || (*e == ',') || (*e == '(')) {
- c= *e;
- *e= '\0';
- tax_id= tax1_getTaxIdByName(b);
-
- if(tax_id > 1) {
- *substring= StringSave(b);
- *e= c;
- *Ids_out= MemNew(sizeof(Int4));
- **Ids_out= tax_id;
- return 1;
- }
- else if(tax_id < 0) {
- *substring= StringSave(b);
- *e= c;
- return tax1_getAllTaxIdByName(*substring, Ids_out);
- }
- *e= c;
- break;
- }
- }
- }
+ /* if multiple lines or ; , ( */
+ for(++e; *e != '\0'; e++) {
+ if((*e == '\n') || (*e == ';') || (*e == ',') || (*e == '(')) {
+ c= *e;
+ *e= '\0';
+ tax_id= tax1_getTaxIdByName(b);
+
+ if(tax_id > 1) {
+ *substring= StringSave(b);
+ *e= c;
+ *Ids_out= MemNew(sizeof(Int4));
+ **Ids_out= tax_id;
+ return 1;
+ }
+ else if(tax_id < 0) {
+ *substring= StringSave(b);
+ *e= c;
+ return tax1_getAllTaxIdByName(*substring, Ids_out);
+ }
+ *e= c;
+ break;
+ }
+ }
+ }
}
return 0;
}
@@ -1889,11 +2075,11 @@ static Int4 storedTaxId(OrgRefPtr orp)
ObjectIdPtr object_id;
for(vnp= orp->db; vnp != NULL; vnp= vnp->next) {
- dbtag= vnp->data.ptrvalue;
- if((dbtag != NULL) && (StringCmp(dbtag->db, "taxon") == 0)) {
- ObjectIdPtr object_id= dbtag->tag;
- return object_id->id;
- }
+ dbtag= vnp->data.ptrvalue;
+ if((dbtag != NULL) && (StringCmp(dbtag->db, "taxon") == 0)) {
+ ObjectIdPtr object_id= dbtag->tag;
+ return object_id->id;
+ }
}
return 0;
@@ -1908,15 +2094,15 @@ static Int4 OrgModCmp(OrgModPtr omp1, OrgModPtr omp2)
if(omp1 == NULL) return 100;
for(;omp2 != NULL; omp2= omp2->next) {
- found= 0;
- for(omp= omp1; omp != NULL; omp= omp->next) {
- if((omp2->subtype == omp->subtype) &&
- (nameCmp(omp2->subname, omp->subname) == 0)) {
- found= 1;
- break;
- }
- }
- if(!found) return 100;
+ found= 0;
+ for(omp= omp1; omp != NULL; omp= omp->next) {
+ if((omp2->subtype == omp->subtype) &&
+ (nameCmp(omp2->subname, omp->subname) == 0)) {
+ found= 1;
+ break;
+ }
+ }
+ if(!found) return 100;
}
return 0;
}
@@ -1962,7 +2148,7 @@ Int4 tax1e_needUpdate(OrgRefPtr inp_orgRef)
db_orgRef= s_tax1_getOrgRef(tax_id, NULL, NULL, NULL /*res->embl_code*/);
if(db_orgRef == NULL) {
- return -2;
+ return -2;
}
return OrgRefCmp(inp_orgRef, db_orgRef);
@@ -1997,16 +2183,16 @@ CharPtr tax1m_getBlastName(Int4 tax_id)
TreeCursorPtr cursor= tree_openCursor(tax_tree, NULL, NULL);
if(tc2_toNode(cursor, tax_id)) {
- TXC_TreeNodePtr tnp;
- Uint2 s;
- do{
- tnp= tree_getNodeData(cursor, &s);
- if((tnp != NULL) && ((tnp->flags & TXC_STHIDE) == 0)) { /* we do have a blast name here */
- res= tnp->node_label + (StringLen(tnp->node_label) + 1);
- break;
- }
- }
- while(tree_parent(cursor));
+ TXC_TreeNodePtr tnp;
+ Uint2 s;
+ do{
+ tnp= tree_getNodeData(cursor, &s);
+ if((tnp != NULL) && ((tnp->flags & TXC_STHIDE) == 0)) { /* we do have a blast name here */
+ res= tnp->node_label + (StringLen(tnp->node_label) + 1);
+ break;
+ }
+ }
+ while(tree_parent(cursor));
}
tree_closeCursor(cursor);