Skip to content

Commit b2e7692

Browse files
committed
dev(WoRMS): add info for deprecated taxon & lineage
1 parent 225b5df commit b2e7692

File tree

4 files changed

+56
-120
lines changed

4 files changed

+56
-120
lines changed

py/API_models/taxonomy.py

Lines changed: 16 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
class TaxaSearchRsp(BaseModel):
1616
id: int = Field(title="Id", description="The taxon/category IDs.", example=14334)
17+
status: str = Field(
18+
title="Status",
19+
description="The taxon/category status, 'D' for Deprecated, 'A' for Approved or 'N' for Not approved.",
20+
example="P",
21+
)
1722
aphia_id: Optional[int] = Field(
1823
title="Aphia Id",
1924
description="The Worms aphia_id of the taxon.",
@@ -33,73 +38,8 @@ class TaxaSearchRsp(BaseModel):
3338
title="Pr",
3439
description="1 if the taxon is in project list, 0 otherwise.",
3540
example=0,
36-
)# TODO: dataclass_to_model(TaxonBO) to avoid repeated fields
37-
class TaxonModel_small(BaseModel):
38-
__config__ = OrmConfig
39-
id: int = Field(title="Id", description="The taxon/category IDs.", example=1)
40-
renm_id: Optional[int] = Field(
41-
title="Renm id",
42-
description="The advised replacement ID if the taxon/category is deprecated.",
43-
default=None,
44-
example="null",
45-
)
46-
name: str = Field(
47-
title="Name", description="The taxon/category verbatim name.", example="living"
48-
)
49-
type: str = Field(
50-
title="Type",
51-
description="The taxon/category type, 'M' for Morpho or 'P' for Phylo.",
52-
example="P",
53-
)
54-
status: str = Field(
55-
title="Status",
56-
description="The taxon/category status, 'D' for Deprecated, 'A' for Approved or 'N' for Notapproved.",
57-
example="P",
58-
)
59-
nb_objects: int = Field(
60-
title="Nb objects",
61-
description="How many objects are classified in this category.",
62-
example=34118,
63-
)
64-
nb_children_objects: int = Field(
65-
title="Nb children objects",
66-
description="How many objects are classified in this category children (not itself).",
67-
example=30091727,
68-
)
69-
display_name: str = Field(
70-
title="Display name",
71-
description="The taxon/category display name.",
72-
example="living<",
73-
)
74-
lineage: List[str] = Field(
75-
title="Lineage",
76-
description="The taxon/category name of ancestors, including self, in first.",
77-
example=["living"],
78-
)
79-
id_lineage: List[int] = Field(
80-
title="Id lineage",
81-
description="The taxon/category IDs of ancestors, including self, in first.",
82-
example=[1],
83-
)
84-
children: List[int] = Field(
85-
title="Children",
86-
description="The taxon/category IDs of children.",
87-
example=[
88-
92952,
89-
2,
90-
92329,
91-
85048,
92-
4,
93-
93599,
94-
93687,
95-
85011,
96-
92951,
97-
93698,
98-
84961,
99-
92696,
100-
3,
101-
],
102-
)
41+
) # TODO: dataclass_to_model(TaxonBO) to avoid repeated fields
42+
10343

10444
# TODO: dataclass_to_model(TaxonBO) to avoid repeated fields
10545
class TaxonModel(BaseModel):
@@ -131,7 +71,13 @@ class TaxonModel(BaseModel):
13171
id_lineage: List[int] = Field(
13272
title="Id lineage",
13373
description="The taxon/category IDs of ancestors, including self, in first.",
134-
example=[1], )
74+
example=[1],
75+
)
76+
lineage_status: str = Field(
77+
title="Id lineage",
78+
description="The taxon ancestors' status, including self, in first.",
79+
example="DDAAA",
80+
)
13581
renm_id: Optional[int] = Field(
13682
title="Renm id",
13783
description="The advised replacement ID if the taxon/category is deprecated.",
@@ -210,35 +156,12 @@ class TaxonomyTreeStatus(BaseModel):
210156
)
211157

212158

