Skip to content

Commit

Permalink
fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fratajcz committed Sep 25, 2024
1 parent a6f63e6 commit 6e0fe4f
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions speos/tests/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,28 @@ def test_all_or_empty_string(self):
self.assertEqual(len(full_mappings), len(also_full_mappings))


class PreprocessorTest(unittest.TestCase):
class PreprocessorTest(TestSetup):
def setUp(self):
self.config = Config()
self.mapping = [{"name": "UC-immune_dysregulation",
"ground_truth": "data/mendelian_gene_sets/Immune_Dysregulation_genes.bed",
"features_file": "data/gwas/UC.genes.out",
"match_type": "perfect",
"significant": "False"},
{"name": "RA-immune_dysregulation",
"ground_truth": "data/mendelian_gene_sets/Immune_Dysregulation_genes.bed",
"features_file": "data/gwas/RA.genes.out",
"match_type": "perfect",
"significant": "True"}]
self.mapping_file_path = "speos/tests/files/mappings.json"
with open(self.mapping_file_path, "w") as file:
json.dump(self.mapping, file)
self.gwasmapper = GWASMapper(mapping_file=self.mapping_file_path)

self.adjacencymapper = AdjacencyMapper()

def tearDown(self) -> None:
os.remove(self.mapping_file_path)
#self.config = Config()
#self.mapping = [{"name": "UC-immune_dysregulation",
# "ground_truth": "data/mendelian_gene_sets/Immune_Dysregulation_genes.bed",
# "features_file": "data/gwas/UC.genes.out",
# "match_type": "perfect",
# "significant": "False"},
# {"name": "RA-immune_dysregulation",
# "ground_truth": "data/mendelian_gene_sets/Immune_Dysregulation_genes.bed",
# "features_file": "data/gwas/RA.genes.out",
# "match_type": "perfect",
# "significant": "True"}]
#self.mapping_file_path = "speos/tests/files/mappings.json"
#with open(self.mapping_file_path, "w") as file:
# json.dump(self.mapping, file)
#self.gwasmapper = GWASMapper(mapping_file=self.mapping_file_path)

#self.adjacencymapper = AdjacencyMapper()
super().setUp()
self.gwasmapper = GWASMapper(self.config.input.gwas_mappings)
self.adjacencymapper = AdjacencyMapper(mapping_file=self.config.input.adjacency_mappings)

def test_single_adjacency(self):
gwasmappings = self.gwasmapper.get_mappings(tags="immune_dysregulation", fields="name")
Expand Down Expand Up @@ -349,8 +349,8 @@ def test_contains_only_directed(self):

def test_log_expression(self):
# check if logarithmizing protein expression works
gwasmappings = self.gwasmapper.get_mappings(tags="immune_dysregulation", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="BioPlex 3-0 293T", fields="name")
gwasmappings = self.gwasmapper.get_mappings(tags="dummy", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="DummyUndirectedGraph", fields="name")
config = self.config.deepcopy()
config.input.log_expression = True
preprocessor = PreProcessor(config, gwasmappings, adjacencies)
Expand All @@ -359,8 +359,8 @@ def test_log_expression(self):

def test_no_gwas(self):
# check if toggling use_gwas works
gwasmappings = self.gwasmapper.get_mappings(tags="immune_dysregulation", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="BioPlex 3-0 293T", fields="name")
gwasmappings = self.gwasmapper.get_mappings(tags="dummy", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="DummyUndirectedGraph", fields="name")
config = self.config.deepcopy()
preprocessor = PreProcessor(config, gwasmappings, adjacencies)
X, y, adj = preprocessor.get_data()
Expand All @@ -378,8 +378,8 @@ def test_no_gwas(self):

def test_no_expression(self):
# check if toggling use_expression works
gwasmappings = self.gwasmapper.get_mappings(tags="immune_dysregulation", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="BioPlex 3.0 293T", fields="name")
gwasmappings = self.gwasmapper.get_mappings(tags="dummy", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="DummyUndirectedGraph", fields="name")
config = self.config.deepcopy()
preprocessor = PreProcessor(config, gwasmappings, adjacencies)

Expand All @@ -399,8 +399,8 @@ def test_no_expression(self):

def test_random_features(self):
# check if toggling off use_expression and use_gwas simultaneously produces random features
gwasmappings = self.gwasmapper.get_mappings(tags="immune_dysregulation", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="BioPlex 3.0 293T", fields="name")
gwasmappings = self.gwasmapper.get_mappings(tags="dummy", fields="name")
adjacencies = self.adjacencymapper.get_mappings(tags="DummyUndirectedGraph", fields="name")
config = self.config.deepcopy()
config.input.use_gwas = False
config.input.use_expression = False
Expand All @@ -417,7 +417,7 @@ def test_xswap_correct(self):
import numpy as np
adjacency = pd.DataFrame(data=np.array([list(range(0, 10)), list(range(10, 20))]).reshape(10, 2))

adjacency_swapped = PreProcessor.xswap(adjacency, 0.4)
adjacency_swapped = PreProcessor._xswap(adjacency, 0.4)

is_identical = 0
for i, row in adjacency.iterrows():
Expand All @@ -427,7 +427,7 @@ def test_xswap_correct(self):
self.assertTrue((adjacency.iloc[:, 0] == adjacency_swapped.iloc[:, 0]).all())
self.assertEqual(is_identical/len(adjacency), 1 - 0.4)

adjacency_swapped = PreProcessor.xswap(adjacency, 0.8)
adjacency_swapped = PreProcessor._xswap(adjacency, 0.8)

is_identical = 0
for i, row in adjacency.iterrows():
Expand All @@ -436,7 +436,7 @@ def test_xswap_correct(self):

self.assertAlmostEqual(is_identical/len(adjacency), 1 - 0.8)

adjacency_swapped = PreProcessor.xswap(adjacency, 1)
adjacency_swapped = PreProcessor._xswap(adjacency, 1)

is_identical = 0
for i, row in adjacency.iterrows():
Expand All @@ -450,7 +450,7 @@ def test_xswap_uneven_rows(self):
import numpy as np
adjacency = pd.DataFrame(data=np.array([list(range(0, 11)), list(range(10, 21))]).reshape(11, 2))

adjacency_swapped = PreProcessor.xswap(adjacency, 0.4)
adjacency_swapped = PreProcessor._xswap(adjacency, 0.4)

is_identical = 0
for i, row in adjacency.iterrows():
Expand All @@ -459,7 +459,7 @@ def test_xswap_uneven_rows(self):

self.assertAlmostEqual(is_identical/len(adjacency), 1 - (4/11))

adjacency_swapped = PreProcessor.xswap(adjacency, 0.8)
adjacency_swapped = PreProcessor._xswap(adjacency, 0.8)

is_identical = 0
for i, row in adjacency.iterrows():
Expand All @@ -468,7 +468,7 @@ def test_xswap_uneven_rows(self):

self.assertAlmostEqual(is_identical/len(adjacency), 1 - (8/11))

adjacency_swapped = PreProcessor.xswap(adjacency, 1)
adjacency_swapped = PreProcessor._xswap(adjacency, 1)

is_identical = 0
for i, row in adjacency.iterrows():
Expand Down Expand Up @@ -627,8 +627,6 @@ def test_dummy_metrics(self):

metrics = preprocessor.get_metrics()

print(metrics)

def test_label_extension(self):
config = Config()
mapping = [ {"name": "UNK-immune_dysregulation",
Expand Down

0 comments on commit 6e0fe4f

Please sign in to comment.