def compound_name_match(self, compound): """ Query NP Atlas DB to see if there is a name match Return boolean match """ res = None if compound.name != "Not named": res = atlas_api.search_name(compound.name) return bool(res)
def longest_substring_name_match(self, compound): res = None struct_inchi = compound.inchikey.split("-")[0] if compound.name != "Not named": longest_substring = next( iter(sorted((compound.name.split()), key=len, reverse=True)) ) comps = atlas_api.search_name(longest_substring) res = any(struct_inchi in c.get("inchikey", "") for c in comps) return bool(res)
def get_npa_compounds(compound): compounds = [] if compound.npaid: res = atlas_api.get_compound(compound.npaid) if res: compounds.append( NPACompound( res.get("id"), res.get("original_name"), atlas_api.get_compound_molblock(compound.npaid), res.get("inchikey"), ) ) struct_res = atlas_api.search_inchikey(compound.inchikey.split("-")[0]) for r in struct_res: id_ = r.get("npaid") if id_ not in [x.npaid for x in compounds]: compounds.append( NPACompound( id_, r.get("original_name"), atlas_api.get_compound_molblock(id_), r.get("inchikey"), ) ) if compound.name != "Not named": name_res = atlas_api.search_name(compound.name) for r in name_res: id_ = r.get("npaid") if id_ not in [x.npaid for x in compounds]: compounds.append( NPACompound( id_, r.get("original_name"), atlas_api.get_compound_molblock(id_), r.get("inchikey"), ) ) return compounds
def test_search_name_bad(): name = "Not named!" res = atlas_api.search_name(name) assert len(res) == 0
def test_search_name(): name = "Not named" res = atlas_api.search_name(name) assert len(res) > 0