コード例 #1
0
    def average_scan(self,
                     start_scan,
                     stop_scan,
                     filter='Full ms',
                     centroid=False):
        average_scan = Extensions.AverageScansInScanRange(
            self.source, start_scan, stop_scan, filter)

        #options = self.source.DefaultMassOptions()
        #options.ToleranceUnits = ToleranceUnits.ppm
        #options.Tolerance = 5.0
        #scanfilter = self.source.GetFilterForScanNumber(start_scan)
        #average_scan = self.source.AverageScansInScanRange(start_scan, stop_scan,
        #scanfilter, options)

        if not average_scan.HasCentroidStream:
            raise IOError("Could not retrieve average scan %d - %d" %
                          (start_scan, stop_scan))
            # May still be able to get a profile mode scan out of it...?
        if centroid:
            return list(
                zip(average_scan.CentroidScan.Masses,
                    average_scan.CentroidScan.Intensities))
        else:
            return list(
                zip(average_scan.SegmentedScan.Positions,
                    average_scan.SegmentedScan.Intensities))
コード例 #2
0
ファイル: rawFileReader.py プロジェクト: Kzra/CoreMS
    def get_average_mass_spectrum_in_scan_range(self,
                                                first_scan: int = None,
                                                last_scan: int = None,
                                                auto_process: bool = True,
                                                ppm_tolerance: float = 5.0,
                                                ms_type=MSOrderType.Ms):
        """
        Averages mass spectra over a scan range using Thermo's AverageScansInScanRange method
        first_scan: int
        last_scan: int
        auto_process: bool
            If true performs peak picking, and noise threshold calculation after creation of mass spectrum object
        ms_type: MSOrderType.MS
            Type of mass spectrum scan, default for full scan acquisition
         Returns:
            MassSpecProfile    
        """

        firstScanNumber = self._initial_scan_number if first_scan is None else first_scan

        lastScanNumber = self._final_scan_number if last_scan is None else last_scan

        d_params = self.set_metadata(firstScanNumber=firstScanNumber,
                                     lastScanNumber=lastScanNumber)

        # 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
        scanFilter = self.iRawDataPlus.GetFilterForScanNumber(firstScanNumber)

        # force it to only look for the MSType
        scanFilter.MSOrder = ms_type

        averageScan = Extensions.AverageScansInScanRange(
            self.iRawDataPlus, firstScanNumber, lastScanNumber, scanFilter,
            options)

        if averageScan:
            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
        else:
            raise Exception(
                'no data found for the MSOrderType = {}'.format(ms_type))
コード例 #3
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
コード例 #4
0
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()
コード例 #5
0
ファイル: RawFileReader.py プロジェクト: m-stofella/UniDec
    def GetAverageSpectrum(self, scanrange=None, outputData=False, filter="FTMS"):
        '''Gets the average spectrum from the RAW file.

        Args:
            scanrange = [ start scan for the chromatogram, end scan for the chromatogram.]
            outputData (bool): the output data flag.
        '''

        if scanrange is None:
            scanrange = [self.FirstSpectrumNumber, self.LastSpectrumNumber]

        # Create the mass options object that will be used when averaging
        # the scans
        options = Extensions.DefaultMassOptions(self.source)
        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
        if filter is None:
            scanFilter = IScanFilter(self.source.GetFilterForScanNumber(scanrange[0]))
        else:
            filterhelper = Extensions.BuildFilterHelper(self.source, filter)
            scanFilter = filterhelper.Filter
        scanStatistics = self.source.GetScanStatsForScanNumber(scanrange[0])

        # 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(
            self.source, scanrange[0], scanrange[1], scanFilter, options)

        if averageScan is None:
            filterhelper = Extensions.BuildFilterHelper(self.source, "Full")
            scanFilter = filterhelper.Filter
            averageScan = Extensions.AverageScansInScanRange(
                self.source, scanrange[0], scanrange[1], scanFilter, options)
        # 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]([1, 6, 7, 9, 11, 12, 14])
        # averageScan = Extensions.AverageScans(self.source, scans, options)

        # Check to see if the scan has centroid data or profile data.  Depending upon the
        # type of data, different methods will be used to read the data.  While the ReadAllSpectra
        # method demonstrates reading the data using the Scan.FromFile method, generating the
        # Scan object takes more time and memory to do, so that method isn't optimum.
        if scanStatistics.IsCentroidScan:
            # Get the centroid (label) data from the RAW file for this
            # scan
            centroidStream = averageScan.CentroidScan

            if outputData:
                for i in range(centroidStream.Length):
                    print('  {} - {:.4f}, {:.0f}, {:.0f}'.format(
                        i, centroidStream.Masses[i], centroidStream.Intensities[i], centroidStream.Charges[i]))
                print()
            self.data = np.transpose(
                [DotNetArrayToNPArray(centroidStream.Masses), DotNetArrayToNPArray(centroidStream.Intensities)])
        else:
            # Get the segmented (low res and profile) scan data
            segmentedScan = averageScan.SegmentedScan
            if outputData:
                for i in range(segmentedScan.Positions.Length):
                    print('  {} - {:.4f}, {:.0f}'.format(
                        i, segmentedScan.Positions[i], segmentedScan.Intensities[i]))
                print()
            self.data = np.transpose(
                [DotNetArrayToNPArray(segmentedScan.Positions), DotNetArrayToNPArray(segmentedScan.Intensities)])
        return self.data