-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_file_loading.py
99 lines (74 loc) · 3.26 KB
/
test_file_loading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sys
import os
# Making sure the root is in the path, kind of a hack
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from massql import msql_fileloading
import json
import pytest
import time
def test_improper_file():
with pytest.raises(Exception):
msql_fileloading.load_file('file.cdf')
def test_gnps_library_loading():
ms1_df, ms2_df = msql_fileloading.load_data("tests/data/gnps-library.json")
print(ms2_df[ms2_df["scan"] == "CCMSLIB00000072227"])
assert(len(ms2_df[ms2_df["scan"] == "CCMSLIB00000072227"]) > 300)
def test_mzml_load():
print("Loading pymzML")
ms1_df, ms2_df = msql_fileloading._load_data_mzML2("tests/data/JB_182_2_fe.mzML")
print(ms2_df)
assert(max(ms2_df["rt"]) > 0)
print("Loading Pyteomics")
ms1_df, ms2_df = msql_fileloading._load_data_mzML_pyteomics("tests/data/JB_182_2_fe.mzML")
print(ms2_df)
assert(max(ms2_df["rt"]) > 0)
def test_mzxml_load():
ms1_df, ms2_df = msql_fileloading.load_data("tests/data/T04251505.mzXML", cache=None)
def test_mgf_load():
ms1_df, ms2_df = msql_fileloading.load_data("tests/data/specs_ms.mgf", cache=None)
def test_mzml_mobility_load():
ms1_df, ms2_df = msql_fileloading.load_data("tests/data/meoh_water_ms2_1_31_1_395.mzML", cache=None)
assert("mobility" in ms2_df)
assert(max(ms2_df["rt"]) > 0)
def test_mzml_rt_seconds():
ms1_df, ms2_df = msql_fileloading.load_data("tests/data/1810E-II.mzML", cache=None)
print(ms2_df)
assert(max(ms2_df["rt"]) < 60)
def test_waters_load():
# This has UV spectra in it, we need to handle that gracefully
ms1_df, ms2_df = msql_fileloading.load_data("tests/data/GT15A.mzML", cache=None)
def test_cache_feather():
# Measure start time
start_time = time.time()
msql_fileloading.load_data("tests/data/JB_182_2_fe.mzML", cache="feather")
msql_fileloading.load_data("tests/data/T04251505.mzXML", cache="feather")
msql_fileloading.load_data("tests/data/meoh_water_ms2_1_31_1_395.mzML", cache="feather")
# Measure end time
end_time = time.time()
print("Feather time: ", end_time - start_time)
def test_nocache():
# Measure start time
start_time = time.time()
msql_fileloading.load_data("tests/data/JB_182_2_fe.mzML", cache=None)
msql_fileloading.load_data("tests/data/T04251505.mzXML", cache=None)
msql_fileloading.load_data("tests/data/meoh_water_ms2_1_31_1_395.mzML", cache=None)
# Measure end time
end_time = time.time()
print("No cache time: ", end_time - start_time)
def test_cache_filename():
input_filename = "tests/data/JB_182_2_fe.mzML"
ms1_filename, ms2_filename = msql_fileloading._determine_feather_cache_filename(input_filename)
assert(ms1_filename == "tests/data/JB_182_2_fe.mzML_ms1.msql.feather")
ms1_filename, ms2_filename = msql_fileloading._determine_feather_cache_filename(input_filename, cache_file="cache_file")
ms1_filename, ms2_filename = msql_fileloading._determine_feather_cache_filename(input_filename, cache_dir="cache_file")
print(ms1_filename, ms2_filename)
def main():
#test_mzml_load()
#test_mzml_mobility_load()
#test_mzml_rt_seconds()
#test_waters_load()
#test_cache_feather()
#test_nocache()
test_cache_filename()
if __name__ == "__main__":
main()