Skip to content

Commit

Permalink
Implement strategy for multi-user scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
memgonzales committed Aug 31, 2023
1 parent 42ed086 commit fd4f500
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 12 additions & 2 deletions callbacks/coexpression/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,19 @@ def do_module_enrichment_analysis(implicated_gene_ids, genomic_intervals, addl_g
implicated_genes = set(implicated_gene_ids)
INPUT_GENES_DIR = create_module_enrichment_results_dir(
genomic_intervals, addl_genes, network, algo, parameters)
ENRICHED_MODULES_PATH = f'{INPUT_GENES_DIR}/enriched_modules.tsv'

if not path_exists(f'{INPUT_GENES_DIR}/enriched_modules.tsv'):
if not path_exists(ENRICHED_MODULES_PATH):
ENRICHED_MODULES_PATH_WITH_TIMESTAMP = append_timestamp_to_filename(
ENRICHED_MODULES_PATH)
MODULES_PATH = f'{const.NETWORK_MODULES}/{network}/MSU/{algo}/{parameters}/{algo}-module-list.tsv'

# ====================================================================================
# This replicates the logic of running the universal enrichment function `enricher()`
# provided by clusterProfiler
# ====================================================================================
with open(MODULES_PATH) as modules_file, open(f'{INPUT_GENES_DIR}/enriched_modules.tsv', 'w') as enriched_modules_file:

with open(MODULES_PATH) as modules_file, open(ENRICHED_MODULES_PATH_WITH_TIMESTAMP, 'w') as enriched_modules_file:
modules = []
background_genes = set()
for idx, line in enumerate(modules_file):
Expand Down Expand Up @@ -217,6 +221,12 @@ def do_module_enrichment_analysis(implicated_gene_ids, genomic_intervals, addl_g

enriched_modules_file.write('\n'.join(significant_adj_p_values))

try:
os.replace(ENRICHED_MODULES_PATH_WITH_TIMESTAMP,
ENRICHED_MODULES_PATH)
except:
pass

return fetch_enriched_modules(INPUT_GENES_DIR)


Expand Down
7 changes: 7 additions & 0 deletions callbacks/file_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import regex as re
import os
from .constants import Constants

import time

const = Constants()


Expand Down Expand Up @@ -67,3 +70,7 @@ def get_path_to_temp(genomic_interval, analysis_type, *args):
temp_dir = re.sub(r'/+', '/', temp_dir)

return temp_dir


def append_timestamp_to_filename(filename):
return f'{filename}.{time.time_ns() // 1000}'

0 comments on commit fd4f500

Please sign in to comment.