def test_extract_nist_metrics(self):
     ''' Compares a subset of the complete list of metrics retrieved from the NIST output file '''
     nist_metrics = parse_metrics._extract_nist_metrics(self.nist_metrics)
     
     # TODO: manually create the full dictionary and compare with nist_metrics instead of subset testing
     nist_subset = {"ms1-2b": ["MS1 During Middle (TIC Median/1000)", "57"],
                    "ms1-5a": ["Precursor m/z - Peptide Ion m/z (Median)", "0.1460"],
                    "ms1-3b": ["MS1 ID Max (Median)", "2.3e+7"]}
     self.assertDictContainsSubset(nist_subset, nist_metrics['ms1'])
     nist_subset = {"c-4a": ["Peak Widths at Half Max over (First Decile)", "6.41"],
                    "c-1b": ["Fraction of Repeat Peptide IDs with Divergent (+ 4 min)", "0.0022"],
                    "c-2a": ["Middle Peptide Retention Time Period (Half Period)", "9.35"]}
     self.assertDictContainsSubset(nist_subset, nist_metrics['chrom'])
 def test_create_report(self):
     ''' Tests the creation of the final report file '''
     # We need to first create the complete metrics dictionary
     metrics_file = resource_filename(__name__, "data/nist_metrics.msqc")
     nist_metrics = parse_metrics._extract_nist_metrics(metrics_file)
     # Add generic metrics
     nist_metrics['generic'] = parse_metrics._extract_generic_metrics(self.rawfile, time.time())
     # Create report (move to the QC directory, otherwise template is not found
     restore_path = os.getcwd()
     os.chdir('QC')
     run_msqc_pipeline._create_report(self.temp_folder, self.rawfilebase, nist_metrics)
     # Test for presence of the report file
     report_file = '{0}/{1}'.format(self.temp_folder, 'index.html')
     self.failUnless(os.path.exists(report_file))
     # Return to the test directory
     os.chdir(restore_path)
    def test_export_metrics_json(self):
        '''
        Tests the writing of metrics in JSON format
        '''
        # Create temporary directory and store metrics in JSON format
        temp_folder = tempfile.mkdtemp(prefix='test_parse_metrics_')

        nist_metrics = parse_metrics._extract_nist_metrics(self.nist_metrics)
        parse_metrics.export_metrics_json(nist_metrics, temp_folder)
        json_metrics = os.path.join(temp_folder, 'metrics.json')
        # Test if JSON file is present
        self.failUnless(os.path.exists(json_metrics))

        # Read JSON file and verify
        nist_metrics = json.load(open('{0}/{1}'.format(temp_folder, 'metrics.json', 'r')))
        self.assertEqual('589.90', nist_metrics['ion']['is-2'][1])

        shutil.rmtree(temp_folder)