From 7d089d58d9e62fba6d61f17f93148054cf7e6730 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 18 Aug 2022 23:36:56 +0300 Subject: bulk fetch n number of traits type probeset --- wqflask/wqflask/correlation/rust_correlation.py | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py index 5c22efbf..fc8ab508 100644 --- a/wqflask/wqflask/correlation/rust_correlation.py +++ b/wqflask/wqflask/correlation/rust_correlation.py @@ -15,6 +15,34 @@ from gn3.computations.rust_correlation import parse_tissue_corr_data from gn3.db_utils import database_connector +def query_probes_metadata(dataset, results): + + """query traits metadata in bulk for probeset""" + + with database_connector() as conn: + with conn.cursor() as cursor: + + query = """ + SELECT ProbeSet.Name,ProbeSet.Chr,ProbeSet.Mb, + Symbol,mean,description,additive,LRS,Geno.Chr, Geno.Mb + from Geno, Species,ProbeSet,ProbeSetXRef,ProbeSetFreeze + where ProbeSet.Name in ({}) and + Species.Name = %s and + Geno.Name = ProbeSetXRef.Locus and + Geno.SpeciesId = Species.Id and + ProbeSet.Id=ProbeSetXRef.ProbeSetId and + ProbeSetFreeze.Id = ProbeSetXRef.ProbeSetFreezeId and + ProbeSetFreeze.Name = %s + """.format(", ".join(["%s"] * len(trait_list))) + + cursor.execute(query, + (tuple(trait_list) + + (dataset.group.species,) + (dataset.name,)) + ) + + return cursor.fetchall() + + def chunk_dataset(dataset, steps, name): results = [] -- cgit v1.2.3 From 4b2203ea3510ca13f28cbda3eef19dfe8cde6a0c Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 18 Aug 2022 23:44:13 +0300 Subject: function to fetch metadata --- wqflask/wqflask/correlation/rust_correlation.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py index fc8ab508..c7dc665f 100644 --- a/wqflask/wqflask/correlation/rust_correlation.py +++ b/wqflask/wqflask/correlation/rust_correlation.py @@ -15,8 +15,7 @@ from gn3.computations.rust_correlation import parse_tissue_corr_data from gn3.db_utils import database_connector -def query_probes_metadata(dataset, results): - +def query_probes_metadata(dataset, trait_list): """query traits metadata in bulk for probeset""" with database_connector() as conn: @@ -43,6 +42,26 @@ def query_probes_metadata(dataset, results): return cursor.fetchall() +def get_metadata(dataset, traits): + + return {trait_name: { + "name": trait_name, + "view": True, + "symbol": symbol, + "dataset": dataset.name, + "dataset_name": dataset.shortname, + "mean": mean, + "description": description, + "additive": additive, + "lrs_score": f"{lrs:3.1f}", + "location": f"Chr{probe_chr}: {probe_mb:.6f}", + "lrs_location": f"Chr{chr_score}: {mb:.6f}" + + } for trait_name, probe_chr, probe_mb, symbol, mean, description, + additive, lrs, chr_score, mb + in query_probes_metadata(dataset, traits)} + + def chunk_dataset(dataset, steps, name): results = [] @@ -296,5 +315,6 @@ def compute_correlation_rust( results, top_a, top_b), "this_trait": this_trait.name, "target_dataset": start_vars['corr_dataset'], + "traits_metadata": get_metadata(target_dataset, list(results.keys())), "return_results": n_top } -- cgit v1.2.3 From cbb5d0cc5874cc67cd562e0e7e983d20714d137e Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 18 Aug 2022 23:52:45 +0300 Subject: integrate code for fetching traits metadata --- wqflask/wqflask/correlation/show_corr_results.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index f5fdd9b3..4910b0e0 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -93,8 +93,7 @@ def correlation_json_for_table(correlation_data, this_trait, this_dataset, targe new_traits_metadata = {} - (file_path, dataset_metadata) = fetch_all_cached_metadata( - target_dataset['name']) + dataset_metadata = correlation_data["traits_metadata"] for i, trait_dict in enumerate(corr_results): trait_name = list(trait_dict.keys())[0] @@ -187,10 +186,6 @@ def correlation_json_for_table(correlation_data, this_trait, this_dataset, targe results_list.append(results_dict) - cache_new_traits_metadata(dataset_metadata, - new_traits_metadata, - file_path) - return json.dumps(results_list) -- cgit v1.2.3