aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests
diff options
context:
space:
mode:
authorAlexanderlacuna2020-11-12 00:45:03 +0300
committerAlexanderlacuna2020-11-12 00:45:03 +0300
commitf4dbdc51102d942079c7159ac48071282ec995ea (patch)
tree4e36f58515878065fb193ed83bf7e4cfa999e9ed /wqflask/tests
parente63e85868ed7b63bbe784368b3c1babf0d1f2088 (diff)
downloadgenenetwork2-f4dbdc51102d942079c7159ac48071282ec995ea.tar.gz
modify tests for marker regression
Diffstat (limited to 'wqflask/tests')
-rw-r--r--wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py8
-rw-r--r--wqflask/tests/wqflask/marker_regression/test_plink_mapping.py4
-rw-r--r--wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py3
-rw-r--r--wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py13
-rw-r--r--wqflask/tests/wqflask/marker_regression/test_run_mapping.py153
5 files changed, 93 insertions, 88 deletions
diff --git a/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py b/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py
index ed72cb33..e47c8335 100644
--- a/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py
+++ b/wqflask/tests/wqflask/marker_regression/test_gemma_mapping.py
@@ -24,6 +24,7 @@ class TestGemmaMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.gemma_mapping.parse_loco_output")
def test_run_gemma_first_run_loco_set_false(self, mock_parse_loco):
+ """add tests for gemma function where first run is set to false"""
dataset = AttributeSetter(
{"group": AttributeSetter({"genofile": "genofile.geno"})})
@@ -50,6 +51,7 @@ class TestGemmaMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.gemma_mapping.os")
@mock.patch("wqflask.marker_regression.gemma_mapping.gen_pheno_txt_file")
def test_run_gemma_first_run_set_true(self, mock_gen_pheno_txt, mock_os, mock_choice, mock_gen_covar, mock_flat_files, mock_logger, mock_parse_loco):
+ """add tests for run_gemma where first run is set to true"""
chromosomes = []
for i in range(1, 5):
chromosomes.append(AttributeSetter({"name": f"CH{i}"}))
@@ -81,6 +83,7 @@ class TestGemmaMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/user/data")
def test_gen_pheno_txt_file(self):
+ """add tests for generating pheno txt file"""
with mock.patch("builtins.open", mock.mock_open())as mock_open:
gen_pheno_txt_file(this_dataset={}, genofile_name="", vals=[
"x", "w", "q", "we", "R"], trait_filename="fitr.re")
@@ -97,6 +100,7 @@ class TestGemmaMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.gemma_mapping.create_trait")
@mock.patch("wqflask.marker_regression.gemma_mapping.create_dataset")
def test_gen_covariates_file(self, create_dataset, create_trait, flat_files):
+ """add tests for generating covariates files"""
covariates = "X1:X2,Y1:Y2,M1:M3,V1:V2"
samplelist = ["X1", "X2", "X3", "X4"]
create_dataset_side_effect = []
@@ -138,6 +142,7 @@ class TestGemmaMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img/")
def test_parse_gemma_output_obj_returned(self):
+ """add test for generating gemma output with obj returned"""
file = """X/Y\t gn2\t21\tQ\tE\tA\tP\tMMB\tCDE\t0.5
X/Y\tgn2\t21322\tQ\tE\tA\tP\tMMB\tCDE\t0.5
chr\tgn1\t12312\tQ\tE\tA\tP\tMMB\tCDE\t0.7
@@ -154,6 +159,7 @@ X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4
@mock.patch("wqflask.marker_regression.gemma_mapping.webqtlConfig.GENERATED_IMAGE_DIR", "/home/user/img")
def test_parse_gemma_output_empty_return(self):
+ """add tests for parse gemma output where nothing returned"""
output_file_results = """chr\t today"""
with mock.patch("builtins.open", mock.mock_open(read_data=output_file_results)) as mock_open:
results = parse_gemma_output(genofile_name="gema_file")
@@ -162,6 +168,7 @@ X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4
@mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp")
@mock.patch("wqflask.marker_regression.gemma_mapping.os")
def test_parse_loco_output_file_found(self, mock_os):
+ """add tests for parse loco output file found"""
mock_os.path.isfile.return_value = True
file_to_write = """{"files":["file_1","file_2"]}"""
pass
@@ -169,6 +176,7 @@ X\tgn7\t2324424\tQ\tE\tA\tP\tMMB\tCDE\t0.4
@mock.patch("wqflask.marker_regression.gemma_mapping.TEMPDIR", "/home/tmp")
@mock.patch("wqflask.marker_regression.gemma_mapping.os")
def test_parse_loco_output_file_not_found(self, mock_os):
+ """add tests for parse loco output file not found"""
mock_os.path.isfile.return_value = False
file_to_write = """{"files":["file_1","file_2"]}"""
diff --git a/wqflask/tests/wqflask/marker_regression/test_plink_mapping.py b/wqflask/tests/wqflask/marker_regression/test_plink_mapping.py
index a5fa0c04..428f45b9 100644
--- a/wqflask/tests/wqflask/marker_regression/test_plink_mapping.py
+++ b/wqflask/tests/wqflask/marker_regression/test_plink_mapping.py
@@ -15,6 +15,7 @@ class AttributeSetter:
class TestPlinkMapping(unittest.TestCase):
def test_build_line_list(self):
+ """testing for building line list"""
line_1 = "this is line one test"
irregular_line = " this is an, irregular line "
exp_line1 = ["this", "is", "line", "one", "test"]
@@ -26,6 +27,7 @@ class TestPlinkMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.plink_mapping.flat_files")
def test_get_samples_from_ped_file(self, mock_flat_files):
+ """test for getting samples from ped file"""
dataset = AttributeSetter({"group": AttributeSetter({"name": "n_1"})})
file_sample = """Expected_1\tline test
Expected_2\there
@@ -41,6 +43,7 @@ Expected_2\there
@mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/")
@mock.patch("wqflask.marker_regression.plink_mapping.get_samples_from_ped_file")
def test_gen_pheno_txt_file_plink(self, mock_samples):
+ """test for getting gen_pheno txt file"""
mock_samples.return_value = ["Expected_1", "Expected_2", "Expected_3"]
trait = AttributeSetter({"name": "TX"})
@@ -62,6 +65,7 @@ Expected_2\there
@mock.patch("wqflask.marker_regression.plink_mapping.TMPDIR", "/home/user/data/")
@mock.patch("wqflask.marker_regression.plink_mapping.build_line_list")
def test_parse_plink_output(self, mock_line_list):
+ """test for parsing plink output"""
chromosomes = [0, 34, 110, 89, 123, 23, 2]
species = AttributeSetter(
{"name": "S1", "chromosomes": AttributeSetter({"chromosomes": chromosomes})})
diff --git a/wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py b/wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py
index 7ece663a..b47f877a 100644
--- a/wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py
+++ b/wqflask/tests/wqflask/marker_regression/test_qtlreaper_mapping.py
@@ -1,13 +1,12 @@
import unittest
from unittest import mock
from wqflask.marker_regression.qtlreaper_mapping import gen_pheno_txt_file
-from wqflask.marker_regression.qtlreaper_mapping import natural_sort
#issues some methods in genofile object are not defined
#modify samples should equal to vals
class TestQtlReaperMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.qtlreaper_mapping.TEMPDIR", "/home/user/data")
- def test_gen_pheno_txt_file(self):
+ def test_gen_pheno_txt_file(self):
vals=["V1","x","V4","V3","x"]
samples=["S1","S2","S3","S4","S5"]
trait_filename="trait_file"
diff --git a/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py b/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py
index 641644cc..9fd32a30 100644
--- a/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py
+++ b/wqflask/tests/wqflask/marker_regression/test_rqtl_mapping.py
@@ -18,23 +18,15 @@ class TestRqtlMapping(unittest.TestCase):
@mock.patch("wqflask.marker_regression.rqtl_mapping.g")
@mock.patch("wqflask.marker_regression.rqtl_mapping.logger")
def test_get_trait_data_type_found(self,mock_logger,mock_db):
+ """test for getting trait data_type return True"""
caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'"""
mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""]
results=get_trait_data_type("traid_id")
mock_db.db.execute.assert_called_with(caller_value)
self.assertEqual(results,"fer434f")
-
- @mock.patch("wqflask.marker_regression.rqtl_mapping.g")
- @mock.patch("wqflask.marker_regression.rqtl_mapping.logger")
- def test_get_trait_data_type_not_found(self,mock_logger,mock_db):
- caller_value="""SELECT value FROM TraitMetadata WHERE type='trait_data_type'"""
- mock_db.db.execute.return_value.fetchone.return_value=["""{"type":"trait_data_type","name":"T1","traid_id":"fer434f"}"""]
- results=get_trait_data_type("other")
- mock_db.db.execute.assert_called_with(caller_value)
- self.assertEqual(results,"numeric")
-
def test_sanitize_rqtl_phenotype(self):
+ """test for sanitizing rqtl phenotype"""
vals=['f',"x","r","x","x"]
results=sanitize_rqtl_phenotype(vals)
expected_phenotype_string='c(f,NA,r,NA,NA)'
@@ -42,6 +34,7 @@ class TestRqtlMapping(unittest.TestCase):
self.assertEqual(results,expected_phenotype_string)
def test_sanitize_rqtl_names(self):
+ """test for sanitzing rqtl names"""
vals=['f',"x","r","x","x"]
expected_sanitized_name="c('f',NA,'r',NA,NA)"
results=sanitize_rqtl_names(vals)
diff --git a/wqflask/tests/wqflask/marker_regression/test_run_mapping.py b/wqflask/tests/wqflask/marker_regression/test_run_mapping.py
index be6e6e48..2af4c3e3 100644
--- a/wqflask/tests/wqflask/marker_regression/test_run_mapping.py
+++ b/wqflask/tests/wqflask/marker_regression/test_run_mapping.py
@@ -28,24 +28,24 @@ class TestRunMapping(unittest.TestCase):
self.group = MockDataSetGroup(
{"genofile": "~/genofiles/g1_file", "name": "GP1_", "species": "Human"})
- chromosomes={
- "3":AttributeSetter({
- "name":"C1",
- "length":"0.04"
- }),
- "4":AttributeSetter({
- "name":"C2",
- "length":"0.03"
- }),
- "5":AttributeSetter({
- "name":"C4",
- "length":"0.01"
- })
- }
+ chromosomes = {
+ "3": AttributeSetter({
+ "name": "C1",
+ "length": "0.04"
+ }),
+ "4": AttributeSetter({
+ "name": "C2",
+ "length": "0.03"
+ }),
+ "5": AttributeSetter({
+ "name": "C4",
+ "length": "0.01"
+ })
+ }
self.dataset = AttributeSetter(
{"fullname": "dataser_1", "group": self.group, "type": "ProbeSet"})
- self.chromosomes=AttributeSetter({"chromosomes":chromosomes})
+ self.chromosomes = AttributeSetter({"chromosomes": chromosomes})
self.trait = AttributeSetter(
{"symbol": "IGFI", "chr": "X1", "mb": 123313})
@@ -142,6 +142,7 @@ class TestRunMapping(unittest.TestCase):
self.assertEqual(result_2, marker_2)
def test_export_mapping_results(self):
+ """test for exporting mapping results"""
datetime_mock = mock.Mock(wraps=datetime.datetime)
datetime_mock.now.return_value = datetime.datetime(
2019, 9, 1, 10, 12, 12)
@@ -206,78 +207,78 @@ class TestRunMapping(unittest.TestCase):
filehandler = mock_open()
filehandler.write.assert_has_calls(write_calls)
-
@mock.patch("wqflask.marker_regression.run_mapping.random.choice")
- def test_write_input_for_browser(self,mock_choice):
- mock_choice.side_effect=["F","i","l","e","s","x"]
- with mock.patch("builtins.open",mock.mock_open()) as mock_open:
- expected=['GP1__Filesx_GWAS', 'GP1__Filesx_ANNOT']
-
- results=write_input_for_browser(this_dataset=self.dataset,gwas_results={},annotations={})
- self.assertEqual(results,expected)
+ def test_write_input_for_browser(self, mock_choice):
+ """test for writing input for browser"""
+ mock_choice.side_effect = ["F", "i", "l", "e", "s", "x"]
+ with mock.patch("builtins.open", mock.mock_open()) as mock_open:
+ expected = ['GP1__Filesx_GWAS', 'GP1__Filesx_ANNOT']
+ results = write_input_for_browser(
+ this_dataset=self.dataset, gwas_results={}, annotations={})
+ self.assertEqual(results, expected)
def test_get_perm_strata(self):
- categorical_vars=["C1","C2","W1"]
- used_samples=["S1","S2"]
- sample_list=AttributeSetter({"sample_attribute_values":{
- "S1":{
- "C1":"c1_value",
- "C2":"c2_value",
- "W1":"w1_value"
+ categorical_vars = ["C1", "C2", "W1"]
+ used_samples = ["S1", "S2"]
+ sample_list = AttributeSetter({"sample_attribute_values": {
+ "S1": {
+ "C1": "c1_value",
+ "C2": "c2_value",
+ "W1": "w1_value"
- },
- "S2":{
- "W1":"w2_value",
- "W2":"w2_value"
+ },
+ "S2": {
+ "W1": "w2_value",
+ "W2": "w2_value"
- },
- "S3":{
+ },
+ "S3": {
- "C1":"c1_value",
- "C2":"c2_value"
+ "C1": "c1_value",
+ "C2": "c2_value"
- },
-
- }})
+ },
- results=get_perm_strata(this_trait={},sample_list=sample_list,categorical_vars=categorical_vars,used_samples=used_samples)
- self.assertEqual(results,[2,1])
+ }})
+ results = get_perm_strata(this_trait={}, sample_list=sample_list,
+ categorical_vars=categorical_vars, used_samples=used_samples)
+ self.assertEqual(results, [2, 1])
def test_get_chr_length(self):
- chromosomes=AttributeSetter({"chromosomes":self.chromosomes})
- dataset=AttributeSetter({"species":chromosomes})
- results=get_chr_lengths(mapping_scale="physic",mapping_method="reaper",dataset=dataset,qtl_results=[])
- chr_lengths=[]
- for key,chromo in self.chromosomes.chromosomes.items():
- chr_lengths.append({"chr":chromo.name,"size":chromo.length})
-
- self.assertEqual(chr_lengths,results)
-
- qtl_results=[{
- "chr":"16",
- "cM":"0.2"
- },
- {
- "chr":"12",
- "cM":"0.5"
- },
- {
- "chr":"18",
- "cM":"0.1"
- },
- {
- "chr":"22",
- "cM":"0.4"
- },
- ]
-
-
-
- result_with_other_mapping_scale=get_chr_lengths(mapping_scale="other",mapping_method="reaper",dataset=dataset,qtl_results=qtl_results)
- expected_value= [{'chr': '1', 'size': '0'}, {'chr': '16', 'size': '500000.0'}, {'chr': '18', 'size': '400000.0'}]
-
- self.assertEqual(result_with_other_mapping_scale,expected_value)
+ """test for getting chromosome length"""
+ chromosomes = AttributeSetter({"chromosomes": self.chromosomes})
+ dataset = AttributeSetter({"species": chromosomes})
+ results = get_chr_lengths(
+ mapping_scale="physic", mapping_method="reaper", dataset=dataset, qtl_results=[])
+ chr_lengths = []
+ for key, chromo in self.chromosomes.chromosomes.items():
+ chr_lengths.append({"chr": chromo.name, "size": chromo.length})
+
+ self.assertEqual(chr_lengths, results)
+
+ qtl_results = [{
+ "chr": "16",
+ "cM": "0.2"
+ },
+ {
+ "chr": "12",
+ "cM": "0.5"
+ },
+ {
+ "chr": "18",
+ "cM": "0.1"
+ },
+ {
+ "chr": "22",
+ "cM": "0.4"
+ },
+ ]
+ result_with_other_mapping_scale = get_chr_lengths(
+ mapping_scale="other", mapping_method="reaper", dataset=dataset, qtl_results=qtl_results)
+ expected_value = [{'chr': '1', 'size': '0'}, {
+ 'chr': '16', 'size': '500000.0'}, {'chr': '18', 'size': '400000.0'}]
+ self.assertEqual(result_with_other_mapping_scale, expected_value)