from cgstats.utils import stats

def test_missing_parse():
    """After demuxing this run, stats failed on empty pf_pc of P012. This test is to make sure we get a 0 now"""

    rs = stats.parse('tests/fixtures/170616_M03284_0062_000000000-B58CV/Unaligned-Y301I8I8Y301/Basecall_Stats_000000000-B58CV/Demultiplex_Stats.htm')

    assert rs['1']['P012']['pf_pc'] == 0

def test_parse():
    assert stats.parse('tests/fixtures/150114_D00134_0168_AHB07NADXX/Unaligned/Basecall_Stats_HB07NADXX/Demultiplex_Stats.htm') == {
        '1': {
            'SIB910A3_sureselect6': {'barcode': 'GCCAAT',
                                    'lane': '1',
                                    'mean_quality_score': 36.45,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '454557',
                                    'q30_bases_pc': 94.33,
                                    'raw_clusters_pc': 13.33,
                                    'readcounts': 43225752,
                                    'sample_name': 'SIB910A3_sureselect6',
                                    'yield_mb': 4366},
            'SIB911A1_sureselect4': {'barcode': 'TGACCA',
                                    'lane': '1',
                                    'mean_quality_score': 36.51,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '959191',
                                    'q30_bases_pc': 94.48,
                                    'raw_clusters_pc': 15.96,
                                    'readcounts': 51778316,
                                    'sample_name': 'SIB911A1_sureselect4',
                                    'yield_mb': 5230},
            'SIB911A2_sureselect5': {'barcode': 'ACAGTG',
                                    'lane': '1',
                                    'mean_quality_score': 36.46,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '959191',
                                    'q30_bases_pc': 94.31,
                                    'raw_clusters_pc': 12.20,
                                    'readcounts': 39563494,
                                    'sample_name': 'SIB911A2_sureselect5',
                                    'yield_mb': 3996},
            'SIB914A11_sureselect11': {'barcode': 'GGCTAC',
                                      'lane': '1',
                                      'mean_quality_score': 36.27,
                                      'perfect_barcodes_pc': 100.00,
                                      'pf_pc': 100.00,
                                      'project_id': '504910',
                                      'q30_bases_pc': 93.71,
                                      'raw_clusters_pc': 11.74,
                                      'readcounts': 38088672,
                                      'sample_name': 'SIB914A11_sureselect11',
                                      'yield_mb': 3847},
            'SIB914A12_sureselect12': {'barcode': 'CTTGTA',
                                      'lane': '1',
                                      'mean_quality_score': 36.49,
                                      'perfect_barcodes_pc': 100.00,
                                      'pf_pc': 100.00,
                                      'project_id': '504910',
                                      'q30_bases_pc': 94.39,
                                      'raw_clusters_pc': 14.86,
                                      'readcounts': 48201748,
                                      'sample_name': 'SIB914A12_sureselect12',
                                      'yield_mb': 4868},
            'SIB914A15_sureselect15': {'barcode': 'GAAACC',
                                      'lane': '1',
                                      'mean_quality_score': 36.46,
                                      'perfect_barcodes_pc': 100.00,
                                      'pf_pc': 100.00,
                                      'project_id': '504910',
                                      'q30_bases_pc': 94.32,
                                      'raw_clusters_pc': 17.87,
                                      'readcounts': 57947620,
                                      'sample_name': 'SIB914A15_sureselect15',
                                      'yield_mb': 5853},
            'SIB914A2_sureselect2': {'barcode': 'CGATGT',
                                    'lane': '1',
                                    'mean_quality_score': 36.40,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '504910',
                                    'q30_bases_pc': 94.11,
                                    'raw_clusters_pc': 9.88,
                                    'readcounts': 32032000,
                                    'sample_name': 'SIB914A2_sureselect2',
                                    'yield_mb': 3235},
            'lane1': {'barcode': 'Undetermined',
                     'lane': '1',
                     'mean_quality_score': 35.46,
                     'perfect_barcodes_pc': 0.00,
                     'pf_pc': 100.00,
                     'project_id': 'Undetermined_indices',
                     'q30_bases_pc': 91.15,
                     'raw_clusters_pc': 4.17,
                     'readcounts': 13520174,
                     'sample_name': 'lane1',
                     'yield_mb': 1366}},
        '2': {
            'SIB910A3_sureselect6': {'barcode': 'GCCAAT',
                                    'lane': '2',
                                    'mean_quality_score': 36.45,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '454557',
                                    'q30_bases_pc': 94.32,
                                    'raw_clusters_pc': 13.31,
                                    'readcounts': 43286568,
                                    'sample_name': 'SIB910A3_sureselect6',
                                    'yield_mb': 4372},
            'SIB911A1_sureselect4': {'barcode': 'TGACCA',
                                    'lane': '2',
                                    'mean_quality_score': 36.51,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '959191',
                                    'q30_bases_pc': 94.48,
                                    'raw_clusters_pc': 15.93,
                                    'readcounts': 51823804,
                                    'sample_name': 'SIB911A1_sureselect4',
                                    'yield_mb': 5234},
            'SIB911A2_sureselect5': {'barcode': 'ACAGTG',
                                    'lane': '2',
                                    'mean_quality_score': 36.46,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '959191',
                                    'q30_bases_pc': 94.33,
                                    'raw_clusters_pc': 12.18,
                                    'readcounts': 39619404,
                                    'sample_name': 'SIB911A2_sureselect5',
                                    'yield_mb': 4002},
            'SIB914A11_sureselect11': {'barcode': 'GGCTAC',
                                      'lane': '2',
                                      'mean_quality_score': 36.27,
                                      'perfect_barcodes_pc': 100.00,
                                      'pf_pc': 100.00,
                                      'project_id': '504910',
                                      'q30_bases_pc': 93.70,
                                      'raw_clusters_pc': 11.76,
                                      'readcounts': 38269896,
                                      'sample_name': 'SIB914A11_sureselect11',
                                      'yield_mb': 3865},
            'SIB914A12_sureselect12': {'barcode': 'CTTGTA',
                                      'lane': '2',
                                      'mean_quality_score': 36.49,
                                      'perfect_barcodes_pc': 100.00,
                                      'pf_pc': 100.00,
                                      'project_id': '504910',
                                      'q30_bases_pc': 94.40,
                                      'raw_clusters_pc': 14.81,
                                      'readcounts': 48191852,
                                      'sample_name': 'SIB914A12_sureselect12',
                                      'yield_mb': 4867},
            'SIB914A15_sureselect15': {'barcode': 'GAAACC',
                                      'lane': '2',
                                      'mean_quality_score': 36.46,
                                      'perfect_barcodes_pc': 100.00,
                                      'pf_pc': 100.00,
                                      'project_id': '504910',
                                      'q30_bases_pc': 94.33,
                                      'raw_clusters_pc': 17.83,
                                      'readcounts': 57997530,
                                      'sample_name': 'SIB914A15_sureselect15',
                                      'yield_mb': 5858},
            'SIB914A2_sureselect2': {'barcode': 'CGATGT',
                                    'lane': '2',
                                    'mean_quality_score': 36.40,
                                    'perfect_barcodes_pc': 100.00,
                                    'pf_pc': 100.00,
                                    'project_id': '504910',
                                    'q30_bases_pc': 94.12,
                                    'raw_clusters_pc': 9.84,
                                    'readcounts': 32016648,
                                    'sample_name': 'SIB914A2_sureselect2',
                                    'yield_mb': 3234},
            'lane2': {'barcode': 'Undetermined',
                     'lane': '2',
                     'mean_quality_score': 35.46,
                     'perfect_barcodes_pc': 0.00,
                     'pf_pc': 100.00,
                     'project_id': 'Undetermined_indices',
                     'q30_bases_pc': 91.17,
                     'raw_clusters_pc': 4.34,
                     'readcounts': 14103704,
                     'sample_name': 'lane2',
                     'yield_mb': 1424}}}
