示例#1
0
    def get_average_mass_spectrum_by_scanlist(
            self,
            scans_list: List[int],
            auto_process: bool = True,
            ppm_tolerance: float = 5.0) -> MassSpecProfile:
        '''
        Averages selected scans mass spectra using Thermo's AverageScans method
        scans_list: list[int]
        auto_process: bool
            If true performs peak picking, and noise threshold calculation after creation of mass spectrum object
        Returns:
            MassSpecProfile
        '''
        """
        Averages selected scans mass spectra using Thermo's AverageScans method
        scans_list: list[int]
        auto_process: bool
            If true performs peak picking, and noise threshold calculation after creation of mass spectrum object
        Returns:
            MassSpecProfile
        """

        d_params = self.set_metadata(scans_list=scans_list)

        # assumes scans is full scan or reduced profile scan

        scans = List[int]()
        for scan in scans_list:
            scans.Add(scan)

        # Create the mass options object that will be used when averaging the scans
        options = MassOptions()
        options.ToleranceUnits = ToleranceUnits.ppm
        options.Tolerance = ppm_tolerance

        # Get the scan filter for the first scan.  This scan filter will be used to located
        # scans within the given scan range of the same type

        averageScan = Extensions.AverageScans(self.iRawDataPlus, scans,
                                              options)

        len_data = averageScan.SegmentedScan.Positions.Length

        mz_list = list(averageScan.SegmentedScan.Positions)
        abund_list = list(averageScan.SegmentedScan.Intensities)

        data_dict = {
            Labels.mz: mz_list,
            Labels.abundance: abund_list,
        }

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

        return mass_spec
def GetAverageSpectrum(rawFile, firstScanNumber: int, lastScanNumber: int,
                       outputData: bool):

    # Create the mass options object that will be used when averaging the scans
    options = MassOptions()

    options.ToleranceUnits = ToleranceUnits.ppm
    options.Tolerance = 5.0

    # Get the scan filter for the first scan.  This scan filter will be used to located
    # scans within the given scan range of the same type
    scanFilter = rawFile.GetFilterForScanNumber(firstScanNumber)

    print(scanFilter.ScanMode)

    # Get the average mass spectrum for the provided scan range. In addition to getting the
    # average scan using a scan range, the library also provides a similar method that takes
    # a time range.
    averageScan = Extensions.AverageScansInScanRange(rawFile, firstScanNumber,
                                                     lastScanNumber,
                                                     scanFilter, options)

    #average= ScanAveragerFactory.GetScanAverager(rawFile)

    #averageScan = rawFile.AverageScansInScanRange(firstScanNumber, lastScanNumber, scanFilter, options)
    if averageScan.HasCentroidStream:

        print("Average spectrum ({0} points)".format(
            averageScan.CentroidScan.Length))

        # Print the spectral data (mass, intensity values)
        #if outputData:

        #    for i in range(averageScan.CentroidScan.Length):

        #        print("  {}\t{}".format(averageScan.CentroidScan.Masses[i], averageScan.CentroidScan.Intensities[i]))

    # This example uses a different method to get the same average spectrum that was calculated in the
    # previous portion of this method.  Instead of passing the start and end scan, a list of scans will
    # be passed to the GetAveragedMassSpectrum function.
    scans = List[int]()
    for scan in (1, 6, 7, 9, 11, 12, 14):
        scans.Add(scan)

    averageScan = Extensions.AverageScans(rawFile, scans, options)

    len_data = averageScan.SegmentedScan.Positions.Length

    mz_list = list(averageScan.SegmentedScan.Positions)
    abund_list = list(averageScan.SegmentedScan.Intensities)

    #for i in range(len_data):

    # mz_list.append(averageScan.SegmentedScan.Positions[i])

    # abund_list.append(averageScan.SegmentedScan.Intensities[i])

    pyplot.plot(mz_list, abund_list)
    #pyplot.show()

    centroid_mz_list = []
    abundance_mz_list = []
    if averageScan.HasCentroidStream:

        print("Average spectrum ({0} points)".format(
            averageScan.CentroidScan.Length))

        # Print the spectral data (mass, intensity values)
        if outputData:

            for i in range(averageScan.CentroidScan.Length):
                centroid_mz_list.append(averageScan.CentroidScan.Masses[i])
                averageScan.CentroidScan.Resolutions
                abundance_mz_list.append(
                    averageScan.CentroidScan.Intensities[i])
                #print("  {}\t{}".format(averageScan.CentroidScan.Masses[i], averageScan.CentroidScan.Intensities[i]) )

    pyplot.plot(centroid_mz_list, abundance_mz_list, linewidth=0, marker='o')
    pyplot.show()

    print()