コード例 #1
0
    def test_TopN_controller_with_simulated_chems(self, fragscan_dataset):
        logger.info(
            'Testing Top-N controller with simulated chemicals -- no noise')
        assert len(fragscan_dataset) == N_CHEMS

        isolation_width = 1
        N = 10
        rt_tol = 15
        mz_tol = 10
        ionisation_mode = POSITIVE

        # create a simulated mass spec without noise and Top-N controller
        mass_spec = IndependentMassSpectrometer(ionisation_mode,
                                                fragscan_dataset)
        controller = TopNController(ionisation_mode, N, isolation_width,
                                    mz_tol, rt_tol, MIN_MS1_INTENSITY)
        min_bound, max_bound = get_rt_bounds(fragscan_dataset, CENTRE_RANGE)

        # create an environment to run both the mass spec and controller
        env = Environment(mass_spec,
                          controller,
                          min_bound,
                          max_bound,
                          progress_bar=True)
        run_environment(env)

        # check that there is at least one non-empty MS2 scan
        check_non_empty_MS2(controller)

        filename = 'topN_controller_simulated_chems_no_noise.mzML'
        check_mzML(env, OUT_DIR, filename)
コード例 #2
0
    def test_intensity_nonoverlap_controller_with_simulated_chems(
            self, fragscan_dataset):
        logger.info(
            'Testing intensity non-overlap controller with simulated chemicals'
        )
        assert len(fragscan_dataset) == N_CHEMS

        isolation_width = 1  # the isolation window in Dalton around a selected precursor ion
        N = 10
        rt_tol = 15
        mz_tol = 10
        min_roi_intensity = 50
        min_roi_length = 0
        ionisation_mode = POSITIVE
        min_bound, max_bound = get_rt_bounds(fragscan_dataset, CENTRE_RANGE)
        rt_box_size, mz_box_size = 1, 0.3

        # create a simulated mass spec with noise and ROI controller
        mass_spec = IndependentMassSpectrometer(ionisation_mode,
                                                fragscan_dataset)
        grid = GridEstimator(
            AllOverlapGrid(min_bound, max_bound, rt_box_size, 0, 3000,
                           mz_box_size), IdentityDrift())
        controller = IntensityNonOverlapController(
            ionisation_mode,
            isolation_width,
            mz_tol,
            MIN_MS1_INTENSITY,
            min_roi_intensity,
            min_roi_length,
            N,
            grid,
            rt_tol=rt_tol,
            min_roi_length_for_fragmentation=0)

        # create an environment to run both the mass spec and controller
        env = Environment(mass_spec,
                          controller,
                          min_bound,
                          max_bound,
                          progress_bar=True)
        run_environment(env)

        assert len(controller.scans[2]) > 0

        # check that there is at least one non-empty MS2 scan
        check_non_empty_MS2(controller)

        # write simulated output to mzML file
        filename = 'intensity_non_overlap_controller_simulated_chems.mzML'
        check_mzML(env, OUT_DIR, filename)
コード例 #3
0
    def test_ms1_controller_with_simulated_chems(self, fragscan_dataset):
        logger.info('Testing MS1 controller with simulated chemicals')

        min_bound, max_bound = get_rt_bounds(fragscan_dataset, CENTRE_RANGE)
        logger.info('RT bounds %s %s' % (min_bound, max_bound))
        assert len(fragscan_dataset) == N_CHEMS

        # create a simulated mass spec and MS1 controller
        mass_spec = IndependentMassSpectrometer(POSITIVE, fragscan_dataset)
        controller = SimpleMs1Controller()

        # create an environment to run both the mass spec and controller
        env = Environment(mass_spec, controller, min_bound, max_bound, progress_bar=True)
        run_environment(env)

        # write simulated output to mzML file
        filename = 'ms1_controller_simulated_chems.mzML'
        check_mzML(env, OUT_DIR, filename)
