Mercurial > repos > pieterlukasse > prims_metabolomics
view rankfilter_GCMS/test/test_rankfilter.py @ 4:80075a4c6543
updated image paths
author | pieter.lukasse@wur.nl |
---|---|
date | Fri, 17 Jan 2014 12:43:05 +0100 |
parents | 9d5f4f5f764b |
children |
line wrap: on
line source
''' Created on Mar 13, 2012 @author: marcelk ''' from GCMS.rankfilter_GCMS.rankfilter import get_data, calibrate, calibrate_poly, convert_rt, convert_rt_poly from pkg_resources import resource_filename # @UnresolvedImport # pylint: disable=E0611 import unittest class Test(unittest.TestCase): def setUp(self): self.calibration = resource_filename(__name__, "data/calibration.txt") self.sample = resource_filename(__name__, "data/sample.txt") def test_get_data(self): samples = get_data(self.sample, ['CAS', 'Name', 'R.T.', 'Forward', 'Reverse', 'Formula']) self.assertEqual(['C29H50O', 'C29H50O', 'C29H50O', 'C29H50O', 'C29H50O', 'C28H48O', 'C28H48O', 'C28H48O', 'C28H48O', 'C27H44O2', 'C29H50O2', 'C29H50O2', 'C29H50O2', 'C29H50O2', 'C29H50O2', 'C28H48O2', 'C28H48O2', 'C28H48O2', 'C28H48O2', 'C30H50O3', 'C29H50O', 'C29H50O', 'C29H50O', 'C29H50O'], samples['Formula']) def test_calibrate(self): standards = get_data(self.calibration, ['Name', 'R.T.', 'RI']) coeff = calibrate(standards) self.assertAlmostEqual(103.19073523551653, coeff[0], 5) self.assertAlmostEqual(277.14374835349395, coeff[1], 5) def test_calibrate_poly(self): standards = get_data(self.calibration, ['Name', 'R.T.', 'RI']) poly_cal = calibrate_poly(standards) self.assertAlmostEqual(0.028897105229818407, poly_cal[0], 5) self.assertAlmostEqual(0.704572097468386, poly_cal[1], 5) self.assertAlmostEqual(51.636852478526357, poly_cal[2], 5) self.assertAlmostEqual(704.95499738104672, poly_cal[3], 5) def test_convert_rt(self): standards = get_data(self.calibration, ['Name', 'R.T.', 'RI']) coeff = calibrate(standards) convert = convert_rt({'R.T.': [5, 10, 15, 20]}, coeff) self.assertAlmostEqual(793.09742453, convert['RIexp'][0], 5) self.assertAlmostEqual(1309.05110071, convert['RIexp'][1], 5) self.assertAlmostEqual(1825.00477689, convert['RIexp'][2], 5) self.assertAlmostEqual(2340.95845306, convert['RIexp'][3], 5) def test_convert_rt_poly(self): standards = get_data(self.calibration, ['Name', 'R.T.', 'RI']) poly_cal = calibrate_poly(standards) convert = convert_rt_poly({'R.T.': [5, 10, 15, 20]}, poly_cal) self.assertAlmostEqual(984.36570036, convert['RIexp'][0], 5) self.assertAlmostEqual(1320.67783714, convert['RIexp'][1], 5) self.assertAlmostEqual(1735.56423664, convert['RIexp'][2], 5) self.assertAlmostEqual(2250.69772778, convert['RIexp'][3], 5) if __name__ == "__main__": #import sys;sys.argv = ['', 'Test.testName'] unittest.main()