tadamz 0.13.0a1__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 (80) hide show
  1. tadamz-0.13.0a1/LICENSE +21 -0
  2. tadamz-0.13.0a1/MANIFEST.in +7 -0
  3. tadamz-0.13.0a1/PKG-INFO +123 -0
  4. tadamz-0.13.0a1/README.md +96 -0
  5. tadamz-0.13.0a1/pyproject.toml +3 -0
  6. tadamz-0.13.0a1/setup.cfg +45 -0
  7. tadamz-0.13.0a1/src/tadamz/__init__.py +28 -0
  8. tadamz-0.13.0a1/src/tadamz/adapt_retention_time.py +329 -0
  9. tadamz-0.13.0a1/src/tadamz/calibration/__init__.py +6 -0
  10. tadamz-0.13.0a1/src/tadamz/calibration/calibrate.py +484 -0
  11. tadamz-0.13.0a1/src/tadamz/calibration/calibration_model.py +443 -0
  12. tadamz-0.13.0a1/src/tadamz/check_qualifier_peaks.py +93 -0
  13. tadamz-0.13.0a1/src/tadamz/classify_peaks.py +33 -0
  14. tadamz-0.13.0a1/src/tadamz/coeluting_peaks.py +221 -0
  15. tadamz-0.13.0a1/src/tadamz/correct_isotopologue_overlays.py +687 -0
  16. tadamz-0.13.0a1/src/tadamz/create_random_forest_peak_classifier.py +137 -0
  17. tadamz-0.13.0a1/src/tadamz/data/default_config.txt +46 -0
  18. tadamz-0.13.0a1/src/tadamz/data/example_peaks_info_table.xlsx +0 -0
  19. tadamz-0.13.0a1/src/tadamz/data/srm_peak_classifier.onnx +0 -0
  20. tadamz-0.13.0a1/src/tadamz/data/srm_table_for_predictor_curated.table +0 -0
  21. tadamz-0.13.0a1/src/tadamz/data/uplc_MS1_QEx_peak_classifier.onnx +0 -0
  22. tadamz-0.13.0a1/src/tadamz/data/uplc_MS1_predictor.table +0 -0
  23. tadamz-0.13.0a1/src/tadamz/emzed_fixes/__init__.py +6 -0
  24. tadamz-0.13.0a1/src/tadamz/emzed_fixes/_empty_peakmap.py +44 -0
  25. tadamz-0.13.0a1/src/tadamz/emzed_fixes/fix_integrate_chromatogram_formats.py +11 -0
  26. tadamz-0.13.0a1/src/tadamz/emzed_fixes/ms_chromatogram_to_peakmap.py +140 -0
  27. tadamz-0.13.0a1/src/tadamz/emzed_fixes/pick_ms_chromatogram_peaks.py +34 -0
  28. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/__init__.py +20 -0
  29. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_integration.py +336 -0
  30. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_shape_models/__init__.py +29 -0
  31. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_shape_models/asymmetric_gauss_model.py +138 -0
  32. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_shape_models/base.py +67 -0
  33. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_shape_models/linear_interpolation_model.py +57 -0
  34. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_shape_models/no_model.py +59 -0
  35. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_shape_models/savgol_model.py +83 -0
  36. tadamz-0.13.0a1/src/tadamz/emzed_fixes/quantification/peak_shape_models/simplified_emg.py +227 -0
  37. tadamz-0.13.0a1/src/tadamz/emzed_fixes/subtract_baselines.py +82 -0
  38. tadamz-0.13.0a1/src/tadamz/example_workflow.py +29 -0
  39. tadamz-0.13.0a1/src/tadamz/extract_peaks.py +470 -0
  40. tadamz-0.13.0a1/src/tadamz/extract_peaks_from_chromatograms.py +52 -0
  41. tadamz-0.13.0a1/src/tadamz/in_out.py +221 -0
  42. tadamz-0.13.0a1/src/tadamz/normalize_peaks.py +189 -0
  43. tadamz-0.13.0a1/src/tadamz/peaks_table.py +34 -0
  44. tadamz-0.13.0a1/src/tadamz/processing_steps.py +154 -0
  45. tadamz-0.13.0a1/src/tadamz/quantify.py +137 -0
  46. tadamz-0.13.0a1/src/tadamz/scoring/__init__.py +6 -0
  47. tadamz-0.13.0a1/src/tadamz/scoring/peak_metrics.py +269 -0
  48. tadamz-0.13.0a1/src/tadamz/scoring/random_forest_peak_classification.py +143 -0
  49. tadamz-0.13.0a1/src/tadamz/std_free_normalization.py +129 -0
  50. tadamz-0.13.0a1/src/tadamz/track_changes.py +104 -0
  51. tadamz-0.13.0a1/src/tadamz/update_sample_information.py +35 -0
  52. tadamz-0.13.0a1/src/tadamz/utils.py +208 -0
  53. tadamz-0.13.0a1/src/tadamz/workflow.py +141 -0
  54. tadamz-0.13.0a1/src/tadamz.egg-info/PKG-INFO +123 -0
  55. tadamz-0.13.0a1/src/tadamz.egg-info/SOURCES.txt +79 -0
  56. tadamz-0.13.0a1/src/tadamz.egg-info/dependency_links.txt +1 -0
  57. tadamz-0.13.0a1/src/tadamz.egg-info/not-zip-safe +1 -0
  58. tadamz-0.13.0a1/src/tadamz.egg-info/requires.txt +7 -0
  59. tadamz-0.13.0a1/src/tadamz.egg-info/top_level.txt +1 -0
  60. tadamz-0.13.0a1/tests/test_adapt_retention_time.py +227 -0
  61. tadamz-0.13.0a1/tests/test_calibrate.py +474 -0
  62. tadamz-0.13.0a1/tests/test_calibration_model.py +113 -0
  63. tadamz-0.13.0a1/tests/test_check_qualifier_peaks.py +87 -0
  64. tadamz-0.13.0a1/tests/test_classify_peaks.py +111 -0
  65. tadamz-0.13.0a1/tests/test_coeluting_peaks.py +758 -0
  66. tadamz-0.13.0a1/tests/test_correct_for_isotopologue_overlays.py +593 -0
  67. tadamz-0.13.0a1/tests/test_create_random_forest_peaks_classifier.py +100 -0
  68. tadamz-0.13.0a1/tests/test_extract_peaks.py +520 -0
  69. tadamz-0.13.0a1/tests/test_extract_peaks_from_chromatograms.py +60 -0
  70. tadamz-0.13.0a1/tests/test_in_out.py +124 -0
  71. tadamz-0.13.0a1/tests/test_normalize.py +521 -0
  72. tadamz-0.13.0a1/tests/test_pick_ms_chromatogram_peaks.py +52 -0
  73. tadamz-0.13.0a1/tests/test_processing_steps.py +95 -0
  74. tadamz-0.13.0a1/tests/test_quantify.py +120 -0
  75. tadamz-0.13.0a1/tests/test_run_workflow.py +193 -0
  76. tadamz-0.13.0a1/tests/test_subtract_baselines.py +260 -0
  77. tadamz-0.13.0a1/tests/test_track_changes.py +99 -0
  78. tadamz-0.13.0a1/tests/test_update_peak_metrics.py +61 -0
  79. tadamz-0.13.0a1/tests/test_update_sample_information.py +43 -0
  80. tadamz-0.13.0a1/tests/test_utils.py +135 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2023] [Patrick Kiefer]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ recursive-include src/tadamz *.table
