Mercurial > repos > pieterlukasse > prims_metabolomics
comparison test/test_query_metexp.py @ 1:071a185c2ced
new tools
| author | pieter.lukasse@wur.nl |
|---|---|
| date | Fri, 24 Oct 2014 12:52:56 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:4b94bb2d381c | 1:071a185c2ced |
|---|---|
| 1 '''Integration tests for the GCMS project''' | |
| 2 | |
| 3 from pkg_resources import resource_filename # @UnresolvedImport # pylint: disable=E0611 | |
| 4 from GCMS import query_metexp | |
| 5 import os.path | |
| 6 import sys | |
| 7 import unittest | |
| 8 | |
| 9 | |
| 10 class IntegrationTest(unittest.TestCase): | |
| 11 | |
| 12 | |
| 13 # def test_MM_calculations(self): | |
| 14 # ''' | |
| 15 # test the implemented method for MM calculations for | |
| 16 # given chemical formulas | |
| 17 # ''' | |
| 18 # export_to_metexp_tabular.init_elements_and_masses_map() | |
| 19 # | |
| 20 # formula = "C8H18O3" | |
| 21 # # should be = 12.01*8 + 1.01*18 + 16*3 = 162.26 | |
| 22 # result = export_to_metexp_tabular.get_molecular_mass(formula) | |
| 23 # self.assertEqual(162.26, result) | |
| 24 # | |
| 25 # formula = "CH2O3Fe2Ni" | |
| 26 # # should be = 12.01*1 + 1.01*2 + 16*3 + 55.85*2 + 58.71 = 232.44 | |
| 27 # result = export_to_metexp_tabular.get_molecular_mass(formula) | |
| 28 # self.assertAlmostEqual(232.44, result, 2) | |
| 29 # | |
| 30 # | |
| 31 # | |
| 32 | |
| 33 | |
| 34 def test_simple(self): | |
| 35 ''' | |
| 36 Simple initial test | |
| 37 ''' | |
| 38 # Create out folder | |
| 39 outdir = "output/metexp_query/" | |
| 40 if not os.path.exists(outdir): | |
| 41 os.makedirs(outdir) | |
| 42 | |
| 43 #Build up arguments and run | |
| 44 | |
| 45 # input_file = sys.argv[1] | |
| 46 # molecular_mass_col = sys.argv[2] | |
| 47 # formula_col = sys.argv[3] | |
| 48 # metexp_dblink_file = sys.argv[4] | |
| 49 # output_result = sys.argv[5] | |
| 50 | |
| 51 input_file = resource_filename(__name__, "data/metexp_query_tabular.txt") | |
| 52 casid_col = "CAS" | |
| 53 formula_col = "FORMULA" | |
| 54 molecular_mass_col = "MM" | |
| 55 metexp_dblink_file = resource_filename(__name__, "data/METEXP Test DB.txt") | |
| 56 output_result = resource_filename(__name__, outdir + "metexp_query_results_added.txt") | |
| 57 | |
| 58 sys.argv = ['test', | |
| 59 input_file, | |
| 60 casid_col, | |
| 61 formula_col, | |
| 62 molecular_mass_col, | |
| 63 metexp_dblink_file, | |
| 64 'GC', | |
| 65 output_result] | |
| 66 | |
| 67 # Execute main function with arguments provided through sys.argv | |
| 68 query_metexp.main() | |
| 69 | |
| 70 # TODO - asserts (base them on DB being filled with test data form metexp unit test for upload method) | |
| 71 # PA | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 def _read_file(filename): | |
| 77 ''' | |
| 78 Helper method to quickly read a file | |
| 79 @param filename: | |
| 80 ''' | |
| 81 with open(filename) as handle: | |
| 82 return handle.read() |
