summaryrefslogtreecommitdiff
path: root/network/taxon1/taxon2/tc2proc.c
diff options
context:
space:
mode:
authorAaron M. Ucko <ucko@debian.org>2005-03-23 17:39:07 +0000
committerAaron M. Ucko <ucko@debian.org>2005-03-23 17:39:07 +0000
commita7c5bff619aa4850d09825888b5f46c7cd086f11 (patch)
tree2ab2dd2ff2977a5e0bcfdd90a17ca4f1a73181fc /network/taxon1/taxon2/tc2proc.c
parentbfbecafe8b6142e8356e8447f0822b43e94b64b7 (diff)
Load ncbi (6.1.20010709) into ncbi-tools6/branches/upstream/current.
Diffstat (limited to 'network/taxon1/taxon2/tc2proc.c')
-rw-r--r--network/taxon1/taxon2/tc2proc.c160
1 files changed, 158 insertions, 2 deletions
diff --git a/network/taxon1/taxon2/tc2proc.c b/network/taxon1/taxon2/tc2proc.c
index 63e1f4c9..0a851f2c 100644
--- a/network/taxon1/taxon2/tc2proc.c
+++ b/network/taxon1/taxon2/tc2proc.c
@@ -196,6 +196,43 @@ Int4 tax1_getParent(Int4 id_tax)
return ret_id;
}
+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);
+ }
+
+ tree_closeCursor(cursor);
+ return (ret_id > 1)? ret_id : -1;
+}
+
int tax1_getChildren(Int4 id_tax, Int4** ids_out)
{
int n= 0;
@@ -528,7 +565,7 @@ 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)) {
+ if(unique && (nameList[i].unique_name != NULL) && (nameList[i].unique_name[0] != '\0')) {
names[i]= nameList[i].unique_name;
nameList[i].unique_name= NULL;
}
@@ -839,7 +876,9 @@ static CharPtr bldLineage(TreeCursorPtr cursor)
if((tnp= tree_getNodeData(cursor, &s)) != NULL) {
rank= tnp->flags & 0xFF;
if(rank > SpeciesRank) {
- if(lineage != NULL) MemFree(lineage);
+ if(lineage != NULL) {
+ lineage = MemFree(lineage);
+ }
continue;
}
if(tnp->tax_id < 2) break;
@@ -1102,6 +1141,15 @@ static OrgModPtr fixModifier(Int4 tax_id, OrgModPtr omp)
_subspec src_ss;
_subspecPtr ss= NULL;
+ memset(&src_ss, 0, sizeof(_subspec));
+
+ if(omp->subtype < 2) {
+ omp->next= NULL;
+ OrgModFree(omp);
+ return NULL;
+ }
+
+
if((omp->subname != NULL) && (omp->subtype != 0)) {
src_ss.stype= omp->subtype;
src_ss.sname= omp->subname;
@@ -1640,5 +1688,113 @@ Int4 tax1_getTaxId4Str(CharPtr str, CharPtr* substring, Int4Ptr *Ids_out)
}
return 0;
}
+
+static int nameCmp(CharPtr s1, CharPtr s2)
+{
+ if((s1 == NULL) && (s2 == NULL)) return 0;
+ if((s1 == NULL) || (s2 == NULL)) return 1;
+
+ return strcmp(s1, s2);
+}
+
+static Int4 storedTaxId(OrgRefPtr orp)
+{
+ ValNodePtr vnp;
+ DbtagPtr dbtag;
+ 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;
+ }
+ }
+
+ return 0;
+}
+
+static Int4 OrgModCmp(OrgModPtr omp1, OrgModPtr omp2)
+{
+ OrgModPtr omp;
+ int found;
+
+ if(omp2 == NULL) return 0;
+ 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;
+ }
+ return 0;
+}
+
+static Int4 OrgRefCmp(OrgRefPtr orp1, OrgRefPtr orp2)
+{
+ OrgNamePtr onp1= orp1->orgname;
+ OrgNamePtr onp2= orp2->orgname;
+
+ if(onp1 == NULL) return 4;
+ if(onp2 == NULL) return -2;
+
+ if(onp1->gcode != onp2->gcode) return 2;
+ if(onp1->mgcode != onp2->mgcode) return 3;
+
+ if(nameCmp(orp1->taxname, orp2->taxname) != 0) return 10;
+
+ if(nameCmp(onp1->lineage, onp2->lineage) != 0) return 20;
+
+ if(nameCmp(orp1->common, orp2->common) != 0) return 30;
+
+ if(onp1->choice != onp2->choice) return 40;
+
+ if(nameCmp(onp1->div, onp2->div) != 0) return 50;
+
+ return OrgModCmp(onp1->mod, onp2->mod);
+}
+
+Int4 tax1e_needUpdate(OrgRefPtr inp_orgRef)
+{
+ Taxon1DataPtr res;
+ Int4 tax_id;
+ OrgRefPtr db_orgRef;
+ int is_species;
+ Boolean need_search_name= TRUE;
+ CharPtr hit_name;
+
+ tax_id= tax1_getTaxIdByOrgRef(inp_orgRef);
+ if(tax_id <= 0) return -1;
+
+ if(tax_id != storedTaxId(inp_orgRef)) return 1;
+
+ db_orgRef= tax1_getOrgRef(tax_id, NULL, NULL, NULL /*res->embl_code*/);
+ if(db_orgRef == NULL) {
+ return -2;
+ }
+
+ return OrgRefCmp(inp_orgRef, db_orgRef);
+}
+
+Boolean tax1_isAlive(void)
+{
+ return (tax1_getTaxIdByName("dog") > 1)? TRUE : FALSE;
+}
+/***************************************************
+ * Get tax_id for given gi
+ * returns:
+ * tax_id if found
+ * 0 if no data or error
+ */
+Int4 tax1_getTaxId4GI(Int4 gi)
+{
+ return tax_getTaxId4GI(gi);
+}