Skip to content

Commit

Permalink
fix exceeded number of requests to CLUE
Browse files Browse the repository at this point in the history
  • Loading branch information
kuredatan committed Oct 28, 2024
1 parent e057bb5 commit 356a685
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/NORDic/NORDic_NI/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
----------
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/NORDic/UTILS/utils_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 356a685

Please sign in to comment.