Skip to content

Commit 892b364

Browse files
authored
Merge pull request #340 from tristan-f-r/data-pickle-repr
test(evaluate): dynamically serialize data.pickle
2 parents 43c284d + 8bdbe39 commit 892b364

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

test/evaluate/input/data.pickle

-3.1 KB
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
A B 0.98 U
2+
B C 0.77 U
3+
C D 0.77 U
4+
D E 0.77 U
5+
E F 0.77 U
6+
F G 0.12 U
7+
G H 0.89 U
8+
H I 0.59 U
9+
I J 0.50 U
10+
J K 0.76 U
11+
K L 0.92 U
12+
L M 0.66 U
13+
M N 0.66 U
14+
N O 0.66 U
15+
O P 0.66 U
16+
P Q 0.66 U
17+
Q R 0.66 U
18+
R S 0.66 U
19+
S T 0.66 U
20+
T U 0.66 U
21+
U V 0.66 U
22+
V W 0.66 U
23+
W X 0.66 U
24+
X Y 0.66 U
25+
Y Z 0.66 U
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODEID prize active dummy sources targets
2+
N
3+
C 5.7 True True

test/evaluate/test_evaluate.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import filecmp
2+
import pickle
23
from pathlib import Path
34

45
import pandas as pd
56

67
import spras.analysis.ml as ml
8+
from spras.dataset import Dataset
79
from spras.evaluation import Evaluation
810

911
INPUT_DIR = 'test/evaluate/input/'
@@ -17,10 +19,24 @@ class TestEvaluate:
1719
@classmethod
1820
def setup_class(cls):
1921
"""
20-
Create the expected output directory
22+
Create the expected output directory and pickled toy dataset file
2123
"""
2224
Path(OUT_DIR).mkdir(parents=True, exist_ok=True)
2325

26+
out_dataset = Path(OUT_DIR, 'data.pickle')
27+
out_dataset.unlink(missing_ok=True)
28+
29+
dataset = Dataset({
30+
"label": 'toy',
31+
"edge_files": ["input-interactome.txt"],
32+
"node_files": ["input-nodes.txt"],
33+
"data_dir": INPUT_DIR,
34+
"other_files": []
35+
})
36+
37+
with open(out_dataset, "wb") as f:
38+
pickle.dump(dataset, f)
39+
2440
def test_precision_recall_pca_chosen_pathway(self):
2541
output_file = Path(OUT_DIR + "test-pr-per-pathway-pca-chosen.txt")
2642
output_file.unlink(missing_ok=True)
@@ -63,7 +79,7 @@ def test_node_ensemble(self):
6379
out_path_file = Path(OUT_DIR + 'node-ensemble.csv')
6480
out_path_file.unlink(missing_ok=True)
6581
ensemble_network = [INPUT_DIR + 'ensemble-network.tsv']
66-
input_network = INPUT_DIR + 'data.pickle'
82+
input_network = OUT_DIR + 'data.pickle'
6783
node_ensemble_dict = Evaluation.edge_frequency_node_ensemble(GS_NODE_TABLE, ensemble_network, input_network)
6884
node_ensemble_dict['ensemble'].to_csv(out_path_file, sep='\t', index=False)
6985
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-node-ensemble.csv', shallow=False)
@@ -72,7 +88,7 @@ def test_empty_node_ensemble(self):
7288
out_path_file = Path(OUT_DIR + 'empty-node-ensemble.csv')
7389
out_path_file.unlink(missing_ok=True)
7490
empty_ensemble_network = [INPUT_DIR + 'empty-ensemble-network.tsv']
75-
input_network = INPUT_DIR + 'data.pickle'
91+
input_network = OUT_DIR + 'data.pickle'
7692
node_ensemble_dict = Evaluation.edge_frequency_node_ensemble(GS_NODE_TABLE, empty_ensemble_network,
7793
input_network)
7894
node_ensemble_dict['empty'].to_csv(out_path_file, sep='\t', index=False)
@@ -84,7 +100,7 @@ def test_multiple_node_ensemble(self):
84100
out_path_empty_file = Path(OUT_DIR + 'empty-node-ensemble.csv')
85101
out_path_empty_file.unlink(missing_ok=True)
86102
ensemble_networks = [INPUT_DIR + 'ensemble-network.tsv', INPUT_DIR + 'empty-ensemble-network.tsv']
87-
input_network = INPUT_DIR + 'data.pickle'
103+
input_network = OUT_DIR + 'data.pickle'
88104
node_ensemble_dict = Evaluation.edge_frequency_node_ensemble(GS_NODE_TABLE, ensemble_networks, input_network)
89105
node_ensemble_dict['ensemble'].to_csv(out_path_file, sep='\t', index=False)
90106
assert filecmp.cmp(out_path_file, EXPECT_DIR + 'expected-node-ensemble.csv', shallow=False)

0 commit comments

Comments
 (0)