protdata 0.1.4__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {protdata-0.1.4 → protdata-0.1.5}/LICENSE +1 -2
- {protdata-0.1.4/protdata.egg-info → protdata-0.1.5}/PKG-INFO +14 -4
- {protdata-0.1.4 → protdata-0.1.5}/README.md +13 -3
- {protdata-0.1.4 → protdata-0.1.5}/docs/source/conf.py +3 -1
- protdata-0.1.5/protdata/io/__init__.py +13 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata/io/maxquant_loader.py +14 -5
- protdata-0.1.5/protdata/io/spectronaut_loader.py +167 -0
- {protdata-0.1.4 → protdata-0.1.5/protdata.egg-info}/PKG-INFO +14 -4
- {protdata-0.1.4 → protdata-0.1.5}/protdata.egg-info/SOURCES.txt +3 -1
- {protdata-0.1.4 → protdata-0.1.5}/pyproject.toml +1 -1
- {protdata-0.1.4 → protdata-0.1.5}/tests/test_loaders.py +2 -0
- protdata-0.1.5/tests/test_spectronaut_loader.py +97 -0
- protdata-0.1.4/protdata/io/__init__.py +0 -6
- {protdata-0.1.4 → protdata-0.1.5}/protdata/__init__.py +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata/io/diann_loader.py +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata/io/fragpipe_loader.py +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata/io/mztab_loader.py +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata/io/utils.py +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata.egg-info/dependency_links.txt +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata.egg-info/requires.txt +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/protdata.egg-info/top_level.txt +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/setup.cfg +0 -0
- {protdata-0.1.4 → protdata-0.1.5}/tests/test_maxquant_loader.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: protdata
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Proteomics data loaders for AnnData format.
|
|
5
5
|
Author: Max Frank
|
|
6
6
|
License-Expression: MIT
|
|
@@ -46,9 +46,19 @@ Dynamic: license-file
|
|
|
46
46
|

