Exemple #1
0
    def test_utilities_massSpectrumBuilder_rtwindow(self):
        """
		Test the RT window filter
		"""

        with self.subTest(msg='All-inclusive window'):
            filteredData = massSpectrumBuilder(self.msData,
                                               correlationThreshold=0.95,
                                               rtWindow=1000,
                                               simulatedSpecra=False)

            expectedFeatureMetadata = pandas.DataFrame(
                [[
                    3.13, 5, '100 - 10 - 1', '3.13_220.1419n',
                    'M+H, M+Na, M+K, 2M+Na', 219.1419,
                    '3.12_127.1212m/z; 5.32_89.9812m/z'
                ],
                 [
                     3.12, 5, '100 - 20', '3.12_170.2233m/z', numpy.nan,
                     170.2233, ''
                 ],
                 [
                     0.56, 5, '90 - 100 - 50', '0.56_214.1245n',
                     'M+H, M+Na, M+K, 2M+Na', 213.1245, ''
                 ]],
                columns=[
                    'Retention Time', 'Peak Width', 'Isotope Distribution',
                    'Feature Name', 'Adducts', 'm/z', 'Correlated Features'
                ])

            expectedFeatureMetadata['Exclusion Details'] = None
            expectedFeatureMetadata['User Excluded'] = False
            expectedFeatureMetadata[[
                'rsdFilter', 'varianceRatioFilter',
                'correlationToDilutionFilter', 'blankFilter',
                'artifactualFilter'
            ]] = pandas.DataFrame([[True, True, True, True, True]],
                                  index=expectedFeatureMetadata.index)

            expectedFeatureMetadata[['rsdSP', 'rsdSS/rsdSP', 'correlationToDilution', 'blankValue']] \
             = pandas.DataFrame([[numpy.nan, numpy.nan, numpy.nan, numpy.nan]],
                    index=expectedFeatureMetadata.index)

            pandas.util.testing.assert_frame_equal(
                filteredData.featureMetadata.sort_index(axis=1),
                expectedFeatureMetadata.sort_index(axis=1))

        with self.subTest(msg='Restrictive window'):
            filteredData = massSpectrumBuilder(self.msData,
                                               correlationThreshold=0.95,
                                               rtWindow=0.1,
                                               simulatedSpecra=False)

            expectedFeatureMetadata = copy.copy(self.msData.featureMetadata)
            expectedFeatureMetadata['Correlated Features'] = ''
            pandas.util.testing.assert_frame_equal(
                filteredData.featureMetadata.sort_index(axis=1),
                expectedFeatureMetadata.sort_index(axis=1))
    def test_utilities_massSpectrumBuilder_correlationThreshold(self):
        """
		Test corr cutoff
		"""
        filteredData = massSpectrumBuilder(self.msData,
                                           correlationThreshold=0.5,
                                           rtWindow=20,
                                           simulatedSpecra=False)

        expectedFeatureMetadata = pandas.DataFrame(
            [[
                3.13, 5, '100 - 10 - 1', '3.13_220.1419n',
                'M+H, M+Na, M+K, 2M+Na', 219.1419,
                '3.12_127.1212m/z; 3.12_170.2233m/z'
            ], [5.32, 5, '100', '5.32_89.9812m/z', numpy.nan, 89.9812, ''],
             [
                 0.56, 5, '90 - 100 - 50', '0.56_214.1245n',
                 'M+H, M+Na, M+K, 2M+Na', 213.1245, ''
             ]],
            columns=[
                'Retention Time', 'Peak Width', 'Isotope Distribution',
                'Feature Name', 'Adducts', 'm/z', 'Correlated Features'
            ])
        pandas.util.testing.assert_frame_equal(filteredData.featureMetadata,
                                               expectedFeatureMetadata)
