From 356a685ccba8807d77a85b6e29747ad083824011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20R=C3=A9da?= Date: Mon, 28 Oct 2024 14:36:09 +0000 Subject: [PATCH] fix exceeded number of requests to CLUE --- src/NORDic/NORDic_NI/functions.py | 6 ++++-- src/NORDic/UTILS/utils_data.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/NORDic/NORDic_NI/functions.py b/src/NORDic/NORDic_NI/functions.py index a7f6197..238a016 100644 --- a/src/NORDic/NORDic_NI/functions.py +++ b/src/NORDic/NORDic_NI/functions.py @@ -85,7 +85,7 @@ def network_identification(file_folder, taxon_id, path_to_genes=None, disgenet_a return solution -def solution_generation(file_folder, taxon_id, path_to_genes=None, disgenet_args=None, network_fname=None, string_args=None, experiments_fname=None, lincs_args=None, edge_args=None, sig_args=None, bonesis_args=None, weights=None, seed=0, njobs=1, force_experiments=True, accept_nonRNA=False,preserve_network_sign=True): +def solution_generation(file_folder, taxon_id, path_to_genes=None, disgenet_args=None, network_fname=None, string_args=None, experiments_fname=None, lincs_args=None, edge_args=None, sig_args=None, bonesis_args=None, weights=None, seed=0, njobs=1, force_experiments=True, accept_nonRNA=False,preserve_network_sign=True, pause_time=0.3): ''' Generates or retrieves the optimal network model @@ -123,6 +123,8 @@ def solution_generation(file_folder, taxon_id, path_to_genes=None, disgenet_args [default=True] : if set to True, returns an error if no experimental profile associated with the genes is found accept_nonRNA : Python bool [default=False] : if set to False, ignores gene names which cannot be converted to EntrezIDs or which are not present in LINCS L1000 + pause_time : Python float + [default=0.3] : pause between requests to the CLUE.io API Returns ---------- @@ -292,7 +294,7 @@ def solution_generation(file_folder, taxon_id, path_to_genes=None, disgenet_args symbols_fname=file_folder+"SYMBOLS.csv" if (not os.path.exists(symbols_fname)): user_key = get_user_key(lincs_args["credentials"]) - pert_df = convert_EntrezGene_LINCSL1000(file_folder, list(probes["Gene ID"]), user_key) + pert_df = convert_EntrezGene_LINCSL1000(file_folder, list(probes["Gene ID"]), user_key, pause_time=pause_time) pert_df.to_csv(symbols_fname) pert_df = pd.read_csv(symbols_fname, index_col=0) diff --git a/src/NORDic/UTILS/utils_data.py b/src/NORDic/UTILS/utils_data.py index 425c95e..c585094 100755 --- a/src/NORDic/UTILS/utils_data.py +++ b/src/NORDic/UTILS/utils_data.py @@ -137,7 +137,7 @@ def convert_genes_EntrezGene(gene_list, taxon_id, app_name, chunksize=100, missi print("%d probes (successful %d, unsuccessful %d)" % (len(probes), len(probes.loc[probes["Gene ID"]!='-']), len(probes.loc[probes["Gene ID"]=="-"]))) return probes -def convert_EntrezGene_LINCSL1000(file_folder, EntrezGenes, user_key, quiet=False): +def convert_EntrezGene_LINCSL1000(file_folder, EntrezGenes, user_key, pause_time=3.7, quiet=False): ''' Converts EntrezIDs to Gene Symbols present in LINCS L1000 @@ -180,7 +180,7 @@ def convert_EntrezGene_LINCSL1000(file_folder, EntrezGenes, user_key, quiet=Fals for entrezid in all_entrezid: params = {"where":{"entrez_id": str(entrezid)},"fields":["gene_symbol"]} request_url = build_url(endpoint, method, params, user_key=user_key) - data = post_request(request_url, quiet=True, pause_time=0.3) + data = post_request(request_url, quiet=True, pause_time=pause_time) if (len(data)==0): continue else: