annotate test/test_query_metexp_LARGE.py @ 0:dffc38727496

initial commit
author pieter.lukasse@wur.nl
date Sat, 07 Feb 2015 22:02:00 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
1 '''Integration tests for the GCMS project'''
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
2
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
3 from pkg_resources import resource_filename # @UnresolvedImport # pylint: disable=E0611
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
4 from GCMS import query_metexp
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
5 import os.path
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
6 import sys
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
7 import unittest
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
8
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
9
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
10 class IntegrationTest(unittest.TestCase):
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
11
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
12
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
13 # def test_MM_calculations(self):
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
14 # '''
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
15 # test the implemented method for MM calculations for
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
16 # given chemical formulas
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
17 # '''
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
18 # export_to_metexp_tabular.init_elements_and_masses_map()
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
19 #
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
20 # formula = "C8H18O3"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
21 # # should be = 12.01*8 + 1.01*18 + 16*3 = 162.26
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
22 # result = export_to_metexp_tabular.get_molecular_mass(formula)
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
23 # self.assertEqual(162.26, result)
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
24 #
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
25 # formula = "CH2O3Fe2Ni"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
26 # # should be = 12.01*1 + 1.01*2 + 16*3 + 55.85*2 + 58.71 = 232.44
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
27 # result = export_to_metexp_tabular.get_molecular_mass(formula)
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
28 # self.assertAlmostEqual(232.44, result, 2)
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
29 #
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
30 #
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
31 #
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
32
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
33
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
34 def test_large(self):
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
35 '''
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
36 Simple test, but on larger set, last test executed in 28s
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
37 '''
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
38 # Create out folder
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
39 outdir = "output/metexp_query/"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
40 if not os.path.exists(outdir):
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
41 os.makedirs(outdir)
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
42
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
43 #Build up arguments and run
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
44
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
45 # input_file = sys.argv[1]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
46 # molecular_mass_col = sys.argv[2]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
47 # formula_col = sys.argv[3]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
48 # metexp_dblink_file = sys.argv[4]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
49 # output_result = sys.argv[5]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
50
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
51 input_file = resource_filename(__name__, "data/metexp_query_tabular_large.txt")
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
52 casid_col = "CAS"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
53 formula_col = "FORMULA"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
54 molecular_mass_col = "MM"
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
55 metexp_dblink_file = resource_filename(__name__, "data/METEXP Test DB.txt")
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
56 output_result = resource_filename(__name__, outdir + "metexp_query_results_added_LARGE.txt")
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
57
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
58 sys.argv = ['test',
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
59 input_file,
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
60 casid_col,
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
61 formula_col,
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
62 molecular_mass_col,
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
63 metexp_dblink_file,
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
64 'GC',
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
65 output_result]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
66
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
67 # Execute main function with arguments provided through sys.argv
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
68 query_metexp.main()
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
69
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
70
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
71
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
72
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
73 def _read_file(filename):
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
74 '''
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
75 Helper method to quickly read a file
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
76 @param filename:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
77 '''
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
78 with open(filename) as handle:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
79 return handle.read()