コード例 #4
0
    def test_smart_roi_controller_with_simulated_chems(self, fragscan_dataset):
        logger.info('Testing ROI controller with simulated chemicals')
        assert len(fragscan_dataset) == N_CHEMS

        isolation_width = 1  # the isolation window in Dalton around a selected precursor ion
        N = 10
        rt_tol = 15
        mz_tol = 10
        min_roi_intensity = 50
        min_roi_length = 0
        ionisation_mode = POSITIVE

        # create a simulated mass spec with noise and ROI controller
        mass_spec = IndependentMassSpectrometer(ionisation_mode,
                                                fragscan_dataset)
        controller = TopN_SmartRoiController(
            ionisation_mode,
            isolation_width,
            mz_tol,
            MIN_MS1_INTENSITY,
            min_roi_intensity,
            min_roi_length,
            N,
            rt_tol,
            min_roi_length_for_fragmentation=0)

        # create an environment to run both the mass spec and controller
        min_bound, max_bound = get_rt_bounds(fragscan_dataset, CENTRE_RANGE)
        env = Environment(mass_spec,
                          controller,
                          min_bound,
                          max_bound,
                          progress_bar=True)
        run_environment(env)

        assert len(controller.scans[2]) > 0

        # check that there is at least one non-empty MS2 scan
        check_non_empty_MS2(controller)

        # write simulated output to mzML file
        filename = 'smart_roi_controller_simulated_chems.mzML'
        check_mzML(env, OUT_DIR, filename)
コード例 #5
0
    def test_AIF_controller_with_simulated_chems(self, fragscan_dataset):
        logger.info('Testing Top-N controller with simulated chemicals')

        # create some chemical object
        assert len(fragscan_dataset) == N_CHEMS

        # isolation_width = 1
        # N = 10
        # rt_tol = 15
        # mz_tol = 10
        ionisation_mode = POSITIVE

        min_mz = 100
        max_mz = 500

        # shorten  the rt range for quicker tests
        # min_rt = 0
        # max_rt = 400

        scan_time_dict = {1: 0.12, 2: 0.06}

        # create a simulated mass spec without noise and Top-N controller
        logger.info('Without noise')
        mass_spec = IndependentMassSpectrometer(ionisation_mode, fragscan_dataset,
                                                scan_duration=scan_time_dict)
        params = AdvancedParams(default_ms1_scan_window=[min_mz, max_mz])
        ms1_source_cid_energy = 30
        controller = AIF(ms1_source_cid_energy, params=params)

        # create an environment to run both the mass spec and controller
        min_bound, max_bound = get_rt_bounds(fragscan_dataset, CENTRE_RANGE)
        env = Environment(mass_spec, controller, min_bound, max_bound, progress_bar=True)

        # set the log level to WARNING so we don't see too many messages when
        # environment is running
        set_log_level_warning()

        # run the simulation
        env.run()

        # set the log level back to DEBUG
        set_log_level_debug()

        # write simulated output to mzML file
        filename = 'AIF_simulated_chems_no_noise.mzML'
        check_mzML(env, OUT_DIR, filename)

        # create a simulated mass spec with noise and Top-N controller
        logger.info('With noise')
        mz_noise = GaussianPeakNoiseLevelSpecific({2: 0.01})
        intensity_noise = GaussianPeakNoiseLevelSpecific({2: 1000.})
        mass_spec = IndependentMassSpectrometer(ionisation_mode, fragscan_dataset,
                                                mz_noise=mz_noise,
                                                intensity_noise=intensity_noise,
                                                scan_duration=scan_time_dict)
        params = AdvancedParams(default_ms1_scan_window=[min_mz, max_mz])
        ms1_source_cid_energy = 30
        controller = AIF(ms1_source_cid_energy, params=params)

        # create an environment to run both the mass spec and controller
        min_bound, max_bound = get_rt_bounds(fragscan_dataset, CENTRE_RANGE)
        env = Environment(mass_spec, controller, min_bound, max_bound, progress_bar=True)

        # set the log level to WARNING so we don't see too many messages
        # when environment is running
        set_log_level_warning()

        # run the simulation
        env.run()

        # set the log level back to DEBUG
        set_log_level_debug()

        # write simulated output to mzML file
        filename = 'AIF_simulated_chems_with_noise.mzML'
        check_mzML(env, OUT_DIR, filename)