213-
class TaxoWormsModel(BaseModel):
159+
class AddWormsTaxonModel(BaseModel):
214160
aphia_id: Optional[int] = Field(
215161
title="AphiaId",
216-
description="The unique numeric aphia_id of the taxon if in Worms.",
162+
description="The unique numeric aphia_id of the taxon in WoRMS.",
217163
example=12876,
218164
)
219-
rank: Optional[str] = Field(
220-
title="Rank",
221-
description="The rank in Worms of the taxon.",
222-
example="Echinodermata X",
223-
)
224-
name: str = Field(
225-
title="Name", description="The name of the taxon.", example="Echinodermata X"
226-
)
227-
lineage: Dict[str, Any] = Field(
228-
title="Taxon Worms lineage",
229-
description="The lineage of the taxon in Worms.",
230-
example={"2": {"AphiaID": 1, "rank": "Superdomain", "scientificname": "Biota"}},
231-
)
232-
status: str = Field(
233-
title="Worms taxon status",
234-
description="The taxon status in worms 'accepted' .",
235-
example="accepted",
236-
)
237-
creator_email: Any = Field(
238-
title="Creator email",
239-
description="Email of the creator of the taxon.",
240-
example="creator.user@emaim.com",
241-
)
242165

243166

244167
class _Taxo2Model(BaseModel):

