@@ -709,23 +709,32 @@ def from_obo_path(
709
709
obo = Obo .from_obonet (graph , strict = strict )
710
710
return obo
711
711
712
- @classmethod
713
- def from_obonet (cls , graph : nx .MultiDiGraph , * , strict : bool = True ) -> "Obo" : # noqa:C901
714
- """Get all of the terms from a OBO graph."""
715
- ontology = normalize_prefix (graph .graph ["ontology" ]) # probably always okay
716
- logger .info ("[%s] extracting OBO using obonet" , ontology )
717
-
712
+ @staticmethod
713
+ def _get_name (graph , ontology : str ) -> str :
718
714
try :
719
- date = datetime . strptime ( graph .graph ["date" ], DATE_FORMAT )
715
+ rv = graph .graph ["name" ]
720
716
except KeyError :
721
- logger .info ("[%s] does not report a date" , ontology )
722
- date = None
717
+ logger .info ("[%s] does not report a name" , ontology )
718
+ rv = ontology
719
+ return rv
723
720
721
+ @staticmethod
722
+ def _get_date (graph , ontology : str ) -> Optional [datetime ]:
724
723
try :
725
- name = graph .graph ["name" ]
724
+ rv = datetime . strptime ( graph .graph ["date" ], DATE_FORMAT )
726
725
except KeyError :
727
- logger .info ("[%s] does not report a name" , ontology )
728
- name = ontology
726
+ logger .info ("[%s] does not report a date" , ontology )
727
+ rv = None
728
+ return rv
729
+
730
+ @classmethod
731
+ def from_obonet (cls , graph : nx .MultiDiGraph , * , strict : bool = True ) -> "Obo" :
732
+ """Get all of the terms from a OBO graph."""
733
+ ontology = normalize_prefix (graph .graph ["ontology" ]) # probably always okay
734
+ logger .info ("[%s] extracting OBO using obonet" , ontology )
735
+
736
+ date = cls ._get_date (graph = graph , ontology = ontology )
737
+ name = cls ._get_name (graph = graph , ontology = ontology )
729
738
730
739
data_version = graph .graph .get ("data-version" )
731
740
if not data_version :
@@ -759,9 +768,8 @@ def from_obonet(cls, graph: nx.MultiDiGraph, *, strict: bool = True) -> "Obo":
759
768
(prefix , identifier ): Reference (
760
769
prefix = prefix ,
761
770
identifier = identifier ,
762
- name = data .get (
763
- "name"
764
- ), # if name isn't available, it means its external to this ontology
771
+ # if name isn't available, it means its external to this ontology
772
+ name = data .get ("name" ),
765
773
)
766
774
for prefix , identifier , data in _iter_obo_graph (graph = graph )
767
775
}
0 commit comments