] #Data dump columns will be ordered according to the order in this list ps_api.process_oql( GOQLtoFindDrugs(TargetIDs, TargetType=TargetType, drugEffect=drugEffect)) if len(ReaxysFields) > 0: FoundDrugs = [ y for x, y in ps_api.Graph.nodes(data=True) if ((ps_api.Graph.out_degree(x) > 0) & (y['ObjTypeName'][0] in ['Small Molecule', 'SmallMol'])) ] print('Found %d drugs in Resnet' % len(FoundDrugs)) ReaxysAPI = RxAPI.Reaxys_API() ReaxysAPI.OpenSession(load_api_config()) foundRxProps = 0 print("Start looking for Reaxys properties") for drug in FoundDrugs: try: inchikeys = drug['InChIKey'] except KeyError: try: RXNIds = drug['Reaxys ID'] except KeyError: continue ReaxysProps = ReaxysAPI.GetCompoundProps(inchikeys, 'IDE.INCHI', ReaxysFields) if len(ReaxysProps) == 0: ReaxysProps = ReaxysAPI.GetCompoundProps( RXNIds, 'IDE.XRN', ReaxysFields)
header=0, index_col=0) concepts_in_file = len(link2concepts) #Script will work faster if you specify what list of object types in your input Entity list entity_types = str(args.entity_types) entity_types = entity_types.replace("Small molecule", 'SmallMol') entity_types = str(entity_types).split(',') if len( args.entity_types) > 0 else [] #If you want to use identifiers other than names enter appropriate Propeprty types into SearchByProperties list #consult with "Resnet Entities&Properties.txt" for the list of available identifier for nodes in the knowledge graph global_start_time = time.time() header_pos = 0 if args.infile_has_header else None search = SemanticSearch(load_api_config()) AnnotateNodesWith = str(args.resnet_retreive_props).split(',') if len( args.resnet_retreive_props) > 0 else [] search.add_ent_props(AnnotateNodesWith) if args.dump_references: search.add_rel_props(['Name', 'Sentence', 'PubYear', 'Title']) if args.use_cache_to_resume: search.load_pandas(None, None, use_cache=True) else: EntityPandas = pd.read_csv(EntityListFile, delimiter='\t', header=header_pos) search.load_pandas(EntityPandas, args.infile_has_header, use_cache=False,
NormalizedCount['#children'] = self.RefCountPandas[self.__temp_id_col__].apply(lambda x: len(x)) NormalizedCount['Final score'] = NormalizedCount['Combined score']/NormalizedCount['#children'] NormalizedCount = NormalizedCount.sort_values(by=['Final score'],ascending=False) NormalizedCount = NormalizedCount.loc[NormalizedCount['Final score'] > 0.0] # removes rows with all zeros # use this filter only if indications linked to GVs are of interest # try: NormalizedCount = NormalizedCount.loc[NormalizedCount[self.__colnameGV__].notna()] # except KeyError: pass return weights.append(NormalizedCount) if __name__ == "__main__": start_time = time.time() DATA_DIR = 'D:/Python/PMI/' APIconfig = load_api_config() rd = TargetIndications(APIconfig) partner_names = ['tetrahydrocannabinol','anandamide'] # if partner_names is empty script will try finding Lgands for Receptor targets and Receptors for Ligand targets partner_class = 'Metabolite ligand' # use it only if partner_names not empty rd.indication_types = ['Disease','Virus'] rd.set_targets(['CNR1'], 'Protein', partner_names=partner_names, partner_class=partner_class,to_inhibit=False, strict_mode=True) # strict mode ranks only indications suggetsed in the literarure without predicting new indications rd.pathway_name_must_include_target = True rd.flush_dump_files() target_indications_ids = rd.find_target_indications() rd.get_pathway_componets() if rd.target_class != 'Ligand': # if target is Ligand use indications4chem_modulators only if its antibody drugs have relations in Resnet
self.set_how2connect(['Regulation'], ['positive'], '') linked_entities_count = self.link2concept(colname, self.similar_drug_ids) print('%d indications %s by %s' % (linked_entities_count, regulated, dcp.similar_drugs)) def fname_prefix(self): indics = ','.join(self.indication_types) rep_pred = 'suggested,predicted ' if self.target_activate_indication else 'suggested ' return rep_pred + indics + ' for ' + self.drug_name if __name__ == "__main__": global_start = time.time() dcp = RepurposeDrug(load_api_config()) drugname = 'THC compounds' targets = ['CNR1', 'CNR2', 'GPR18', 'GPR55', 'GPR119'] similars = [ ] #['Infliximab', 'Etanercept', 'Golimumab', 'Certolizumab', 'Afelimomab'] # for 'Humira'/TNF #similars = ['osimertinib', 'gefitinib', 'brigatinib', 'zalutumumab', 'nimotuzumab', 'matuzumab'] # for 'erlotinib'/'EGFR partner_names = ['tetrahydrocannabinol', 'anandamide'] partner_class = 'Metabolite ligand' dcp.set_drug(drugname, similars, include_children=True, indication_types=['CellProcess']) dcp.set_targets(targets, 'Protein',
import time import pandas as pd import argparse import textwrap from ElsevierAPI import load_api_config from ElsevierAPI.ResnetAPI.FolderContent import FolderContent ps_api = FolderContent(load_api_config()) def map2pathways(entity2folder2pathway: dict, id2pathways: dict, folderName, FilterBy: list, SearchByProperties=None): SearchByProperties = [ 'Name', 'Alias' ] if SearchByProperties is None else SearchByProperties IdtoMembersCollector = dict() for pathway in id2pathways.values(): if pathway['ObjTypeName'][0] == 'Pathway': PathwayName = pathway['Name'][0] PathwayIds = pathway['Id'] IdtoMembersInPathway = ps_api.get_pathway_member_ids( PathwayIds=PathwayIds, only_entities=FilterBy, with_properties=SearchByProperties) for entity_Id in IdtoMembersInPathway.keys(): try: entity2folder2pathway[entity_Id][folderName].append( PathwayName)
''' parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, epilog=textwrap.dedent(instructions)) parser.add_argument('-i', '--infile', type=str, default='') parser.add_argument('-x', '--format', type=str, default='RNEF', choices=['RNEF', 'SBGN']) parser.add_argument('-f', '--folder', type=str, default='') parser.add_argument('-r', '--resume_from', type=str, default='') args = parser.parse_args() api_cofig_file = 'D:/Python/ENTELLECT_API/ElsevierAPI/APIconfig.json' ps_api = FolderContent(load_api_config(api_cofig_file)) if args.infile: urnList = [ u[0] for u in csv.reader(open(args.infile, "r"), delimiter="\t") ] print('Attempting to download %s pathways from %s' % (len(urnList), args.infile)) urnlistfile = args.infile[:len(args.infile) - 4] fout_name = '{urnlist} pathways.rnef'.format(urnlist=urnlistfile) with open('download_by_pathway_urns.log', 'w') as fout: with redirect_stdout(fout): urn2pathway = ps_api.load_containers( ) #works 40 sec - cache result to your application ps_api.urns2rnef(urnList, fout_name, args.format)
def open_api_session(api_config_filename): """This function points at API object.""" config = load_api_config(api_config_filename) api = ElsevierAPI.ResnetAPI.FolderContent.FolderContent(config, False) return api