py/API_operations/TaxonomyService.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ def search(
9292
renm_id = a_rec["rename_to"]
9393
is_preset = 1 if classif_id in preset else 0
9494
to_add = TaxaSearchRsp(
95-
id=classif_id, renm_id=renm_id, text=a_rec["display_name"], pr=is_preset
95+
id=classif_id,
96+
aphia_id=a_rec["aphia_id"],
97+
status=a_rec["taxostatus"],
98+
renm_id=renm_id,
99+
text=a_rec["display_name"],
100+
pr=is_preset,
96101
)
97102
if classif_id in return_order:
98103
mru_ret.append(to_add)

py/BO/Taxonomy.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
logger = get_logger(__name__)
3232

33+
3334
class TaxonBO(object):
3435
"""
3536
Holder of a node of a taxonomy tree. Used for Unieuk tree and for WoRMS one.
@@ -43,6 +44,7 @@ class TaxonBO(object):
4344
"display_name",
4445
"lineage",
4546
"id_lineage",
47+
"lineage_status",
4648
"renm_id",
4749
"nb_objects",
4850
"nb_children_objects",
@@ -62,10 +64,11 @@ def __init__(
6264
nb_children_objects: int,
6365
lineage: List[str],
6466
id_lineage: List[ClassifIDT],
65-
aphia_id:Optional[int]=None,
66-
rank:Optional[str]=None,
67-
closest_worms:Optional[int]=None,
68-
closest_phylo:Optional[int]=None,
67+
lineage_status: str,
68+
aphia_id: Optional[int] = None,
69+
rank: Optional[str] = None,
70+
closest_worms: Optional[int] = None,
71+
closest_phylo: Optional[int] = None,
6972
children: Optional[List[ClassifIDT]] = None,
7073
rename_id: Optional[int] = None,
7174
):
@@ -87,10 +90,11 @@ def __init__(
8790
self.display_name = display_name
8891
self.lineage = lineage
8992
self.id_lineage = id_lineage
90-
self.aphia_id=aphia_id
91-
self.rank=rank
92-
self.closest_worms=closest_worms
93-
self.closest_phylo=closest_phylo
93+
self.lineage_status = lineage_status
94+
self.aphia_id = aphia_id
95+
self.rank = rank
96+
self.closest_worms = closest_worms
97+
self.closest_phylo = closest_phylo
9498
self.children = children
9599

96100
def top_down_lineage(self, sep: str = ">"):
@@ -117,9 +121,7 @@ def keep_phylo(session: Session, classif_id_seen: ClassifIDListT):
117121
Return input IDs, for the existing ones with 'P' type.
118122
"""
119123
sql = text(
120-
"SELECT id "
121-
" FROM taxonomy "
122-
" WHERE id = ANY (:een) AND taxotype = 'P'"
124+
"SELECT id " " FROM taxonomy " " WHERE id = ANY (:een) AND taxotype = 'P'"
123125
)
124126
res: Result = session.execute(sql, {"een": list(classif_id_seen)})
125127
return {an_id for an_id, in res}
@@ -266,6 +268,7 @@ def query(
266268
tf.c.aphia_id,
267269
tf.c.rename_to,
268270
tf.c.display_name,
271+
tf.c.taxostatus,
269272
priority,
270273
],
271274
bind=bind,
@@ -494,6 +497,8 @@ def do_deletes(cls, session: Session, to_delete: List[ClassifIDT]) -> None:
494497
session.delete(taxon)
495498
finally:
496499
session.execute(text("alter table taxonomy enable trigger all"))
500+
501+
497502
class TaxonBOSet(object):
498503
"""
499504
Many taxa.
@@ -548,22 +553,25 @@ def __init__(self, session: Session, taxon_ids: ClassifIDListT):
548553
cat_type = lst_rec[3]
549554
cat_status = lst_rec[4]
550555
rename_id = lst_rec[6]
551-
aphia_id : Optional[int] = lst_rec[2]
552-
rank : Optional[str] = lst_rec[5]
556+
aphia_id: Optional[int] = lst_rec[2]
557+
rank: Optional[str] = lst_rec[5]
553558
numf = 7
554559
lineage_id = [an_id for an_id in lst_rec[0::numf] if an_id is not None]
560+
lineage_status = "".join(
561+
[a_status for a_status in lst_rec[4::numf] if a_status is not None]
562+
)
555563
lineage = [name for name in lst_rec[1::numf] if name is not None]
556-
closest_phylo:Optional[int]=None
557-
closest_worms:Optional[int]=None
558-
if cat_type=="M":
559-
next=[i for i,r in enumerate(lst_rec[3::numf]) if r=="P"]
564+
closest_phylo: Optional[int] = None
565+
if cat_type == "M":
566+
next = [i for i, r in enumerate(lst_rec[3::numf]) if r == "P"]
560567
if len(next):
561-
i=next[0]
562-
closest_phylo=lst_rec[0::numf][i]
563-
next=[i for i,r in enumerate(lst_rec[2::numf]) if r is not None]
568+
i = next[0]
569+
closest_phylo = lst_rec[0::numf][i]
570+
closest_worms: Optional[int] = None
571+
next = [i for i, r in enumerate(lst_rec[2::numf]) if r is not None]
564572
if len(next):
565-
i=next[0]
566-
closest_worms=lst_rec[0::numf][i]
573+
i = next[0]
574+
closest_worms = lst_rec[0::numf][i]
567575
# assert lineage_id[-1] in (1, 84960, 84959), "Unexpected root %s" % str(lineage_id[-1])
568576
self.taxa.append(
569577
TaxonBO(
@@ -574,11 +582,12 @@ def __init__(self, session: Session, taxon_ids: ClassifIDListT):
574582
nbobj2, # type:ignore
575583
lineage,
576584
lineage_id, # type:ignore
585+
lineage_status,
577586
rename_id=rename_id,
578587
aphia_id=aphia_id,
579588
rank=rank,
580589
closest_worms=closest_worms,
581-
closest_phylo=closest_phylo
590+
closest_phylo=closest_phylo,
582591
)
583592
)
584593
self.get_children(session)
@@ -603,7 +612,6 @@ def get_cardinalities(self, session: Session):
603612
for an_id, a_sum in qry:
604613
bos_per_id[an_id].nb_objects = a_sum
605614

606-
607615
def as_list(self) -> List[TaxonBO]:
608616
return self.taxa
609617

py/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
TaxonomyTreeStatus,
9797
TaxonUsageModel,
9898
TaxonCentral,
99-
TaxoWormsModel,
99+
AddWormsTaxonModel,
100100
)
101101
from API_operations.CRUD.Collections import CollectionsService
102102
from API_operations.CRUD.Constants import ConstantsService
@@ -187,7 +187,7 @@
187187

188188
app = FastAPI(
189189
title="EcoTaxa",
190-
version="0.0.41",
190+
version="0.0.42",
191191
# openapi URL as seen from navigator, this is included when /docs is required
192192
# which serves swagger-ui JS app. Stay in /api sub-path.
193193
openapi_url="/api/openapi.json",

0 commit comments

Comments
 (0)