-
Notifications
You must be signed in to change notification settings - Fork 20
/
plugin_setup.py
278 lines (259 loc) · 12 KB
/
plugin_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# ----------------------------------------------------------------------------
# Copyright (c) 2016-2020, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import importlib
from qiime2.plugin import (
Plugin, Metadata, MetadataColumn, Categorical, Bool, Str, Int, Float,
Range, Citations, TypeMatch
)
from q2_types.sample_data import SampleData
from q2_types.per_sample_sequences import (
SequencesWithQuality, PairedEndSequencesWithQuality,
JoinedSequencesWithQuality)
import q2_demux
from ._type import (RawSequences, EMPSingleEndSequences, EMPPairedEndSequences,
ErrorCorrectionDetails)
from ._format import (EMPMultiplexedDirFmt, ErrorCorrectionDetailsDirFmt,
EMPSingleEndDirFmt, EMPSingleEndCasavaDirFmt,
EMPPairedEndDirFmt, EMPPairedEndCasavaDirFmt)
citations = Citations.load('citations.bib', package='q2_demux')
plugin = Plugin(
name='demux',
version=q2_demux.__version__,
website='https://github.com/qiime2/q2-demux',
package='q2_demux',
description=('This QIIME 2 plugin supports demultiplexing of '
'single-end and paired-end sequence reads and '
'visualization of sequence quality information.'),
short_description='Plugin for demultiplexing & viewing sequence quality.'
)
plugin.register_semantic_types(
RawSequences, EMPSingleEndSequences, EMPPairedEndSequences,
ErrorCorrectionDetails)
plugin.register_formats(EMPMultiplexedDirFmt, ErrorCorrectionDetailsDirFmt,
EMPSingleEndDirFmt, EMPSingleEndCasavaDirFmt,
EMPPairedEndDirFmt, EMPPairedEndCasavaDirFmt)
# TODO: remove when aliasing exists
plugin.register_semantic_type_to_format(
RawSequences,
artifact_format=EMPSingleEndDirFmt
)
plugin.register_semantic_type_to_format(
EMPSingleEndSequences,
artifact_format=EMPSingleEndDirFmt
)
plugin.register_semantic_type_to_format(
EMPPairedEndSequences,
artifact_format=EMPPairedEndDirFmt
)
plugin.register_semantic_type_to_format(
ErrorCorrectionDetails,
artifact_format=ErrorCorrectionDetailsDirFmt
)
plugin.methods.register_function(
function=q2_demux.emp_single,
# TODO: remove RawSequences by creating an alias to EMPSequences
inputs={'seqs': (RawSequences |
EMPSingleEndSequences |
EMPPairedEndSequences)},
parameters={'barcodes': MetadataColumn[Categorical],
'golay_error_correction': Bool,
'rev_comp_barcodes': Bool,
'rev_comp_mapping_barcodes': Bool,
'ignore_description_mismatch': Bool},
outputs=[('per_sample_sequences', SampleData[SequencesWithQuality]),
('error_correction_details', ErrorCorrectionDetails)],
input_descriptions={
'seqs': 'The single-end sequences to be demultiplexed.'
},
parameter_descriptions={
'barcodes': 'The sample metadata column containing the per-sample '
'barcodes.',
'golay_error_correction': 'Perform 12nt Golay error correction on the '
'barcode reads.',
'rev_comp_barcodes': 'If provided, the barcode sequence reads will be '
'reverse complemented prior to demultiplexing.',
'rev_comp_mapping_barcodes': 'If provided, the barcode sequences in '
'the sample metadata will be reverse '
'complemented prior to demultiplexing.',
'ignore_description_mismatch': 'If True, ignore mismatches in '
'sequence record description fields.'
},
output_descriptions={
'per_sample_sequences': 'The resulting demultiplexed sequences.',
'error_correction_details': 'Detail about the barcode error '
'corrections.'
},
name='Demultiplex sequence data generated with the EMP protocol.',
description=('Demultiplex sequence data (i.e., map barcode reads to '
'sample ids) for data generated with the Earth Microbiome '
'Project (EMP) amplicon sequencing protocol. Details about '
'this protocol can be found at '
'http://www.earthmicrobiome.org/protocols-and-standards/'),
citations=[
citations['hamady2008'],
citations['hamady2009']]
)
plugin.methods.register_function(
function=q2_demux.emp_paired,
inputs={'seqs': EMPPairedEndSequences},
parameters={'barcodes': MetadataColumn[Categorical],
'golay_error_correction': Bool,
'rev_comp_barcodes': Bool,
'rev_comp_mapping_barcodes': Bool,
'ignore_description_mismatch': Bool},
outputs=[
('per_sample_sequences', SampleData[PairedEndSequencesWithQuality]),
('error_correction_details', ErrorCorrectionDetails),
],
input_descriptions={
'seqs': 'The paired-end sequences to be demultiplexed.'
},
parameter_descriptions={
'barcodes': 'The sample metadata column containing the per-sample '
'barcodes.',
'golay_error_correction': 'Perform 12nt Golay error correction on the '
'barcode reads.',
'rev_comp_barcodes': 'If provided, the barcode sequence reads will be '
'reverse complemented prior to demultiplexing.',
'rev_comp_mapping_barcodes': 'If provided, the barcode sequences in '
'the sample metadata will be reverse '
'complemented prior to demultiplexing.',
'ignore_description_mismatch': 'If True, ignore mismatches in '
'sequence record description fields.'
},
output_descriptions={
'per_sample_sequences': 'The resulting demultiplexed sequences.',
'error_correction_details': 'Detail about the barcode error '
'corrections.'
},
name=('Demultiplex paired-end sequence data generated with the EMP '
'protocol.'),
description=('Demultiplex paired-end sequence data (i.e., map barcode '
'reads to sample ids) for data generated with the Earth '
'Microbiome Project (EMP) amplicon sequencing protocol. '
'Details about this protocol can be found at '
'http://www.earthmicrobiome.org/protocols-and-standards/'),
citations=[
citations['hamady2008'],
citations['hamady2009']]
)
plugin.visualizers.register_function(
function=q2_demux.summarize,
inputs={'data':
SampleData[SequencesWithQuality |
PairedEndSequencesWithQuality |
JoinedSequencesWithQuality]},
parameters={'n': Int},
input_descriptions={
'data': 'The demultiplexed sequences to be summarized.'
},
parameter_descriptions={
'n': ('The number of sequences that should be selected at random for '
'quality score plots. The quality plots will present the '
'average positional qualities across all of the sequences '
'selected. If input sequences are paired end, plots will be '
'generated for both forward and reverse reads for the same `n` '
'sequences.')
},
name='Summarize counts per sample.',
description=('Summarize counts per sample for all samples, and generate '
'interactive positional quality plots based on `n` randomly '
'selected sequences.')
)
plugin.methods.register_function(
function=q2_demux.subsample_single,
inputs={'sequences': SampleData[SequencesWithQuality |
PairedEndSequencesWithQuality]},
parameters={'fraction': Float % Range(0, 1,
inclusive_start=False,
inclusive_end=False)},
outputs=[
('subsampled_sequences', SampleData[SequencesWithQuality])
],
input_descriptions={
'sequences': 'The demultiplexed sequences to be subsampled.'
},
parameter_descriptions={
'fraction': ('The fraction of sequences to retain in subsample.')
},
output_descriptions={
'subsampled_sequences': 'The subsampled sequences.'
},
name='Subsample single-end sequences without replacement.',
description=('Generate a random subsample of single-end sequences '
'containing approximately the fraction of input sequences '
'specified by the fraction parameter. The number of output '
'samples will always be equal to the number of input '
'samples, even if some of those samples contain no '
'sequences after subsampling.')
)
plugin.methods.register_function(
function=q2_demux.subsample_paired,
inputs={'sequences': SampleData[PairedEndSequencesWithQuality]},
parameters={'fraction': Float % Range(0, 1,
inclusive_start=False,
inclusive_end=False)},
outputs=[
('subsampled_sequences', SampleData[PairedEndSequencesWithQuality])
],
input_descriptions={
'sequences': 'The demultiplexed sequences to be subsampled.'
},
parameter_descriptions={
'fraction': ('The fraction of sequences to retain in subsample.')
},
output_descriptions={
'subsampled_sequences': 'The subsampled sequences.'
},
name='Subsample paired-end sequences without replacement.',
description=('Generate a random subsample of paired-end sequences '
'containing approximately the fraction of input sequences '
'specified by the fraction parameter. The number of output '
'samples will always be equal to the number of input '
'samples, even if some of those samples contain no '
'sequences after subsampling.')
)
T = TypeMatch([SequencesWithQuality, PairedEndSequencesWithQuality,
JoinedSequencesWithQuality])
plugin.methods.register_function(
function=q2_demux.filter_samples,
inputs={'demux': SampleData[T]},
parameters={'metadata': Metadata,
'where': Str,
'exclude_ids': Bool},
outputs=[
('filtered_demux', SampleData[T])
],
input_descriptions={
'demux': 'The demultiplexed data from which samples should be '
'filtered.'
},
parameter_descriptions={
'metadata': 'Sample metadata indicating which sample ids to filter. '
'The optional `where` parameter may be used to filter ids '
'based on specified conditions in the metadata. The '
'optional `exclude_ids` parameter may be used to exclude '
'the ids specified in the metadata from the filter.',
'where': 'Optional SQLite WHERE clause specifying sample metadata '
'criteria that must be met to be included in the filtered '
'data. If not provided, all samples in `metadata` that are '
'also in the demultiplexed data will be retained.',
'exclude_ids': 'Defaults to False. If True, the samples selected by '
'the `metadata` and optional `where` parameter will be '
'excluded from the filtered data.',
},
output_descriptions={
'filtered_demux': 'Filtered demultiplexed data.'
},
name='Filter samples out of demultiplexed data.',
description='Filter samples indicated in given metadata out of '
'demultiplexed data. Specific samples can be further selected '
'with the WHERE clause, and the `exclude_ids` parameter '
'allows for filtering of all samples not specified.',
)
importlib.import_module('q2_demux._transformer')