From 219991f8fbfc4c09ee24a894ded7e3271765d27a Mon Sep 17 00:00:00 2001 From: Marc Duby Date: Fri, 23 Aug 2024 13:53:12 -0400 Subject: [PATCH] gene_nmf: added ability to set pvalue --- app/novelty/gene_nmf/gene_nmf_adapter.py | 8 ++++---- tests/test_gene_nmf_adapter.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/novelty/gene_nmf/gene_nmf_adapter.py b/app/novelty/gene_nmf/gene_nmf_adapter.py index f3f3de9..7ad263d 100644 --- a/app/novelty/gene_nmf/gene_nmf_adapter.py +++ b/app/novelty/gene_nmf/gene_nmf_adapter.py @@ -77,14 +77,14 @@ # methods -def get_gene_nmf_novelty_for_gene_list(list_input_genes, log=False): +def get_gene_nmf_novelty_for_gene_list(list_input_genes, p_value_cutoff=P_VALUE_CUTOFF, log=False): ''' 'will process the gene nmf call for the gene list given and return the gene novelty ''' map_result = {} # get the calculated data - map_gene_novelty, list_input_translated = process_genes(list_input_genes=list_input_genes) + map_gene_novelty, list_input_translated = process_genes(list_input_genes=list_input_genes, p_value_cutoff=p_value_cutoff) # log result logger.info("got novelty result map of size: {}".format(len(map_gene_novelty))) @@ -97,7 +97,7 @@ def get_gene_nmf_novelty_for_gene_list(list_input_genes, log=False): return map_result -def process_genes(list_input_genes, log=False): +def process_genes(list_input_genes, p_value_cutoff, log=False): ''' processes the input genes ''' @@ -112,7 +112,7 @@ def process_genes(list_input_genes, log=False): # do the calculations list_factor, list_factor_genes, list_factor_gene_sets, gene_factor, gene_set_factor, map_gene_novelty = cutils.calculate_factors(matrix_gene_sets_gene_original=matrix_gene_sets, - p_value=P_VALUE_CUTOFF, + p_value=p_value_cutoff, list_gene=list_input_translated, list_system_genes=list_system_genes, map_gene_index=map_gene_index, map_gene_set_index=map_gene_set_index, diff --git a/tests/test_gene_nmf_adapter.py b/tests/test_gene_nmf_adapter.py index 5cffee8..691ea96 100644 --- a/tests/test_gene_nmf_adapter.py +++ b/tests/test_gene_nmf_adapter.py @@ -143,3 +143,23 @@ def test_get_gene_nmf_novelty_for_gene_list(): assert len(map_result.get('gene_results')) == len(list_gene_test) + +def test_get_gene_nmf_novelty_for_gene_list_and_pvalue(): + """ + Test that the gene nmf adaptare novelty function works. + """ + # initialize + map_result = {} + + # call method + map_result = adapter.get_gene_nmf_novelty_for_gene_list(list_input_genes=list_gene_test, p_value_cutoff=0.2, log=True) + + # logger + logger.info("got map result of size: {}".format(len(map_result.get('gene_results')))) + + # test + assert map_result is not None + assert map_result.get('gene_results') is not None + assert len(map_result.get('gene_results')) > 0 + assert len(map_result.get('gene_results')) == len(list_gene_test) +