Skip to content

Commit 39b2dec

Browse files
author
sarah.mubeen
committed
update tests
1 parent 17da0d6 commit 39b2dec

3 files changed

Lines changed: 75 additions & 26 deletions

File tree

tests/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
INPUT_SCORES = os.path.join(RESOURCES_FOLDER, 'input_scores.csv')
2121
INPUT_UNLABELED_SCORES = os.path.join(RESOURCES_FOLDER, 'input_unlabeled_scores.csv')
2222

23+
NETWORKS_FOLDER = os.path.join(RESOURCES_FOLDER, 'networks')
24+
NETWORK_PATH = os.path.join(NETWORKS_FOLDER, 'network_1.csv')
25+
2326
OUTPUT_RAW_SCORES = os.path.join(RESOURCES_FOLDER, 'output_raw_scores.csv')
2427
OUTPUT_Z_SCORES = os.path.join(RESOURCES_FOLDER, 'output_z_scores.csv')
2528
OUTPUT_ML_SCORES = os.path.join(RESOURCES_FOLDER, 'output_ml_scores.csv')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Source,Target
2+
A,B
3+
A,D
4+
B,C
5+
B,G
6+
C,D
7+
C,E
8+
C,F
9+
D,E
10+
E,F
11+
G,F

tests/test_input.py

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from diffupy.constants import *
99
from diffupy.matrix import Matrix
10-
from diffupy.process_input import process_input
10+
from diffupy.process_input import process_input, map_nodes
11+
from diffupy.utils import process_network
1112
from diffupy.validate_input import _validate_scores
1213
from tests.constants import *
1314

