def add_mesh_parents(bio_ontology: BioOntology): """Add missing root level nodes to the MeSH ontology.""" for letter, name in mesh_roots_map.items(): bio_ontology.add_node(bio_ontology.label('MESH', letter), name=name) edges_to_add = [] for node in bio_ontology.nodes(): # First deal with subtree root nodes subtree = is_mesh_subroot_node(bio_ontology, node) if subtree is not None: edges_to_add.append(( node, bio_ontology.label('MESH', subtree), {'type': 'isa'} )) db_ns, db_id = bio_ontology.get_ns_id(node) # Then deal with supplementary concepts if db_ns == 'MESH' and db_id.startswith('C') \ and db_id != 'C': # To skip the previously added subroot node edges_to_add.append(( node, bio_ontology.label('MESH', 'S'), {'type': 'isa'} )) bio_ontology.add_edges_from(edges_to_add)
def add_ido_parents(bio_ontology: BioOntology): ido_root = bio_ontology.label('IDO', '0') bio_ontology.add_node(ido_root, name='infectious disease concept') edges_to_add = [] for node in bio_ontology.nodes(): if bio_ontology.get_ns(node) == 'IDO' and not \ bio_ontology.get_parents(*bio_ontology.get_ns_id(node)): edges_to_add.append((node, ido_root, {'type': 'isa'})) bio_ontology.add_edges_from(edges_to_add)
def add_chebi_parents(bio_ontology: BioOntology): """Add missing root level nodes to the ChEBI ontology.""" chebi_root = bio_ontology.label('CHEBI', 'CHEBI:0') bio_ontology.add_node(chebi_root, name='small molecule') edges_to_add = [] for node in {'CHEBI:CHEBI:24431', 'CHEBI:CHEBI:36342', 'CHEBI:CHEBI:50906'}: edges_to_add.append((node, chebi_root, {'type': 'isa'})) bio_ontology.add_edges_from(edges_to_add)