protdata 0.1.3__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.
Files changed (25) hide show
  1. protdata-0.1.5/LICENSE +27 -0
  2. {protdata-0.1.3/protdata.egg-info → protdata-0.1.5}/PKG-INFO +41 -7
  3. protdata-0.1.5/README.md +98 -0
  4. {protdata-0.1.3 → protdata-0.1.5}/docs/source/conf.py +4 -1
  5. protdata-0.1.5/protdata/io/__init__.py +13 -0
  6. {protdata-0.1.3 → protdata-0.1.5}/protdata/io/diann_loader.py +4 -5
  7. {protdata-0.1.3 → protdata-0.1.5}/protdata/io/fragpipe_loader.py +11 -10
  8. {protdata-0.1.3 → protdata-0.1.5}/protdata/io/maxquant_loader.py +19 -11
  9. {protdata-0.1.3 → protdata-0.1.5}/protdata/io/mztab_loader.py +4 -5
  10. protdata-0.1.5/protdata/io/spectronaut_loader.py +167 -0
  11. {protdata-0.1.3 → protdata-0.1.5/protdata.egg-info}/PKG-INFO +41 -7
  12. {protdata-0.1.3 → protdata-0.1.5}/protdata.egg-info/SOURCES.txt +3 -1
  13. {protdata-0.1.3 → protdata-0.1.5}/protdata.egg-info/requires.txt +1 -0
  14. {protdata-0.1.3 → protdata-0.1.5}/pyproject.toml +32 -1
  15. {protdata-0.1.3 → protdata-0.1.5}/tests/test_loaders.py +8 -2
  16. protdata-0.1.5/tests/test_spectronaut_loader.py +97 -0
  17. protdata-0.1.3/LICENSE +0 -11
  18. protdata-0.1.3/README.md +0 -65
  19. protdata-0.1.3/protdata/io/__init__.py +0 -6
  20. {protdata-0.1.3 → protdata-0.1.5}/protdata/__init__.py +0 -0
  21. {protdata-0.1.3 → protdata-0.1.5}/protdata/io/utils.py +0 -0
  22. {protdata-0.1.3 → protdata-0.1.5}/protdata.egg-info/dependency_links.txt +0 -0
  23. {protdata-0.1.3 → protdata-0.1.5}/protdata.egg-info/top_level.txt +0 -0
  24. {protdata-0.1.3 → protdata-0.1.5}/setup.cfg +0 -0
  25. {protdata-0.1.3 → protdata-0.1.5}/tests/test_maxquant_loader.py +0 -0
protdata-0.1.5/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, CZ Biohub SF, LLC
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of the copyright holder nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: protdata
3
- Version: 0.1.3
3
+ Version: 0.1.5
4
4
  Summary: Proteomics data loaders for AnnData format.
5
5
  Author: Max Frank
6
6
  License-Expression: MIT
@@ -32,6 +32,7 @@ Requires-Dist: sphinx-issues>=5.0.1; extra == "docs"
32
32
  Requires-Dist: sphinx-copybutton; extra == "docs"
33
33
  Requires-Dist: sphinx-toolbox>=3.8.0; extra == "docs"
34
34
  Requires-Dist: sphinxext.opengraph; extra == "docs"
35
+ Requires-Dist: sphinx_design; extra == "docs"
35
36
  Requires-Dist: myst-nb; extra == "docs"
36
37
  Requires-Dist: scanpydoc[theme,typehints]>=0.15.3; extra == "docs"
37
38
  Requires-Dist: awkward>=2.3; extra == "docs"
@@ -42,10 +43,22 @@ Dynamic: license-file
42
43
  # protdata
43
44
 
44
45
  [![Test](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml/badge.svg)](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml)