Exemple #3
0
    def test_utilities_massSpectrumBuilder(self):
        """
		Test defaults
		"""

        filteredData = massSpectrumBuilder(self.msData,
                                           correlationThreshold=0.95,
                                           rtWindow=20,
                                           simulatedSpecra=True)

        expectedFeatureMetadata = pandas.DataFrame(
            [[
                3.13, 5, '100 - 10 - 1', '3.13_220.1419n',
                'M+H, M+Na, M+K, 2M+Na', 219.1419, '3.12_127.1212m/z',
                [(127.1212, 100.0), (128.124555, 10.0), (129.12791, 1.0),
                 (221.14917599999998, 100.0), (222.15253099999998, 10.0),
                 (223.15588599999998, 1.0), (243.131118, 100.0),
                 (244.13447299999999, 10.0), (245.13782799999998, 1.0),
                 (259.105058, 100.0), (260.108413, 10.0), (261.111768, 1.0),
                 (463.273018, 100.0), (464.276373, 10.0), (465.279728, 1.0)]
            ],
             [
                 3.12, 5, '100 - 20', '3.12_170.2233m/z', numpy.nan, 170.2233,
                 '', [(170.2233, 100.0), (171.226655, 20.0)]
             ],
             [
                 5.32, 5, '100', '5.32_89.9812m/z', numpy.nan, 89.9812, '',
                 [(89.9812, 100)]
             ],
             [
                 0.56, 5, '90 - 100 - 50', '0.56_214.1245n',
                 'M+H, M+Na, M+K, 2M+Na', 213.1245, '',
                 [(215.131776, 90.0), (216.135131, 100.0), (217.138486, 50.0),
                  (237.113718, 90.0), (238.117073, 100.0), (239.120428, 50.0),
                  (253.087658, 90.0), (254.091013, 100.0), (255.094368, 50.0),
                  (451.238218, 90.0), (452.241573, 100.0), (453.244928, 50.0)]
             ]],
            columns=[
                'Retention Time', 'Peak Width', 'Isotope Distribution',
                'Feature Name', 'Adducts', 'm/z', 'Correlated Features',
                'Mass Spectrum'
            ])
        expectedFeatureMetadata['Exclusion Details'] = None
        expectedFeatureMetadata['User Excluded'] = False
        expectedFeatureMetadata[[
            'rsdFilter', 'varianceRatioFilter', 'correlationToDilutionFilter',
            'blankFilter', 'artifactualFilter'
        ]] = pandas.DataFrame([[True, True, True, True, True]],
                              index=expectedFeatureMetadata.index)

        expectedFeatureMetadata[['rsdSP', 'rsdSS/rsdSP', 'correlationToDilution', 'blankValue']] \
         = pandas.DataFrame([[numpy.nan, numpy.nan, numpy.nan, numpy.nan]], index=expectedFeatureMetadata.index)

        pandas.util.testing.assert_frame_equal(
            filteredData.featureMetadata.sort_index(axis=1),
            expectedFeatureMetadata.sort_index(axis=1))
    def test_utilities_massSpectrumBuilder_rtwindow(self):
        """
		Test the RT window filter
		"""

        with self.subTest(msg='All-inclusive window'):
            filteredData = massSpectrumBuilder(self.msData,
                                               correlationThreshold=0.95,
                                               rtWindow=1000,
                                               simulatedSpecra=False)

            expectedFeatureMetadata = pandas.DataFrame(
                [[
                    3.13, 5, '100 - 10 - 1', '3.13_220.1419n',
                    'M+H, M+Na, M+K, 2M+Na', 219.1419,
                    '3.12_127.1212m/z; 5.32_89.9812m/z'
                ],
                 [
                     3.12, 5, '100 - 20', '3.12_170.2233m/z', numpy.nan,
                     170.2233, ''
                 ],
                 [
                     0.56, 5, '90 - 100 - 50', '0.56_214.1245n',
                     'M+H, M+Na, M+K, 2M+Na', 213.1245, ''
                 ]],
                columns=[
                    'Retention Time', 'Peak Width', 'Isotope Distribution',
                    'Feature Name', 'Adducts', 'm/z', 'Correlated Features'
                ])
            pandas.util.testing.assert_frame_equal(
                filteredData.featureMetadata, expectedFeatureMetadata)

        with self.subTest(msg='Restrictive window'):
            filteredData = massSpectrumBuilder(self.msData,
                                               correlationThreshold=0.95,
                                               rtWindow=0.1,
                                               simulatedSpecra=False)

            expectedFeatureMetadata = copy.copy(self.msData.featureMetadata)
            expectedFeatureMetadata['Correlated Features'] = ''
            pandas.util.testing.assert_frame_equal(
                filteredData.featureMetadata, expectedFeatureMetadata)
    def test_utilities_massSpectrumBuilder_log(self):
        """
		Test log attribute
		"""
        filteredData = massSpectrumBuilder(self.msData,
                                           correlationThreshold=0.8,
                                           rtWindow=50,
                                           simulatedSpecra=False)

        self.assertEqual(
            filteredData.Attributes['Log'][-1][1],
            "Redundant features removed with rtWindow of: %f seconds and correlationThreshold of: %f."
            % (50, 0.8))