Example #1
0
def ms_from_array_centroid(mz, abundance, rp, s2n, dataname, polarity=-1, auto_process=True):

    data_dict = {Labels.mz: mz, Labels.abundance: abundance, Labels.s2n : s2n, Labels.rp: rp}
    
    output_parameters = get_output_parameters(polarity, dataname)
        
    return MassSpecCentroid(data_dict, output_parameters)
Example #2
0
    def _import_mass_spectra(self, d_params, auto_process=True):
        results = []
        # Each_Mass_Spectrum = namedtuple('each_mass_spectrum', ['mass_list', 'abundance_list', 'retention_time', 'scan_number', 'tic_number'])

        if self.check_load_success():

            """get number of scans"""

            list_Tics = list()

            list_RetentionTimeSeconds = list()

            list_scans = list()

            """key = scan_number or retention time"""
            # print(self.initial_scan_number, self.final_scan_number)
            for scan_number in range(
                self.initial_scan_number, self.final_scan_number + 1
            ):
                #print(scan_number)
                # scan_number = scan_number + 1

                "only import FULL scans and Profile Mode, it ignores all others"

                if self.check_full_scan(scan_number):

                    if self.is_profile_scan_for_scan_num(scan_number):

                        d_params["label"] = Labels.thermo_centroid

                        d_params["polarity"] = self.get_polarity_mode(scan_number)

                        d_params["rt"], TIC = self.get_ScanHeaderInfoForScanNum(
                            scan_number
                        )

                        d_params["scan_number"] = scan_number

                        list_RetentionTimeSeconds.append(d_params.get("rt"))

                        list_Tics.append(TIC)

                        list_scans.append(scan_number)

                        data_dict = self.get_data(scan_number, d_params)

                        #results.append((data, d_params))
                        
                        mass_spec = MassSpecCentroid(data_dict, d_params)
                        
                        self.LCMS.add_mass_spectrum(mass_spec)

            #pool = multiprocessing.Pool(5)
            #result = pool.starmap(MassSpecCentroid, results)
            #for ms in result:
            #self.LCMS.add_mass_spectrum(ms)
            
            self.LCMS.retention_time = list_RetentionTimeSeconds
            self.LCMS.set_tic_list(list_Tics)
            self.LCMS.set_scans_number_list(list_scans)
Example #3
0
    def get_mass_spectrum(self,
                          scan_number=0,
                          time_index=-1,
                          auto_process=True,
                          loadSettings=True) -> MassSpecCentroid:

        dataframe = self.get_dataframe()

        if not set([
                'H/C', 'O/C', 'Heteroatom Class', 'Ion Type', 'Is Isotopologue'
        ]).issubset(dataframe.columns):
            raise ValueError("%s it is not a valid CoreMS file" %
                             str(self.file_location))

        self.check_columns(dataframe.columns)

        dataframe.rename(columns=self.parameters.header_translate,
                         inplace=True)

        polarity = dataframe['Ion Charge'].values[0]

        output_parameters = self.get_output_parameters(polarity)

        mass_spec_obj = MassSpecCentroid(dataframe.to_dict(orient='list'),
                                         output_parameters)

        if loadSettings: self.load_settings(mass_spec_obj, output_parameters)

        self.add_molecular_formula(mass_spec_obj, dataframe)

        return mass_spec_obj
