Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def test_flexible_non_overlap_controller_with_beer_chems_and_smartROI_rules(
            self):
        logger.info(
            'Testing flexible non-overlap controller with QC beer chemicals and '
            'SmartROI rules')

        isolation_width = 1  # the isolation window in Dalton around a selected precursor ion
        N = 10
        rt_tol = 15
        mz_tol = 10
        min_roi_intensity = 5000
        min_roi_length = 10
        ionisation_mode = POSITIVE
        rt_box_size, mz_box_size = 1, 0.3

        # create a simulated mass spec with noise and ROI controller
        mass_spec = IndependentMassSpectrometer(ionisation_mode, BEER_CHEMS)
        grid = GridEstimator(
            AllOverlapGrid(BEER_MIN_BOUND, BEER_MAX_BOUND, rt_box_size, 0,
                           3000, mz_box_size), IdentityDrift())
        controller = FlexibleNonOverlapController(
            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,
            roi_type=ROI_TYPE_SMART,
            reset_length_seconds=1e6,
            intensity_increase_factor=10,
            drop_perc=0.1 / 100)

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

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

        # write simulated output to mzML file
        filename = 'flexible_non_overlap_qcbeer_chems_smartroi.mzML'
        check_mzML(env, OUT_DIR, filename)
Ejemplo n.º 3
0
    def test_intensity_non_overlap_controller_with_beer_chems_and_weighteddew_rules(
            self):
        logger.info(
            'Testing intensity non-overlap controller with QC beer chemicals '
            'and WeightedDEW rules')

        isolation_width = 1  # the isolation window in Dalton around a selected precursor ion
        N = 10
        rt_tol = 120
        exclusion_t_0 = 15
        mz_tol = 10
        min_roi_intensity = 5000
        min_roi_length = 10
        ionisation_mode = POSITIVE
        rt_box_size, mz_box_size = 1, 0.3

        # create a simulated mass spec with noise and ROI controller
        mass_spec = IndependentMassSpectrometer(ionisation_mode, BEER_CHEMS)
        grid = GridEstimator(
            AllOverlapGrid(BEER_MIN_BOUND, BEER_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,
            exclusion_method=ROI_EXCLUSION_WEIGHTED_DEW,
            exclusion_t_0=exclusion_t_0)

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

        # 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_qcbeer_chems_weighteddew.mzML'
        check_mzML(env, OUT_DIR, filename)
Ejemplo n.º 4
0
def non_overlap_experiment(datasets,
                           base_chemicals,
                           rt_range,
                           isolation_width,
                           mz_tol,
                           min_ms1_intensity,
                           min_roi_intensity,
                           min_roi_length,
                           N,
                           rt_tol,
                           min_roi_length_for_fragmentation,
                           rt_box_size,
                           mz_box_size,
                           ionisation_mode=POSITIVE):
    env_list = []
    grid = GridEstimator(
        LocatorGrid(rt_range[0], rt_range[1], rt_box_size, 0, 3000,
                    mz_box_size), IdentityDrift())
    for i in range(len(datasets)):
        mass_spec = IndependentMassSpectrometer(ionisation_mode, datasets[i])
        controller = NonOverlapController(
            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=min_roi_length_for_fragmentation)
        env = Environment(mass_spec,
                          controller,
                          rt_range[0],
                          rt_range[1],
                          progress_bar=True)
        env.run()
        env_list.append(env)
    final_evaluation = evaluate_multiple_simulated_env(
        env_list, base_chemicals=base_chemicals)
    return env_list, final_evaluation
Ejemplo n.º 5
0
def run_vimms(no_injections, rt_box_size, mz_box_size):
    rt_range = [(0, 1440)]
    min_rt, max_rt = rt_range[0]
    ionisation_mode, isolation_width = POSITIVE, 1
    N, rt_tol, mz_tol, min_ms1_intensity = 10, 15, 10, 5000
    min_roi_intensity, min_roi_length, min_roi_length_for_fragmentation = \
        500, 3, 3
    grid = GridEstimator(
        LocatorGrid(min_rt, max_rt, rt_box_size, 0, 3000, mz_box_size),
        IdentityDrift())

    hmdbpath = os.path.join(os.path.abspath(os.getcwd()), "..", "..", "tests",
                            "fixtures", "hmdb_compounds.p")
    hmdb = load_obj(hmdbpath)
    df = DatabaseFormulaSampler(hmdb, min_mz=100, max_mz=1000)
    cm = ChemicalMixtureCreator(df, adduct_prior_dict={POSITIVE: {"M+H": 1}})
    chemicals = cm.sample(2000, 1)

    boxes = []
    for i in range(no_injections):
        mz_noise = GaussianPeakNoise(0.1)
        mass_spec = IndependentMassSpectrometer(POSITIVE, chemicals,
                                                mz_noise=mz_noise)
        controller = NonOverlapController(
            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=min_roi_length_for_fragmentation
        )
        env = Environment(mass_spec, controller, min_rt, max_rt,
                          progress_bar=True)
        set_log_level_warning()
        env.run()
        boxes.append(
            [r.to_box(0.01, 0.01) for r in controller.roi_builder.get_rois()])
    return boxes
Ejemplo n.º 6
0
def case_control_non_overlap_experiment_evaluation(
        datasets,
        min_rt,
        max_rt,
        N,
        isolation_window,
        mz_tol,
        rt_tol,
        min_ms1_intensity,
        min_roi_intensity,
        min_roi_length,
        rt_box_size,
        mz_box_size,
        min_roi_length_for_fragmentation,
        scoring_params=None,
        base_chemicals=None,
        mzmine_files=None,
        rt_tolerance=100,
        experiment_dir=None,
        box_method='mean',
        roi_type=ROI_TYPE_NORMAL,
        reset_length_seconds=1e6,
        intensity_increase_factor=10,
        drop_perc=0.1 / 100,
        exclusion_method=ROI_EXCLUSION_DEW,
        exclusion_t_0=None,
        progress_bar=False):
    if base_chemicals is not None or mzmine_files is not None:
        env_list = []
        grid = CaseControlGridEstimator(AllOverlapGrid(min_rt, max_rt,
                                                       rt_box_size, 0, 3000,
                                                       mz_box_size),
                                        IdentityDrift(),
                                        rt_tolerance=rt_tolerance,
                                        box_method=box_method)
        mzml_files = []
        source_files = ['sample_' + str(i) for i in range(len(datasets))]
        for i in range(len(datasets)):
            mass_spec = IndependentMassSpectrometer(POSITIVE, datasets[i])
            controller = FlexibleNonOverlapController(
                POSITIVE,
                isolation_window,
                mz_tol,
                min_ms1_intensity,
                min_roi_intensity,
                min_roi_length,
                N,
                grid,
                rt_tol=rt_tol,
                min_roi_length_for_fragmentation=
                min_roi_length_for_fragmentation,
                scoring_params=scoring_params,
                roi_type=roi_type,
                reset_length_seconds=reset_length_seconds,
                intensity_increase_factor=intensity_increase_factor,
                drop_perc=drop_perc,
                exclusion_method=exclusion_method,
                exclusion_t_0=exclusion_t_0)
            env = Environment(mass_spec,
                              controller,
                              min_rt,
                              max_rt,
                              progress_bar=progress_bar)
            env.run()
            if progress_bar is False:
                print('Processed dataset ' + str(i))
            env_list.append(env)
            if base_chemicals is None:
                file_link = os.path.join(experiment_dir,
                                         source_files[i] + '.mzml')
                mzml_files.append(file_link)
                env.write_mzML(experiment_dir, source_files[i] + '.mzml')
        if base_chemicals is not None:
            evaluation = evaluate_multiple_simulated_env(
                env_list, base_chemicals=base_chemicals)
        else:
            roi_aligner = FrequentistRoiAligner(rt_tolerance=rt_tolerance)
            for i in range(len(mzml_files)):
                roi_aligner.add_picked_peaks(mzml_files[i], mzmine_files[i],
                                             source_files[i], 'mzmine')
            evaluation = evaluate_multi_peak_roi_aligner(
                roi_aligner, source_files, True)
        return env_list, evaluation
    else:
        return None, None