Mercurial > repos > pieterlukasse > prims_metabolomics
view test/test_export_to_metexp_tabular.py @ 7:64380b35b8a6
testing image part
author | pieter.lukasse@wur.nl |
---|---|
date | Tue, 21 Jan 2014 16:15:25 +0100 |
parents | 9d5f4f5f764b |
children | 19d8fd10248e |
line wrap: on
line source
'''Integration tests for the GCMS project''' from pkg_resources import resource_filename # @UnresolvedImport # pylint: disable=E0611 from GCMS import export_to_metexp_tabular import os.path import sys import unittest class IntegrationTest(unittest.TestCase): def test_combine_output_simple(self): ''' comment me ''' # Create out folder outdir = "output/metexp/" if not os.path.exists(outdir): os.makedirs(outdir) #Build up arguments and run rankfilter_and_caslookup_combined_file = resource_filename(__name__, "data/dummy1_produced_combine_output_single.txt") msclust_quantification_and_spectra_file = resource_filename(__name__, "data/dummy1_sim.txt") output_csv = resource_filename(__name__, outdir + "metexp_tabular.txt") sys.argv = ['test', rankfilter_and_caslookup_combined_file, msclust_quantification_and_spectra_file, output_csv] # Execute main function with arguments provided through sys.argv export_to_metexp_tabular.main() ''' # Asserts are based on reading in with process_data and comparing values of # certain columns # Check 3: library_lookup RI column, centrotype column, ri_svr column are correct: caslookup_items = combine_output._process_data(input_caslookup) rankfilter_items = combine_output._process_data(input_rankfilter) # check that the caslookup RI column is correctly maintained in its original order in # the combined file: ri_caslookup = caslookup_items['RI'] ri_combine_single = combine_result_single_items['RI'] self.assertListEqual(ri_caslookup, ri_combine_single) # check the centrotype column's integrity: centrotype_caslookup = caslookup_items['Centrotype'] centrotype_combine_single = combine_result_single_items['Centrotype'] centrotype_rankfilter = _get_centrotype_rankfilter(rankfilter_items['ID']) self.assertListEqual(centrotype_caslookup, centrotype_combine_single) self.assertListEqual(centrotype_caslookup, centrotype_rankfilter) # integration and integrity checks: file_NIST = resource_filename(__name__, "data/integration/NIST_identification_results_tabular.txt") file_NIST_items = combine_output._process_data(file_NIST) # check that rank filter output has exactly the same ID items as the original NIST input file: self.assertListEqual(file_NIST_items['ID'], rankfilter_items['ID']) # check the same for the CAS column: self.assertListEqual(_get_strippedcas(file_NIST_items['CAS']), rankfilter_items['CAS']) # now check the NIST CAS column against the cas lookup results: cas_NIST = _get_processedcas(file_NIST_items['CAS']) self.assertListEqual(cas_NIST, caslookup_items['CAS']) # now check the CAS of the combined result. If all checks are OK, it means the CAS column's order # and values remained stable throughout all steps: self.assertListEqual(rankfilter_items['CAS'], combine_result_single_items['CAS']) # check that the rankfilter RIsvr column is correctly maintained in its original order in # the combined file: risvr_rankfilter = rankfilter_items['RIsvr'] risvr_combine_single = combine_result_single_items['RIsvr'] self.assertListEqual(risvr_rankfilter, risvr_combine_single) ''' def _read_file(filename): ''' Helper method to quickly read a file @param filename: ''' with open(filename) as handle: return handle.read()