msreport 0.0.24__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 (44) hide show
  1. msreport-0.0.24/LICENSE.txt +202 -0
  2. msreport-0.0.24/PKG-INFO +128 -0
  3. msreport-0.0.24/README.md +100 -0
  4. msreport-0.0.24/msreport/__init__.py +13 -0
  5. msreport-0.0.24/msreport/aggregate/__init__.py +0 -0
  6. msreport-0.0.24/msreport/aggregate/condense.py +163 -0
  7. msreport-0.0.24/msreport/aggregate/pivot.py +132 -0
  8. msreport-0.0.24/msreport/aggregate/summarize.py +281 -0
  9. msreport-0.0.24/msreport/analyze.py +586 -0
  10. msreport-0.0.24/msreport/errors.py +10 -0
  11. msreport-0.0.24/msreport/export.py +526 -0
  12. msreport-0.0.24/msreport/fasta.py +28 -0
  13. msreport-0.0.24/msreport/helper/__init__.py +23 -0
  14. msreport-0.0.24/msreport/helper/calc.py +120 -0
  15. msreport-0.0.24/msreport/helper/maxlfq.py +339 -0
  16. msreport-0.0.24/msreport/helper/table.py +267 -0
  17. msreport-0.0.24/msreport/helper/temp.py +99 -0
  18. msreport-0.0.24/msreport/impute.py +275 -0
  19. msreport-0.0.24/msreport/isobar.py +161 -0
  20. msreport-0.0.24/msreport/normalize.py +496 -0
  21. msreport-0.0.24/msreport/peptidoform.py +283 -0
  22. msreport-0.0.24/msreport/plot.py +1129 -0
  23. msreport-0.0.24/msreport/qtable.py +537 -0
  24. msreport-0.0.24/msreport/reader.py +2357 -0
  25. msreport-0.0.24/msreport/rinterface/__init__.py +3 -0
  26. msreport-0.0.24/msreport/rinterface/limma.py +126 -0
  27. msreport-0.0.24/msreport/rinterface/rinstaller.py +35 -0
  28. msreport-0.0.24/msreport/rinterface/rscripts/limma.R +104 -0
  29. msreport-0.0.24/msreport.egg-info/PKG-INFO +128 -0
  30. msreport-0.0.24/msreport.egg-info/SOURCES.txt +42 -0
  31. msreport-0.0.24/msreport.egg-info/dependency_links.txt +1 -0
  32. msreport-0.0.24/msreport.egg-info/requires.txt +12 -0
  33. msreport-0.0.24/msreport.egg-info/top_level.txt +1 -0
  34. msreport-0.0.24/pyproject.toml +55 -0
  35. msreport-0.0.24/setup.cfg +4 -0
  36. msreport-0.0.24/setup.py +3 -0
  37. msreport-0.0.24/tests/test_analyze.py +333 -0
  38. msreport-0.0.24/tests/test_export.py +69 -0
  39. msreport-0.0.24/tests/test_helper.py +557 -0
  40. msreport-0.0.24/tests/test_impute.py +123 -0
  41. msreport-0.0.24/tests/test_isobar.py +138 -0
  42. msreport-0.0.24/tests/test_maxlfq.py +351 -0
  43. msreport-0.0.24/tests/test_peptidoform.py +237 -0
  44. msreport-0.0.24/tests/test_qtable.py +501 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.4
