-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathbase_params.py
More file actions
346 lines (298 loc) · 9.11 KB
/
base_params.py
File metadata and controls
346 lines (298 loc) · 9.11 KB
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
"""General parameters common to many functions in the public API."""
from typing import Final, List, Mapping, Optional, Sequence, Tuple, Union
from pydantic import Field
from typing_extensions import Annotated, TypeAlias
from ..util import (
contig_param_type,
region_param_type,
single_contig_param_type,
single_region_param_type,
chunks_param_type,
Region,
)
contig: TypeAlias = Annotated[
single_contig_param_type,
"""
Reference genome contig name. See the `contigs` property for valid contig
names.
""",
]
contigs: TypeAlias = Annotated[
contig_param_type,
"""
Reference genome contig name. See the `contigs` property for valid contig
names. Can also be a sequence (e.g., list) of contigs.
""",
]
region: TypeAlias = Annotated[
single_region_param_type,
"""
Region of the reference genome. Can be a contig name, region string
(formatted like "{contig}:{start}-{end}"), or identifier of a genome
feature such as a gene or transcript.
""",
]
regions: TypeAlias = Annotated[
region_param_type,
"""
Region of the reference genome. Can be a contig name, region string
(formatted like "{contig}:{start}-{end}"), or identifier of a genome
feature such as a gene or transcript. Can also be a sequence (e.g., list)
of regions.
""",
]
regions_tuple: TypeAlias = Tuple[Region, ...]
release: TypeAlias = Annotated[
Union[str, Sequence[str]],
"Release version identifier.",
]
sample_set: TypeAlias = Annotated[
str,
"Sample set identifier.",
]
sample_sets: TypeAlias = Annotated[
Union[Sequence[str], str],
"""
List of sample sets and/or releases. Can also be a single sample set or
release.
""",
]
sample_sets_tuple: TypeAlias = Tuple[sample_set, ...]
sample_query: TypeAlias = Annotated[
str,
"""
A pandas query string to be evaluated against the sample metadata, to
select samples to be included in the returned data. E.g.,
"country == 'Uganda'". If the query returns zero results, a warning
will be emitted with fuzzy-match suggestions for possible typos or
case mismatches.
""",
]
sample_query_options: TypeAlias = Annotated[
dict,
"""
A dictionary of arguments that will be passed through to pandas query() or
eval(), e.g. parser, engine, local_dict, global_dict, resolvers.
""",
]
sample_indices: TypeAlias = Annotated[
List[int],
"""
Advanced usage parameter. A list of indices of samples to select,
corresponding to the order in which the samples are found within the
sample metadata. Either provide this parameter or sample_query, not
both.
""",
]
sample_indices_tuple: TypeAlias = Tuple[int, ...]
sample: TypeAlias = Annotated[
Union[str, int],
"Sample identifier or index within sample set.",
]
samples: TypeAlias = Annotated[
Union[
sample,
List[sample],
Tuple[sample, ...],
],
"Sample identifier or index within sample set. Multiple values can also be provided as a list or tuple.",
]
def _validate_sample_selection_params(
*,
sample_query: Optional[sample_query],
sample_indices: Optional[sample_indices],
):
if sample_query is not None and sample_indices is not None:
raise ValueError(
"Please provide either sample_query or sample_indices, not both."
)
cohort1_query: TypeAlias = Annotated[
str,
"""
A pandas query string to be evaluated against the sample metadata,
to select samples for the first cohort.
""",
]
cohort2_query: TypeAlias = Annotated[
str,
"""
A pandas query string to be evaluated against the sample metadata,
to select samples for the second cohort.
""",
]
site_mask: TypeAlias = Annotated[
str,
"""
Which site filters mask to apply. See the `site_mask_ids` property for
available values.
""",
]
site_class: TypeAlias = Annotated[
str,
"""
Select sites belonging to one of the following classes: CDS_DEG_4,
(4-fold degenerate coding sites), CDS_DEG_2_SIMPLE (2-fold simple
degenerate coding sites), CDS_DEG_0 (non-degenerate coding sites),
INTRON_SHORT (introns shorter than 100 bp), INTRON_LONG (introns
longer than 200 bp), INTRON_SPLICE_5PRIME (intron within 2 bp of
5' splice site), INTRON_SPLICE_3PRIME (intron within 2 bp of 3'
splice site), UTR_5PRIME (5' untranslated region), UTR_3PRIME (3'
untranslated region), INTERGENIC (intergenic, more than 10 kbp from
a gene).
""",
]
cohort_size: TypeAlias = Annotated[
int,
Field(ge=1),
"""
Randomly down-sample to this value if the number of samples in the
cohort is greater. Raise an error if the number of samples is less
than this value.
""",
]
min_cohort_size: TypeAlias = Annotated[
int,
Field(ge=1),
"""
Minimum cohort size. Raise an error if the number of samples is
less than this value.
""",
]
max_cohort_size: TypeAlias = Annotated[
int,
Field(ge=1),
"""
Randomly down-sample to this value if the number of samples in the
cohort is greater.
""",
]
random_seed: TypeAlias = Annotated[
int,
Field(ge=0),
"Random seed used for reproducible down-sampling.",
]
gene: TypeAlias = Annotated[
str,
"""
Gene identifier. Can be either a gene ID or gene name.
Gene names are matched case-insensitively.
""",
]
transcript: TypeAlias = Annotated[
str,
"Gene transcript identifier.",
]
cohort: TypeAlias = Annotated[
Union[str, Tuple[str, str]],
"""
Either a string giving one of the predefined cohort labels, or a
pair of strings giving a custom cohort label and a sample query.
""",
]
cohorts: TypeAlias = Annotated[
Union[str, Mapping[str, str]],
"""
Either a string giving the name of a predefined cohort set (e.g.,
"admin1_month") or a dict mapping custom cohort labels to sample
queries.
""",
]
n_jack: TypeAlias = Annotated[
int,
Field(ge=1),
"""
Number of blocks to divide the data into for the block jackknife
estimation of confidence intervals. N.B., larger is not necessarily
better.
""",
]
confidence_level: TypeAlias = Annotated[
float,
Field(gt=0, lt=1),
"""
Confidence level to use for confidence interval calculation. E.g., 0.95
means 95% confidence interval.
""",
]
field: TypeAlias = Annotated[str, "Name of array or column to access."]
inline_array: TypeAlias = Annotated[
bool,
"Passed through to dask `from_array()`.",
]
inline_array_default: inline_array = True
chunks: TypeAlias = Annotated[
chunks_param_type,
"""
Define how input data being read from zarr should be divided into chunks
for a dask computation. If 'native', use underlying zarr chunks. If a string
specifying a target memory size, e.g., '300 MiB', resize chunks in arrays
with more than one dimension to match this size. If 'auto', let dask decide
chunk size. If 'ndauto', let dask decide chunk size but only for arrays with
more than one dimension. If 'ndauto0', as 'ndauto' but only vary the first
chunk dimension. If 'ndauto1', as 'ndauto' but only vary the second chunk
dimension. If 'ndauto01', as 'ndauto' but only vary the first and second
chunk dimensions. Also, can be a tuple of integers, or a callable which
accepts the native chunks as a single argument and returns a valid dask
chunks value.
""",
]
# Match the native zarr chunk sizes by default. N.B., some functions may
# choose a different default, especially if they need to retrieve larger
# amounts of data.
native_chunks: chunks = "native"
gff_attributes: TypeAlias = Annotated[
Optional[Union[Sequence[str], str]],
"""
GFF attribute keys to unpack into dataframe columns. Provide "*" to unpack all
attributes.
""",
]
DEFAULT: Final[str] = "default"
n_snps: TypeAlias = Annotated[
int,
Field(ge=1),
"""
The desired number of SNPs to use when running the analysis.
SNPs will be evenly thinned to approximately this number.
""",
]
thin_offset: TypeAlias = Annotated[
int,
Field(ge=0),
"""
Starting index for SNP thinning. Change this to repeat the analysis
using a different set of SNPs.
""",
]
min_minor_ac: TypeAlias = Annotated[
Union[int, float],
"""
The minimum minor allele count. SNPs with a minor allele count
below this value will be excluded. Can also be a float, which will
be interpreted as a fraction.
""",
]
max_missing_an: TypeAlias = Annotated[
Union[int, float],
"""
The maximum number of missing allele calls to accept. SNPs with
more than this value will be excluded. Set to 0 to require no
missing calls. Can also be a float, which will be interpreted as
a fraction.
""",
]
snp_query: TypeAlias = Annotated[
str,
"""
A pandas query string to be evaluated against the SNP data,
to select SNPs to be included
""",
]
return_dataset: TypeAlias = Annotated[
bool,
"""
If True, return an xarray Dataset containing computed results as
additional data variables. If False (default), return the legacy
format (numpy array or tuple) for backward compatibility.
""",
]