Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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