Mercurial > repos > pieterlukasse > prims_metabolomics
annotate test/test_export_to_metexp_tabular.py @ 61:d685210eef3e
fix in pdftotabular tool
author | pieter.lukasse@wur.nl |
---|---|
date | Fri, 19 Dec 2014 15:30:13 +0100 |
parents | 19d8fd10248e |
children |
rev | line source |
---|---|
0 | 1 '''Integration tests for the GCMS project''' |
2 | |
3 from pkg_resources import resource_filename # @UnresolvedImport # pylint: disable=E0611 | |
4 from GCMS import export_to_metexp_tabular | |
5 import os.path | |
6 import sys | |
7 import unittest | |
8 | |
9 | |
10 class IntegrationTest(unittest.TestCase): | |
11 | |
12 | |
21
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
13 def test_MM_calculations(self): |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
14 ''' |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
15 test the implemented method for MM calculations for |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
16 given chemical formulas |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
17 ''' |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
18 export_to_metexp_tabular.init_elements_and_masses_map() |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
19 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
20 formula = "C8H18O3" |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
21 # should be = 12.01*8 + 1.01*18 + 16*3 = 162.26 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
22 result = export_to_metexp_tabular.get_molecular_mass(formula) |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
23 self.assertEqual(162.26, result) |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
24 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
25 formula = "CH2O3Fe2Ni" |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
26 # should be = 12.01*1 + 1.01*2 + 16*3 + 55.85*2 + 58.71 = 232.44 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
27 result = export_to_metexp_tabular.get_molecular_mass(formula) |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
28 self.assertAlmostEqual(232.44, result, 2) |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
29 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
30 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
31 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
32 |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
33 |
0 | 34 def test_combine_output_simple(self): |
35 ''' | |
36 comment me | |
37 ''' | |
38 # Create out folder | |
39 outdir = "output/metexp/" | |
40 if not os.path.exists(outdir): | |
41 os.makedirs(outdir) | |
42 | |
43 #Build up arguments and run | |
44 | |
45 rankfilter_and_caslookup_combined_file = resource_filename(__name__, "data/dummy1_produced_combine_output_single.txt") | |
46 msclust_quantification_and_spectra_file = resource_filename(__name__, "data/dummy1_sim.txt") | |
47 output_csv = resource_filename(__name__, outdir + "metexp_tabular.txt") | |
48 | |
49 sys.argv = ['test', | |
50 rankfilter_and_caslookup_combined_file, | |
51 msclust_quantification_and_spectra_file, | |
21
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
52 output_csv, |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
53 'tomato', |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
54 'leafs', |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
55 'test experiment', |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
56 'pieter', |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
57 'DB5 column'] |
19d8fd10248e
* Added interface to METEXP data store, including tool to fire queries in batch mode
pieter.lukasse@wur.nl
parents:
0
diff
changeset
|
58 |
0 | 59 # Execute main function with arguments provided through sys.argv |
60 export_to_metexp_tabular.main() | |
61 | |
62 ''' | |
63 # Asserts are based on reading in with process_data and comparing values of | |
64 # certain columns | |
65 | |
66 # Check 3: library_lookup RI column, centrotype column, ri_svr column are correct: | |
67 caslookup_items = combine_output._process_data(input_caslookup) | |
68 rankfilter_items = combine_output._process_data(input_rankfilter) | |
69 | |
70 # check that the caslookup RI column is correctly maintained in its original order in | |
71 # the combined file: | |
72 ri_caslookup = caslookup_items['RI'] | |
73 ri_combine_single = combine_result_single_items['RI'] | |
74 self.assertListEqual(ri_caslookup, ri_combine_single) | |
75 | |
76 # check the centrotype column's integrity: | |
77 centrotype_caslookup = caslookup_items['Centrotype'] | |
78 centrotype_combine_single = combine_result_single_items['Centrotype'] | |
79 centrotype_rankfilter = _get_centrotype_rankfilter(rankfilter_items['ID']) | |
80 self.assertListEqual(centrotype_caslookup, centrotype_combine_single) | |
81 self.assertListEqual(centrotype_caslookup, centrotype_rankfilter) | |
82 | |
83 # integration and integrity checks: | |
84 file_NIST = resource_filename(__name__, "data/integration/NIST_identification_results_tabular.txt") | |
85 file_NIST_items = combine_output._process_data(file_NIST) | |
86 # check that rank filter output has exactly the same ID items as the original NIST input file: | |
87 self.assertListEqual(file_NIST_items['ID'], rankfilter_items['ID']) | |
88 # check the same for the CAS column: | |
89 self.assertListEqual(_get_strippedcas(file_NIST_items['CAS']), rankfilter_items['CAS']) | |
90 # now check the NIST CAS column against the cas lookup results: | |
91 cas_NIST = _get_processedcas(file_NIST_items['CAS']) | |
92 self.assertListEqual(cas_NIST, caslookup_items['CAS']) | |
93 # now check the CAS of the combined result. If all checks are OK, it means the CAS column's order | |
94 # and values remained stable throughout all steps: | |
95 self.assertListEqual(rankfilter_items['CAS'], combine_result_single_items['CAS']) | |
96 | |
97 # check that the rankfilter RIsvr column is correctly maintained in its original order in | |
98 # the combined file: | |
99 risvr_rankfilter = rankfilter_items['RIsvr'] | |
100 risvr_combine_single = combine_result_single_items['RIsvr'] | |
101 self.assertListEqual(risvr_rankfilter, risvr_combine_single) | |
102 ''' | |
103 | |
104 | |
105 | |
106 def _read_file(filename): | |
107 ''' | |
108 Helper method to quickly read a file | |
109 @param filename: | |
110 ''' | |
111 with open(filename) as handle: | |
112 return handle.read() |