Exemple #1
0
def test_mgf_empty(empty_mgf, ignore_unknown, read_mgf_f):
    """An empty mgf file should not throw an error but yield an empty list
    """

    data = list(read_mgf_f(str(empty_mgf), ignore_unknown=ignore_unknown))
    assert isinstance(data, list)
    assert len(data) == 0
Exemple #2
0
def test_mgf_pepmass_comma(invalid_mgf, ignore_unknown, read_mgf_f):
    """Comma can be used as decimal separator for `pepmass`"""

    mzs, _, p = invalid_mgf
    gen = read_mgf_f(str(p), ignore_unknown=ignore_unknown)
    for i, (params, _) in enumerate(gen):
        assert pytest.approx(params['pepmass']) == mzs[i]
Exemple #3
0
def test_mgf_data(valid_mgf, ignore_unknown, read_mgf_f):
    """`read` should return the same data arrays than the ones written in mgf.
    """

    _, spectra, p = valid_mgf
    gen = read_mgf_f(str(p), ignore_unknown=ignore_unknown)
    for i, (_, data) in enumerate(gen):
        assert pytest.approx(data) == spectra[i]
Exemple #4
0
def test_mgf_pepmass(valid_mgf, ignore_unknown, read_mgf_f):
    """`read` should return the same *m/z* values than the ones written in mgf.
    """

    mzs, _, p = valid_mgf
    gen = read_mgf_f(str(p), ignore_unknown=ignore_unknown)
    for i, (params, _) in enumerate(gen):
        assert pytest.approx(params['pepmass']) == mzs[i]
Exemple #5
0
def test_mgf_invalid(invalid_mgf, ignore_unknown, read_mgf_f):
    """Invalid pepmass declaration should be ignored.
    """

    _, _, p = invalid_mgf
    gen = read_mgf_f(str(p), ignore_unknown=ignore_unknown)
    for i, (params, data) in enumerate(gen):
        if i == 2:
            assert 'pepmass' not in params
Exemple #6
0
def test_mgf_data_comma(invalid_mgf, ignore_unknown, read_mgf_f):
    """Comma use as a separator in data arrays will lead to truncated floats.
    """

    _, spectra, p = invalid_mgf
    gen = read_mgf_f(str(p), ignore_unknown=ignore_unknown)
    for i, (_, data) in enumerate(gen):
        if i == 2:
            assert data[:, MZ] == pytest.approx(spectra[i][:, MZ], abs=1)
            assert np.count_nonzero(data[:, INTENSITY]) == 0
Exemple #7
0
def test_mgf_noions(noions_mgf, ignore_unknown, read_mgf_f):
    """A mgf file with only one entry where there is no ions should not throw an
       error.
    """

    data = list(read_mgf_f(str(noions_mgf), ignore_unknown=ignore_unknown))
    assert isinstance(data, list)
    assert len(data) == 1
    assert data[0][1].size == 0
    assert data[0][1].shape == (0, 2)
Exemple #8
0
def test_mgf_mz_zero(invalid_mgf, read_mgf_f):
    """A peak with an mz equal to zero should be ignored."""

    mzs, spectra, p = invalid_mgf
    data = list(read_mgf_f(str(p), ignore_unknown=True))
    assert len(data) == len(mzs)
    for i, (params, d) in enumerate(data):
        if i == 2:
            assert len(d) == len(spectra[i]) - 1
            assert pytest.approx(d) == spectra[i][1:]
        else:
            assert len(d) == len(spectra[i])
            assert pytest.approx(d) == spectra[i]
Exemple #9
0
def test_mgf_non_existing(filename, ignore_unknown, read_mgf_f):
    """A filename that does not exists should throw a FileNotFoundError
    """

    with pytest.raises(FileNotFoundError):
        data = list(read_mgf_f(filename, ignore_unknown=ignore_unknown))