Пример #1
0
def test_chromatogram():

    pm = _load()

    rtmin = pm.spectra[0].rt
    rtmax = pm.spectra[-1].rt
    mzmin = min(min(s.peaks[:, 0]) for s in pm.spectra)
    mzmax = max(max(s.peaks[:, 0]) for s in pm.spectra)


    rts, chromo = chromatogram(pm, 0, 0, 0, 0, 1)
    assert len(rts) == 0
    assert len(chromo) == 0

    rts, chromo = chromatogram(pm, 0, 10000, 0, 10000, 2)
    assert len(rts) == 0
    assert len(chromo) == 0

    rts, chromo = chromatogram(pm, 0, 1000, rtmin, rtmin, 1)
    assert len(rts) == 1
    assert len(chromo) == 1

    rts, chromo = chromatogram(pm, 0, 1000, rtmax, rtmax, 1)
    assert len(rts) == 1
    assert len(chromo) == 1

    rts, chromo = chromatogram(pm, mzmin - 1e-5, mzmin - 1e-5, rtmin, rtmax, 1)
    assert len(rts) == 2540
    assert len(chromo) == 2540
    assert sum(chromo) == 0.0

    rts, chromo = chromatogram(pm, mzmax + 1e-5, mzmax + 1e-5, rtmin, rtmax, 1)
    assert len(rts) == 2540
    assert len(chromo) == 2540
    assert sum(chromo) == 0.0

    rts, chromo = chromatogram(pm, 0, 1000, 41, 41.5, 1)
    assert len(rts) == 34
    assert len(chromo) == 34

    assert abs(rts[0] -  41.00279998779) < 1e-4, rts[0]
    assert abs(chromo[0] - 33628524.55078125) < 1e-2, chromo[0]

    rts, chromo = chromatogram(pm, 0, 1000, 41, 3000, 1)
    assert len(rts) == 216
    assert len(chromo) == 216

    assert abs(rts[215] - 44.89799880) < 1e-5, rts[215]
    assert abs(chromo[215] - 309048.935241) < 1e-2, chromo[215]

    rts, chromo = chromatogram(pm, 0, 1000, rtmax + 10, rtmax + 20, 1)
    assert len(rts) == 0
    assert len(chromo) == 0
Пример #2
0
    def chromatogram(self, mzmin, mzmax, rtmin=None, rtmax=None, msLevel=None):
        """
        extracts chromatogram in given rt- and mz-window.
        returns a tuple ``(rts, intensities)`` where ``rts`` is a list of
        rt values (in seconds, as always)  and ``intensities`` is a
        list of same length containing the summed up peaks for each
        rt value.
        """
        if not self.spectra:
            return [], []
        if rtmin is None:
            rtmin = self.spectra[0].rt
        if rtmax is None:
            rtmax = self.spectra[-1].rt

        if msLevel is None:
            msLevel = min(self.getMsLevels())

        if OPTIMIZATIONS_INSTALLED:
            rts, iis = emzed_optimizations.chromatogram(
                self, mzmin, mzmax, rtmin, rtmax, msLevel)
            # fix bug in old version of emzed_optimizations:
            # fails if rtmin and rtmax are beyond max rt in peakmap !
            f = (rts >= rtmin) * (rts <= rtmax)
            return rts[f], iis[f]

        specs = self.levelNSpecsInRange(msLevel, rtmin, rtmax)

        rts = [s.rt for s in specs]
        intensities = [s.intensityInRange(mzmin, mzmax) for s in specs]
        return rts, intensities
Пример #3
0
    def chromatogram(self, mzmin, mzmax, rtmin=None, rtmax=None, msLevel=None):
        """
        extracts chromatogram in given rt- and mz-window.
        returns a tuple ``(rts, intensities)`` where ``rts`` is a list of
        rt values (in seconds, as always)  and ``intensities`` is a
        list of same length containing the summed up peaks for each
        rt value.
        """
        if not self.spectra:
            return [], []
        if rtmin is None:
            rtmin = self.spectra[0].rt
        if rtmax is None:
            rtmax = self.spectra[-1].rt

        if msLevel is None:
            msLevel = min(self.getMsLevels())

        if OPTIMIZATIONS_INSTALLED:
            rts, iis = emzed_optimizations.chromatogram(self, mzmin, mzmax, rtmin, rtmax, msLevel)
            # fix bug in old version of emzed_optimizations:
            # fails if rtmin and rtmax are beyond max rt in peakmap !
            f = (rts >= rtmin) * (rts <= rtmax)
            return rts[f], iis[f]

        specs = self.levelNSpecsInRange(msLevel, rtmin, rtmax)

        rts = [s.rt for s in specs]
        intensities = [s.intensityInRange(mzmin, mzmax) for s in specs]
        return rts, intensities
Пример #4
0
def test_chromatogram():

    pm = _load()

    rtmin = pm.spectra[0].rt
    rtmax = pm.spectra[-1].rt
    mzmin = min(min(s.peaks[:, 0]) for s in pm.spectra)
    mzmax = max(max(s.peaks[:, 0]) for s in pm.spectra)

    rts, chromo = chromatogram(pm, 0, 0, 0, 0, 1)
    assert len(rts) == 0
    assert len(chromo) == 0

    rts, chromo = chromatogram(pm, 0, 10000, 0, 10000, 2)
    assert len(rts) == 0
    assert len(chromo) == 0

    rts, chromo = chromatogram(pm, 0, 1000, rtmin, rtmin, 1)
    assert len(rts) == 1
    assert len(chromo) == 1

    rts, chromo = chromatogram(pm, 0, 1000, rtmax, rtmax, 1)
    assert len(rts) == 1
    assert len(chromo) == 1

    rts, chromo = chromatogram(pm, mzmin - 1e-5, mzmin - 1e-5, rtmin, rtmax, 1)
    assert len(rts) == 2540
    assert len(chromo) == 2540
    assert sum(chromo) == 0.0

    rts, chromo = chromatogram(pm, mzmax + 1e-5, mzmax + 1e-5, rtmin, rtmax, 1)
    assert len(rts) == 2540
    assert len(chromo) == 2540
    assert sum(chromo) == 0.0

    rts, chromo = chromatogram(pm, 0, 1000, 41, 41.5, 1)
    assert len(rts) == 34
    assert len(chromo) == 34

    assert abs(rts[0] - 41.00279998779) < 1e-4, rts[0]
    assert abs(chromo[0] - 33628524.55078125) < 1e-2, chromo[0]

    rts, chromo = chromatogram(pm, 0, 1000, 41, 3000, 1)
    assert len(rts) == 216
    assert len(chromo) == 216

    assert abs(rts[215] - 44.89799880) < 1e-5, rts[215]
    assert abs(chromo[215] - 309048.935241) < 1e-2, chromo[215]

    rts, chromo = chromatogram(pm, 0, 1000, rtmax + 10, rtmax + 20, 1)
    assert len(rts) == 0
    assert len(chromo) == 0