46
+ ![PyPI - Version](https://img.shields.io/pypi/v/protdata)
47
+ [![docs online](https://img.shields.io/badge/docs-online-blue)](https://protdata-czbiohub.vercel.app/)
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>
45
58
 
46
59
  Proteomics data loaders for the [AnnData](https://anndata.readthedocs.io/) format.
47
60
 
48
- 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.
49
62
 
50
63
  ## Features
51
64
 
@@ -53,25 +66,37 @@ This package provides loader functions to import proteomics data (e.g., MaxQuant
53
66
  - **Reads metadata**: Automatically extracts and organizes sample and protein metadata
54
67
 
55
68
  ## Installation
69
+
70
+ Protdata has minimal dependencies listed in [pyproject.toml](https://github.com/czbiohub-sf/protdata/blob/main/pyproject.toml)
71
+
72
+ To install the latest release from PyPI, run:
73
+
56
74
  ```bash
57
75
  pip install protdata
58
76
  ```
59
77
 
78
+ Or install from source:
79
+ ```bash
80
+ git clone https://github.com/czbiohub-sf/protdata.git
81
+ cd protdata
82
+ pip install -e . # or make setup-develop for developers
83
+ ```
84
+
60
85
  ## Usage Example
61
86
 
62
87
  ### MaxQuant Import
63
88
 
64
- You can download an example proteinGroups [file here](https://zenodo.org/records/3774452/files/MaxQuant_Protein_Groups.tabular?download=1)
89
+ You can download an example proteinGroups [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/proteinGroups.txt)
65
90
  ```python
66
91
  import protdata
67
92
 
68
93
  adata = load_maxquant_to_anndata("/path/to/proteinGroups.txt")
69
94
  print(adata)
70
- ```
95
+ ```
71
96
 
72
97
  ### DIA-NN Import
73
98
 
74
- You can download an example DIA-NN report [file here](https://github.com/vdemichev/DiaNN/raw/master/diann-output-examples/report.pg_matrix.tsv)
99
+ You can download an example DIA-NN report [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/report.pg_matrix.tsv)
75
100
 
76
101
  ```python
77
102
  from protdata.io import read_diann
@@ -82,7 +107,7 @@ print(adata)
82
107
 
83
108
  ### FragPipe Import
84
109
 
85
- You can download an example FragPipe output [file here](https://github.com/Nesvilab/philosopher/blob/master/testdata/combined_protein.tsv?raw=true)
110
+ You can download an example FragPipe output [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/combined_protein.tsv)
86
111
 
87
112
  ```python
88
113
  from protdata.io import read_fragpipe
@@ -93,7 +118,7 @@ print(adata)
93
118
 
94
119
  ### mzTab Import
95
120
 
96
- You can download an example mzTab [file here](https://raw.githubusercontent.com/HUPO-PSI/mzTab/refs/heads/master/examples/1_0-Proteomics-Release/SILAC_SQ.mzTab)
121
+ You can download an example mzTab [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/SILAC_SQ.mzTab)
97
122
 
98
123
  ```python
99
124
  from protdata.io import read_mztab
@@ -101,6 +126,15 @@ from protdata.io import read_mztab
101
126
  adata = read_mztab("/path/to/SILAC_SQ.mzTab")
102
127
  print(adata)
103
128
  ```
129
+ ## Authors
130
+
131
+ `protdata` is created and maintained by the [Computational Biology Platform](https://www.czbiohub.org/comp-biology/) at the [Chan Zuckerberg Biohub San Francisco](https://www.czbiohub.org/sf/).
132
+
133
+ To get in touch please use the [GihHub issues](https://github.com/czbiohub-sf/protdata/issues) page.
104
134
 
135
+ ## Contributing
105
136
 
137
+ If you want to contribute to `protdata`, please read the [Contribution Guide](https://protdata.sf.czbiohub.org/contributing.html)
106
138
 
139
+ ## Changelog
140
+ See [Release Notes](https://protdata.sf.czbiohub.org/release_notes.html)
@@ -0,0 +1,98 @@
1
+ # protdata
2
+
3
+ [![Test](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml/badge.svg)](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml)
4
+ ![PyPI - Version](https://img.shields.io/pypi/v/protdata)
5
+ [![docs online](https://img.shields.io/badge/docs-online-blue)](https://protdata-czbiohub.vercel.app/)
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
+
17
+ Proteomics data loaders for the [AnnData](https://anndata.readthedocs.io/) format.
18
+
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.
20
+
21
+ ## Features
22
+
23
+ - **Multiple formats**: Support for MaxQuant, FragPipe, DIA-NN, and mzTab files
24
+ - **Reads metadata**: Automatically extracts and organizes sample and protein metadata
25
+
26
+ ## Installation
27
+
28
+ Protdata has minimal dependencies listed in [pyproject.toml](https://github.com/czbiohub-sf/protdata/blob/main/pyproject.toml)
29
+
30
+ To install the latest release from PyPI, run:
31
+
32
+ ```bash
33
+ pip install protdata
34
+ ```
35
+
36
+ Or install from source:
37
+ ```bash
38
+ git clone https://github.com/czbiohub-sf/protdata.git
39
+ cd protdata
40
+ pip install -e . # or make setup-develop for developers
41
+ ```
42
+
43
+ ## Usage Example
44
+
45
+ ### MaxQuant Import
46
+
47
+ You can download an example proteinGroups [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/proteinGroups.txt)
48
+ ```python
49
+ import protdata
50
+
51
+ adata = load_maxquant_to_anndata("/path/to/proteinGroups.txt")
52
+ print(adata)
53
+ ```
54
+
55
+ ### DIA-NN Import
56
+
57
+ You can download an example DIA-NN report [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/report.pg_matrix.tsv)
58
+
59
+ ```python
60
+ from protdata.io import read_diann
61
+
62
+ adata = read_diann("/path/to/report.pg_matrix.tsv")
63
+ print(adata)
64
+ ```
65
+
66
+ ### FragPipe Import
67
+
68
+ You can download an example FragPipe output [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/combined_protein.tsv)
69
+
70
+ ```python
71
+ from protdata.io import read_fragpipe
72
+
73
+ adata = read_fragpipe("/path/to/combined_protein.tsv")
74
+ print(adata)
75
+ ```
76
+
77
+ ### mzTab Import
78
+
79
+ You can download an example mzTab [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/SILAC_SQ.mzTab)
80
+
81
+ ```python
82
+ from protdata.io import read_mztab
83
+
84
+ adata = read_mztab("/path/to/SILAC_SQ.mzTab")
85
+ print(adata)
86
+ ```
87
+ ## Authors
88
+
89
+ `protdata` is created and maintained by the [Computational Biology Platform](https://www.czbiohub.org/comp-biology/) at the [Chan Zuckerberg Biohub San Francisco](https://www.czbiohub.org/sf/).
90
+
91
+ To get in touch please use the [GihHub issues](https://github.com/czbiohub-sf/protdata/issues) page.
92
+
93
+ ## Contributing
94
+
95
+ If you want to contribute to `protdata`, please read the [Contribution Guide](https://protdata.sf.czbiohub.org/contributing.html)
96
+
97
+ ## Changelog
98
+ See [Release Notes](https://protdata.sf.czbiohub.org/release_notes.html)
@@ -27,6 +27,7 @@ master_doc = "index"
27
27
  default_role = "literal"
28
28
  exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"]
29
29
  pygments_style = "sphinx"
30
+ html_favicon = "_static/img/protdata_favicon.svg"
30
31
 
31
32
  extensions = [
32
33
  "myst_nb",
@@ -61,12 +62,14 @@ issues_github_path = "czbiohub-sf/protdata"
61
62
 
62
63
  nitpicky = True
63
64
  nitpick_ignore = []
65
+ # scanpydoc is deprecated in favour of scverse-doc; silence the notice until we migrate
66
+ suppress_warnings = ["scanpydoc.deprecated"]
64
67
 
65
68
  intersphinx_mapping = dict(
66
69
  python=("https://docs.python.org/3", None),
67
70
  numpy=("https://numpy.org/doc/stable", None),
68
71
  pandas=("https://pandas.pydata.org/pandas-docs/stable", None),
69
- anndata=("https://anndata.readthedocs.io/en/stable/", None),
72
+ anndata=("https://anndata.scverse.org/en/stable/", None),
70
73
  scipy=("https://docs.scipy.org/doc/scipy", None),
71
74
  h5py=("https://docs.h5py.org/en/latest", None),
72
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
+ ]
@@ -27,12 +27,11 @@ def read_diann(
27
27
 
28
28
  Returns
29
29
  -------
30
- anndata.AnnData
31
- AnnData object with:
30
+ :class:`anndata.AnnData` object with:
32
31
 
33
- - X: intensity matrix (samples x proteins)
34
- - var: protein metadata (indexed by protein group IDs)
35
- - obs: sample metadata (indexed by sample names)
32
+ - ``X``: intensity matrix (samples x proteins)
33
+ - ``var``: protein metadata (indexed by protein group IDs)
34
+ - ``obs``: sample metadata (indexed by sample names)
36
35
  """
37
36
  if isinstance(file, pd.DataFrame):
38
37
  df = file.copy()
@@ -1,8 +1,10 @@
1
- import pandas as pd
2
- import numpy as np
3
- import anndata as ad
4
- from typing import Union
5
1
  import warnings
2
+ from typing import Union
3
+
4
+ import anndata as ad
5
+ import numpy as np
6
+ import pandas as pd
7
+
6
8
  from .utils import cleanup_obsvar
7
9
 
8
10
 
@@ -33,13 +35,12 @@ def read_fragpipe(
33
35
 
34
36
  Returns
35
37
  -------
36
- anndata.AnnData
37
- AnnData object with:
38
+ :class:`anndata.AnnData` object with:
38
39
 
39
- - X: intensity matrix (samples x proteins)
40
- - var: protein metadata (indexed by protein IDs)
41
- - obs: sample metadata (indexed by sample names)
42
- - layers: additional intensity matrices if multiple intensity column suffixes are provided
40
+ - ``X``: intensity matrix (samples x proteins)
41
+ - ``var``: protein metadata (indexed by protein IDs)
42
+ - ``obs``: sample metadata (indexed by sample names)
43
+ - ``layers``: additional intensity matrices if multiple intensity column suffixes are provided
43
44
  """
44
45
  if isinstance(intensity_column_suffixes, str):
45
46
  intensity_column_suffixes = [intensity_column_suffixes]
@@ -45,24 +45,32 @@ def read_maxquant(
45
45
 
46
46
  Returns
47
47
  -------
48
- anndata.AnnData
49
- AnnData object with:
48
+ :class:`anndata.AnnData` object with:
50
49
 
51
- - X: intensity matrix (samples x proteins)
52
- - var: protein metadata (indexed by protein IDs)
53
- - obs: sample metadata (indexed by sample names)
54
- - layers: additional intensity matrices if multiple intensity column prefixes are provided
50
+ - ``X``: intensity matrix (samples x proteins)
51
+ - ``var``: protein metadata (indexed by protein IDs)
52
+ - ``obs``: sample metadata (indexed by sample names)
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 (``_``).
55
59
  """
56
60
  if isinstance(intensity_column_prefixes, str):
57
61
  intensity_column_prefixes = [intensity_column_prefixes]
58
62
 
59
- main_intensity_column = intensity_column_prefixes[0]
60
63
  if isinstance(file, pd.DataFrame):
61
64
  df = file
62
65
  else:
63
66
  df = pd.read_csv(file, sep=sep, low_memory=False)
64
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
+
65
72
  # Find intensity columns
73
+ main_intensity_column = intensity_column_prefixes[0]
66
74
  intensity_cols = [
67
75
  col for col in df.columns if col.startswith(main_intensity_column)
68
76
  ]
@@ -85,11 +93,11 @@ def read_maxquant(
85
93
  if col in [prefix + sample_name for sample_name in sample_names]
86
94
  ]
87
95
  if len(prefix_cols) == len(sample_names):
88
- # Cannot have '/' in the key (hdf5 interprets as a group for serialization)
89
- layers[prefix.strip().replace("/", "_")] = (
90
- df[prefix_cols].to_numpy(dtype=np.float32).T
91
- )
96
+ layers[prefix.strip()] = df[prefix_cols].to_numpy(dtype=np.float32).T
92
97
  else:
98
+ print(prefix_cols)
99
+ print(len(prefix_cols))
100
+ print(len(sample_names))
93
101
  warnings.warn(
94
102
  f"Number of columns for prefix '{prefix}' does not match number of samples."
95
103
  )
@@ -24,12 +24,11 @@ def read_mztab(
24
24
 
25
25
  Returns
26
26
  -------
27
- anndata.AnnData
28
- AnnData object with:
27
+ :class:`anndata.AnnData` object with:
29
28
 
30
- - X: intensity matrix (proteins x samples)
31
- - var: protein metadata (indexed by protein accession)
32
- - obs: sample metadata (indexed by sample names)
29
+ - ``X``: intensity matrix (samples x proteins)
30
+ - ``var``: protein metadata (indexed by protein accession)
31
+ - ``obs``: sample metadata (indexed by sample names)
33
32
  """
34
33
  if isinstance(file, pd.DataFrame):
35
34
  df = file.copy()
@@ -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
3
+ Version: 0.1.5
4
4
  Summary: Proteomics data loaders for AnnData format.
5
5
  Author: Max Frank
6
6
  License-Expression: MIT
@@ -32,6 +32,7 @@ Requires-Dist: sphinx-issues>=5.0.1; extra == "docs"
32
32
  Requires-Dist: sphinx-copybutton; extra == "docs"
33
33
  Requires-Dist: sphinx-toolbox>=3.8.0; extra == "docs"
34
34
  Requires-Dist: sphinxext.opengraph; extra == "docs"
35
+ Requires-Dist: sphinx_design; extra == "docs"
35
36
  Requires-Dist: myst-nb; extra == "docs"
36
37
  Requires-Dist: scanpydoc[theme,typehints]>=0.15.3; extra == "docs"
37
38
  Requires-Dist: awkward>=2.3; extra == "docs"
@@ -42,10 +43,22 @@ Dynamic: license-file
42
43
  # protdata
43
44
 
44
45
  [![Test](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml/badge.svg)](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml)
46
+ ![PyPI - Version](https://img.shields.io/pypi/v/protdata)
47
+ [![docs online](https://img.shields.io/badge/docs-online-blue)](https://protdata-czbiohub.vercel.app/)
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>
45
58
 
46
59
  Proteomics data loaders for the [AnnData](https://anndata.readthedocs.io/) format.
47
60
 
48
- 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.
49
62
 
50
63
  ## Features
51
64
 
@@ -53,25 +66,37 @@ This package provides loader functions to import proteomics data (e.g., MaxQuant
53
66
  - **Reads metadata**: Automatically extracts and organizes sample and protein metadata
54
67
 
55
68
  ## Installation
69
+
70
+ Protdata has minimal dependencies listed in [pyproject.toml](https://github.com/czbiohub-sf/protdata/blob/main/pyproject.toml)
71
+
72
+ To install the latest release from PyPI, run:
73
+
56
74
  ```bash
57
75
  pip install protdata
58
76
  ```
59
77
 
78
+ Or install from source:
79
+ ```bash
80
+ git clone https://github.com/czbiohub-sf/protdata.git
81
+ cd protdata
82
+ pip install -e . # or make setup-develop for developers
83
+ ```
84
+
60
85
  ## Usage Example
61
86
 
62
87
  ### MaxQuant Import
63
88
 
64
- You can download an example proteinGroups [file here](https://zenodo.org/records/3774452/files/MaxQuant_Protein_Groups.tabular?download=1)
89
+ You can download an example proteinGroups [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/proteinGroups.txt)
65
90
  ```python
66
91
  import protdata
67
92
 
68
93
  adata = load_maxquant_to_anndata("/path/to/proteinGroups.txt")
69
94
  print(adata)
70
- ```
95
+ ```
71
96
 
72
97
  ### DIA-NN Import
73
98
 
74
- You can download an example DIA-NN report [file here](https://github.com/vdemichev/DiaNN/raw/master/diann-output-examples/report.pg_matrix.tsv)
99
+ You can download an example DIA-NN report [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/report.pg_matrix.tsv)
75
100
 
76
101
  ```python
77
102
  from protdata.io import read_diann
@@ -82,7 +107,7 @@ print(adata)
82
107
 
83
108
  ### FragPipe Import
84
109
 
85
- You can download an example FragPipe output [file here](https://github.com/Nesvilab/philosopher/blob/master/testdata/combined_protein.tsv?raw=true)
110
+ You can download an example FragPipe output [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/combined_protein.tsv)
86
111
 
87
112
  ```python
88
113
  from protdata.io import read_fragpipe
@@ -93,7 +118,7 @@ print(adata)
93
118
 
94
119
  ### mzTab Import
95
120
 
96
- You can download an example mzTab [file here](https://raw.githubusercontent.com/HUPO-PSI/mzTab/refs/heads/master/examples/1_0-Proteomics-Release/SILAC_SQ.mzTab)
121
+ You can download an example mzTab [file here](https://github.com/czbiohub-sf/protdata/raw/main/data/SILAC_SQ.mzTab)
97
122
 
98
123
  ```python
99
124
  from protdata.io import read_mztab
@@ -101,6 +126,15 @@ from protdata.io import read_mztab
101
126
  adata = read_mztab("/path/to/SILAC_SQ.mzTab")
102
127
  print(adata)
103
128
  ```
129
+ ## Authors
130
+
131
+ `protdata` is created and maintained by the [Computational Biology Platform](https://www.czbiohub.org/comp-biology/) at the [Chan Zuckerberg Biohub San Francisco](https://www.czbiohub.org/sf/).
132
+
133
+ To get in touch please use the [GihHub issues](https://github.com/czbiohub-sf/protdata/issues) page.
104
134
 
135
+ ## Contributing
105
136
 
137
+ If you want to contribute to `protdata`, please read the [Contribution Guide](https://protdata.sf.czbiohub.org/contributing.html)
106
138
 
139
+ ## Changelog
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
@@ -20,6 +20,7 @@ sphinx-issues>=5.0.1
20
20
  sphinx-copybutton
21
21
  sphinx-toolbox>=3.8.0
22
22
  sphinxext.opengraph
23
+ sphinx_design
23
24
  myst-nb
24
25
  scanpydoc[theme,typehints]>=0.15.3
25
26
  awkward>=2.3
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "protdata"
3
- version = "0.1.3"
3
+ version = "0.1.5"
4
4
  description = "Proteomics data loaders for AnnData format."
5
5
  requires-python = ">=3.9, <4.0"
6
6
  authors = [
@@ -41,6 +41,7 @@ docs = [
41
41
  "sphinx-copybutton",
42
42
  "sphinx-toolbox>=3.8.0",
43
43
  "sphinxext.opengraph",
44
+ "sphinx_design",
44
45
  "myst-nb",
45
46
  "scanpydoc[theme,typehints] >=0.15.3",
46
47
  "awkward>=2.3",
@@ -52,5 +53,35 @@ docs = [
52
53
  requires = ["setuptools>=61.0"]
53
54
  build-backend = "setuptools.build_meta"
54
55
 
56
+ [tool.black]
57
+ exclude = '''
58
+ /(
59
+ \.eggs
60
+ | \.git
61
+ | \.hg
62
+ | \.mypy_cache
63
+ | \.tox
64
+ | \.venv
65
+ | _build
66
+ | buck-out
67
+ | build
68
+ | dist
69
+ | data
70
+ )/
71
+ '''
72
+
73
+ [tool.flake8]
74
+ exclude = [
75
+ ".git",
76
+ "__pycache__",
77
+ "docs/source/conf.py",
78
+ "build",
79
+ "dist",
80
+ "data",
81
+ ]
82
+
83
+ [tool.pylint]
84
+ ignore-paths = ["data"]
85
+
55
86
  [tool.setuptools.packages.find]
56
87
  where = ["."]
@@ -1,9 +1,13 @@
1
1
  import os
2
- import pytest
2
+
3
3
  import anndata as ad
4
- from protdata.io.maxquant_loader import read_maxquant
4
+ import pytest
5
+
6
+ from protdata.io.diann_loader import read_diann
5
7
  from protdata.io.fragpipe_loader import read_fragpipe
8
+ from protdata.io.maxquant_loader import read_maxquant
6
9
  from protdata.io.mztab_loader import read_mztab
10
+ from protdata.io.spectronaut_loader import read_spectronaut
7
11
 
8
12
  data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data"))
9
13
 
@@ -14,6 +18,8 @@ data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data"))
14
18
  ("proteinGroups.txt", read_maxquant),
15
19
  ("combined_protein.tsv", read_fragpipe),
16
20
  ("SILAC_SQ.mzTab", read_mztab),
21
+ ("report.pg_matrix.tsv", read_diann),
22
+ ("spectronaut_normal.tsv", read_spectronaut),
17
23
  ],
18
24
  )
19
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
+ )
protdata-0.1.3/LICENSE DELETED
@@ -1,11 +0,0 @@
1
- # Released under MIT License
2
-
3
- Copyright (c) 2013 Mark Otto.
4
-
5
- Copyright (c) 2017 Andrew Fong.
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
-
9
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
protdata-0.1.3/README.md DELETED
@@ -1,65 +0,0 @@
1
- # protdata
2
-
3
- [![Test](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml/badge.svg)](https://github.com/czbiohub-sf/protdata/actions/workflows/test.yml)
4
-
5
- Proteomics data loaders for the [AnnData](https://anndata.readthedocs.io/) format.
6
-
7
- 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.
8
-
9
- ## Features
10
-
11
- - **Multiple formats**: Support for MaxQuant, FragPipe, DIA-NN, and mzTab files
12
- - **Reads metadata**: Automatically extracts and organizes sample and protein metadata
13
-
14
- ## Installation
15
- ```bash
16
- pip install protdata
17
- ```
18
-
19
- ## Usage Example
20
-
21
- ### MaxQuant Import
22
-
23
- You can download an example proteinGroups [file here](https://zenodo.org/records/3774452/files/MaxQuant_Protein_Groups.tabular?download=1)
24
- ```python
25
- import protdata
26
-
27
- adata = load_maxquant_to_anndata("/path/to/proteinGroups.txt")
28
- print(adata)
29
- ```
30
-
31
- ### DIA-NN Import
32
-
33
- You can download an example DIA-NN report [file here](https://github.com/vdemichev/DiaNN/raw/master/diann-output-examples/report.pg_matrix.tsv)
34
-
35
- ```python
36
- from protdata.io import read_diann
37
-
38
- adata = read_diann("/path/to/report.pg_matrix.tsv")
39
- print(adata)
40
- ```
41
-
42
- ### FragPipe Import
43
-
44
- You can download an example FragPipe output [file here](https://github.com/Nesvilab/philosopher/blob/master/testdata/combined_protein.tsv?raw=true)
45
-
46
- ```python
47
- from protdata.io import read_fragpipe
48
-
49
- adata = read_fragpipe("/path/to/combined_protein.tsv")
50
- print(adata)
51
- ```
52
-
53
- ### mzTab Import
54
-
55
- You can download an example mzTab [file here](https://raw.githubusercontent.com/HUPO-PSI/mzTab/refs/heads/master/examples/1_0-Proteomics-Release/SILAC_SQ.mzTab)
56
-
57
- ```python
58
- from protdata.io import read_mztab
59
-
60
- adata = read_mztab("/path/to/SILAC_SQ.mzTab")
61
- print(adata)
62
- ```
63
-
64
-
65
-
@@ -1,6 +0,0 @@
1
- from .maxquant_loader import read_maxquant
2
- from .diann_loader import read_diann
3
- from .fragpipe_loader import read_fragpipe
4
- from .mztab_loader import read_mztab
5
-
6
- __all__ = ["read_maxquant", "read_diann", "read_fragpipe", "read_mztab"]
File without changes
File without changes
File without changes