Esempio n. 1
0
    def __init__(self,
                 sequence_manager,
                 controller_method,
                 mass_spec_param_dict,
                 dataset_file,
                 variable_params_dict,
                 base_params_dict,
                 mzml_file=None,
                 roi_params=RoiParams(min_intensity=10, min_length=5),
                 ps=None,
                 parallel=True):

        self.sequence_manager = sequence_manager
        self.parallel = parallel
        self.controller_method = controller_method
        self.mass_spec_param_dict = mass_spec_param_dict
        self.dataset_file = dataset_file
        self.mzml_file = mzml_file
        if self.dataset_file is None:
            cm = ChemicalMixtureFromMZML(self.mzml_file, roi_params=roi_params)
            dataset = cm.sample(None, 2)
            dataset_name = os.path.join(sequence_manager.base_dir,
                                        Path(mzml_file).stem + '.p')
            save_obj(dataset, dataset_name)
            self.dataset_file = dataset_name
            if self.sequence_manager.ms1_picked_peaks_file is None and len(
                    self.sequence_manager.evaluation_methods) > 0:
                self.sequence_manager.ms1_picked_peaks_file = self.sequence_manager.pick_peaks(
                    self.mzml_file, None, 1)
        self.variable_params_dict = variable_params_dict
        self.base_params_dict = base_params_dict
        sequence_manager.controller_schedule = self._generate_controller_schedule(
        )
        super().__init__(sequence_manager, self.parallel, ps=ps)
Esempio n. 2
0
    def test_mean_scan_time_from_mzml(self):
        ionisation_mode = POSITIVE
        N = 10
        isolation_width = 0.7
        mz_tol = 0.01
        rt_tol = 15
        min_ms1_intensity = 10
        controller = TopNController(ionisation_mode, N, isolation_width,
                                    mz_tol, rt_tol, min_ms1_intensity)

        # extract chemicals from mzML
        roi_params = RoiParams(min_intensity=10, min_length=5)
        cm = ChemicalMixtureFromMZML(MZML_FILE, roi_params=roi_params)
        chems = cm.sample(None, 2)

        # extract mean timing per scan level from mzML
        sd = MzMLScanTimeSampler(MZML_FILE, use_mean=True)
        ms = IndependentMassSpectrometer(ionisation_mode,
                                         chems,
                                         scan_duration=sd)

        # run simulation
        env = Environment(ms, controller, 500, 600, progress_bar=True)
        set_log_level_warning()
        env.run()
        filename = 'test_scan_time_mean_from_mzml.mzML'
        check_mzML(env, OUT_DIR, filename)
Esempio n. 3
0
def extract_chemicals(seed_file, params_dict):
    """
    Extract chemicals from a seed file
    :param seed_file: the seed file in mzML format, should be a DDA file
    (containing MS1 and MS2 scans)
    :param params_dict: a dictionary of parameters to extract ROI
    :return: a list of UnknownChemical objects
    """
    logger.info('Seed file = %s' % seed_file)
    logger.info('params = %s' % params_dict)

    rp = RoiParams(**params_dict)
    cm = ChemicalMixtureFromMZML(seed_file, roi_params=rp)
    dataset = cm.sample(None, 2)
    return dataset
Esempio n. 4
0
 def add_dataset_files(self, sequence_manager, mzml_file_list):
     for i in range(len(sequence_manager.controller_schedule['Dataset'])):
         if mzml_file_list[sequence_manager.schedule_idx[i]] is not None:
             mzml_file = mzml_file_list[sequence_manager.schedule_idx[i]]
             cm = ChemicalMixtureFromMZML(mzml_file,
                                          roi_params=self.roi_params)
             dataset = cm.sample(None, 2)
             dataset_name = os.path.join(
                 sequence_manager.base_dir,
                 Path(mzml_file_list[sequence_manager.schedule_idx[i]]).stem
                 + '.p')
             save_obj(dataset, dataset_name)
             sequence_manager.controller_schedule['Dataset'][
                 i] = dataset_name
     return sequence_manager
Esempio n. 5
0
def extract_roi(file_names,
                out_dir,
                pattern,
                mzml_path,
                param_dict=DEFAULT_MZML_CHEMICAL_CREATOR_PARAMS):
    """
    Extract ROI for all mzML files listed in file_names, and turn them
    into Chemical objecs
    :param file_names: a list of mzML file names
    :param out_dir: output directory to store pickled chemicals. If None,
    then the current directory is used
    :param pattern: pattern for output file
    :param mzml_path: input directory containing all the mzML files in
    file_names.
    :param ps: a peak sampler object
    :param param_dict: dictionary of parameters
    :return: a list of extracted Chemicals, one for each mzML file
    """
    # extract ROI for all mzML files in file_names
    datasets = []
    for i in range(len(file_names)):

        # if mzml_path is provided, use that as the front part of filename
        if mzml_path is not None:
            mzml_file = os.path.join(mzml_path, file_names[i])
        else:
            mzml_file = file_names[i]

        rp = RoiParams(**param_dict)
        cm = ChemicalMixtureFromMZML(mzml_file, roi_params=rp)
        dataset = cm.sample(None, 2)
        datasets.append(dataset)

        # save extracted chemicals
        if out_dir is None:
            # if no out_dir provided, then same in the same location
            # as the mzML file
            dataset_name = os.path.splitext(mzml_file)[0] + '.p'
            save_obj(dataset, dataset_name)
        else:
            # else save the chemicals in our_dir, using pattern as the filename
            basename = os.path.basename(file_names[i])
            out_name = pattern % int(basename.split('_')[2])
            save_obj(dataset, os.path.join(out_dir, out_name))

    return datasets
Esempio n. 6
0
 def test_chemical_mixture_from_mzml(self):
     roi_params = RoiParams(min_intensity=10, min_length=5)
     cm = ChemicalMixtureFromMZML(MZML_FILE, roi_params=roi_params)
     d = cm.sample(None, 2)
     assert len(d) == len(cm.good_rois)
Esempio n. 7
0
def chems_from_mzml():
    np.random.seed(0)
    rand.seed(0)
    roi_params = RoiParams(min_intensity=10, min_length=5)
    cm = ChemicalMixtureFromMZML(MZML_FILE, roi_params=roi_params)
    return cm.sample(None, 2)