예제 #1
0
def readAllSpectra(rawFile, firstScanNumber: int, lastScanNumber: int,
                   outputData: bool):

    for scanNumber in range(firstScanNumber, lastScanNumber + 1):

        scanFilter = rawFile.GetFilterForScanNumber(firstScanNumber)

        print(scanFilter.ToString())

        # Get the scan from the RAW file.  This method uses the Scan.FromFile method which returns a
        # Scan object that contains both the segmented and centroid (label) data from an FTMS scan
        # or just the segmented data in non-FTMS scans.  The GetSpectrum method demonstrates an
        # alternative method for reading scans.

        scan = Scan.FromFile(rawFile, scanNumber)

        # If that scan contains FTMS data then Centroid stream will be populated so check to see if it is present.
        labelSize = 0

        if scan.HasCentroidStream:

            labelSize = scan.CentroidScan.Length

        # for non-FTMS data, the preferred data will be populated
        dataSize = scan.PreferredMasses.Length

        if outputData:

            print("Spectrum {0} - {1}: normal {2}, label {3} points".format(
                scanNumber, scanFilter.ToString(), dataSize, labelSize))
예제 #2
0
def CalculateMassPrecision(rawFile, scanNumber: int):

    # Get the scan from the RAW file
    scan = Scan.FromFile(rawFile, scanNumber)

    # Get the scan event and from the scan event get the analyzer type for this scan
    scanEvent = rawFile.GetScanEventForScanNumber(scanNumber)

    scanFilter = rawFile.GetFilterForScanNumber(scanNumber)

    print(scanFilter.MassAnalyzer)
    print(scanEvent)

    # Get the trailer extra data to get the ion time for this file
    logEntry = rawFile.GetTrailerExtraInformation(scanNumber)

    print(logEntry.Labels)

    trailerHeadings = List[String]()
    trailerValues = List[String]()
    for i in range(logEntry.Length):

        trailerHeadings.Add(String(logEntry.Labels[i]))
        trailerValues.Add(String(logEntry.Values[i]))

    # create the mass precision estimate object
    precisionEstimate = PrecisionEstimate()

    # Get the ion time from the trailer extra data values
    ionTime = precisionEstimate.GetIonTime(scanFilter.MassAnalyzer, scan,
                                           trailerHeadings, trailerValues)

    # Calculate the mass precision for the scan
    listResults = precisionEstimate.GetMassPrecisionEstimate(
        scan, scanFilter.MassAnalyzer, ionTime,
        rawFile.RunHeader.MassResolution)

    # Output the mass precision results
    if len(listResults) > 0:

        print("Mass Precision Results:")

        for result in listResults:

            print("Mass {}, mmu = {}, ppm = {}".format(
                result.Mass, result.MassAccuracyInMmu,
                result.MassAccuracyInPpm))
예제 #3
0
    def CalculateMassPrecision(self, scanNumber=1):
        '''Calculates the mass precision for a spectrum.

        Args:
            scanNumber (int): the scan to process.
        '''

        # Get the scan from the RAW file
        scan = Scan.FromFile(self.source, scanNumber)

        # Get the scan event and from the scan event get the analyzer type for this scan
        scanEvent = IScanEventBase(self.source.GetScanEventForScanNumber(scanNumber))

        # Get the trailer extra data to get the ion time for this file
        logEntry = self.source.GetTrailerExtraInformation(scanNumber)

        trailerHeadings = List[str]()
        trailerValues = List[str]()
        for i in range(logEntry.Length):
            trailerHeadings.Add(logEntry.Labels[i])
            trailerValues.Add(logEntry.Values[i])

        # Create the mass precision estimate object
        precisionEstimate = PrecisionEstimate()

        # Get the ion time from the trailer extra data values
        ionTime = precisionEstimate.GetIonTime(scanEvent.MassAnalyzer, scan, trailerHeadings, trailerValues)

        # Calculate the mass precision for the scan
        listResults = precisionEstimate.GetMassPrecisionEstimate(
            scan, scanEvent.MassAnalyzer, ionTime, self.source.RunHeader.MassResolution)

        # Output the mass precision results
        ''''''
        # if listResults.Count:
        #    print('Mass Precision Results:')

        for result in listResults:
            print('Mass {:.5f}, mmu = {:.3f}, ppm = {:.2f}'.format(
                result.Mass, result.MassAccuracyInMmu, result.MassAccuracyInPpm))
예제 #4
0
def AnalyzeAllScans(rawFile, firstScanNumber: int, lastScanNumber: int):

    # Test the preferred (normal) data and centroid (high resolution/label) data
    failedCentroid = 0
    failedPreferred = 0

    for scanNumber in range(firstScanNumber, lastScanNumber + 1):
        # Get each scan from the RAW file
        scan = Scan.FromFile(rawFile, scanNumber)

        # Check to see if the RAW file contains label (high-res) data and if it is present
        # then look for any data that is out of order
        if scan.HasCentroidStream:

            if scan.CentroidScan.Length > 0:

                currentMass = scan.CentroidScan.Masses[0]

                for index in range(1, scan.CentroidScan.Length):

                    if scan.CentroidScan.Masses[index] > currentMass:

                        currentMass = scan.CentroidScan.Masses[index]

                    else:

                        if failedCentroid == 0:

                            print(
                                "First failure: Failed in scan data at: Scan: "
                                + scanNumber + " Mass: " +
                                currentMass.ToString("F4"))

                        failedCentroid += 1

        # Check the normal (non-label) data in the RAW file for any out-of-order data
        if scan.PreferredMasses.Length > 0:

            currentMass = scan.PreferredMasses[0]

            # print(scan.PreferredMasses.Length, scan.CentroidScan.Length, scan.SegmentedScan.Positions.Length)

            for index in range(1, scan.PreferredMasses.Length):

                if scan.PreferredMasses[index] > currentMass:

                    currentMass = scan.PreferredMasses[index]

                else:

                    if (failedPreferred == 0):

                        print("First failure: Failed in scan data at: Scan: " +
                              str(scanNumber) + " Mass: " +
                              currentMass.ToString("F2"))

                    failedPreferred += 1

    # Display a message indicating if any of the scans had data that was "out of order"
    if failedPreferred == 0 and failedCentroid == 0:

        print("Analysis completed: No out of order data found")

    else:

        print("Analysis completed: Preferred data failed: " +
              str(failedPreferred) + " Centroid data failed: " +
              str(failedCentroid))