aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/correlation/pre_computes.py9
-rw-r--r--wqflask/wqflask/correlation/rust_correlation.py19
2 files changed, 12 insertions, 16 deletions
diff --git a/wqflask/wqflask/correlation/pre_computes.py b/wqflask/wqflask/correlation/pre_computes.py
index 2831bd39..720eab09 100644
--- a/wqflask/wqflask/correlation/pre_computes.py
+++ b/wqflask/wqflask/correlation/pre_computes.py
@@ -25,17 +25,16 @@ def cache_trait_metadata(dataset_name, data):
current_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
txn.put(b"creation_date", current_date.encode())
return "success"
-
except lmdb.Error as error:
pass
-def read_trait_metadata(dataset_name):
+def read_trait_metadata(dataset_name,dataset_type):
try:
- with lmdb.open(os.path.join(TMPDIR,f"metadata_{dataset_name}"),
+ with lmdb.open(os.path.join("/tmp/",f"metadata_{dataset_type}"),
readonly=True, lock=False) as env:
with env.begin() as txn:
- db_name = txn.get(dataset_name.encode())
- return (pickle.loads(db_name) if db_name else {})
+ metadata = txn.get(dataset_name.encode())
+ return (pickle.loads(metadata)["data"] if metadata else {})
except lmdb.Error as error:
return {}
diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py
index 41dd77a1..18f8c622 100644
--- a/wqflask/wqflask/correlation/rust_correlation.py
+++ b/wqflask/wqflask/correlation/rust_correlation.py
@@ -64,12 +64,13 @@ def get_metadata(dataset, traits):
def __location__(probe_chr, probe_mb):
if probe_mb:
return f"Chr{probe_chr}: {probe_mb:.6f}"
- return f"Chr{probe_chr}: ???"
- cached_metadata = read_trait_metadata(dataset.name)
- to_fetch_metadata = list(
- set(traits).difference(list(cached_metadata.keys())))
- if to_fetch_metadata:
- results = {**({trait_name: {
+ return f"Chr{probe_chr}: ???"
+
+ cached_metadata = read_trait_metadata(dataset.name,"ProbeSet")
+ if cached_metadata:
+ return {trait:cached_metadata.get(trait) for trait in traits}
+ else:
+ return {**({trait_name: {
"name": trait_name,
"view": True,
"symbol": symbol,
@@ -88,11 +89,7 @@ def get_metadata(dataset, traits):
} for trait_name, probe_chr, probe_mb, symbol, mean, description,
additive, lrs, chr_score, mb
- in query_probes_metadata(dataset, to_fetch_metadata)}), **cached_metadata}
- cache_trait_metadata(dataset.name, results)
- return results
- return cached_metadata
-
+ in query_probes_metadata(dataset, traits)})}
def chunk_dataset(dataset, steps, name):