diff options
author | Frederick Muriuki Muriithi | 2022-10-05 06:04:52 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-10-05 06:04:52 +0300 |
commit | fb4aa5d0a3a33f980b754cac3e69b8cbd63e3855 (patch) | |
tree | 6a28a1d361c0f8c72b169c4076f3be98ea7d1ef2 /wqflask | |
parent | 6f5f94d2d59f2f558697b455f0e4b732e5e958e3 (diff) | |
download | genenetwork2-fb4aa5d0a3a33f980b754cac3e69b8cbd63e3855.tar.gz |
Bug: Check for compatible datasets for a correlation type
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/correlation/exceptions.py | 12 | ||||
-rw-r--r-- | wqflask/wqflask/correlation/rust_correlation.py | 13 |
2 files changed, 25 insertions, 0 deletions
diff --git a/wqflask/wqflask/correlation/exceptions.py b/wqflask/wqflask/correlation/exceptions.py new file mode 100644 index 00000000..8e9c8516 --- /dev/null +++ b/wqflask/wqflask/correlation/exceptions.py @@ -0,0 +1,12 @@ +"""Correlation-Specific Exceptions""" + +class WrongCorrelationType(Exception): + """Raised when a correlation is requested for incompatible datasets.""" + + def __init__(self, trait, target_dataset, corr_method): + message = ( + f"It is not possible to compute the '{corr_method}' correlations " + f"between trait '{trait.name}' and the data in the " + f"'{target_dataset.fullname}' dataset. " + "Please try again after selecting another type of correlation.") + super().__init__(message) diff --git a/wqflask/wqflask/correlation/rust_correlation.py b/wqflask/wqflask/correlation/rust_correlation.py index 51e24cd9..df030e72 100644 --- a/wqflask/wqflask/correlation/rust_correlation.py +++ b/wqflask/wqflask/correlation/rust_correlation.py @@ -17,6 +17,8 @@ from gn3.computations.rust_correlation import get_sample_corr_data from gn3.computations.rust_correlation import parse_tissue_corr_data from gn3.db_utils import database_connector +from wqflask.correlation.exceptions import WrongCorrelationType + def query_probes_metadata(dataset, trait_list): """query traits metadata in bulk for probeset""" @@ -267,12 +269,20 @@ def __compute_sample_corr__( target_data, list(sample_data.values()), method, ",", corr_type, n_top) +def __datasets_compatible_p__(trait_dataset, target_dataset, corr_method): + return not ( + corr_method in ("tissue", "Tissue r", "Literature r", "lit") + and (trait_dataset.type == "ProbeSet" and + target_dataset.type in ("Publish", "Geno"))) def __compute_tissue_corr__( start_vars: dict, corr_type: str, method: str, n_top: int, target_trait_info: tuple): """Compute the tissue correlations""" (this_dataset, this_trait, target_dataset, sample_data) = target_trait_info + if not __datasets_compatible_p__(this_dataset, target_dataset, corr_type): + raise WrongCorrelationType(this_trait, target_dataset, corr_type) + trait_symbol_dict = target_dataset.retrieve_genes("Symbol") corr_result_tissue_vals_dict = get_trait_symbol_and_tissue_values( symbol_list=list(trait_symbol_dict.values())) @@ -294,6 +304,9 @@ def __compute_lit_corr__( target_trait_info: tuple): """Compute the literature correlations""" (this_dataset, this_trait, target_dataset, sample_data) = target_trait_info + if not __datasets_compatible_p__(this_dataset, target_dataset, corr_type): + raise WrongCorrelationType(this_trait, target_dataset, corr_type) + target_dataset_type = target_dataset.type this_dataset_type = this_dataset.type (this_trait_geneid, geneid_dict, species) = do_lit_correlation( |