3030
3131logger = get_logger (__name__ )
3232
33+
3334class 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+
497502class 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
0 commit comments