mgnify-pipelines-toolkit 0.0.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.
Potentially problematic release.
This version of mgnify-pipelines-toolkit might be problematic. Click here for more details.
- mgnify_pipelines_toolkit-0.0.5/LICENSE +201 -0
- mgnify_pipelines_toolkit-0.0.5/PKG-INFO +84 -0
- mgnify_pipelines_toolkit-0.0.5/README.md +67 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/__init__.py +0 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/__init__.py +0 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/get_subunits.py +96 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/get_subunits_coords.py +42 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/mapseq2biom.py +157 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/__init__.py +0 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/are_there_primers.py +123 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/assess_inflection_point_mcp.py +142 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/assess_mcp_proportions.py +174 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/classify_var_regions.py +474 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/find_mcp_inflection_points.py +79 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/make_asv_count_table.py +249 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/remove_ambiguous_reads.py +75 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/rev_comp_se_primers.py +41 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit/v6/v6_amplicon/standard_primer_agrep.py +285 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit.egg-info/PKG-INFO +84 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit.egg-info/SOURCES.txt +24 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit.egg-info/dependency_links.txt +1 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit.egg-info/entry_points.txt +13 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit.egg-info/requires.txt +3 -0
- mgnify_pipelines_toolkit-0.0.5/mgnify_pipelines_toolkit.egg-info/top_level.txt +1 -0
- mgnify_pipelines_toolkit-0.0.5/pyproject.toml +46 -0
- mgnify_pipelines_toolkit-0.0.5/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mgnify_pipelines_toolkit
|
|
3
|
+
Version: 0.0.5
|
|
4
|
+
Summary: Collection of scripts and tools for MGnify pipelines
|
|
5
|
+
Author-email: MGnify team <metagenomics-help@ebi.ac.uk>
|
|
6
|
+
License: Apache Software License 2.0
|
|
7
|
+
Keywords: bioinformatics,pipelines,metagenomics
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: biopython==1.81
|
|
15
|
+
Requires-Dist: numpy==1.24.3
|
|
16
|
+
Requires-Dist: pandas==2.0.2
|
|
17
|
+
|
|
18
|
+
# mgnify-pipelines-toolkit
|
|
19
|
+
|
|
20
|
+
This Python package contains a collection of scripts and tools for including in MGnify pipelines. Scripts stored here are mainly for:
|
|
21
|
+
|
|
22
|
+
- One-off production scripts that perform specific tasks in pipelines
|
|
23
|
+
- Scripts that have few dependencies
|
|
24
|
+
- Scripts that don't have existing containers built to run them
|
|
25
|
+
- Scripts for which building an entire container would be too bulky of a solution to deploy in pipelines
|
|
26
|
+
|
|
27
|
+
This package can be built and uploaded to PyPi, to be installed using pip. The package bundles scripts and makes them executable from the command-line when this package is installed.
|
|
28
|
+
|
|
29
|
+
> **Soon: this repository will be made available on bioconda for even easier integration in nextflow/nf-core pipelines**.
|
|
30
|
+
|
|
31
|
+
## How to install
|
|
32
|
+
|
|
33
|
+
Currently this package is only available on TestPyPi and is installed like this:
|
|
34
|
+
|
|
35
|
+
`pip install -i https://test.pypi.org/simple/ --no-deps mgnify-pipelines-toolkit`
|
|
36
|
+
|
|
37
|
+
You should then be able to run the packages from the command-line. For example to run the `get_subunits.py` script:
|
|
38
|
+
|
|
39
|
+
`get_subunits -i ${easel_coords} -n ${meta.id}`
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Building and uploading to PyPi
|
|
43
|
+
This command this build the package:
|
|
44
|
+
|
|
45
|
+
`python3 -m build`
|
|
46
|
+
|
|
47
|
+
Then this command will upload it to Test-PyPi (you will need to generate an API token)
|
|
48
|
+
|
|
49
|
+
`python3 -m twine upload --repository testpypi dist/mgnify_pipelines_toolkit-0.0.x*`
|
|
50
|
+
|
|
51
|
+
To upload it to actual PyPi:
|
|
52
|
+
|
|
53
|
+
`python3 -m twine upload dist/*`
|
|
54
|
+
|
|
55
|
+
## Adding a new script to the package
|
|
56
|
+
|
|
57
|
+
### New script requirements
|
|
58
|
+
|
|
59
|
+
There are a few requirements for your script:
|
|
60
|
+
- It needs to have a named main function of some kind. See `mgnify_pipelines_toolkit/v6/get_subunits.py` and the `main()` function for an example
|
|
61
|
+
- Because this package is meant to be run from the command-line, make sure your script can easily pass arguments using tools like `argparse` or `click`
|
|
62
|
+
- A small amount of dependencies. This requirement is subjective, but for example if your script only requires a handful of basic packages like `Biopython`, `numpy`, `pandas`, etc., then it's fine. However if the script has a more extensive list of dependencies, a container is probably a better fit.
|
|
63
|
+
|
|
64
|
+
### How to add a new script
|
|
65
|
+
|
|
66
|
+
To add a new Python script, first copy it over to the `mgnify_pipelines_toolkit` directory in this repository, specifically to the subdirectory that makes the most sense. If none of the subdirectories make sense for your script, create a new one. If your script doesn't have a `main()` type function yet, write one.
|
|
67
|
+
|
|
68
|
+
Then, open `pyproject.toml` as you will need to add some bits. First, any dependencies required (include the version) to the `dependencies` field.
|
|
69
|
+
|
|
70
|
+
Then, scroll down to the `[project.scripts]` line. Here, you will create an alias command for running your script from the command-line. In the example line:
|
|
71
|
+
|
|
72
|
+
`get_subunits = "mgnify_pipelines_toolkit.v6.get_subunits:main"`
|
|
73
|
+
|
|
74
|
+
- `get_subunits` is the alias
|
|
75
|
+
- `mgnify_pipelines_toolkit.v6.get_subunits` will link the alias to the script with the path `mgnify_pipelines_toolkit/v6/get_subunits.py`
|
|
76
|
+
- `:main` will specifically call the function named `main()` when the alias is run.
|
|
77
|
+
|
|
78
|
+
When you have setup this command, executing `get_subunits` on the command-line will be the equivalent of doing:
|
|
79
|
+
|
|
80
|
+
`from mgnify_pipelines_toolkit.v6.get_subunits import main; main()`
|
|
81
|
+
|
|
82
|
+
Finally, you will need to bump up the version in the `version` line. How/when we bump versions is to be determined.
|
|
83
|
+
|
|
84
|
+
At the moment, these should be the only steps required to setup your script in this package (which is subject to change).
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# mgnify-pipelines-toolkit
|
|
2
|
+
|
|
3
|
+
This Python package contains a collection of scripts and tools for including in MGnify pipelines. Scripts stored here are mainly for:
|
|
4
|
+
|
|
5
|
+
- One-off production scripts that perform specific tasks in pipelines
|
|
6
|
+
- Scripts that have few dependencies
|
|
7
|
+
- Scripts that don't have existing containers built to run them
|
|
8
|
+
- Scripts for which building an entire container would be too bulky of a solution to deploy in pipelines
|
|
9
|
+
|
|
10
|
+
This package can be built and uploaded to PyPi, to be installed using pip. The package bundles scripts and makes them executable from the command-line when this package is installed.
|
|
11
|
+
|
|
12
|
+
> **Soon: this repository will be made available on bioconda for even easier integration in nextflow/nf-core pipelines**.
|
|
13
|
+
|
|
14
|
+
## How to install
|
|
15
|
+
|
|
16
|
+
Currently this package is only available on TestPyPi and is installed like this:
|
|
17
|
+
|
|
18
|
+
`pip install -i https://test.pypi.org/simple/ --no-deps mgnify-pipelines-toolkit`
|
|
19
|
+
|
|
20
|
+
You should then be able to run the packages from the command-line. For example to run the `get_subunits.py` script:
|
|
21
|
+
|
|
22
|
+
`get_subunits -i ${easel_coords} -n ${meta.id}`
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Building and uploading to PyPi
|
|
26
|
+
This command this build the package:
|
|
27
|
+
|
|
28
|
+
`python3 -m build`
|
|
29
|
+
|
|
30
|
+
Then this command will upload it to Test-PyPi (you will need to generate an API token)
|
|
31
|
+
|
|
32
|
+
`python3 -m twine upload --repository testpypi dist/mgnify_pipelines_toolkit-0.0.x*`
|
|
33
|
+
|
|
34
|
+
To upload it to actual PyPi:
|
|
35
|
+
|
|
36
|
+
`python3 -m twine upload dist/*`
|
|
37
|
+
|
|
38
|
+
## Adding a new script to the package
|
|
39
|
+
|
|
40
|
+
### New script requirements
|
|
41
|
+
|
|
42
|
+
There are a few requirements for your script:
|
|
43
|
+
- It needs to have a named main function of some kind. See `mgnify_pipelines_toolkit/v6/get_subunits.py` and the `main()` function for an example
|
|
44
|
+
- Because this package is meant to be run from the command-line, make sure your script can easily pass arguments using tools like `argparse` or `click`
|
|
45
|
+
- A small amount of dependencies. This requirement is subjective, but for example if your script only requires a handful of basic packages like `Biopython`, `numpy`, `pandas`, etc., then it's fine. However if the script has a more extensive list of dependencies, a container is probably a better fit.
|
|
46
|
+
|
|
47
|
+
### How to add a new script
|
|
48
|
+
|
|
49
|
+
To add a new Python script, first copy it over to the `mgnify_pipelines_toolkit` directory in this repository, specifically to the subdirectory that makes the most sense. If none of the subdirectories make sense for your script, create a new one. If your script doesn't have a `main()` type function yet, write one.
|
|
50
|
+
|
|
51
|
+
Then, open `pyproject.toml` as you will need to add some bits. First, any dependencies required (include the version) to the `dependencies` field.
|
|
52
|
+
|
|
53
|
+
Then, scroll down to the `[project.scripts]` line. Here, you will create an alias command for running your script from the command-line. In the example line:
|
|
54
|
+
|
|
55
|
+
`get_subunits = "mgnify_pipelines_toolkit.v6.get_subunits:main"`
|
|
56
|
+
|
|
57
|
+
- `get_subunits` is the alias
|
|
58
|
+
- `mgnify_pipelines_toolkit.v6.get_subunits` will link the alias to the script with the path `mgnify_pipelines_toolkit/v6/get_subunits.py`
|
|
59
|
+
- `:main` will specifically call the function named `main()` when the alias is run.
|
|
60
|
+
|
|
61
|
+
When you have setup this command, executing `get_subunits` on the command-line will be the equivalent of doing:
|
|
62
|
+
|
|
63
|
+
`from mgnify_pipelines_toolkit.v6.get_subunits import main; main()`
|
|
64
|
+
|
|
65
|
+
Finally, you will need to bump up the version in the `version` line. How/when we bump versions is to be determined.
|
|
66
|
+
|
|
67
|
+
At the moment, these should be the only steps required to setup your script in this package (which is subject to change).
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
from Bio import SeqIO
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
SSU = "SSU_rRNA"
|
|
9
|
+
LSU = "LSU_rRNA"
|
|
10
|
+
Seq5S = "mtPerm-5S"
|
|
11
|
+
Seq5_8S = "5_8S_rRNA"
|
|
12
|
+
|
|
13
|
+
SSU_rRNA_archaea = "SSU_rRNA_archaea"
|
|
14
|
+
SSU_rRNA_bacteria = "SSU_rRNA_bacteria"
|
|
15
|
+
SSU_rRNA_eukarya = "SSU_rRNA_eukarya"
|
|
16
|
+
SSU_rRNA_microsporidia = "SSU_rRNA_microsporidia"
|
|
17
|
+
|
|
18
|
+
LSU_rRNA_archaea = "LSU_rRNA_archaea"
|
|
19
|
+
LSU_rRNA_bacteria = "LSU_rRNA_bacteria"
|
|
20
|
+
LSU_rRNA_eukarya = "LSU_rRNA_eukarya"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def set_model_names(prefix, name):
|
|
24
|
+
pattern_dict = {}
|
|
25
|
+
pattern_dict[SSU] = os.path.join(directory, f'{name}_SSU.fasta')
|
|
26
|
+
pattern_dict[SSU_rRNA_archaea] = os.path.join(directory, f'{prefix}{name}_{SSU_rRNA_archaea}.RF01959.fa')
|
|
27
|
+
pattern_dict[SSU_rRNA_bacteria] = os.path.join(directory, f'{prefix}{name}_{SSU_rRNA_bacteria}.RF00177.fa')
|
|
28
|
+
pattern_dict[SSU_rRNA_eukarya] = os.path.join(directory, f'{prefix}{name}_{SSU_rRNA_eukarya}.RF01960.fa')
|
|
29
|
+
pattern_dict[SSU_rRNA_microsporidia] = os.path.join(directory, f'{prefix}{name}_{SSU_rRNA_microsporidia}.RF02542.fa')
|
|
30
|
+
pattern_dict[LSU] = os.path.join(directory, f'{name}_LSU.fasta')
|
|
31
|
+
pattern_dict[LSU_rRNA_archaea] = os.path.join(directory, f'{prefix}{name}_{LSU_rRNA_archaea}.RF02540.fa')
|
|
32
|
+
pattern_dict[LSU_rRNA_bacteria] = os.path.join(directory, f'{prefix}{name}_{LSU_rRNA_bacteria}.RF02541.fa')
|
|
33
|
+
pattern_dict[LSU_rRNA_eukarya] = os.path.join(directory, f'{prefix}{name}_{LSU_rRNA_eukarya}.RF02543.fa')
|
|
34
|
+
pattern_dict[Seq5S] = os.path.join(directory, f'{name}_5S.fa')
|
|
35
|
+
pattern_dict[Seq5_8S] = os.path.join(directory, f'{name}_5_8S.fa')
|
|
36
|
+
return pattern_dict
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main():
|
|
40
|
+
parser = argparse.ArgumentParser(
|
|
41
|
+
description="Extract lsu, ssu and 5s and other models"
|
|
42
|
+
)
|
|
43
|
+
parser.add_argument(
|
|
44
|
+
"-i", "--input", dest="input", help="Input fasta file", required=True
|
|
45
|
+
)
|
|
46
|
+
parser.add_argument(
|
|
47
|
+
"-p", "--prefix", dest="prefix", help="prefix for models", required=False
|
|
48
|
+
)
|
|
49
|
+
parser.add_argument("-n", "--name", dest="name", help="Accession", required=True)
|
|
50
|
+
|
|
51
|
+
args = parser.parse_args()
|
|
52
|
+
prefix = args.prefix if args.prefix else ""
|
|
53
|
+
name = args.name if args.name else "accession"
|
|
54
|
+
|
|
55
|
+
directory = "sequence-categorisation"
|
|
56
|
+
if not os.path.exists(directory):
|
|
57
|
+
os.makedirs(directory)
|
|
58
|
+
directory_ncRNA = os.path.join("sequence-categorisation", "ncRNA")
|
|
59
|
+
if not os.path.exists(directory_ncRNA):
|
|
60
|
+
os.makedirs(directory_ncRNA)
|
|
61
|
+
|
|
62
|
+
print('Start fasta mode')
|
|
63
|
+
pattern_dict = set_model_names(prefix, name)
|
|
64
|
+
coding_rna = [SSU_rRNA_archaea, SSU_rRNA_bacteria, SSU_rRNA_eukarya, SSU_rRNA_microsporidia,
|
|
65
|
+
LSU_rRNA_archaea, LSU_rRNA_bacteria, LSU_rRNA_eukarya, Seq5S, Seq5_8S]
|
|
66
|
+
open_files = {}
|
|
67
|
+
for record in SeqIO.parse(args.input, "fasta"):
|
|
68
|
+
model = '-'.join(record.id.split('/')[0].split('-')[1:])
|
|
69
|
+
if model in coding_rna:
|
|
70
|
+
filename = pattern_dict[model]
|
|
71
|
+
else:
|
|
72
|
+
filename = os.path.join(directory_ncRNA, f'{prefix}{name}_{model}.fasta')
|
|
73
|
+
if model not in open_files:
|
|
74
|
+
file_out = open(filename, 'w')
|
|
75
|
+
open_files[model] = file_out
|
|
76
|
+
SeqIO.write(record, open_files[model], "fasta")
|
|
77
|
+
|
|
78
|
+
if model in (SSU_rRNA_archaea, SSU_rRNA_bacteria, SSU_rRNA_eukarya, SSU_rRNA_microsporidia):
|
|
79
|
+
if SSU not in open_files:
|
|
80
|
+
file_out = open(pattern_dict[SSU], 'w')
|
|
81
|
+
open_files[SSU] = file_out
|
|
82
|
+
SeqIO.write(record, open_files[SSU], "fasta")
|
|
83
|
+
if model in (LSU_rRNA_archaea, LSU_rRNA_bacteria, LSU_rRNA_eukarya):
|
|
84
|
+
if LSU not in open_files:
|
|
85
|
+
file_out = open(pattern_dict[LSU], 'w')
|
|
86
|
+
open_files[LSU] = file_out
|
|
87
|
+
SeqIO.write(record, open_files[LSU], "fasta")
|
|
88
|
+
|
|
89
|
+
for item in open_files:
|
|
90
|
+
open_files[item].close()
|
|
91
|
+
|
|
92
|
+
if len(os.listdir(directory_ncRNA)) == 0:
|
|
93
|
+
os.rmdir(directory_ncRNA)
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
import gzip
|
|
7
|
+
from Bio import SeqIO
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
SSU_coords = "SSU_coords"
|
|
11
|
+
LSU_coords = "LSU_coords"
|
|
12
|
+
SSU_count = 0
|
|
13
|
+
LSU_count = 0
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
parser = argparse.ArgumentParser(description="Extract lsu, ssu and 5s")
|
|
17
|
+
parser.add_argument("-i", "--input", dest="input", help="Input fasta file", required=True)
|
|
18
|
+
parser.add_argument("-l", "--lsu", dest="lsu", help="LSU pattern", required=True)
|
|
19
|
+
parser.add_argument("-s", "--ssu", dest="ssu", help="SSU pattern", required=True)
|
|
20
|
+
|
|
21
|
+
if len(sys.argv) == 1:
|
|
22
|
+
parser.print_help()
|
|
23
|
+
else:
|
|
24
|
+
args = parser.parse_args()
|
|
25
|
+
|
|
26
|
+
with open(SSU_coords, 'w') as out_ssu, open(LSU_coords, 'w') as out_lsu, open(args.input, 'r') as input:
|
|
27
|
+
for line in input:
|
|
28
|
+
if args.lsu in line:
|
|
29
|
+
out_lsu.write(line)
|
|
30
|
+
LSU_count += 1
|
|
31
|
+
elif args.ssu in line:
|
|
32
|
+
out_ssu.write(line)
|
|
33
|
+
SSU_count += 1
|
|
34
|
+
with open("RNA-counts", 'w') as count:
|
|
35
|
+
count.write("LSU count\t" + str(LSU_count) + "\nSSU count\t" + str(SSU_count))
|
|
36
|
+
|
|
37
|
+
out_ssu.close()
|
|
38
|
+
out_lsu.close()
|
|
39
|
+
count.close()
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import csv
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
parser = argparse.ArgumentParser(add_help="Convert the mapseq otutable to biome")
|
|
9
|
+
parser.add_argument(
|
|
10
|
+
"--otu-table",
|
|
11
|
+
required=True,
|
|
12
|
+
help=(
|
|
13
|
+
"The OTU table produced for the taxonomies found in"
|
|
14
|
+
" the reference databases that was used with MAPseq."
|
|
15
|
+
),
|
|
16
|
+
)
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"--query",
|
|
19
|
+
required=True,
|
|
20
|
+
help="The output from the MAPseq that assigns a taxonomy to a sequence.",
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--out-file", required=True, help="The file storing the tsv file."
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--krona", required=False, help="Output file name for the Krona text"
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"--label",
|
|
30
|
+
required=False,
|
|
31
|
+
default="Unspecified",
|
|
32
|
+
help="Label to add to the top of the outfile OTU table.",
|
|
33
|
+
)
|
|
34
|
+
parser.add_argument("--no-tax-id-file", required=True, help="TODO")
|
|
35
|
+
parser.add_argument("--taxid", action="store_true")
|
|
36
|
+
|
|
37
|
+
args = parser.parse_args()
|
|
38
|
+
|
|
39
|
+
tax_counter = {}
|
|
40
|
+
|
|
41
|
+
with open(args.query, "r") as query_fh:
|
|
42
|
+
tax = ""
|
|
43
|
+
for line in query_fh.readlines():
|
|
44
|
+
if line.startswith("#"):
|
|
45
|
+
# Skip counts
|
|
46
|
+
continue
|
|
47
|
+
# Pull out the fields that we need
|
|
48
|
+
line = line.strip()
|
|
49
|
+
fields = line.split("\t")
|
|
50
|
+
|
|
51
|
+
if len(fields) < 14:
|
|
52
|
+
tax = "Unclassified"
|
|
53
|
+
else:
|
|
54
|
+
if not fields[13]:
|
|
55
|
+
tax = "Unclassified"
|
|
56
|
+
else:
|
|
57
|
+
tax = fields[13]
|
|
58
|
+
while tax.endswith("__"):
|
|
59
|
+
fds = tax.split(";")
|
|
60
|
+
fds = fds[:-1]
|
|
61
|
+
tax = ";".join(fds)
|
|
62
|
+
|
|
63
|
+
if tax in tax_counter:
|
|
64
|
+
tax_counter[tax]["count"] += 1
|
|
65
|
+
else:
|
|
66
|
+
tax_counter[tax] = {"count": 1, "otu": 1, "taxid": ""}
|
|
67
|
+
|
|
68
|
+
with open(args.otu_table, "r") as otu_table_fh:
|
|
69
|
+
csv_reader = csv.reader(otu_table_fh, delimiter="\t")
|
|
70
|
+
next(csv_reader)
|
|
71
|
+
for row in csv_reader:
|
|
72
|
+
# Simple two column table, OTU code and taxonomy string.
|
|
73
|
+
otu = row[0]
|
|
74
|
+
tax = row[1]
|
|
75
|
+
tax_id = row[2] if len(row) >= 3 else None
|
|
76
|
+
# Have we seen this tax string? Store the OTU
|
|
77
|
+
if tax in tax_counter:
|
|
78
|
+
tax_counter[tax]["otu"] = otu
|
|
79
|
+
if tax_id:
|
|
80
|
+
tax_counter[tax]["taxid"] = tax_id
|
|
81
|
+
|
|
82
|
+
for tax in tax_counter.keys():
|
|
83
|
+
if tax_counter[tax]["otu"] is None:
|
|
84
|
+
raise ValueError(f"Fatal, |{tax}| has not got an OTU code assigned")
|
|
85
|
+
|
|
86
|
+
output_header = []
|
|
87
|
+
notaxidfile_header = []
|
|
88
|
+
|
|
89
|
+
if args.taxid:
|
|
90
|
+
if args.label.startswith("UNITE"):
|
|
91
|
+
output_header = [
|
|
92
|
+
"# OTU ID",
|
|
93
|
+
args.label,
|
|
94
|
+
"taxonomy",
|
|
95
|
+
]
|
|
96
|
+
else:
|
|
97
|
+
output_header = [
|
|
98
|
+
"# OTU ID",
|
|
99
|
+
args.label,
|
|
100
|
+
"taxonomy",
|
|
101
|
+
"taxid",
|
|
102
|
+
]
|
|
103
|
+
notaxidfile_header = [
|
|
104
|
+
"# OTU ID",
|
|
105
|
+
args.label,
|
|
106
|
+
"taxonomy",
|
|
107
|
+
]
|
|
108
|
+
else:
|
|
109
|
+
output_header = [
|
|
110
|
+
"# OTU ID",
|
|
111
|
+
args.label,
|
|
112
|
+
"taxonomy",
|
|
113
|
+
]
|
|
114
|
+
notaxidfile_header = [
|
|
115
|
+
"# OTU ID",
|
|
116
|
+
args.label,
|
|
117
|
+
"taxonomy",
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
with open(args.out_file, "w") as output_fh:
|
|
121
|
+
output_fh.write("# Constructed from biom file\n")
|
|
122
|
+
output_csv = csv.writer(output_fh, delimiter="\t")
|
|
123
|
+
output_csv.writerow(output_header)
|
|
124
|
+
for tax in sorted(tax_counter.keys()):
|
|
125
|
+
row = [
|
|
126
|
+
tax_counter[tax]["otu"],
|
|
127
|
+
f"{float(tax_counter[tax]['count']):.1f}",
|
|
128
|
+
tax,
|
|
129
|
+
]
|
|
130
|
+
if args.taxid:
|
|
131
|
+
row.append(tax_counter[tax]["taxid"])
|
|
132
|
+
output_csv.writerow(row)
|
|
133
|
+
|
|
134
|
+
if args.taxid:
|
|
135
|
+
with open(args.no_tax_id_file, "w") as notaxidfile_fh:
|
|
136
|
+
notaxidfile_fh.write("# Constructed from biom file\n")
|
|
137
|
+
csv_writer = csv.writer(notaxidfile_fh, delimiter="\t")
|
|
138
|
+
csv_writer.writerow(notaxidfile_header)
|
|
139
|
+
for tax in sorted(tax_counter.keys()):
|
|
140
|
+
csv_writer.writerow(
|
|
141
|
+
[
|
|
142
|
+
tax_counter[tax]["otu"],
|
|
143
|
+
f"{float(tax_counter[tax]['count']):.1f}",
|
|
144
|
+
tax,
|
|
145
|
+
]
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
if args.krona:
|
|
149
|
+
with open(args.krona, "w") as k:
|
|
150
|
+
for tax in sorted(tax_counter.keys()):
|
|
151
|
+
tax_mod = tax.replace(r"\D_\d{1}__", "")
|
|
152
|
+
tax_mod = "\t".join(tax_mod.split(";"))
|
|
153
|
+
k.write(f"{tax_counter[tax]['count']}\t{tax_mod}\n")
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
if __name__ == "__main__":
|
|
157
|
+
main()
|
|
File without changes
|