def centroid(scan, threshold = None):
    """
    Centroids profile-mode data given in [(M/Z, intensity)] format.
    """
    from internalAlgorithms import average
    
    if not scan:
        return scan
    
    if not threshold:
        assert not isinstance(scan, Iterator), ("centroid() requires explicit "
                                                "threshold value if given an "
                                                "Iterator argument.")

        threshold = average(list(zip(*scan))[1])
        
    peaks = []
    peak = []
    for pt in scan:
        if pt[1] > threshold:
            peak.append(pt)
        elif peak:
            centMZ = average(list(zip(*peak))[0], weights = list(zip(*peak))[1])
            centInt = max(list(zip(*peak))[1])
            if len(pt) == 4:
                centNoise = average(list(zip(*peak))[2], weights = list(zip(*peak))[1])
                centCharge = max(list(zip(*peak))[3])
                peaks.append((centMZ, centInt, centNoise, centCharge))
            else:
                peaks.append((centMZ, centInt))
            peak = []
    return peaks
示例#2
0
    def calculate_bounds(self, absolute_scan_lookup):
        regionIndices = zip(*self.regions)[0]
        self.scans = [absolute_scan_lookup[x] for x in regionIndices]
        self.scanrange = min(self.scans), max(self.scans)

        self.regions = [(absolute_scan_lookup[x], y) for x, y in self.regions]

        minMZs = [min(zip(*peaks)[0]) for y, peaks in self.regions]
        avgC12 = average(minMZs)
        while not all([abs(x - avgC12) < 0.05 for x in minMZs]):
            oddOneOut = max(minMZs, key=lambda x: abs(x - avgC12))
            minMZs.remove(oddOneOut)
            avgC12 = average(minMZs)
        self.mz = avgC12

        xic = pts_to_bins([(x[0], min(x[1], key=lambda pt:
                                      (pt[0] - avgC12))[1])
                           for x in self.regions], 100)
        ints = [0.0] + list(zip(*xic)[1]) + [0.0]
        self.skewness = skew(ints)
        self.kurtosis = kurtosis(ints)
def signal_noise(spectrum, minSN):
    """
    Filters the spectrum by a signal-to-noise threshold, by finding the subset
    of lowest-intensity peaks that match a specified minimum signal-to-noise
    ratio and discarding those.
    """
    
    # Ought to do a binary search!
    
    if not minSN or not float(minSN):
        return spectrum
    
    minSN = float(minSN)
    spectrum.sort(key = lambda x: x[1])
    for i in range(0, len(spectrum)):
        ints = [x[1] for x in spectrum[i:]]
        SN = average(ints) / std(ints)
        if SN > minSN:
            return spectrum[i:]
    
    return spectrum