コード例 #1
0
def loadPeakMap(path=None):
    """ loads mzXML, mzML and mzData files

        If *path* is missing, a dialog for file selection is opened
        instead.
    """

    # local import in order to keep namespaces clean
    import ms
    import os.path
    import sys
    from   pyopenms import MSExperiment, FileHandler
    from   libms.DataStructures import PeakMap

    if isinstance(path, unicode):
        path = path.encode(sys.getfilesystemencoding())
    elif path is None:
        path = ms.askForSingleFile(extensions="mzML mzXML mzData".split())
        if path is None:
            return None

    # open-ms returns empty peakmap if file not exists, so we
    # check ourselves:
    if not os.path.exists(path):
        raise Exception("file %s does not exist" % path)
    if not os.path.isfile(path):
        raise Exception("path %s is not a file" % path)

    experiment = MSExperiment()
    fh  = FileHandler()
    if sys.platform == "win32":
        path = path.replace("/","\\") # needed for network shares
    fh.loadExperiment(path, experiment)

    return PeakMap.fromMSExperiment(experiment)
コード例 #2
0
ファイル: load_utils.py プロジェクト: sartmann/emzed2
def loadPeakMap(path=None):
    """ loads mzXML, mzML and mzData files

        If *path* is missing, a dialog for file selection is opened
        instead.
    """

    # local import in order to keep namespaces clean
    import os.path
    import sys
    from pyopenms import MSExperiment, FileHandler
    from ..core.data_types import PeakMap

    path = _prepare_path(path, extensions=["mzML", "mzXML", "mzData"])
    if path is None:
        return None

    # open-ms returns empty peakmap if file not exists, so we
    # check ourselves:
    if not os.path.exists(path):
        raise Exception("file %s does not exist" % path)
    if not os.path.isfile(path):
        raise Exception("path %s is not a file" % path)

    experiment = MSExperiment()
    fh = FileHandler()
    if sys.platform == "win32":
        path = path.replace("/", "\\")  # needed for network shares
    fh.loadExperiment(path, experiment)

    return PeakMap.fromMSExperiment(experiment)
コード例 #3
0
def read_ms1_experiment(filepath):
    source_experiment = MSExperiment()
    file_handler = FileHandler()
    # bytes is required by `loadExperiment()` called below
    typed_fp = filepath if isinstance(filepath, bytes) else filepath.encode()
    file_handler.loadExperiment(typed_fp, source_experiment)

    ms1_experiment = MSExperiment()
    for spectrum in source_experiment:
        if spectrum.getMSLevel() == 1:
            ms1_experiment.addSpectrum(spectrum)
    return ms1_experiment
コード例 #4
0
    def read_ms1_experiment(filepath):
        # pylint: disable=import-outside-toplevel,no-name-in-module,import-error
        from pyopenms import FileHandler, MSExperiment

        source_experiment = MSExperiment()
        file_handler = FileHandler()
        # bytes is required by `loadExperiment()` called below
        typed_fp = filepath if isinstance(filepath,
                                          bytes) else filepath.encode()
        file_handler.loadExperiment(typed_fp, source_experiment)

        ms1_experiment = MSExperiment()
        for spectrum in source_experiment:
            if spectrum.getMSLevel() == 1:
                ms1_experiment.addSpectrum(spectrum)
        return ms1_experiment