9
9
@pytest .mark .parametrize ("label,rid" , [
10
10
("foo" , None ),
11
11
("2644605" , None ),
12
- ("R-HSA-2644605" , "2644605" ),
13
- ("r-hsa-2644605" , "2644605" ),
14
- ("foo_R-HSA-2644605_boo" , "2644605" ),
15
- ("foo_r-hsa-2644605_boo" , "2644605" ),
16
- ("foo.R-HSA-2644605-boo" , "2644605" ),
17
- ("foo-R-HSA-2644605.boo" , "2644605" ),
18
- ("foo-R-HSA-2644605boo" , "2644605" ),
19
- ("http://www.reactome.org/content/detail/R-HSA-2644605" , "2644605" ),
12
+ ("R-HSA-2644605" , "R-HSA- 2644605" ),
13
+ ("r-hsa-2644605" , "R-HSA- 2644605" ),
14
+ ("foo_R-HSA-2644605_boo" , "R-HSA- 2644605" ),
15
+ ("foo_r-hsa-2644605_boo" , "R-HSA- 2644605" ),
16
+ ("foo.R-HSA-2644605-boo" , "R-HSA- 2644605" ),
17
+ ("foo-R-HSA-2644605.boo" , "R-HSA- 2644605" ),
18
+ ("foo-R-HSA-2644605boo" , "R-HSA- 2644605" ),
19
+ ("http://www.reactome.org/content/detail/R-HSA-2644605" , "R-HSA- 2644605" ),
20
20
])
21
21
def test_extract_reactome_id (label , rid ):
22
22
assert rid == extract_reactome_id (label )
23
23
24
24
25
- @pytest .mark .parametrize ("label,title" , [
26
- ("foo" , "N/A" ),
27
- ("foo.R-HSA-2644605-boo" , "FBXW7 Mutants and NOTCH1 in Cancer" ),
25
+ @pytest .mark .parametrize ("label,title,offline" , [
26
+ ("foo" , "N/A" , False ),
27
+ ("foo" , "N/A" , True ),
28
+ ("foo.R-HSA-2644605-boo" , "FBXW7 Mutants and NOTCH1 in Cancer" , False ),
29
+ ("foo.R-HSA-2644605-boo" , "FBXW7 Mutants and NOTCH1 in Cancer" , True ),
28
30
])
29
- def test_fetch_title (label , title ):
30
- assert title == fetch_title (label )
31
+ def test_fetch_title (test_data , label , title , offline ):
32
+ kw = {}
33
+ if offline :
34
+ kw ['pathways_db_path' ] = test_data ("reactome/ReactomePathways.txt" )
35
+
36
+ assert title == fetch_title (label , ** kw )[0 ]
37
+
38
+
39
+ @pytest .mark .parametrize ("offline" , [True , False ])
40
+ def test_fetch_titles (test_data , offline ):
41
+ kw = {}
42
+ if offline :
43
+ kw ['pathways_db_path' ] = test_data ("reactome/ReactomePathways.txt" )
44
+
45
+ assert ['FBXW7 Mutants and NOTCH1 in Cancer' , '2-LTR circle formation' ] == fetch_title (
46
+ "R-HSA-2644605" , "R-HSA-164843" , ** kw
47
+ )
31
48
32
49
33
50
def test_cli_help (capfd ):
34
51
run ("python" , "{}/reports/annotate_reactome.py" .format (PROJECT_ROOT_PATH ),
35
52
"-h" )
36
53
output = capfd .readouterr ()
37
54
assert """python {}/reports/annotate_reactome.py -h
38
- usage: annotate_reactome.py [-h] [-F FS] [-o PATH] PATH INT_OR_STR
55
+ usage: annotate_reactome.py [-h] [--db PATH] [- F FS] [-o PATH] PATH INT_OR_STR
39
56
40
57
Annotates table containing http://www.reactome.org pathways ids (R-HSA-nnnnn)
41
58
with pathways titles
@@ -47,37 +64,48 @@ def test_cli_help(capfd):
47
64
48
65
optional arguments:
49
66
-h, --help show this help message and exit
67
+ --db PATH ReactomePathways.txt file path (default: None)
50
68
-F FS Field separator, auto-detect if not specified (default: None)
51
69
-o PATH Output path (default: None)
52
70
""" .format (PROJECT_ROOT_PATH ) == output [0 ]
53
71
assert "" == output [1 ]
54
72
55
73
56
- @pytest .mark .parametrize ("file,args,result_stdout,result_stderr,fresult" , [
57
- ("empty.csv" , ["1" ], "" , "File is empty: " , None ),
58
- ("no_header_comma.csv" , ["1" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None ),
59
- ("no_header_comma.csv" , ["0" ], "" , "Column index should be >= 1, but was: 0" , None ),
60
- ("no_header_comma.csv" , ["1" ], "" , "" , "no_header_comma.result.txt" ),
61
- ("header_index_comma.csv" , ["1" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None ),
62
- ("header_index_comma.csv" , ["1" ], "" , "" , "header_index_comma.result1.txt" ),
63
- ("header_index_comma.csv" , ["''" ], "" , "" , "header_index_comma.result2.txt" ),
64
- ("header_colname_comma.csv" , ["1" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None ),
65
- ("header_colname_comma.csv" , ["1" ], "" , "" , "header_colname_comma.result1.txt" ),
66
- ("header_colname_comma.csv" , ["data" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None ),
67
- ("header_colname_comma.csv" , ["data" ], "" , "" , "header_colname_comma.result2.txt" ),
74
+ @pytest .mark .parametrize ("file,args,result_stdout,result_stderr,fresult,offline" , [
75
+ # offline
76
+ ("empty.csv" , ["1" ], "" , "File is empty: " , None , True ),
77
+ ("no_header_comma.csv" , ["1" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None , True ),
78
+ ("no_header_comma.csv" , ["0" ], "" , "Column index should be >= 1, but was: 0" , None , True ),
79
+ ("no_header_comma.csv" , ["1" ], "" , "" , "no_header_comma.result.txt" , True ),
80
+ ("header_index_comma.csv" , ["1" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None , True ),
81
+ ("header_index_comma.csv" , ["1" ], "" , "" , "header_index_comma.result1.txt" , True ),
82
+ ("header_index_comma.csv" , ["''" ], "" , "" , "header_index_comma.result2.txt" , True ),
83
+ ("header_colname_comma.csv" , ["1" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None , True ),
84
+ ("header_colname_comma.csv" , ["1" ], "" , "" , "header_colname_comma.result1.txt" , True ),
85
+ ("header_colname_comma.csv" , ["data" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None , True ),
86
+ ("header_colname_comma.csv" , ["data" ], "" , "" , "header_colname_comma.result2.txt" , True ),
68
87
("header_colname_comma.csv" , ["data" , "-F','" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" ,
69
- None ),
70
- ("header_colname_tab.tsv" , ["data" ], "" , "" , "header_colname_comma.result2.txt" ),
71
- ("header_colname_tab.tsv" , ["data" , "-F'\t '" ], "" , "" , "header_colname_tab.result.txt" ),
88
+ None , True ),
89
+ ("header_colname_tab.tsv" , ["data" ], "" , "" , "header_colname_comma.result2.txt" , True ),
90
+ ("header_colname_tab.tsv" , ["data" , "-F'\t '" ], "" , "" , "header_colname_tab.result.txt" , True ),
72
91
("header_colname_comma.csv" , ["data" , "-F' '" ], "" ,
73
- "KeyError: 'the label [data] is not in the [columns]'" , None ),
92
+ "KeyError: 'the label [data] is not in the [columns]'" , None , True ),
93
+
94
+ # using web access:
95
+ ("header_colname_comma.csv" , ["1" ], "FBXW7 Mutants and NOTCH1 in Cancer" , "" , None , False ),
74
96
])
75
- def test_foo (test_data , tmp_path , capfd , file , args , result_stdout , result_stderr , fresult ):
97
+ def test_cli (test_data , tmp_path , capfd , file , args , result_stdout , result_stderr , fresult ,
98
+ offline ):
99
+
100
+ pathways_db_path = test_data ("reactome/ReactomePathways.txt" ) if offline else None
76
101
input_path = str (test_data ("reactome/" + file ))
77
102
78
103
if fresult :
79
104
args .append ("-o " + str (tmp_path / "result.txt" ))
80
105
106
+ if pathways_db_path :
107
+ args .append ("--db " + pathways_db_path )
108
+
81
109
run (
82
110
"python" , "{}/reports/annotate_reactome.py" .format (PROJECT_ROOT_PATH ),
83
111
input_path ,
0 commit comments