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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
1 '''Integration tests for the GCMS project'''
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
2
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
3 from pkg_resources import resource_filename # @UnresolvedImport # pylint: disable=E0611
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
4 from GCMS import export_to_metexp_tabular
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
5 import os.path
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
6 import sys
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
7 import unittest
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
8
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
9
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
10 class IntegrationTest(unittest.TestCase):
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
11
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
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
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
34 def test_combine_output_simple(self):
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
35 '''
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
36 comment me
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
37 '''
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
38 # Create out folder
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
39 outdir = "output/metexp/"
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
40 if not os.path.exists(outdir):
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
41 os.makedirs(outdir)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
42
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
43 #Build up arguments and run
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
44
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
45 rankfilter_and_caslookup_combined_file = resource_filename(__name__, "data/dummy1_produced_combine_output_single.txt")
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
46 msclust_quantification_and_spectra_file = resource_filename(__name__, "data/dummy1_sim.txt")
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
47 output_csv = resource_filename(__name__, outdir + "metexp_tabular.txt")
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
48
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
49 sys.argv = ['test',
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
50 rankfilter_and_caslookup_combined_file,
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
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
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
59 # Execute main function with arguments provided through sys.argv
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
60 export_to_metexp_tabular.main()
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
61
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
62 '''
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
63 # Asserts are based on reading in with process_data and comparing values of
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
64 # certain columns
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
65
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
66 # Check 3: library_lookup RI column, centrotype column, ri_svr column are correct:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
67 caslookup_items = combine_output._process_data(input_caslookup)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
68 rankfilter_items = combine_output._process_data(input_rankfilter)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
69
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
70 # check that the caslookup RI column is correctly maintained in its original order in
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
71 # the combined file:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
72 ri_caslookup = caslookup_items['RI']
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
73 ri_combine_single = combine_result_single_items['RI']
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
74 self.assertListEqual(ri_caslookup, ri_combine_single)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
75
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
76 # check the centrotype column's integrity:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
77 centrotype_caslookup = caslookup_items['Centrotype']
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
78 centrotype_combine_single = combine_result_single_items['Centrotype']
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
79 centrotype_rankfilter = _get_centrotype_rankfilter(rankfilter_items['ID'])
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
80 self.assertListEqual(centrotype_caslookup, centrotype_combine_single)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
81 self.assertListEqual(centrotype_caslookup, centrotype_rankfilter)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
82
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
83 # integration and integrity checks:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
84 file_NIST = resource_filename(__name__, "data/integration/NIST_identification_results_tabular.txt")
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
85 file_NIST_items = combine_output._process_data(file_NIST)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
86 # check that rank filter output has exactly the same ID items as the original NIST input file:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
87 self.assertListEqual(file_NIST_items['ID'], rankfilter_items['ID'])
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
88 # check the same for the CAS column:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
89 self.assertListEqual(_get_strippedcas(file_NIST_items['CAS']), rankfilter_items['CAS'])
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
90 # now check the NIST CAS column against the cas lookup results:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
91 cas_NIST = _get_processedcas(file_NIST_items['CAS'])
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
92 self.assertListEqual(cas_NIST, caslookup_items['CAS'])
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
93 # now check the CAS of the combined result. If all checks are OK, it means the CAS column's order
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
94 # and values remained stable throughout all steps:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
95 self.assertListEqual(rankfilter_items['CAS'], combine_result_single_items['CAS'])
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
96
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
97 # check that the rankfilter RIsvr column is correctly maintained in its original order in
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
98 # the combined file:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
99 risvr_rankfilter = rankfilter_items['RIsvr']
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
100 risvr_combine_single = combine_result_single_items['RIsvr']
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
101 self.assertListEqual(risvr_rankfilter, risvr_combine_single)
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
102 '''
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
103
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
104
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
105
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
106 def _read_file(filename):
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
107 '''
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
108 Helper method to quickly read a file
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
109 @param filename:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
110 '''
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
111 with open(filename) as handle:
9d5f4f5f764b Initial commit to toolshed
pieter.lukasse@wur.nl
parents:
diff changeset
112 return handle.read()