@@ -20,99 +21,133 @@ class ValidateTest(unittest.TestCase):
2021
def test_quantitative_bin_id(self):
2122
"""Test codify input for quantitative scoring methods- only entity IDs given (binary labels)."""
2223
input = NODE_TEST_PATH
23-
input_scores_dict = process_input(
24+
input_labels_dict = process_input(
2425
input, method=RAW, binning=True, absolute_value=True, p_value=0.05, threshold=None,
2526
)
26-
self.assertEqual(input_scores_dict, {'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1})
27+
self.assertEqual(input_labels_dict, {'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1})
2728

2829
def test_quantitative_bin_fc_sign(self):
2930
"""Test codify input for quantitative scoring methods- logFC given (binary, signed labels)."""
3031
input = NODE_LOGFC_TEST_PATH
31-
input_scores_dict = process_input(
32+
input_labels_dict = process_input(
3233
input, method=RAW, binning=True, absolute_value=False, p_value=0.05, threshold=0.5,
3334
)
34-
self.assertEqual(input_scores_dict, {'A': 1, 'B': 1, 'C': 0, 'D': 0, 'E': -1})
35+
self.assertEqual(input_labels_dict, {'A': 1, 'B': 1, 'C': 0, 'D': 0, 'E': -1})
3536

3637
def test_quantitative_bin_fc_abs(self):
3738
"""Test codify input for quantitative scoring methods- logFC given (binary, absolute values)."""
3839
input = NODE_LOGFC_TEST_PATH
39-
input_scores_dict = process_input(
40+
input_labels_dict = process_input(
4041
input, method=RAW, binning=True, absolute_value=True, p_value=0.05, threshold=0.5,
4142
)
42-
self.assertEqual(input_scores_dict, {'A': 1, 'B': 1, 'C': 0, 'D': 0, 'E': 1})
43+
self.assertEqual(input_labels_dict, {'A': 1, 'B': 1, 'C': 0, 'D': 0, 'E': 1})
4344

4445
def test_quantitative_bin_fcp_sign(self):
4546
"""Test codify input for quantitative scoring methods- logFC and adj. p-value given (binary, signed labels)."""
4647
input = NODE_LOGFC_PVAL_TEST_PATH
47-
input_scores_dict = process_input(
48+
input_labels_dict = process_input(
4849
input, method=RAW, binning=True, absolute_value=False, p_value=0.05, threshold=0.5,
4950
)
50-
self.assertEqual(input_scores_dict, {'A': 0, 'B': 1, 'C': 0, 'D': 0, 'E': -1})
51+
self.assertEqual(input_labels_dict, {'A': 0, 'B': 1, 'C': 0, 'D': 0, 'E': -1})
5152

5253
def test_quantitative_bin_fcp_abs(self):
5354
"""Test codify input for quant. scoring methods- logFC and adj. p-value given (binary, absolute values)."""
5455
input = NODE_LOGFC_PVAL_TEST_PATH
55-
input_scores_dict = process_input(
56+
input_labels_dict = process_input(
5657
input, method=RAW, binning=True, absolute_value=True, p_value=0.05, threshold=0.5,
5758
)
58-
self.assertEqual(input_scores_dict, {'A': 0, 'B': 1, 'C': 0, 'D': 0, 'E': 1})
59+
self.assertEqual(input_labels_dict, {'A': 0, 'B': 1, 'C': 0, 'D': 0, 'E': 1})
5960

6061
def test_quantitative_fc_sign(self):
6162
"""Test codify input for quantitative scoring methods- logFC given (quantitative, signed labels)."""
6263
input = NODE_LOGFC_TEST_PATH
63-
input_scores_dict = process_input(
64+
input_labels_dict = process_input(
6465
input, method=RAW, binning=False, absolute_value=False, p_value=0.05, threshold=0.5,
6566
)
66-
self.assertEqual(input_scores_dict, {'A': 0.7, 'B': 1.2, 'C': 0, 'D': 0, 'E': -2.2})
67+
self.assertEqual(input_labels_dict, {'A': 0.7, 'B': 1.2, 'C': 0, 'D': 0, 'E': -2.2})
6768

6869
def test_quantitative_fc_abs(self):
6970
"""Test codify input for quantitative scoring methods- logFC given (quant., absolute values)."""
7071
input = NODE_LOGFC_TEST_PATH
71-
input_scores_dict = process_input(
72+
input_labels_dict = process_input(
7273
input, method=RAW, binning=False, absolute_value=True, p_value=0.05, threshold=0.5,
7374
)
74-
self.assertEqual(input_scores_dict, {'A': 0.7, 'B': 1.2, 'C': 0, 'D': 0, 'E': 2.2})
75+
self.assertEqual(input_labels_dict, {'A': 0.7, 'B': 1.2, 'C': 0, 'D': 0, 'E': 2.2})
7576

7677
def test_quantitative_fcp_sign(self):
7778
"""Test codify input for quantitative scoring methods- logFC and adj. p-value given (quant., signed labels)."""
7879
input = NODE_LOGFC_PVAL_TEST_PATH
79-
input_scores_dict = process_input(
80+
input_labels_dict = process_input(
8081
input, method=RAW, binning=False, absolute_value=False, p_value=0.05, threshold=0.5,
8182
)
82-
self.assertEqual(input_scores_dict, {'A': 0, 'B': 1.2, 'C': 0, 'D': 0, 'E': -2.2})
83+
self.assertEqual(input_labels_dict, {'A': 0, 'B': 1.2, 'C': 0, 'D': 0, 'E': -2.2})
8384

8485
def test_quantitative_fcp_abs(self):
8586
"""Test codify input for quant. scoring methods- logFC and adj. p-value given (quant., absolute values)."""
8687
input = NODE_LOGFC_PVAL_TEST_PATH
87-
input_scores_dict = process_input(
88+
input_labels_dict = process_input(
8889
input, method=RAW, binning=False, absolute_value=True, p_value=0.05, threshold=0.5,
8990
)
90-
self.assertEqual(input_scores_dict, {'A': 0, 'B': 1.2, 'C': 0, 'D': 0, 'E': 2.2})
91+
self.assertEqual(input_labels_dict, {'A': 0, 'B': 1.2, 'C': 0, 'D': 0, 'E': 2.2})
9192

9293
def test_non_quantitative_bin_id(self):
9394
"""Test codify input for non-quantitative scoring methods- only entity IDs given (binary labels)."""
9495
input = NODE_TEST_PATH
95-
input_scores_dict = process_input(
96+
input_labels_dict = process_input(
9697
input, method=ML, binning=True, absolute_value=True, p_value=0.05, threshold=None,
9798
)
98-
99-
self.assertEqual(input_scores_dict, {'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1})
99+
self.assertEqual(input_labels_dict, {'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1})
100100

101101
def test_non_quantitative_bin_fc_abs(self):
102102
"""Test codify input for non-quantitative scoring methods- logFC given (binary, absolute values (sign))."""
103103
input = NODE_LOGFC_TEST_PATH
104-
input_scores_dict = process_input(
104+
input_labels_dict = process_input(
105105
input, method=ML, binning=True, absolute_value=True, p_value=0.05, threshold=0.5,
106106
)
107-
self.assertEqual(input_scores_dict, {'A': 1, 'B': 1, 'C': -1, 'D': -1, 'E': 1})
107+
self.assertEqual(input_labels_dict, {'A': 1, 'B': 1, 'C': -1, 'D': -1, 'E': 1})
108108

109109
def test_non_quantitative_bin_fcp_abs(self):
110110
"""Test codify input for non-quant. scoring methods- logFC and adj. p-value given (binary, absolute values)."""
111111
input = NODE_LOGFC_PVAL_TEST_PATH
112-
input_scores_dict = process_input(
112+
input_labels_dict = process_input(
113113
input, method=ML, binning=True, absolute_value=True, p_value=0.05, threshold=0.5,
114114
)
115-
self.assertEqual(input_scores_dict, {'A': -1, 'B': 1, 'C': -1, 'D': -1, 'E': 1})
115+
self.assertEqual(input_labels_dict, {'A': -1, 'B': 1, 'C': -1, 'D': -1, 'E': 1})
116+
117+
def test_network(self):
118+
"""Test generate graph from csv."""
119+
graph = process_network(NETWORK_PATH, CSV)
120+
graph_nodes = set(graph.nodes())
121+
graph_edges = set(graph.edges())
122+
123+
self.assertEqual(graph_nodes, {'A', 'B', 'C', 'D', 'E', 'F', 'G'})
124+
self.assertEqual(graph_edges, {
125+
('A', 'B'),
126+
('A', 'D'),
127+
('B', 'C'),
128+
('B', 'G'),
129+
('C', 'D'),
130+
('C', 'E'),
131+
('C', 'F'),
132+
('D', 'E'),
133+
('E', 'F'),
134+
('G', 'F'),
135+
})
136+
137+
def test_node_mapping(self):
138+
"""Test mapping of nodes in input to nodes in network"""
139+
140+
input = NODE_LOGFC_TEST_PATH
141+
input_labels_dict = process_input(
142+
input, method=RAW, binning=False, absolute_value=True, p_value=0.05, threshold=0.5,
143+
)
144+
145+
graph = process_network(NETWORK_PATH, CSV)
146+
graph_nodes = list(graph.nodes())
147+
148+
mapped_nodes_list = map_nodes(input_labels_dict, graph_nodes)
149+
150+
self.assertEqual(mapped_nodes_list, [0.0, 1.0, 0.0, 0.0, None, 1.0, None, None, None])
116151

117152
def test_validate_scores_1(self):
118153
"""Test validate scores 1."""

0 commit comments

Comments
 (0)