|
|
47
47
|
[](https://protdata-czbiohub.vercel.app/)
|
|
48
48
|
|
|
49
|
+
<a href="https://protdata.sf.czbiohub.org">
|
|
50
|
+
<img
|
|
51
|
+
src="https://raw.githubusercontent.com/czbiohub-sf/protdata/refs/heads/main/docs/source/_static/img/protdata_schema.svg"
|
|
52
|
+
class="dark-light"
|
|
53
|
+
align="right"
|
|
54
|
+
width="150"
|
|
55
|
+
alt="image"
|
|
56
|
+
/>
|
|
57
|
+
</a>
|
|
58
|
+
|
|
49
59
|
Proteomics data loaders for the [AnnData](https://anndata.readthedocs.io/) format.
|
|
50
60
|
|
|
51
|
-
This package provides loader functions to import proteomics data (e.g., MaxQuant) into the AnnData structure for downstream analysis and integration with single-cell and multi-omics workflows.
|
|
61
|
+
This package provides loader functions to import proteomics data (e.g., MaxQuant) into the AnnData structure for downstream analysis and easy integration with single-cell and multi-omics workflows.
|
|
52
62
|
|
|
53
63
|
## Features
|
|
54
64
|
|
|
@@ -124,7 +134,7 @@ To get in touch please use the [GihHub issues](https://github.com/czbiohub-sf/pr
|
|
|
124
134
|
|
|
125
135
|
## Contributing
|
|
126
136
|
|
|
127
|
-
If you want to contribute to `protdata`, please read the [Contribution Guide](https://
|
|
137
|
+
If you want to contribute to `protdata`, please read the [Contribution Guide](https://protdata.sf.czbiohub.org/contributing.html)
|
|
128
138
|
|
|
129
139
|
## Changelog
|
|
130
|
-
See [Release Notes](https://
|
|
140
|
+
See [Release Notes](https://protdata.sf.czbiohub.org/release_notes.html)
|
|
@@ -4,9 +4,19 @@
|
|
|
4
4
|

|
|
5
5
|
[](https://protdata-czbiohub.vercel.app/)
|
|
6
6
|
|
|
7
|
+
<a href="https://protdata.sf.czbiohub.org">
|
|
8
|
+
<img
|
|
9
|
+
src="https://raw.githubusercontent.com/czbiohub-sf/protdata/refs/heads/main/docs/source/_static/img/protdata_schema.svg"
|
|
10
|
+
class="dark-light"
|
|
11
|
+
align="right"
|
|
12
|
+
width="150"
|
|
13
|
+
alt="image"
|
|
14
|
+
/>
|
|
15
|
+
</a>
|
|
16
|
+
|
|
7
17
|
Proteomics data loaders for the [AnnData](https://anndata.readthedocs.io/) format.
|
|
8
18
|
|
|
9
|
-
This package provides loader functions to import proteomics data (e.g., MaxQuant) into the AnnData structure for downstream analysis and integration with single-cell and multi-omics workflows.
|
|
19
|
+
This package provides loader functions to import proteomics data (e.g., MaxQuant) into the AnnData structure for downstream analysis and easy integration with single-cell and multi-omics workflows.
|
|
10
20
|
|
|
11
21
|
## Features
|
|
12
22
|
|
|
@@ -82,7 +92,7 @@ To get in touch please use the [GihHub issues](https://github.com/czbiohub-sf/pr
|
|
|
82
92
|
|
|
83
93
|
## Contributing
|
|
84
94
|
|
|
85
|
-
If you want to contribute to `protdata`, please read the [Contribution Guide](https://
|
|
95
|
+
If you want to contribute to `protdata`, please read the [Contribution Guide](https://protdata.sf.czbiohub.org/contributing.html)
|
|
86
96
|
|
|
87
97
|
## Changelog
|
|
88
|
-
See [Release Notes](https://
|
|
98
|
+
See [Release Notes](https://protdata.sf.czbiohub.org/release_notes.html)
|
|
@@ -62,12 +62,14 @@ issues_github_path = "czbiohub-sf/protdata"
|
|
|
62
62
|
|
|
63
63
|
nitpicky = True
|
|
64
64
|
nitpick_ignore = []
|
|
65
|
+
# scanpydoc is deprecated in favour of scverse-doc; silence the notice until we migrate
|
|
66
|
+
suppress_warnings = ["scanpydoc.deprecated"]
|
|
65
67
|
|
|
66
68
|
intersphinx_mapping = dict(
|
|
67
69
|
python=("https://docs.python.org/3", None),
|
|
68
70
|
numpy=("https://numpy.org/doc/stable", None),
|
|
69
71
|
pandas=("https://pandas.pydata.org/pandas-docs/stable", None),
|
|
70
|
-
anndata=("https://anndata.
|
|
72
|
+
anndata=("https://anndata.scverse.org/en/stable/", None),
|
|
71
73
|
scipy=("https://docs.scipy.org/doc/scipy", None),
|
|
72
74
|
h5py=("https://docs.h5py.org/en/latest", None),
|
|
73
75
|
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .diann_loader import read_diann
|
|
2
|
+
from .fragpipe_loader import read_fragpipe
|
|
3
|
+
from .maxquant_loader import read_maxquant
|
|
4
|
+
from .mztab_loader import read_mztab
|
|
5
|
+
from .spectronaut_loader import read_spectronaut
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"read_maxquant",
|
|
9
|
+
"read_diann",
|
|
10
|
+
"read_fragpipe",
|
|
11
|
+
"read_mztab",
|
|
12
|
+
"read_spectronaut",
|
|
13
|
+
]
|
|
@@ -51,17 +51,26 @@ def read_maxquant(
|
|
|
51
51
|
- ``var``: protein metadata (indexed by protein IDs)
|
|
52
52
|
- ``obs``: sample metadata (indexed by sample names)
|
|
53
53
|
- ``layers``: additional intensity matrices if multiple intensity column prefixes are provided
|
|
54
|
+
|
|
55
|
+
Notes
|
|
56
|
+
-----
|
|
57
|
+
- The first intensity column prefix is used for the main matrix (X), others are stored as layers if present.
|
|
58
|
+
- Forward slashes (``/``) are not allowed in hdf5 keys, so they are replaced with underscores (``_``).
|
|
54
59
|
"""
|
|
55
60
|
if isinstance(intensity_column_prefixes, str):
|
|
56
61
|
intensity_column_prefixes = [intensity_column_prefixes]
|
|
57
62
|
|
|
58
|
-
main_intensity_column = intensity_column_prefixes[0]
|
|
59
63
|
if isinstance(file, pd.DataFrame):
|
|
60
64
|
df = file
|
|
61
65
|
else:
|
|
62
66
|
df = pd.read_csv(file, sep=sep, low_memory=False)
|
|
63
67
|
|
|
68
|
+
# Forward slashes are not allowed in hdf5 keys
|
|
69
|
+
df.columns = df.columns.str.replace("/", "_")
|
|
70
|
+
intensity_column_prefixes = [x.replace("/", "_") for x in intensity_column_prefixes]
|
|
71
|
+
|
|
64
72
|
# Find intensity columns
|
|
73
|
+
main_intensity_column = intensity_column_prefixes[0]
|
|
65
74
|
intensity_cols = [
|
|
66
75
|
col for col in df.columns if col.startswith(main_intensity_column)
|
|
67
76
|
]
|
|
@@ -84,11 +93,11 @@ def read_maxquant(
|
|
|
84
93
|
if col in [prefix + sample_name for sample_name in sample_names]
|
|
85
94
|
]
|
|
86
95
|
if len(prefix_cols) == len(sample_names):
|
|
87
|
-
|
|
88
|
-
layers[prefix.strip().replace("/", "_")] = (
|
|
89
|
-
df[prefix_cols].to_numpy(dtype=np.float32).T
|
|
90
|
-
)
|
|
96
|
+
layers[prefix.strip()] = df[prefix_cols].to_numpy(dtype=np.float32).T
|
|
91
97
|
else:
|
|
98
|
+
print(prefix_cols)
|
|
99
|
+
print(len(prefix_cols))
|
|
100
|
+
print(len(sample_names))
|
|
92
101
|
warnings.warn(
|
|
93
102
|
f"Number of columns for prefix '{prefix}' does not match number of samples."
|
|
94
103
|
)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
3
|
+
|
|
4
|
+
import anndata as ad
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def read_spectronaut(
|
|
9
|
+
file: str,
|
|
10
|
+
intensity_columns: Optional[List[str] | str] = ["PG.Quantity"],
|
|
11
|
+
index_column: Optional[str] = "PG.ProteinGroups",
|
|
12
|
+
sample_column: Optional[str] = "R.FileName",
|
|
13
|
+
sep="\t",
|
|
14
|
+
):
|
|
15
|
+
"""
|
|
16
|
+
Load Spectronaut results into an AnnData object.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
file
|
|
21
|
+
Path to the Spectronaut results file.
|
|
22
|
+
intensity_columns
|
|
23
|
+
Name of the intensity column.
|
|
24
|
+
index_column
|
|
25
|
+
Name of the column to use as protein index.
|
|
26
|
+
sample_column
|
|
27
|
+
Name of the column to use as sample index.
|
|
28
|
+
sep
|
|
29
|
+
File separator.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
:class:`anndata.AnnData` object with:
|
|
34
|
+
|
|
35
|
+
- ``X``: intensity matrix (samples x proteins)
|
|
36
|
+
- ``var``: protein metadata (indexed by protein group IDs)
|
|
37
|
+
- ``obs``: sample metadata (indexed by sample names)
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
if isinstance(intensity_columns, str):
|
|
41
|
+
intensity_columns = [intensity_columns]
|
|
42
|
+
# Check that intensity columns are all at the same level as the index column
|
|
43
|
+
index_level = index_column.split(".")[0]
|
|
44
|
+
intensity_levels = [col.split(".")[0] for col in intensity_columns]
|
|
45
|
+
if not all(level == index_level for level in intensity_levels):
|
|
46
|
+
raise ValueError(
|
|
47
|
+
f"Intensity columns {intensity_columns} are not all at the same level as the index column {index_column}"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
sample_levels = ("E", "R")
|
|
51
|
+
possible_levels = ("PG", "PEP", "EG", "FG", "F")
|
|
52
|
+
df = _read_csv_auto_decimal(file, sep=sep)
|
|
53
|
+
|
|
54
|
+
sample_level = sample_column.split(".")[0]
|
|
55
|
+
sample_idx = sample_levels.index(sample_level)
|
|
56
|
+
var_levels = sample_levels[: sample_idx + 1]
|
|
57
|
+
var_levels = tuple(f"{level}." for level in var_levels)
|
|
58
|
+
var_cols = [
|
|
59
|
+
col
|
|
60
|
+
for col in df.columns
|
|
61
|
+
if col.startswith(var_levels) and df[col].notna().sum() > 0
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
dfp = df.pivot_table(
|
|
65
|
+
index=index_column,
|
|
66
|
+
columns=var_cols,
|
|
67
|
+
values=intensity_columns,
|
|
68
|
+
aggfunc="mean",
|
|
69
|
+
observed=True,
|
|
70
|
+
dropna=True,
|
|
71
|
+
).T
|
|
72
|
+
dfpx = dfp.loc[intensity_columns[0]]
|
|
73
|
+
|
|
74
|
+
# Report if intensities were not unique for pivoting and aggregated. This might not be what the user wants.
|
|
75
|
+
for intensity_column in intensity_columns:
|
|
76
|
+
if df[intensity_column].nunique() > dfpx.size:
|
|
77
|
+
warnings.warn(
|
|
78
|
+
f"{intensity_column} is not unique within {index_column} and {sample_column}, pivoting with mean aggregation. Make sure this is what you want!"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Construct obs
|
|
82
|
+
obs = dfpx.index.to_frame().set_index(sample_column)
|
|
83
|
+
|
|
84
|
+
# Construct var
|
|
85
|
+
# Only columns that are coarser than the value column make sense to keep in var
|
|
86
|
+
var_levels = tuple(
|
|
87
|
+
f"{level}."
|
|
88
|
+
for level in possible_levels[: possible_levels.index(index_level) + 1]
|
|
89
|
+
)
|
|
90
|
+
varg = df.loc[:, df.columns.str.startswith(var_levels)].groupby(
|
|
91
|
+
index_column, observed=True, dropna=False
|
|
92
|
+
)
|
|
93
|
+
uniquecols = varg.nunique().eq(1).all(axis=0)
|
|
94
|
+
uniquecols = uniquecols[uniquecols].index
|
|
95
|
+
var = varg[uniquecols].first().reindex(dfpx.columns)
|
|
96
|
+
|
|
97
|
+
# Get the layers
|
|
98
|
+
layers = {}
|
|
99
|
+
for intensity_column in intensity_columns[1:]:
|
|
100
|
+
layers[intensity_column] = dfp.loc[intensity_column]
|
|
101
|
+
|
|
102
|
+
# Create AnnData
|
|
103
|
+
uns = {
|
|
104
|
+
"RawInfo": {
|
|
105
|
+
"Search_Engine": "Spectronaut",
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
adata = ad.AnnData(X=dfpx.to_numpy(), obs=obs, var=var, uns=uns, layers=layers)
|
|
109
|
+
return adata
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _read_csv_auto_decimal(
|
|
113
|
+
path: str,
|
|
114
|
+
*,
|
|
115
|
+
sample_rows: int = 2000,
|
|
116
|
+
trials: List[Dict[str, Optional[str]]] = [
|
|
117
|
+
{
|
|
118
|
+
"decimal": ".",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"decimal": ",",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
**kwargs: Any,
|
|
125
|
+
) -> pd.DataFrame:
|
|
126
|
+
"""
|
|
127
|
+
Read a CSV by trying multiple (decimal, thousands) configurations on a sample
|
|
128
|
+
using a fixed `sep` (no separator inference). Picks the best config and
|
|
129
|
+
re-reads the full file once.
|
|
130
|
+
|
|
131
|
+
Parameters
|
|
132
|
+
----------
|
|
133
|
+
path : str
|
|
134
|
+
CSV file path.
|
|
135
|
+
sample_rows : int
|
|
136
|
+
Number of rows to sample for scoring.
|
|
137
|
+
trials : list of dict
|
|
138
|
+
List of {'decimal': <'.' or ','>, 'thousands': <'.' or ',' or None>} to try.
|
|
139
|
+
**kwargs : Any
|
|
140
|
+
Passed through to `pd.read_csv`.
|
|
141
|
+
|
|
142
|
+
Returns
|
|
143
|
+
-------
|
|
144
|
+
DataFrame
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
scores: List[Tuple[int, Dict[str, Optional[str]]]] = []
|
|
148
|
+
base_kwargs = dict(kwargs)
|
|
149
|
+
|
|
150
|
+
for cfg in trials:
|
|
151
|
+
try:
|
|
152
|
+
samp = pd.read_csv(path, nrows=sample_rows, **base_kwargs, **cfg)
|
|
153
|
+
num = samp.select_dtypes(include="number")
|
|
154
|
+
# Score = (non-NaN numeric cells)*10 + (# numeric cols)
|
|
155
|
+
frac_valid = 1.0 - num.isna().to_numpy().mean()
|
|
156
|
+
score = frac_valid * 10000 + num.shape[1] # or any large scale
|
|
157
|
+
|
|
158
|
+
scores.append((score, cfg))
|
|
159
|
+
except Exception:
|
|
160
|
+
scores.append((-1, cfg))
|
|
161
|
+
|
|
162
|
+
best_score, best_cfg = max(scores, key=lambda x: x[0])
|
|
163
|
+
if best_score < 0:
|
|
164
|
+
# All trials failed; fall back to single read with caller's sep and defaults
|
|
165
|
+
return pd.read_csv(path, **base_kwargs)
|
|
166
|
+
|
|
167
|
+
return pd.read_csv(path, **base_kwargs, **best_cfg)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: protdata
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Proteomics data loaders for AnnData format.
|
|
5
5
|
Author: Max Frank
|
|
6
6
|
License-Expression: MIT
|
|
@@ -46,9 +46,19 @@ Dynamic: license-file
|
|
|
46
46
|

|
|
47
47
|
[](https://protdata-czbiohub.vercel.app/)
|
|
48
48
|
|
|
49
|
+
<a href="https://protdata.sf.czbiohub.org">
|
|
50
|
+
<img
|
|
51
|
+
src="https://raw.githubusercontent.com/czbiohub-sf/protdata/refs/heads/main/docs/source/_static/img/protdata_schema.svg"
|
|
52
|
+
class="dark-light"
|
|
53
|
+
align="right"
|
|
54
|
+
width="150"
|
|
55
|
+
alt="image"
|
|
56
|
+
/>
|
|
57
|
+
</a>
|
|
58
|
+
|
|
49
59
|
Proteomics data loaders for the [AnnData](https://anndata.readthedocs.io/) format.
|
|
50
60
|
|
|
51
|
-
This package provides loader functions to import proteomics data (e.g., MaxQuant) into the AnnData structure for downstream analysis and integration with single-cell and multi-omics workflows.
|
|
61
|
+
This package provides loader functions to import proteomics data (e.g., MaxQuant) into the AnnData structure for downstream analysis and easy integration with single-cell and multi-omics workflows.
|
|
52
62
|
|
|
53
63
|
## Features
|
|
54
64
|
|
|
@@ -124,7 +134,7 @@ To get in touch please use the [GihHub issues](https://github.com/czbiohub-sf/pr
|
|
|
124
134
|
|
|
125
135
|
## Contributing
|
|
126
136
|
|
|
127
|
-
If you want to contribute to `protdata`, please read the [Contribution Guide](https://
|
|
137
|
+
If you want to contribute to `protdata`, please read the [Contribution Guide](https://protdata.sf.czbiohub.org/contributing.html)
|
|
128
138
|
|
|
129
139
|
## Changelog
|
|
130
|
-
See [Release Notes](https://
|
|
140
|
+
See [Release Notes](https://protdata.sf.czbiohub.org/release_notes.html)
|
|
@@ -14,6 +14,8 @@ protdata/io/diann_loader.py
|
|
|
14
14
|
protdata/io/fragpipe_loader.py
|
|
15
15
|
protdata/io/maxquant_loader.py
|
|
16
16
|
protdata/io/mztab_loader.py
|
|
17
|
+
protdata/io/spectronaut_loader.py
|
|
17
18
|
protdata/io/utils.py
|
|
18
19
|
tests/test_loaders.py
|
|
19
|
-
tests/test_maxquant_loader.py
|
|
20
|
+
tests/test_maxquant_loader.py
|
|
21
|
+
tests/test_spectronaut_loader.py
|
|
@@ -7,6 +7,7 @@ from protdata.io.diann_loader import read_diann
|
|
|
7
7
|
from protdata.io.fragpipe_loader import read_fragpipe
|
|
8
8
|
from protdata.io.maxquant_loader import read_maxquant
|
|
9
9
|
from protdata.io.mztab_loader import read_mztab
|
|
10
|
+
from protdata.io.spectronaut_loader import read_spectronaut
|
|
10
11
|
|
|
11
12
|
data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data"))
|
|
12
13
|
|
|
@@ -18,6 +19,7 @@ data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data"))
|
|
|
18
19
|
("combined_protein.tsv", read_fragpipe),
|
|
19
20
|
("SILAC_SQ.mzTab", read_mztab),
|
|
20
21
|
("report.pg_matrix.tsv", read_diann),
|
|
22
|
+
("spectronaut_normal.tsv", read_spectronaut),
|
|
21
23
|
],
|
|
22
24
|
)
|
|
23
25
|
def test_loader(filename, loader, tmp_path):
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import warnings
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pandas as pd
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from protdata.io.spectronaut_loader import read_spectronaut
|
|
9
|
+
|
|
10
|
+
# Absolute path provided by the user for local validation
|
|
11
|
+
LOCAL_DATA_PATH = os.path.abspath(
|
|
12
|
+
os.path.join(os.path.dirname(__file__), "../data/spectronaut_normal.tsv")
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_spectronaut_pivot_warning_and_shape():
|
|
17
|
+
with pytest.warns(UserWarning, match="pivoting with mean aggregation"):
|
|
18
|
+
adata = read_spectronaut(
|
|
19
|
+
LOCAL_DATA_PATH,
|
|
20
|
+
index_column="EG.Workflow",
|
|
21
|
+
intensity_columns=["EG.Cscore", "EG.Qvalue"],
|
|
22
|
+
)
|
|
23
|
+
assert adata.shape == (9, 1)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_spectronaut_no_warning_and_shape():
|
|
27
|
+
with warnings.catch_warnings(record=True) as caught:
|
|
28
|
+
warnings.simplefilter("always")
|
|
29
|
+
adata = read_spectronaut(
|
|
30
|
+
LOCAL_DATA_PATH,
|
|
31
|
+
index_column="EG.ModifiedSequence",
|
|
32
|
+
intensity_columns=["EG.Cscore", "EG.Qvalue"],
|
|
33
|
+
)
|
|
34
|
+
assert len(caught) == 0
|
|
35
|
+
assert adata.shape == (9, 14)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _count_nonnull_grouped_values(
|
|
39
|
+
df: pd.DataFrame, index_col: str, sample_col: str, intensity_col: str
|
|
40
|
+
) -> int:
|
|
41
|
+
grouped = (
|
|
42
|
+
df[[index_col, sample_col, intensity_col]]
|
|
43
|
+
.groupby([index_col, sample_col], observed=True, dropna=False)[intensity_col]
|
|
44
|
+
.apply(lambda s: pd.notna(s).any())
|
|
45
|
+
)
|
|
46
|
+
return int(grouped.sum())
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _count_nonnull_in_matrix(matrix: np.ndarray) -> int:
|
|
50
|
+
return int(np.count_nonzero(~np.isnan(matrix)))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_spectronaut_pivot_nonnull_counts_match_local_data():
|
|
54
|
+
assert os.path.isfile(LOCAL_DATA_PATH)
|
|
55
|
+
# Read raw for ground truth counting (file uses comma decimals)
|
|
56
|
+
df = pd.read_csv(LOCAL_DATA_PATH, sep="\t", decimal=",")
|
|
57
|
+
adata = read_spectronaut(LOCAL_DATA_PATH)
|
|
58
|
+
|
|
59
|
+
grouped_nonnull = _count_nonnull_grouped_values(
|
|
60
|
+
df,
|
|
61
|
+
index_col="PG.ProteinGroups",
|
|
62
|
+
sample_col="R.FileName",
|
|
63
|
+
intensity_col="PG.Quantity",
|
|
64
|
+
)
|
|
65
|
+
matrix_nonnull = _count_nonnull_in_matrix(adata.X)
|
|
66
|
+
|
|
67
|
+
assert matrix_nonnull == grouped_nonnull
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_spectronaut_layers_shape_and_presence():
|
|
71
|
+
assert os.path.isfile(LOCAL_DATA_PATH)
|
|
72
|
+
adata = read_spectronaut(
|
|
73
|
+
LOCAL_DATA_PATH,
|
|
74
|
+
intensity_columns=["PG.Quantity", "PG.Cscore"],
|
|
75
|
+
)
|
|
76
|
+
assert "PG.Cscore" in adata.layers
|
|
77
|
+
assert adata.layers["PG.Cscore"].shape == adata.X.shape
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_spectronaut_uns_and_obs_metadata():
|
|
81
|
+
assert os.path.isfile(LOCAL_DATA_PATH)
|
|
82
|
+
adata = read_spectronaut(LOCAL_DATA_PATH)
|
|
83
|
+
assert adata.uns["RawInfo"]["Search_Engine"] == "Spectronaut"
|
|
84
|
+
# obs index is the sample identifier column
|
|
85
|
+
assert adata.obs.index.name == "R.FileName"
|
|
86
|
+
# expect at least one other sample-level column to be present
|
|
87
|
+
assert "R.Replicate" in adata.obs.columns or "R.Condition" in adata.obs.columns
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_spectronaut_level_mismatch_raises():
|
|
91
|
+
assert os.path.isfile(LOCAL_DATA_PATH)
|
|
92
|
+
with pytest.raises(ValueError):
|
|
93
|
+
read_spectronaut(
|
|
94
|
+
LOCAL_DATA_PATH,
|
|
95
|
+
index_column="EG.Workflow",
|
|
96
|
+
intensity_columns=["PG.Quantity"],
|
|
97
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|