def find_compound_by_unii(self, unii): """ Find compound by a unii """ # slect * is not a good practice rather than * distinct listing is better. id = "UNII:" + unii query = """ select UNII.UNII, UNII.PT, UNII.RN, UNII.NCIT, UNII.PUBCHEM, UNII.INCHIKEY, UNII.SMILES, RXNCONSO.CODE from RXNCONSO join UNII on RXNCONSO.CODE = UNII.UNII where (UNII.UNII = ?) """ cur = connection.execute( query, (unii, )) # in order to make the varible as a tuple of one explicitely. compound = Element(id=id, biolink_class='ChemicalSubstance', identifiers={'unii': unii}, attributes=self.find_compound_attributes(unii), connections=[], source=self.info.name) # TODO issue SQL query and collect results # for each hit (i.e., of the same drug name, an unlikely but possible occurrence) for row in cur.fetchall(): if (row['UNII'] == unii): compound.names_synonyms = [ Names(name=row['PT'], synonyms=[], source=UNIISOURCE) ] # add names & synonyms from the database compound.identifiers = { 'unii': id, 'cas': 'CAS:' + row['RN'], 'ncit': 'NCIT:' + row['NCIT'], 'inchikey': row['INCHIKEY'], 'smiles': row['SMILES'], 'pubchem': 'CID:' + str(row['pubchem']) } return [compound]
def get_or_create_indication(self, row, indications, indication_list): mesh_id = MESH+row['mesh_id'] efo_id = row['efo_id'] if mesh_id is not None and mesh_id in indications: return indications[mesh_id] if efo_id is not None and efo_id in indications: return indications[efo_id] id = mesh_id if mesh_id is not None else efo_id names = Names(name = row['mesh_heading'],synonyms=[],source=SOURCE) indication = Element(id=id, biolink_class=DISEASE,connections=[]) indication.identifiers={'efo':[]} indication.names_synonyms=[names] indication.source = self.info.name if mesh_id is not None: indications[mesh_id] = indication indication.identifiers['mesh'] = mesh_id if efo_id is not None: indications[efo_id] = indication indication_list.append(indication) return indication