2
+ Name: msreport
3
+ Version: 0.0.24
4
+ Summary: Post processing and analysis of quantitative proteomics data
5
+ Author-email: "David M. Hollenstein" <hollenstein.david@gmail.com>
6
+ License: Apache-2.0
7
+ Keywords: mass spectrometry,proteomics,post processing,data analysis
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE.txt
15
+ Requires-Dist: adjustText<1.0.0,>=0.7.0
16
+ Requires-Dist: matplotlib>=3.5.2
17
+ Requires-Dist: numpy>=1.21.5
18
+ Requires-Dist: pandas>=1.4.4
19
+ Requires-Dist: profasta>=0.0.4
20
+ Requires-Dist: pyteomics>=4.6.0
21
+ Requires-Dist: pyyaml>=6.0.0
22
+ Requires-Dist: rpy2>=3.5.3
23
+ Requires-Dist: scikit-learn>=1.0.0
24
+ Requires-Dist: scipy>=1.9.1
25
+ Requires-Dist: seaborn>=0.12.0
26
+ Requires-Dist: statsmodels>=0.13.2
27
+ Dynamic: license-file
28
+
29
+ [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
30
+
31
+
32
+ # MsReport
33
+
34
+
35
+ ## Introduction
36
+
37
+ MsReport is a python library that allows simple and standardized post processing of
38
+ quantitative proteomics data from bottom up, mass spectrometry experiments. Currently
39
+ working with label free protein quantification reports from MaxQuant and FragPipe is
40
+ fully supported. Other data analysis pipelines can be added by writing a software
41
+ specific reader function.
42
+
43
+ MsReport is primarily developed as a tool for the Mass Spectrometry Facility at the Max
44
+ Perutz Labs (University of Vienna), to allow the generation of Quantitative Protein and
45
+ PTM reports, and to facilitate project specific data analysis tasks.
46
+
47
+
48
+ ## Release
49
+
50
+ Development is currently in early alpha and the interface is not yet stable.
51
+
52
+
53
+ ## Scope
54
+
55
+ The `reader` module contains software specific reader classes that provide access to the
56
+ outputs of the respective software. Reader instances allow importing protein and ion
57
+ tables, and provide the ability to standardize column names and data formats during the
58
+ import. To do so, reader classes must know the file structure and naming conventions of
59
+ the respective software.
60
+
61
+ The `qtable` class allows storing and accessing quantitative data from a particular
62
+ level of abstraction, such as proteins or ions, and an experimental design table that
63
+ describes to which experiment a sample belongs to. The quantitative data are in the wide
64
+ format, i.e. the quantification data of each sample is stored in a separate column. The
65
+ `Qtable` allows convenient handling and access to quantitative data through information
66
+ from the experimental design, and represents the data structure used by the `analyze`,
67
+ `plot`, and `export` modules.
68
+
69
+ The `analyze` module provides a high-level interface for post-processing of quantitative
70
+ data, such as filtering valid values, normalization between samples, imputation of
71
+ missing values, and statistical testing with the R package LIMMA.
72
+
73
+ The `plot` module allows generation of quality control and data analysis plots.
74
+
75
+ Using methods from the `export` module allows conversion and export of quantitative data
76
+ into the Amica input format, and generating contaminant tables for the inspection of
77
+ potential contaminants.
78
+
79
+ Additional scripts
80
+
81
+ - The `excel_report` module enables the creation of a formatted excel protein report
82
+ by using the XlsxReport library.
83
+ - The `benchmark` module contains functions to generate benchmark plots from multiple
84
+ `Qtable` instances, and can be used for method or software comparison.
85
+
86
+
87
+ ## Install
88
+
89
+ If you do not already have a Python installation, we recommend installing the
90
+ [Anaconda distribution](https://www.continuum.io/downloads) of Continuum Analytics,
91
+ which already contains a large number of popular Python packages for Data Science.
92
+ Alternatively, you can also get Python from the
93
+ [Python homepage](https://www.python.org/downloads/windows). MsReport requires Python
94
+ version 3.9 or higher.
95
+
96
+ You can use pip to install MsReport from the distribution file with the following
97
+ command:
98
+
99
+ ```
100
+ pip install msreport-X.Y.Z-py3-none-any.whl
101
+ ```
102
+
103
+ To uninstall the MsReport library type:
104
+
105
+ ```
106
+ pip uninstall msreport
107
+ ```
108
+
109
+
110
+ ### Installation when using Anaconda
111
+ If you are using Anaconda, you will need to install the MsReport package into a conda
112
+ environment. Open the Anaconda navigator, activate the conda environment you want to
113
+ use, run the "CMD.exe" application to open a terminal, and then use the pip install
114
+ command as described above.
115
+
116
+
117
+ ### Additional requirements
118
+
119
+ MsReport provides an interface to the R package LIMMA for differential expression
120
+ analysis, which requires a local installation of R (R version 3.4 or higher) and the
121
+ system environment variable "R_HOME" to be set to the R home directory. Note that it
122
+ might be necessary to restart the computer after adding the "R_HOME" variable. The R
123
+ home directory can also be found from within R by using the command below, and might
124
+ look similar to "C:\Program Files\R\R-4.2.1" on windows.
125
+
126
+ ```
127
+ normalizePath(R.home("home"))
128
+ ```
@@ -0,0 +1,100 @@
1
+ [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
2
+
3
+
4
+ # MsReport
5
+
6
+
7
+ ## Introduction
8
+
9
+ MsReport is a python library that allows simple and standardized post processing of
10
+ quantitative proteomics data from bottom up, mass spectrometry experiments. Currently
11
+ working with label free protein quantification reports from MaxQuant and FragPipe is
12
+ fully supported. Other data analysis pipelines can be added by writing a software
13
+ specific reader function.
14
+
15
+ MsReport is primarily developed as a tool for the Mass Spectrometry Facility at the Max
16
+ Perutz Labs (University of Vienna), to allow the generation of Quantitative Protein and
17
+ PTM reports, and to facilitate project specific data analysis tasks.
18
+
19
+
20
+ ## Release
21
+
22
+ Development is currently in early alpha and the interface is not yet stable.
23
+
24
+
25
+ ## Scope
26
+
27
+ The `reader` module contains software specific reader classes that provide access to the
28
+ outputs of the respective software. Reader instances allow importing protein and ion
29
+ tables, and provide the ability to standardize column names and data formats during the
30
+ import. To do so, reader classes must know the file structure and naming conventions of
31
+ the respective software.
32
+
33
+ The `qtable` class allows storing and accessing quantitative data from a particular
34
+ level of abstraction, such as proteins or ions, and an experimental design table that
35
+ describes to which experiment a sample belongs to. The quantitative data are in the wide
36
+ format, i.e. the quantification data of each sample is stored in a separate column. The
37
+ `Qtable` allows convenient handling and access to quantitative data through information
38
+ from the experimental design, and represents the data structure used by the `analyze`,
39
+ `plot`, and `export` modules.
40
+
41
+ The `analyze` module provides a high-level interface for post-processing of quantitative
42
+ data, such as filtering valid values, normalization between samples, imputation of
43
+ missing values, and statistical testing with the R package LIMMA.
44
+
45
+ The `plot` module allows generation of quality control and data analysis plots.
46
+
47
+ Using methods from the `export` module allows conversion and export of quantitative data
48
+ into the Amica input format, and generating contaminant tables for the inspection of
49
+ potential contaminants.
50
+
51
+ Additional scripts
52
+
53
+ - The `excel_report` module enables the creation of a formatted excel protein report
54
+ by using the XlsxReport library.
55
+ - The `benchmark` module contains functions to generate benchmark plots from multiple
56
+ `Qtable` instances, and can be used for method or software comparison.
57
+
58
+
59
+ ## Install
60
+
61
+ If you do not already have a Python installation, we recommend installing the
62
+ [Anaconda distribution](https://www.continuum.io/downloads) of Continuum Analytics,
63
+ which already contains a large number of popular Python packages for Data Science.
64
+ Alternatively, you can also get Python from the
65
+ [Python homepage](https://www.python.org/downloads/windows). MsReport requires Python
66
+ version 3.9 or higher.
67
+
68
+ You can use pip to install MsReport from the distribution file with the following
69
+ command:
70
+
71
+ ```
72
+ pip install msreport-X.Y.Z-py3-none-any.whl
73
+ ```
74
+
75
+ To uninstall the MsReport library type:
76
+
77
+ ```
78
+ pip uninstall msreport
79
+ ```
80
+
81
+
82
+ ### Installation when using Anaconda
83
+ If you are using Anaconda, you will need to install the MsReport package into a conda
84
+ environment. Open the Anaconda navigator, activate the conda environment you want to
85
+ use, run the "CMD.exe" application to open a terminal, and then use the pip install
86
+ command as described above.
87
+
88
+
89
+ ### Additional requirements
90
+
91
+ MsReport provides an interface to the R package LIMMA for differential expression
92
+ analysis, which requires a local installation of R (R version 3.4 or higher) and the
93
+ system environment variable "R_HOME" to be set to the R home directory. Note that it
94
+ might be necessary to restart the computer after adding the "R_HOME" variable. The R
95
+ home directory can also be found from within R by using the command below, and might
96
+ look similar to "C:\Program Files\R\R-4.2.1" on windows.
97
+
98
+ ```
99
+ normalizePath(R.home("home"))
100
+ ```
@@ -0,0 +1,13 @@
1
+ from msreport.qtable import Qtable
2
+ from msreport.reader import MaxQuantReader, FragPipeReader, SpectronautReader
3
+
4
+ from msreport.fasta import import_protein_database
5
+
6
+ import msreport.analyze
7
+ import msreport.export
8
+ import msreport.impute
9
+ import msreport.normalize
10
+ import msreport.plot
11
+ import msreport.reader
12
+
13
+ __version__ = "0.0.24"
File without changes
@@ -0,0 +1,163 @@
1
+ import numpy as np
2
+
3
+ import msreport.helper.maxlfq as MAXLFQ
4
+
5
+
6
+ def join_str(array: np.ndarray, sep: str = ";") -> str:
7
+ """Returns a joined string of sorted values from the array.
8
+
9
+ Note that empty strings or np.nan are not included in the joined string.
10
+ """
11
+ elements = []
12
+ for value in array.flatten():
13
+ if value != "" and not (isinstance(value, float) and np.isnan(value)):
14
+ elements.append(str(value))
15
+ return sep.join(sorted(elements))
16
+
17
+
18
+ def join_str_per_column(array: np.ndarray, sep: str = ";") -> np.ndarray:
19
+ """Returns for each column a joined string of sorted values.
20
+
21
+ Note that empty strings or np.nan are not included in the joined string.
22
+ """
23
+ return np.array([join_str(i) for i in array.transpose()])
24
+
25
+
26
+ def join_unique_str(array: np.ndarray, sep: str = ";") -> str:
27
+ """Returns a joined string of unique sorted values from the array."""
28
+ elements = []
29
+ for value in array.flatten():
30
+ if value != "" and not (isinstance(value, float) and np.isnan(value)):
31
+ elements.append(str(value))
32
+ return sep.join(sorted(set(elements)))
33
+
34
+
35
+ def join_unique_str_per_column(array: np.ndarray, sep: str = ";") -> np.ndarray:
36
+ """Returns for each column a joined strings of unique sorted values."""
37
+ return np.array([join_unique_str(i) for i in array.transpose()])
38
+
39
+
40
+ def sum(array: np.ndarray) -> float:
41
+ """Returns sum of values from one or multiple columns.
42
+
43
+ Note that if no finite values are present in the array np.nan is returned.
44
+ """
45
+ array = array.flatten()
46
+ if np.isfinite(array).any():
47
+ return np.nansum(array)
48
+ else:
49
+ return np.nan
50
+
51
+
52
+ def sum_per_column(array: np.ndarray) -> np.ndarray:
53
+ """Returns for each column the sum of values.
54
+
55
+ Note that if no finite values are present in a column np.nan is returned.
56
+ """
57
+ return np.array([sum(i) for i in array.transpose()])
58
+
59
+
60
+ def maximum(array: np.ndarray) -> float:
61
+ """Returns the highest finitevalue from one or multiple columns."""
62
+ array = array.flatten()
63
+ if np.isfinite(array).any():
64
+ return np.nanmax(array)
65
+ else:
66
+ return np.nan
67
+
68
+
69
+ def maximum_per_column(array: np.ndarray) -> np.ndarray:
70
+ """Returns for each column the highest finite value."""
71
+ return np.array([maximum(i) for i in array.transpose()])
72
+
73
+
74
+ def minimum(array: np.ndarray) -> int:
75
+ """Returns the lowest finite value from one or multiple columns."""
76
+ array = array.flatten()
77
+ if np.isfinite(array).any():
78
+ return np.nanmin(array)
79
+ else:
80
+ return np.nan
81
+
82
+
83
+ def minimum_per_column(array: np.ndarray) -> np.ndarray:
84
+ """Returns for each column the lowest finite value."""
85
+ return np.array([minimum(i) for i in array.transpose()])
86
+
87
+
88
+ def count_unique(array: np.ndarray) -> int:
89
+ """Returns the number of unique values from one or multiple columns.
90
+
91
+ Note that empty strings or np.nan are not counted as unique values.
92
+ """
93
+ unique_elements = {
94
+ x for x in array.flatten() if not (isinstance(x, float) and np.isnan(x))
95
+ }
96
+ unique_elements.discard("")
97
+
98
+ return len(unique_elements)
99
+
100
+
101
+ def count_unique_per_column(array: np.ndarray) -> np.ndarray:
102
+ """Returns for each column the number of unique values.
103
+
104
+ Note that empty strings or np.nan are not counted as unique values.
105
+ """
106
+ if array.size > 0:
107
+ return np.array([count_unique(i) for i in array.transpose()])
108
+ else:
109
+ return np.full(array.shape[0], 0)
110
+
111
+
112
+ def profile_by_median_ratio_regression(array: np.ndarray) -> np.ndarray:
113
+ """Calculates abundance profiles by lstsq regression of pair-wise median ratios.
114
+
115
+ The function performs a least squares regression of pair-wise median ratios to
116
+ calculate estimated abundance profiles.
117
+
118
+ Args:
119
+ array: A two-dimensional array containing abundance values, with the first
120
+ dimension corresponding to rows and the second dimension to columns.
121
+ Abundance values must not be log transformed.
122
+
123
+ Returns:
124
+ An array containing estimated abundance profiles, with length equal to the
125
+ number of columns in the input array.
126
+ """
127
+ ratio_matrix = MAXLFQ.calculate_pairwise_median_log_ratio_matrix(
128
+ array, log_transformed=False
129
+ )
130
+ coef_matrix, ratio_array, initial_rows = MAXLFQ.prepare_coefficient_matrix(
131
+ ratio_matrix
132
+ )
133
+ log_profile = MAXLFQ.log_profiles_by_lstsq(coef_matrix, ratio_array)
134
+ profile = np.power(2, log_profile)
135
+ return profile
136
+
137
+
138
+ def sum_by_median_ratio_regression(array: np.ndarray) -> np.ndarray:
139
+ """Calculates summed abundance by lstsq regression of pair-wise median ratios.
140
+
141
+ The function performs a least squares regression of pair-wise median ratios to
142
+ calculate estimated abundance profiles. These profiles are then scaled based on the
143
+ input array such that the columns with finite profile values are used and the sum of
144
+ the scaled profiles matches the sum of the input array.
145
+
146
+ Args:
147
+ array: A two-dimensional array containing abundance values, with the first
148
+ dimension corresponding to rows and the second dimension to columns.
149
+ Abundance values must not be log transformed.
150
+
151
+ Returns:
152
+ An array containing summed abundance estimates, with length equal to the number
153
+ of columns in the input array.
154
+ """
155
+ profile = profile_by_median_ratio_regression(array)
156
+ scaled_profile = profile
157
+ if np.isfinite(profile).any():
158
+ profile_mask = np.isfinite(profile)
159
+ scaled_profile[profile_mask] = profile[profile_mask] * (
160
+ np.nansum(array[:, profile_mask]) / np.nansum(profile[profile_mask])
161
+ )
162
+
163
+ return scaled_profile