Mercurial > repos > pieterlukasse > prims_metabolomics
comparison test/test_export_to_metexp_tabular.py @ 0:4b94bb2d381c
Initial commit to toolshed
| author | pieter.lukasse@wur.nl |
|---|---|
| date | Thu, 16 Jan 2014 13:22:38 +0100 |
| parents | |
| children | 071a185c2ced |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4b94bb2d381c |
|---|---|
| 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 | |
| 13 def test_combine_output_simple(self): | |
| 14 ''' | |
| 15 comment me | |
| 16 ''' | |
| 17 # Create out folder | |
| 18 outdir = "output/metexp/" | |
| 19 if not os.path.exists(outdir): | |
| 20 os.makedirs(outdir) | |
| 21 | |
| 22 #Build up arguments and run | |
| 23 | |
| 24 rankfilter_and_caslookup_combined_file = resource_filename(__name__, "data/dummy1_produced_combine_output_single.txt") | |
| 25 msclust_quantification_and_spectra_file = resource_filename(__name__, "data/dummy1_sim.txt") | |
| 26 output_csv = resource_filename(__name__, outdir + "metexp_tabular.txt") | |
| 27 | |
| 28 sys.argv = ['test', | |
| 29 rankfilter_and_caslookup_combined_file, | |
| 30 msclust_quantification_and_spectra_file, | |
| 31 output_csv] | |
| 32 # Execute main function with arguments provided through sys.argv | |
| 33 export_to_metexp_tabular.main() | |
| 34 | |
| 35 ''' | |
| 36 # Asserts are based on reading in with process_data and comparing values of | |
| 37 # certain columns | |
| 38 | |
| 39 # Check 3: library_lookup RI column, centrotype column, ri_svr column are correct: | |
| 40 caslookup_items = combine_output._process_data(input_caslookup) | |
| 41 rankfilter_items = combine_output._process_data(input_rankfilter) | |
| 42 | |
| 43 # check that the caslookup RI column is correctly maintained in its original order in | |
| 44 # the combined file: | |
| 45 ri_caslookup = caslookup_items['RI'] | |
| 46 ri_combine_single = combine_result_single_items['RI'] | |
| 47 self.assertListEqual(ri_caslookup, ri_combine_single) | |
| 48 | |
| 49 # check the centrotype column's integrity: | |
| 50 centrotype_caslookup = caslookup_items['Centrotype'] | |
| 51 centrotype_combine_single = combine_result_single_items['Centrotype'] | |
| 52 centrotype_rankfilter = _get_centrotype_rankfilter(rankfilter_items['ID']) | |
| 53 self.assertListEqual(centrotype_caslookup, centrotype_combine_single) | |
| 54 self.assertListEqual(centrotype_caslookup, centrotype_rankfilter) | |
| 55 | |
| 56 # integration and integrity checks: | |
| 57 file_NIST = resource_filename(__name__, "data/integration/NIST_identification_results_tabular.txt") | |
| 58 file_NIST_items = combine_output._process_data(file_NIST) | |
| 59 # check that rank filter output has exactly the same ID items as the original NIST input file: | |
| 60 self.assertListEqual(file_NIST_items['ID'], rankfilter_items['ID']) | |
| 61 # check the same for the CAS column: | |
| 62 self.assertListEqual(_get_strippedcas(file_NIST_items['CAS']), rankfilter_items['CAS']) | |
| 63 # now check the NIST CAS column against the cas lookup results: | |
| 64 cas_NIST = _get_processedcas(file_NIST_items['CAS']) | |
| 65 self.assertListEqual(cas_NIST, caslookup_items['CAS']) | |
| 66 # now check the CAS of the combined result. If all checks are OK, it means the CAS column's order | |
| 67 # and values remained stable throughout all steps: | |
| 68 self.assertListEqual(rankfilter_items['CAS'], combine_result_single_items['CAS']) | |
| 69 | |
| 70 # check that the rankfilter RIsvr column is correctly maintained in its original order in | |
| 71 # the combined file: | |
| 72 risvr_rankfilter = rankfilter_items['RIsvr'] | |
| 73 risvr_combine_single = combine_result_single_items['RIsvr'] | |
| 74 self.assertListEqual(risvr_rankfilter, risvr_combine_single) | |
| 75 ''' | |
| 76 | |
| 77 | |
| 78 | |
| 79 def _read_file(filename): | |
| 80 ''' | |
| 81 Helper method to quickly read a file | |
| 82 @param filename: | |
| 83 ''' | |
| 84 with open(filename) as handle: | |
| 85 return handle.read() |