2
+ recursive-include src/tadamz *.xlsx
3
+ recursive-include src/tadamz *.txt
4
+ recursive-include src/tadamz *.onnx
5
+ recursive-inclöude docs *.md
6
+
7
+ recursive-exclude * __pycache__
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: tadamz
3
+ Version: 0.13.0a1
4
+ Summary: package for targeted LC-MS(/MS) data analysis
5
+ Author: Patrick
6
+ Author-email: pkiefer@ethz.ch
7
+ License: MIT License
8
+ Classifier: Intended Audience :: Science/Research
9
+ Classifier: Intended Audience :: End Users/Desktop
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Natural Language :: English
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: pyyaml
20
+ Requires-Dist: uncertainties
21
+ Requires-Dist: skl2onnx==1.16.0
22
+ Requires-Dist: onnx==1.16.1
23
+ Requires-Dist: onnxruntime==1.16.3
24
+ Requires-Dist: pybaselines==1.1.0
25
+ Requires-Dist: emzed>=3.0.0a16
26
+ Dynamic: license-file
27
+
28
+ # tadamz
29
+
30
+
31
+
32
+ ## Getting started
33
+
34
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
35
+
36
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
37
+
38
+ ## Add your files
39
+
40
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
41
+ - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
42
+
43
+ ```
44
+ cd existing_repo
45
+ git remote add origin https://gitlab.com/emzed3_extensions/targeted.git
46
+ git branch -M main
47
+ git push -uf origin main
48
+ ```
49
+
50
+ ## Integrate with your tools
51
+
52
+ - [ ] [Set up project integrations](https://gitlab.com/emzed3_extensions/targeted/-/settings/integrations)
53
+
54
+ ## Collaborate with your team
55
+
56
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
57
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
58
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
59
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
60
+ - [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
61
+
62
+ ## Test and Deploy
63
+
64
+ Use the built-in continuous integration in GitLab.
65
+
66
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
67
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
68
+ - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
69
+ - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
70
+ - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
71
+
72
+ ***
73
+
74
+ # Editing this README
75
+
76
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
77
+
78
+ ## Suggestions for a good README
79
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
80
+
81
+ ## Name
82
+ Choose a self-explaining name for your project.
83
+
84
+ ## Description
85
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
86
+
87
+ ## Badges
88
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
89
+
90
+ ## Visuals
91
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
92
+
93
+ ## Installation
94
+ The package tadamz can be installed using pip, either within a separate venv or from the emzed-spyder IPython console:
95
+ ~~~
96
+ pip install https://gitlab.com/emzed3_extensions/targeted.git
97
+ ~~~~
98
+ emzed, emzed-webgui, and pyaml will be installed automatically as a dependencies if necessary.
99
+
100
+ ## Usage
101
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
102
+
103
+ ## Support
104
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
105
+
106
+ ## Roadmap
107
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
108
+
109
+ ## Contributing
110
+ State if you are open to contributions and what your requirements are for accepting them.
111
+
112
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
113
+
114
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
115
+
116
+ ## Authors and acknowledgment
117
+ Show your appreciation to those who have contributed to the project.
118
+
119
+ ## License
120
+ For open source projects, say how it is licensed.
121
+
122
+ ## Project status
123
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
@@ -0,0 +1,96 @@
1
+ # tadamz
2
+
3
+
4
+
5
+ ## Getting started
6
+
7
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
8
+
9
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
10
+
11
+ ## Add your files
12
+
13
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
14
+ - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
15
+
16
+ ```
17
+ cd existing_repo
18
+ git remote add origin https://gitlab.com/emzed3_extensions/targeted.git
19
+ git branch -M main
20
+ git push -uf origin main
21
+ ```
22
+
23
+ ## Integrate with your tools
24
+
25
+ - [ ] [Set up project integrations](https://gitlab.com/emzed3_extensions/targeted/-/settings/integrations)
26
+
27
+ ## Collaborate with your team
28
+
29
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
30
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
31
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
32
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
33
+ - [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
34
+
35
+ ## Test and Deploy
36
+
37
+ Use the built-in continuous integration in GitLab.
38
+
39
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
40
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
41
+ - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
42
+ - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
43
+ - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
44
+
45
+ ***
46
+
47
+ # Editing this README
48
+
49
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
50
+
51
+ ## Suggestions for a good README
52
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
53
+
54
+ ## Name
55
+ Choose a self-explaining name for your project.
56
+
57
+ ## Description
58
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
59
+
60
+ ## Badges
61
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
62
+
63
+ ## Visuals
64
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
65
+
66
+ ## Installation
67
+ The package tadamz can be installed using pip, either within a separate venv or from the emzed-spyder IPython console:
68
+ ~~~
69
+ pip install https://gitlab.com/emzed3_extensions/targeted.git
70
+ ~~~~
71
+ emzed, emzed-webgui, and pyaml will be installed automatically as a dependencies if necessary.
72
+
73
+ ## Usage
74
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
75
+
76
+ ## Support
77
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
78
+
79
+ ## Roadmap
80
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
81
+
82
+ ## Contributing
83
+ State if you are open to contributions and what your requirements are for accepting them.
84
+
85
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
86
+
87
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
88
+
89
+ ## Authors and acknowledgment
90
+ Show your appreciation to those who have contributed to the project.
91
+
92
+ ## License
93
+ For open source projects, say how it is licensed.
94
+
95
+ ## Project status
96
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 40.6.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,45 @@
1
+ [metadata]
2
+ name = tadamz
3
+ version = attr: tadamz.__version__
4
+ license = MIT License
5
+ description = package for targeted LC-MS(/MS) data analysis
6
+ long_description = file: README.md
7
+ long_description_content_type = text/markdown
8
+ author = Patrick
9
+ author_email = pkiefer@ethz.ch
10
+ classifiers =
11
+ Intended Audience :: Science/Research
12
+ Intended Audience :: End Users/Desktop
13
+ License :: OSI Approved :: MIT License
14
+ Natural Language :: English
15
+ Programming Language :: Python :: 3
16
+ Programming Language :: Python :: 3.9
17
+ Programming Language :: Python :: 3.10
18
+ Operating System :: OS Independent
19
+
20
+ [options]
21
+ install_requires =
22
+ pyyaml
23
+ uncertainties
24
+ skl2onnx==1.16.0
25
+ onnx==1.16.1
26
+ onnxruntime==1.16.3
27
+ pybaselines==1.1.0
28
+ emzed>=3.0.0a16
29
+ include_package_data = True
30
+ packages = find:
31
+ package_dir =
32
+ =src
33
+ zip_safe = False
34
+ python_requires = >=3.10
35
+
36
+ [options.packages.find]
37
+ where = src
38
+
39
+ [options.package_data]
40
+ * = *.txt, *.xlsx, *.table , *.md, *.onnx
41
+
42
+ [egg_info]
43
+ tag_build =
44
+ tag_date = 0
45
+
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Jul 3 15:56:21 2023
4
+
5
+ @author: pkiefer
6
+ """
7
+ __author__ = "Patrick Kiefer"
8
+ __email__ = "pkiefer@ethz.ch"
9
+ __credits__ = "ETH Zurich, Institute of Microbiology"
10
+
11
+ __version__ = "0.13.0a1"
12
+
13
+ # from . import score_peaks_quality
14
+ # from . import extract_peaks
15
+ from .in_out import load_config
16
+
17
+ # from .calibration.basic_calibration_functions import CalibrationModel
18
+ from . import workflow
19
+
20
+ # sfrom . calibration import basic_calibration_functions
21
+ # from . import normalize_peaks
22
+ # from . import peaks_table
23
+ # from . import processing_steps
24
+ # from . import quantify
25
+ # from . import utils
26
+ # from . import workflow
27
+ from .workflow import run_workflow, postprocess_result_table, run_calibration
28
+ from .create_random_forest_peak_classifier import generate_peak_classifier
@@ -0,0 +1,329 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Tue Feb 21 12:56:10 2023
4
+
5
+ @author: pkiefer
6
+ Concept
7
+ There are 2 approaches
8
+ 1) via fit (in that case the alignment peaks_table originates from a measurement)
9
+ 2) from internal standard: The simplest approach: we select most important
10
+ peak based on internal standard: Problems of mass isomers;
11
+ -> solutions
12
+ The risk in case of several in
13
+
14
+ """
15
+ import numpy as np
16
+ from emzed import RtType, Table
17
+ from emzed.quantification import integrate_chromatograms
18
+
19
+
20
+ ######################################################
21
+ # Local adaptation
22
+
23
+
24
+ from scipy.signal import savgol_filter
25
+
26
+
27
+ def local_adjust(t, min_fwhm=2.0, integration_algorithm="linear"):
28
+ _determine_shift(t)
29
+ _set_windows(t, min_fwhm, "rt_chromatogram")
30
+ integrate_chromatograms(t, integration_algorithm, in_place=True)
31
+ t.add_or_replace_column(
32
+ "rt_chromatogram",
33
+ t.apply(determine_rt, t.model_chromatogram, t.rt_chromatogram),
34
+ RtType,
35
+ )
36
+
37
+
38
+ def _determine_shift(t):
39
+ t.add_column("lboundary", t.rtmin_chromatogram - t.rt_chromatogram, RtType)
40
+ t.add_column("rboundary", t.rtmax_chromatogram - t.rt_chromatogram, RtType)
41
+ _update_spectral_distance(t)
42
+ t.replace_column(
43
+ "rtmin_chromatogram",
44
+ (t.rt_max_shift > 0).then_else(
45
+ t.rt_chromatogram - t.rt_max_shift, t.rt_chromatogram - t.min_tol
46
+ ),
47
+ RtType,
48
+ )
49
+ t.replace_column(
50
+ "rtmax_chromatogram",
51
+ (t.rt_max_shift > 0).then_else(
52
+ t.rt_chromatogram + t.rt_max_shift, t.rt_chromatogram + t.min_tol
53
+ ),
54
+ RtType,
55
+ )
56
+ integrate_chromatograms(t, "linear", in_place=True)
57
+ t.add_column(
58
+ "temp", t.apply(determine_rt, t.model_chromatogram, t.rt_chromatogram), RtType
59
+ )
60
+ t.replace_column("temp", t.temp.if_not_none_else(t.rt_chromatogram), RtType)
61
+ t.replace_column("rtmin_chromatogram", t.lboundary + t.temp, RtType)
62
+ t.replace_column("rtmax_chromatogram", t.rboundary + t.temp, RtType)
63
+ integrate_chromatograms(t, "linear", in_place=True)
64
+ t.drop_columns("lboundary", "rboundary", "temp", "min_tol")
65
+
66
+
67
+ def _update_spectral_distance(t):
68
+ t.add_column(
69
+ "min_tol",
70
+ t.apply(
71
+ _max_delta_spec,
72
+ t.chromatogram,
73
+ t.rtmin_chromatogram,
74
+ t.rtmax_chromatogram,
75
+ t.rt_max_shift,
76
+ ignore_nones=False,
77
+ ),
78
+ RtType,
79
+ )
80
+
81
+
82
+ def _max_delta_spec(*kwargs):
83
+ epsilon = 1e-2 # value to increase numerical stability but with no significant influence on
84
+ # rt shift
85
+ if not _check_params(kwargs):
86
+ return epsilon
87
+ chrom, rtmin, rtmax, rttol = kwargs
88
+ rts = chrom.rts
89
+ peak_range = rts[(rts >= rtmin - rttol) & (rts <= rtmax + rttol)]
90
+ deltas = np.diff(peak_range)
91
+ return max(deltas) + epsilon if len(deltas) else epsilon
92
+
93
+
94
+ def _check_params(kwargs):
95
+ chrom, rtmin, rtmax, rttol = kwargs
96
+ cond1 = len(chrom) if chrom is not None else False
97
+ cond2 = [v is not None for v in [rtmin, rtmax, rttol]]
98
+ return cond1 and cond2
99
+
100
+
101
+ def _set_windows(t, min_fwhm=2.0, rt_value_column=None):
102
+ params = [t.model_chromatogram, min_fwhm]
103
+ params.append(t[rt_value_column]) if rt_value_column else params.append(None)
104
+ t.add_column("temp", t.apply(adapt_window, *params), object)
105
+ t.add_column("_rtmin", t.apply(lambda v: v[0], t.temp), RtType)
106
+ t.add_column("_rtmax", t.apply(lambda v: v[1], t.temp), RtType)
107
+ t.replace_column(
108
+ "rtmin_chromatogram",
109
+ t._rtmin.is_not_none().then_else(t._rtmin, t.rtmin_chromatogram),
110
+ RtType,
111
+ )
112
+ t.replace_column(
113
+ "rtmax_chromatogram",
114
+ t._rtmax.is_not_none().then_else(t._rtmax, t.rtmax_chromatogram),
115
+ RtType,
116
+ )
117
+
118
+ t.drop_columns("temp", "_rtmin", "_rtmax")
119
+
120
+
121
+ """
122
+ Bug only zero intensity values
123
+ """
124
+
125
+
126
+ def adapt_window(model, min_fwhm, rt=None):
127
+ rts, ints = model.graph()
128
+ if not len(rts):
129
+ return None, None
130
+ smoothed = _get_smoothed(ints)
131
+ rt_ = _determine_rt(rts, smoothed)
132
+ rt = rt if rt_ is None else rt_
133
+ if rt is None:
134
+ return None, None
135
+ fwhm = _determine_fwhm(rts, smoothed, rt, min_fwhm)
136
+ f_asym = _determine_asymmetric_factor(rts, smoothed, rt)
137
+ left_pos = np.argwhere(np.logical_and(rts >= rt - 2 * f_asym * fwhm, rts < rt))
138
+ right_pos = np.argwhere(np.logical_and(rts <= rt + 2 / f_asym * fwhm, rts > rt))
139
+ start = _min_value_pos(left_pos, smoothed, False)
140
+ start = start if start else 0
141
+ stop = _min_value_pos(right_pos, smoothed)
142
+ stop = stop if stop else len(rts) - 1
143
+ return rts[start], rts[stop]
144
+
145
+
146
+ def _min_value_pos(positions, intensities, rightside=True):
147
+
148
+ if len(positions):
149
+ i = np.where(intensities[positions] == min(intensities[positions]))
150
+ index = 0 if rightside else -1
151
+ return positions[i][index]
152
+
153
+
154
+ def determine_rt(model, rt):
155
+ # rtmin, rtmax = limits
156
+ rts, ints = model.graph()
157
+ if len(ints):
158
+ smoothed = _get_smoothed(ints)
159
+ rt = _determine_rt(rts, smoothed)
160
+ return rt
161
+
162
+
163
+ def _get_smoothed(values):
164
+ try:
165
+ smoothed = savgol_filter(values, 7, 3)
166
+ # we exclude negative intensity values
167
+ smoothed[smoothed < 0] = 0
168
+ return smoothed
169
+ except:
170
+ return values
171
+
172
+
173
+ def _determine_rt(rts, smoothed):
174
+ i = np.where(smoothed == max(smoothed))[0]
175
+ i = int((min(i) + max(i)) / 2)
176
+ return rts[i]
177
+
178
+
179
+ def _determine_asymmetric_factor(rts, smoothed, rt):
180
+ max_int = _determine_max_int(rt, rts, smoothed)
181
+ pos = np.where(np.logical_and(smoothed >= 0.2 * max_int, smoothed <= max_int))[0]
182
+ diff_pos = np.diff(pos)
183
+ check = np.where(diff_pos > 1)[0] + 1
184
+ blocks = np.split(pos, check)
185
+ i = np.where(abs(rts - rt) == np.min(abs(rts - rt)))[0]
186
+ for block in blocks:
187
+ if i in block:
188
+ left = len(block[block <= i])
189
+ right = len(block[block >= i])
190
+ return left / right
191
+ return 1.0
192
+
193
+
194
+ def _determine_fwhm(rts, smoothed, rt, min_fwhm=2.0):
195
+ fwhm = min_fwhm
196
+ max_int = _determine_max_int(rt, rts, smoothed)
197
+ pos = np.where(np.logical_and(smoothed >= 0.5 * max_int, smoothed <= max_int))[0]
198
+ diff_pos = np.diff(pos)
199
+ check = np.where(diff_pos > 1)[0] + 1
200
+ blocks = np.split(pos, check)
201
+ i = np.where(abs(rts - rt) == np.min(abs(rts - rt)))[0]
202
+ for block in blocks:
203
+ if i in block:
204
+ fwhm = rts[max(block)] - rts[min(block)]
205
+ return fwhm if fwhm > min_fwhm else min_fwhm
206
+
207
+
208
+ def _determine_max_int(rt, rts, ints):
209
+ diffs = abs(rts - rt)
210
+ pos = np.where(diffs == min(diffs))
211
+ return max(ints[pos])
212
+
213
+
214
+ # ___________________ coeluting peaks ____________________
215
+ # based on cosine similarity scoring
216
+
217
+
218
+ def adapt_rt_by_coeluting_peaks(
219
+ t,
220
+ group_id_column="compound",
221
+ reference_column="is_coelution_reference_peak",
222
+ only_use_ref_peaks=True,
223
+ sample_wise=True,
224
+ min_fwhm=2.0,
225
+ **kwargs
226
+ ):
227
+ if len(t):
228
+ t.add_enumeration("rowid")
229
+ rid2algo = dict(zip(t.rowid, t.peak_shape_model_chromatogram))
230
+
231
+ # integration_algorithm = t_.peak_shape_model_chromatogram.unique_value()
232
+ temp_cols = "_rt_ref", "_fwhm_ref", "_ok", "_rtmin_ref", "_rtmax_ref", "rowid"
233
+ _add_rt_ref_columns(
234
+ t, reference_column, group_id_column, only_use_ref_peaks, sample_wise
235
+ )
236
+ t.add_column("_ok", (t.peak_coelutes == "ok").then_else(True, False), bool)
237
+ t_ok = t.filter(t._ok)
238
+ tables = [t_ok]
239
+ t_crit = t.filter(t._ok == False)
240
+ t.drop_columns(*temp_cols)
241
+ _move_rt_windows(t_crit, "sgolay", min_fwhm)
242
+ t_crit.replace_column(
243
+ "peak_shape_model_chromatogram",
244
+ t_crit.apply(rid2algo.get, t_crit.rowid),
245
+ str,
246
+ )
247
+ for t_ in t_crit.split_by_iter("peak_shape_model_chromatogram"):
248
+ algo = t_.peak_shape_model_chromatogram.unique_value()
249
+ integrate_chromatograms(t_, algo, in_place=True)
250
+ tables.append(t_)
251
+ t = Table.stack_tables(tables)
252
+ t.drop_columns(*temp_cols)
253
+ return t
254
+
255
+
256
+ def _add_rt_ref_columns(
257
+ t, reference_column, group_col, only_use_ref_peaks, sample_wise
258
+ ):
259
+ group_cols = [t[group_col]]
260
+ if sample_wise:
261
+ group_cols.append(t.filename)
262
+
263
+ if only_use_ref_peaks:
264
+ assert reference_column is not None
265
+ t.add_column(
266
+ "_rt_ref",
267
+ t.group_by(*group_cols).aggregate(
268
+ _get_ref_rt, t.rt_chromatogram, t[reference_column]
269
+ ),
270
+ RtType,
271
+ )
272
+ t.add_column(
273
+ "_rtmin_ref",
274
+ t.group_by(*group_cols).aggregate(
275
+ _get_ref_rt, t.rtmin_chromatogram, t[reference_column]
276
+ ),
277
+ RtType,
278
+ )
279
+ t.add_column(
280
+ "_rtmax_ref",
281
+ t.group_by(*group_cols).aggregate(
282
+ _get_ref_rt, t.rtmax_chromatogram, t[reference_column]
283
+ ),
284
+ RtType,
285
+ )
286
+ else:
287
+ t.add_column(
288
+ "_rt_ref", t.group_by(*group_cols).median(t.rt_chromatogram), RtType
289
+ )
290
+ t.add_column(
291
+ "_rtmin_ref", t.group_by(*group_cols).median(t.rtmin_chromatogram), RtType
292
+ )
293
+ t.add_column(
294
+ "_rtmax_ref", t.group_by(*group_cols).median(t.rtmax_chromatogram), RtType
295
+ )
296
+ t.add_column("_fwhm_ref", (t._rtmax_ref - t._rtmin_ref) / 4, float)
297
+
298
+
299
+ def _move_rt_windows(t, integration_algorithm, min_fwhm):
300
+ t.replace_column(
301
+ "rtmin_chromatogram",
302
+ t.rtmin_chromatogram + t._rt_ref - t.rt_chromatogram,
303
+ RtType,
304
+ )
305
+ t.replace_column(
306
+ "rtmax_chromatogram",
307
+ t.rtmax_chromatogram + t._rt_ref - t.rt_chromatogram,
308
+ RtType,
309
+ )
310
+
311
+ integrate_chromatograms(t, "linear", in_place=True)
312
+ _set_windows(t, min_fwhm, "_rt_ref")
313
+ # bug fix
314
+ # special case: zero len peaks: rmse calculation fails.
315
+ # we apply linear instead
316
+ try:
317
+ integrate_chromatograms(t, integration_algorithm, in_place=True)
318
+ except:
319
+ integrate_chromatograms(t, "linear", in_place=True)
320
+ t.add_or_replace_column(
321
+ "rt_chromatogram",
322
+ t.apply(determine_rt, t.model_chromatogram, t.rt_chromatogram),
323
+ RtType,
324
+ )
325
+
326
+
327
+ def _get_ref_rt(rts, references):
328
+ rts_ = [rt for rt, ref in zip(rts, references) if ref]
329
+ return np.mean(rts_)
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Tue Jun 11 09:22:41 2024
4
+
5
+ @author: pkiefer
6
+ """