Skip to content

Commit b6a86df

Browse files
committed
Formatting
1 parent cd538e1 commit b6a86df

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

spras/evaluation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,13 @@ def precision_recall_curve_node_ensemble(node_ensembles: dict, node_table: pd.Da
156156
@param node_ensembles: dict of the pre-computed node_ensemble(s)
157157
@param node_table: gold standard nodes
158158
@param output_png: filename to save the precision and recall curves as a .png image
159-
@param output_file: filename to save the precision, recall, threshold values, average precision, and baseline precision
159+
@param output_file: filename to save the precision, recall, threshold values, average precision, and baseline
160+
average precision
160161
"""
161162
gold_standard_nodes = set(node_table[Evaluation.NODE_ID])
162163

163164
# make color palette per ensemble label name
164-
label_names = list(node_ensembles)
165+
label_names = list(node_ensembles.keys())
165166
color_palette = create_palette(label_names)
166167

167168
plt.figure(figsize=(10, 7))
@@ -215,7 +216,6 @@ def precision_recall_curve_node_ensemble(node_ensembles: dict, node_table: pd.Da
215216
f"This should not happen unless the input network for pathway reconstruction is empty."
216217
)
217218

218-
219219
if 'ensemble' not in label_names:
220220
plt.title('Precision-Recall Curve Per Algorithm Specific Ensemble')
221221
else:

test/evaluate/input/ensemble-network.tsv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Node1 Node2 Frequency Direction
22
A B 0.5 U
33
B A 0.5 U
44
Q R 0.01 U
5-
Z X 0.66 U
5+
Z X 0.66 U

test/evaluate/input/gs_node_table.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ NODEID
22
A
33
B
44
Q
5-
Z
5+
Z

test/evaluate/test_evaluate.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
INPUT_DIR = 'test/evaluate/input/'
99
OUT_DIR = 'test/evaluate/output/'
1010
EXPECT_DIR = 'test/evaluate/expected/'
11-
GS_NODE_TABLE = pd.read_csv(INPUT_DIR + "gs_node_table.csv", header=0)
11+
GS_NODE_TABLE = pd.read_csv(INPUT_DIR + 'gs_node_table.csv', header=0)
1212

1313

1414
class TestEvaluate:
@@ -25,16 +25,17 @@ def test_node_ensemble(self):
2525
ensemble_network = [INPUT_DIR + 'ensemble-network.tsv']
2626
input_network = INPUT_DIR + 'data.pickle'
2727
node_ensemble_dict = Evaluation.edge_frequency_node_ensemble(GS_NODE_TABLE, ensemble_network, input_network)
28-
node_ensemble_dict['ensemble'].to_csv(out_path_file, sep="\t", index=False)
28+
node_ensemble_dict['ensemble'].to_csv(out_path_file, sep='\t', index=False)
2929
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-node-ensemble.csv', shallow=False)
3030

3131
def test_empty_node_ensemble(self):
3232
out_path_file = Path(OUT_DIR + 'empty-node-ensemble.csv')
3333
out_path_file.unlink(missing_ok=True)
3434
empty_ensemble_network = [INPUT_DIR + 'empty-ensemble-network.tsv']
3535
input_network = INPUT_DIR + 'data.pickle'
36-
node_ensemble_dict = Evaluation.edge_frequency_node_ensemble(GS_NODE_TABLE, empty_ensemble_network, input_network)
37-
node_ensemble_dict['empty'].to_csv(out_path_file, sep="\t", index=False)
36+
node_ensemble_dict = Evaluation.edge_frequency_node_ensemble(GS_NODE_TABLE, empty_ensemble_network,
37+
input_network)
38+
node_ensemble_dict['empty'].to_csv(out_path_file, sep='\t', index=False)
3839
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-empty-node-ensemble.csv', shallow=False)
3940

4041
def test_multiple_node_ensemble(self):
@@ -45,41 +46,44 @@ def test_multiple_node_ensemble(self):
4546
ensemble_networks = [INPUT_DIR + 'ensemble-network.tsv', INPUT_DIR + 'empty-ensemble-network.tsv']
4647
input_network = INPUT_DIR + 'data.pickle'
4748
node_ensemble_dict = Evaluation.edge_frequency_node_ensemble(GS_NODE_TABLE, ensemble_networks, input_network)
48-
node_ensemble_dict['ensemble'].to_csv(out_path_file, sep="\t", index=False)
49+
node_ensemble_dict['ensemble'].to_csv(out_path_file, sep='\t', index=False)
4950
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-node-ensemble.csv', shallow=False)
50-
node_ensemble_dict['empty'].to_csv(out_path_empty_file, sep="\t", index=False)
51+
node_ensemble_dict['empty'].to_csv(out_path_empty_file, sep='\t', index=False)
5152
assert filecmp.cmp(out_path_empty_file, EXPECT_DIR + 'expected-empty-node-ensemble.csv', shallow=False)
5253

5354
def test_precision_recall_curve_ensemble_nodes(self):
5455
out_path_png = Path(OUT_DIR + "pr-curve-ensemble-nodes.png")
5556
out_path_png.unlink(missing_ok=True)
5657
out_path_file = Path(OUT_DIR + "pr-curve-ensemble-nodes.txt")
5758
out_path_file.unlink(missing_ok=True)
58-
ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble.csv', sep="\t", header=0)
59+
ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble.csv', sep='\t', header=0)
5960
node_ensembles_dict = {'ensemble': ensemble_file}
60-
Evaluation.precision_recall_curve_node_ensemble(node_ensembles_dict, GS_NODE_TABLE, str(out_path_png), str(out_path_file))
61+
Evaluation.precision_recall_curve_node_ensemble(node_ensembles_dict, GS_NODE_TABLE, str(out_path_png),
62+
str(out_path_file))
6163
assert out_path_png.exists()
6264
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-pr-curve-ensemble-nodes.txt', shallow=False)
6365

6466
def test_precision_recall_curve_ensemble_nodes_empty(self):
65-
out_path_png = Path(OUT_DIR+"pr-curve-ensemble-nodes-empty.png")
67+
out_path_png = Path(OUT_DIR + "pr-curve-ensemble-nodes-empty.png")
6668
out_path_png.unlink(missing_ok=True)
67-
out_path_file = Path(OUT_DIR+"pr-curve-ensemble-nodes-empty.txt")
69+
out_path_file = Path(OUT_DIR + "pr-curve-ensemble-nodes-empty.txt")
6870
out_path_file.unlink(missing_ok=True)
69-
empty_ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble-empty.csv', sep="\t", header=0)
71+
empty_ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble-empty.csv', sep='\t', header=0)
7072
node_ensembles_dict = {'ensemble': empty_ensemble_file}
71-
Evaluation.precision_recall_curve_node_ensemble(node_ensembles_dict, GS_NODE_TABLE, str(out_path_png), str(out_path_file))
73+
Evaluation.precision_recall_curve_node_ensemble(node_ensembles_dict, GS_NODE_TABLE, str(out_path_png),
74+
str(out_path_file))
7275
assert out_path_png.exists()
7376
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-pr-curve-ensemble-nodes-empty.txt', shallow=False)
7477

7578
def test_precision_recall_curve_multiple_ensemble_nodes(self):
76-
out_path_png = Path(OUT_DIR+"pr-curve-multiple-ensemble-nodes.png")
79+
out_path_png = Path(OUT_DIR + "pr-curve-multiple-ensemble-nodes.png")
7780
out_path_png.unlink(missing_ok=True)
78-
out_path_file = Path(OUT_DIR+"pr-curve-multiple-ensemble-nodes.txt")
81+
out_path_file = Path(OUT_DIR + "pr-curve-multiple-ensemble-nodes.txt")
7982
out_path_file.unlink(missing_ok=True)
80-
ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble.csv', sep="\t", header=0)
81-
empty_ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble-empty.csv', sep="\t", header=0)
83+
ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble.csv', sep='\t', header=0)
84+
empty_ensemble_file = pd.read_csv(INPUT_DIR + 'node-ensemble-empty.csv', sep='\t', header=0)
8285
node_ensembles_dict = {'ensemble1': ensemble_file, 'ensemble2': ensemble_file, 'ensemble3': empty_ensemble_file}
83-
Evaluation.precision_recall_curve_node_ensemble(node_ensembles_dict, GS_NODE_TABLE, str(out_path_png), str(out_path_file))
86+
Evaluation.precision_recall_curve_node_ensemble(node_ensembles_dict, GS_NODE_TABLE, str(out_path_png),
87+
str(out_path_file))
8488
assert out_path_png.exists()
8589
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-pr-curve-multiple-ensemble-nodes.txt', shallow=False)

0 commit comments

Comments
 (0)