Example #4
0
    def get_mass_spectrum(self,
                          polarity,
                          scan=0,
                          auto_process=True,
                          loadSettings=True):
        '''
         The MassListBaseClass object reads mass list data types and returns the mass spectrum obj

        Parameters
        ----------
        polarity: int 
            +1 or -1 
        '''
        # delimiter = "  " or " " or  "," or "\t" etc

        if self.isCentroid:

            dataframe = self.get_dataframe()

            self.check_columns(dataframe.columns)

            self.clean_data_frame(dataframe)

            dataframe.rename(columns=self.parameters.header_translate,
                             inplace=True)

            output_parameters = self.get_output_parameters(polarity)

            mass_spec = MassSpecCentroid(dataframe.to_dict(orient='list'),
                                         output_parameters)

            if loadSettings: self.load_settings(mass_spec, output_parameters)

            return mass_spec

        else:

            dataframe = self.get_dataframe()

            self.check_columns(dataframe.columns)

            output_parameters = self.get_output_parameters(polarity)

            self.clean_data_frame(dataframe)

            dataframe.rename(columns=self.parameters.header_translate,
                             inplace=True)

            mass_spec = MassSpecProfile(dataframe.to_dict(orient='list'),
                                        output_parameters,
                                        auto_process=auto_process)

            if loadSettings: self.load_settings(mass_spec, output_parameters)

            return mass_spec
Example #5
0
    def get_centroid_msms_data(self, scan):

        d_params = self.set_metadata(scans_list=[scan],
                                     label=Labels.thermo_centroid)

        centroidStream = self.iRawDataPlus.GetCentroidStream(scan, False)

        noise = list(centroidStream.Noises)

        baselines = list(centroidStream.Baselines)

        rp = list(centroidStream.Resolutions)

        magnitude = list(centroidStream.Intensities)

        mz = list(centroidStream.Masses)

        # charge = scans_labels[5]
        array_noise_std = (np.array(noise) - np.array(baselines)) / 3
        l_signal_to_noise = np.array(magnitude) / array_noise_std

        d_params['baselise_noise'] = np.average(array_noise_std)

        d_params['baselise_noise_std'] = np.std(array_noise_std)

        data_dict = {
            Labels.mz: mz,
            Labels.abundance: magnitude,
            Labels.rp: rp,
            Labels.s2n: list(l_signal_to_noise)
        }

        mass_spec = MassSpecCentroid(data_dict, d_params, auto_process=False)
        mass_spec.settings.threshold_method = 'relative_abundance'
        mass_spec.settings.relative_abundance_threshold = 1
        mass_spec.process_mass_spec()
        return mass_spec
Example #6
0
    def _import_mass_spectra(self, d_params, auto_process=True):

        # if self.check_load_success():
        """get number of scans"""

        list_Tics = list()

        list_RetentionTimeSeconds = list()

        list_scans = list()

        for scan_number in range(self.initial_scan_number,
                                 self.final_scan_number + 1):

            "only import FULL scans it ignores all others"

            scanStatistics = self.iRawDataPlus.GetScanStatsForScanNumber(
                scan_number)

            d_params["label"] = Labels.thermo_profile

            d_params["polarity"] = self.get_polarity_mode(scan_number)

            d_params["rt"] = self.iRawDataPlus.RetentionTimeFromScanNumber(
                scan_number)

            d_params["scan_number"] = scan_number

            list_RetentionTimeSeconds.append(d_params.get("rt"))

            list_Tics.append(scanStatistics.TIC)

            list_scans.append(scan_number)

            if self.check_full_scan(scan_number):

                data_dict = self.get_data(scan_number, d_params, "Profile")

                print("loading profile scan number: ", scan_number)

                mass_spec = MassSpecProfile(data_dict,
                                            d_params,
                                            auto_process=auto_process)

                self.lcms.add_mass_spectrum(mass_spec)

            else:

                data_dict = self.get_data(scan_number, d_params, "Centroid")

                print("loading centroid scan number: ", scan_number)

                mass_spec = MassSpecCentroid(data_dict, d_params)

                self.lcms.add_mass_spectrum(mass_spec)

        #pool = multiprocessing.Pool(5)
        #result = pool.starmap(MassSpecCentroid, results)
        # for ms in result:
        # self.lcms.add_mass_spectrum(ms)

        self.lcms.retention_time(list_RetentionTimeSeconds)
        self.lcms.tic = list_Tics
        self.lcms.scans_number = list_scans