def _add_node(chebi_id, chebi_ids, rels, chem_manager): '''Constructs a node from libChEBI.''' if chebi_id not in chebi_ids: chebi_ids.append(chebi_id) chem_id, entity = chem_manager.add_chemical({'chebi': chebi_id}) for incoming in entity.get_incomings(): target_id = incoming.get_target_chebi_id() chebi_ent = ChebiEntity(target_id) if chebi_ent.get_parent_id(): target_id = chebi_ent.get_parent_id() _add_node(target_id, chebi_ids, rels, chem_manager) rels.append([target_id, incoming.get_type(), chem_id])
def _add_node(chebi_id, chebi_ids, rels, chem_manager): '''Constructs a node from libChEBI.''' if chebi_id not in chebi_ids: chebi_ids.append(chebi_id) chem_id, entity = chem_manager.add_chemical({'chebi': chebi_id}) for incoming in entity.get_incomings(): target_id = incoming.get_target_chebi_id() chebi_ent = ChebiEntity(target_id) if chebi_ent.get_parent_id(): target_id = chebi_ent.get_parent_id() _add_node(target_id, chebi_ids, rels, chem_manager) rels.append([target_id, incoming.get_type(), chem_id])
def _get_chebi_data(chebi_id, properties): '''Gets ChEBI data.''' chebi_ent = ChebiEntity(str(chebi_id)) if chebi_ent.get_parent_id(): chebi_id = chebi_ent.get_parent_id() else: chebi_id = chebi_ent.get_id() properties['chebi'] = chebi_id formula = chebi_ent.get_formula() charge = chebi_ent.get_charge() inchi = chebi_ent.get_inchi() smiles = chebi_ent.get_smiles() if formula: properties['formula'] = formula if not math.isnan(charge): properties['charge'] = charge if inchi: properties['inchi'] = inchi if smiles: properties['smiles'] = smiles properties['name'] = chebi_ent.get_name() properties['names:string[]'] = \ [name.get_name() for name in chebi_ent.get_names()] + \ [chebi_ent.get_name()] for db_acc in chebi_ent.get_database_accessions(): namespace = ns_utils.resolve_namespace( db_acc.get_type(), True) if namespace is not None: properties[namespace] = db_acc.get_accession_number() return chebi_id, chebi_ent
def _get_chebi_data(chebi_id, properties, array_delimiter): '''Gets ChEBI data.''' chebi_ent = ChebiEntity(str(chebi_id)) if chebi_ent.get_parent_id(): chebi_id = chebi_ent.get_parent_id() else: chebi_id = chebi_ent.get_id() properties['chebi'] = chebi_id formula = chebi_ent.get_formula() charge = chebi_ent.get_charge() inchi = chebi_ent.get_inchi() smiles = chebi_ent.get_smiles() if formula: properties['formula'] = formula if not math.isnan(charge): properties['charge:float'] = charge if inchi: properties['inchi'] = inchi if smiles: properties['smiles'] = smiles properties['name'] = chebi_ent.get_name() properties['names:string[]'] = \ array_delimiter.join([name.get_name() for name in chebi_ent.get_names()] + [chebi_ent.get_name()]) for db_acc in chebi_ent.get_database_accessions(): namespace = ns_utils.resolve_namespace(db_acc.get_type(), True) if namespace is not None: properties[namespace] = db_acc.get_accession_number() return chebi_id, chebi_ent