예제 #1
0
def test_load_from_mzxml():
    """Test parsing of mzxml file to spectrum objects"""

    module_root = os.path.dirname(__file__)
    mzxml_file = os.path.join(module_root, "testdata.mzXML")
    spectrum = next(load_from_mzxml(mzxml_file))

    assert len(list(
        load_from_mzxml(mzxml_file))) == 1, "Expected single spectrum"
    assert int(spectrum.get(
        "precursor_mz")) == 343, "Expected different precursor m/z"
    assert spectrum.get("charge") == -1, "Expected different charge."
    assert len(spectrum.peaks) == 50
예제 #2
0
파일: utils.py 프로젝트: iomega/ms2query
def convert_files_to_matchms_spectrum_objects(
        file_name) -> Union[List[Spectrum], None]:
    """Loads spectra from your spectrum file into memory as matchms Spectrum object

    The following file extensions can be loaded in with this function:
    "mzML", "json", "mgf", "msp", "mzxml", "usi" and "pickle".
    A pickled file is expected to directly contain a list of matchms spectrum objects.

    Args:
    -----
    file_name:
        Path to file containing spectra, with file extension "mzML", "json", "mgf", "msp",
        "mzxml", "usi" or "pickle"
    """
    assert os.path.exists(
        file_name), f"The specified file: {file_name} does not exists"

    file_extension = os.path.splitext(file_name)[1].lower()
    if file_extension == ".mzml":
        return list(importing.load_from_mzml(file_name))
    if file_extension == ".json":
        return list(importing.load_from_json(file_name))
    if file_extension == ".mgf":
        return list(importing.load_from_mgf(file_name))
    if file_extension == ".msp":
        return list(importing.load_from_msp(file_name))
    if file_extension == ".mzxml":
        return list(importing.load_from_mzxml(file_name))
    if file_extension == ".usi":
        return list(importing.load_from_usi(file_name))
    if file_extension == ".pickle":
        return load_pickled_file(file_name)
    print(f"File extension of file: {file_name} is not recognized")
    return None
예제 #3
0
def test_load_from_mzxml_ms_levels():
    """Test parsing of mzxml file to spectrum objects using different ms levels."""

    module_root = os.path.dirname(__file__)
    mzxml_file = os.path.join(module_root, "testdata.mzXML")

    expected_num_spectra = [1, 1, 3, 0]
    for i in range(4):
        ms_level = i + 1
        spectrums = list(load_from_mzxml(mzxml_file, ms_level))
        assert len(spectrums) == expected_num_spectra[i], (
            f"Expected different number of spectrums for ms_level={ms_level}")