clipkit 2.12.2__tar.gz → 2.13.1__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.
- {clipkit-2.12.2 → clipkit-2.13.1}/PKG-INFO +20 -1
- {clipkit-2.12.2 → clipkit-2.13.1}/README.md +19 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/api.py +4 -4
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/args_processing.py +17 -2
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/clipkit.py +66 -14
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/exceptions.py +4 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/modes.py +6 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/msa.py +185 -76
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/parser.py +36 -20
- clipkit-2.13.1/clipkit/stop_codons.py +67 -0
- clipkit-2.13.1/clipkit/version.py +1 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/write.py +33 -20
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit.egg-info/PKG-INFO +20 -1
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit.egg-info/SOURCES.txt +1 -0
- clipkit-2.12.2/clipkit/version.py +0 -1
- {clipkit-2.12.2 → clipkit-2.13.1}/LICENSE.md +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/__init__.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/__main__.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/ecomp/__init__.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/ecomp/reader.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/ecomp/writer.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/files.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/guide_tree.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/helpers.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/logger.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/plot_report.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/settings.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/site_classification.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/smart_gap_helper.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/stats.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit/warnings.py +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit.egg-info/dependency_links.txt +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit.egg-info/entry_points.txt +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit.egg-info/requires.txt +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/clipkit.egg-info/top_level.txt +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/pyproject.toml +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/setup.cfg +0 -0
- {clipkit-2.12.2 → clipkit-2.13.1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clipkit
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.13.1
|
|
4
4
|
Summary: Alignment trimming software for phylogenetics.
|
|
5
5
|
Home-page: https://github.com/jlsteenwyk/clipkit
|
|
6
6
|
Author: Jacob L. Steenwyk
|
|
@@ -101,6 +101,25 @@ Release automation details are documented in [RELEASE.md](RELEASE.md).
|
|
|
101
101
|
pip install clipkit
|
|
102
102
|
# run
|
|
103
103
|
clipkit input.fa
|
|
104
|
+
|
|
105
|
+
# mask all in-frame stops in a codon-aligned nucleotide MSA
|
|
106
|
+
clipkit coding.fa --codon --sequence_type nt --remove_stop_codons all
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The same operation is available through the Python API:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from clipkit import clipkit
|
|
113
|
+
|
|
114
|
+
trim_run, stats = clipkit(
|
|
115
|
+
input_file_path="coding.fa",
|
|
116
|
+
mode="gappy",
|
|
117
|
+
gaps=0.9,
|
|
118
|
+
sequence_type="nt",
|
|
119
|
+
codon=True,
|
|
120
|
+
remove_stop_codons="all",
|
|
121
|
+
)
|
|
122
|
+
print(trim_run.stop_codon_masking.summary)
|
|
104
123
|
```
|
|
105
124
|
|
|
106
125
|
**eComp archives**
|
|
@@ -67,6 +67,25 @@ Release automation details are documented in [RELEASE.md](RELEASE.md).
|
|
|
67
67
|
pip install clipkit
|
|
68
68
|
# run
|
|
69
69
|
clipkit input.fa
|
|
70
|
+
|
|
71
|
+
# mask all in-frame stops in a codon-aligned nucleotide MSA
|
|
72
|
+
clipkit coding.fa --codon --sequence_type nt --remove_stop_codons all
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The same operation is available through the Python API:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from clipkit import clipkit
|
|
79
|
+
|
|
80
|
+
trim_run, stats = clipkit(
|
|
81
|
+
input_file_path="coding.fa",
|
|
82
|
+
mode="gappy",
|
|
83
|
+
gaps=0.9,
|
|
84
|
+
sequence_type="nt",
|
|
85
|
+
codon=True,
|
|
86
|
+
remove_stop_codons="all",
|
|
87
|
+
)
|
|
88
|
+
print(trim_run.stop_codon_masking.summary)
|
|
70
89
|
```
|
|
71
90
|
|
|
72
91
|
**eComp archives**
|
|
@@ -5,7 +5,7 @@ from .clipkit import run
|
|
|
5
5
|
from .files import FileFormat
|
|
6
6
|
from .helpers import SeqType, write_msa
|
|
7
7
|
from .logger import logger
|
|
8
|
-
from .modes import TrimmingMode
|
|
8
|
+
from .modes import StopCodonMode, TrimmingMode
|
|
9
9
|
from .plot_report import write_trim_plot_report
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
@@ -28,6 +28,7 @@ def clipkit(
|
|
|
28
28
|
output_file_format=FileFormat.fasta,
|
|
29
29
|
sequence_type: Union[SeqType, str, None] = None,
|
|
30
30
|
codon: bool = False,
|
|
31
|
+
remove_stop_codons: Union[StopCodonMode, str, None] = None,
|
|
31
32
|
ends_only=False,
|
|
32
33
|
threads: int = 1,
|
|
33
34
|
plot_trim_report_path: Union[str, None] = None,
|
|
@@ -43,9 +44,7 @@ def clipkit(
|
|
|
43
44
|
has_raw_alignment = raw_alignment is not None
|
|
44
45
|
has_input_path = input_file_path is not None
|
|
45
46
|
if has_raw_alignment == has_input_path:
|
|
46
|
-
raise ValueError(
|
|
47
|
-
"Provide exactly one of raw_alignment or input_file_path."
|
|
48
|
-
)
|
|
47
|
+
raise ValueError("Provide exactly one of raw_alignment or input_file_path.")
|
|
49
48
|
if has_raw_alignment and raw_alignment == "":
|
|
50
49
|
raise ValueError("raw_alignment cannot be empty.")
|
|
51
50
|
if has_input_path and input_file_path == "":
|
|
@@ -94,6 +93,7 @@ def clipkit(
|
|
|
94
93
|
quiet,
|
|
95
94
|
ends_only,
|
|
96
95
|
threads,
|
|
96
|
+
remove_stop_codons,
|
|
97
97
|
)
|
|
98
98
|
|
|
99
99
|
if plot_trim_report_path:
|
|
@@ -3,7 +3,8 @@ import os.path
|
|
|
3
3
|
import sys
|
|
4
4
|
|
|
5
5
|
from .helpers import SeqType
|
|
6
|
-
from .
|
|
6
|
+
from .exceptions import StopCodonValidationError
|
|
7
|
+
from .modes import StopCodonMode, TrimmingMode
|
|
7
8
|
from .settings import DEFAULT_AA_GAP_CHARS
|
|
8
9
|
|
|
9
10
|
logger = logging.getLogger(__name__)
|
|
@@ -70,6 +71,17 @@ def process_args(args) -> dict:
|
|
|
70
71
|
use_log = args.log or False
|
|
71
72
|
quiet = args.quiet or False
|
|
72
73
|
sequence_type = SeqType(args.sequence_type.lower()) if args.sequence_type else None
|
|
74
|
+
remove_stop_codons_arg = getattr(args, "remove_stop_codons", None)
|
|
75
|
+
remove_stop_codons = (
|
|
76
|
+
StopCodonMode(remove_stop_codons_arg) if remove_stop_codons_arg else None
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
if remove_stop_codons is not None and not codon:
|
|
80
|
+
raise StopCodonValidationError("Stop codon masking requires --codon.")
|
|
81
|
+
if remove_stop_codons is not None and sequence_type == SeqType.aa:
|
|
82
|
+
raise StopCodonValidationError(
|
|
83
|
+
"Stop codon masking requires nucleotide input (--sequence_type nt)."
|
|
84
|
+
)
|
|
73
85
|
|
|
74
86
|
if codon and mode == TrimmingMode.c3:
|
|
75
87
|
logger.warning(
|
|
@@ -94,7 +106,9 @@ def process_args(args) -> dict:
|
|
|
94
106
|
|
|
95
107
|
if mode == TrimmingMode.cst:
|
|
96
108
|
if not auxiliary_file:
|
|
97
|
-
logger.warning(
|
|
109
|
+
logger.warning(
|
|
110
|
+
"CST mode requires an auxiliary file via -a/--auxiliary_file."
|
|
111
|
+
)
|
|
98
112
|
sys.exit()
|
|
99
113
|
if not os.path.isfile(auxiliary_file):
|
|
100
114
|
logger.warning("Auxiliary file does not exist.")
|
|
@@ -107,6 +121,7 @@ def process_args(args) -> dict:
|
|
|
107
121
|
output_file_format=args.output_file_format,
|
|
108
122
|
auxiliary_file=auxiliary_file,
|
|
109
123
|
codon=codon,
|
|
124
|
+
remove_stop_codons=remove_stop_codons,
|
|
110
125
|
sequence_type=sequence_type,
|
|
111
126
|
complement=complement,
|
|
112
127
|
gaps=gaps,
|
|
@@ -9,7 +9,7 @@ from multiprocessing import cpu_count
|
|
|
9
9
|
|
|
10
10
|
from Bio.Align import MultipleSeqAlignment
|
|
11
11
|
from .args_processing import process_args
|
|
12
|
-
from .exceptions import InvalidInputFileFormat
|
|
12
|
+
from .exceptions import InvalidInputFileFormat, StopCodonValidationError
|
|
13
13
|
from .files import (
|
|
14
14
|
get_alignment_and_format,
|
|
15
15
|
FileFormat,
|
|
@@ -26,12 +26,17 @@ from .helpers import (
|
|
|
26
26
|
)
|
|
27
27
|
from .guide_tree import build_parsimony_guide_tree
|
|
28
28
|
from .logger import logger, log_file_logger
|
|
29
|
-
from .modes import TrimmingMode
|
|
29
|
+
from .modes import StopCodonMode, TrimmingMode
|
|
30
30
|
from .msa import MSA
|
|
31
31
|
from .parser import create_parser
|
|
32
32
|
from .plot_report import write_trim_plot_report
|
|
33
33
|
from .settings import DEFAULT_AA_GAP_CHARS, DEFAULT_NT_GAP_CHARS
|
|
34
34
|
from .smart_gap_helper import smart_gap_threshold_determination
|
|
35
|
+
from .stop_codons import (
|
|
36
|
+
StopCodonMaskingStats,
|
|
37
|
+
normalize_stop_codon_mode,
|
|
38
|
+
validate_stop_codon_configuration,
|
|
39
|
+
)
|
|
35
40
|
from .version import __version__ as current_version
|
|
36
41
|
from .warnings import (
|
|
37
42
|
warn_if_all_sites_were_trimmed,
|
|
@@ -43,7 +48,7 @@ from .write import (
|
|
|
43
48
|
write_output_files_message,
|
|
44
49
|
)
|
|
45
50
|
|
|
46
|
-
from dataclasses import dataclass
|
|
51
|
+
from dataclasses import dataclass, field
|
|
47
52
|
|
|
48
53
|
|
|
49
54
|
@dataclass
|
|
@@ -56,6 +61,9 @@ class TrimRun:
|
|
|
56
61
|
output_file_format: FileFormat
|
|
57
62
|
gaps: float
|
|
58
63
|
codon: bool
|
|
64
|
+
stop_codon_masking: StopCodonMaskingStats = field(
|
|
65
|
+
default_factory=StopCodonMaskingStats
|
|
66
|
+
)
|
|
59
67
|
version: str = current_version
|
|
60
68
|
|
|
61
69
|
@property
|
|
@@ -127,13 +135,23 @@ def run(
|
|
|
127
135
|
quiet: bool,
|
|
128
136
|
ends_only: bool,
|
|
129
137
|
threads: int = 1,
|
|
138
|
+
remove_stop_codons: Union[StopCodonMode, str, None] = None,
|
|
130
139
|
):
|
|
131
|
-
alignment, input_file_format = get_alignment_and_format(
|
|
140
|
+
alignment, input_file_format = get_alignment_and_format(
|
|
141
|
+
input_file, input_file_format
|
|
142
|
+
)
|
|
132
143
|
|
|
133
144
|
if threads < 1:
|
|
134
145
|
raise ValueError("threads must be an integer >= 1")
|
|
135
146
|
|
|
136
147
|
sequence_type = sequence_type or get_seq_type(alignment)
|
|
148
|
+
remove_stop_codons = normalize_stop_codon_mode(remove_stop_codons)
|
|
149
|
+
validate_stop_codon_configuration(
|
|
150
|
+
remove_stop_codons,
|
|
151
|
+
codon=codon,
|
|
152
|
+
sequence_type=sequence_type,
|
|
153
|
+
alignment_length=alignment.get_alignment_length(),
|
|
154
|
+
)
|
|
137
155
|
|
|
138
156
|
if not gap_characters:
|
|
139
157
|
gap_characters = get_gap_chars(sequence_type)
|
|
@@ -171,6 +189,12 @@ def run(
|
|
|
171
189
|
)
|
|
172
190
|
|
|
173
191
|
msa = create_msa(alignment, gap_characters, effective_threads)
|
|
192
|
+
stop_codon_masking = (
|
|
193
|
+
msa.mask_stop_codons(remove_stop_codons)
|
|
194
|
+
if remove_stop_codons is not None
|
|
195
|
+
else StopCodonMaskingStats()
|
|
196
|
+
)
|
|
197
|
+
gap_characters = msa.gap_chars
|
|
174
198
|
|
|
175
199
|
# determine smart_gap threshold
|
|
176
200
|
if mode in {
|
|
@@ -178,6 +202,12 @@ def run(
|
|
|
178
202
|
TrimmingMode.kpi_smart_gap,
|
|
179
203
|
TrimmingMode.kpic_smart_gap,
|
|
180
204
|
}:
|
|
205
|
+
if (
|
|
206
|
+
mode in {TrimmingMode.kpi_smart_gap, TrimmingMode.kpic_smart_gap}
|
|
207
|
+
and not msa._requires_uppercase_normalization
|
|
208
|
+
):
|
|
209
|
+
# Populate reusable raw counts before calculating gappyness.
|
|
210
|
+
_ = msa.site_classification_types
|
|
181
211
|
gaps = smart_gap_threshold_determination(
|
|
182
212
|
alignment,
|
|
183
213
|
gap_characters,
|
|
@@ -197,14 +227,15 @@ def run(
|
|
|
197
227
|
)
|
|
198
228
|
|
|
199
229
|
trim_run = TrimRun(
|
|
200
|
-
alignment,
|
|
201
|
-
msa,
|
|
202
|
-
gap_characters,
|
|
203
|
-
sequence_type,
|
|
204
|
-
input_file_format,
|
|
205
|
-
output_file_format,
|
|
206
|
-
gaps,
|
|
207
|
-
codon,
|
|
230
|
+
alignment=alignment,
|
|
231
|
+
msa=msa,
|
|
232
|
+
gap_characters=gap_characters,
|
|
233
|
+
sequence_type=sequence_type,
|
|
234
|
+
input_file_format=input_file_format,
|
|
235
|
+
output_file_format=output_file_format,
|
|
236
|
+
gaps=gaps,
|
|
237
|
+
codon=codon,
|
|
238
|
+
stop_codon_masking=stop_codon_masking,
|
|
208
239
|
)
|
|
209
240
|
|
|
210
241
|
return trim_run, msa.stats
|
|
@@ -230,6 +261,7 @@ def execute(
|
|
|
230
261
|
plot_trim_report: Union[str, None] = None,
|
|
231
262
|
auxiliary_file: str = None,
|
|
232
263
|
threads: int = 1,
|
|
264
|
+
remove_stop_codons: Union[StopCodonMode, str, None] = None,
|
|
233
265
|
**kwargs,
|
|
234
266
|
) -> None:
|
|
235
267
|
fh = None
|
|
@@ -248,6 +280,7 @@ def execute(
|
|
|
248
280
|
logger.disabled = True
|
|
249
281
|
|
|
250
282
|
start_time = time.time()
|
|
283
|
+
remove_stop_codons = normalize_stop_codon_mode(remove_stop_codons)
|
|
251
284
|
|
|
252
285
|
if validate_only:
|
|
253
286
|
try:
|
|
@@ -261,6 +294,12 @@ def execute(
|
|
|
261
294
|
return
|
|
262
295
|
|
|
263
296
|
validated_sequence_type = sequence_type or get_seq_type(alignment)
|
|
297
|
+
validate_stop_codon_configuration(
|
|
298
|
+
remove_stop_codons,
|
|
299
|
+
codon=codon,
|
|
300
|
+
sequence_type=validated_sequence_type,
|
|
301
|
+
alignment_length=alignment.get_alignment_length(),
|
|
302
|
+
)
|
|
264
303
|
validated_gap_characters = gap_characters or get_gap_chars(
|
|
265
304
|
validated_sequence_type
|
|
266
305
|
)
|
|
@@ -292,6 +331,9 @@ def execute(
|
|
|
292
331
|
gap_characters=validated_gap_characters,
|
|
293
332
|
mode=mode.value,
|
|
294
333
|
codon=codon,
|
|
334
|
+
stop_codon_masking=StopCodonMaskingStats(
|
|
335
|
+
mode=remove_stop_codons
|
|
336
|
+
).summary,
|
|
295
337
|
complement=complement,
|
|
296
338
|
ends_only=ends_only,
|
|
297
339
|
threads_requested=threads,
|
|
@@ -317,6 +359,7 @@ def execute(
|
|
|
317
359
|
quiet,
|
|
318
360
|
ends_only,
|
|
319
361
|
threads,
|
|
362
|
+
remove_stop_codons,
|
|
320
363
|
)
|
|
321
364
|
except InvalidInputFileFormat:
|
|
322
365
|
logger.error(
|
|
@@ -338,6 +381,7 @@ def execute(
|
|
|
338
381
|
codon,
|
|
339
382
|
use_log,
|
|
340
383
|
ends_only,
|
|
384
|
+
trim_run.stop_codon_masking,
|
|
341
385
|
)
|
|
342
386
|
|
|
343
387
|
if dry_run:
|
|
@@ -385,6 +429,7 @@ def execute(
|
|
|
385
429
|
gap_characters=trim_run.gap_characters,
|
|
386
430
|
mode=mode.value,
|
|
387
431
|
codon=codon,
|
|
432
|
+
stop_codon_masking=trim_run.stop_codon_masking.summary,
|
|
388
433
|
complement=complement,
|
|
389
434
|
ends_only=ends_only,
|
|
390
435
|
threads_requested=threads,
|
|
@@ -404,7 +449,11 @@ def execute(
|
|
|
404
449
|
)
|
|
405
450
|
logger.info(f"Wrote trim plot report to {plot_trim_report}")
|
|
406
451
|
|
|
407
|
-
write_output_stats(
|
|
452
|
+
write_output_stats(
|
|
453
|
+
stats,
|
|
454
|
+
start_time,
|
|
455
|
+
stop_codon_masking=trim_run.stop_codon_masking,
|
|
456
|
+
)
|
|
408
457
|
finally:
|
|
409
458
|
if fh is not None:
|
|
410
459
|
log_file_logger.removeHandler(fh)
|
|
@@ -432,7 +481,10 @@ def main(argv=None):
|
|
|
432
481
|
|
|
433
482
|
args = parser.parse_args(argv)
|
|
434
483
|
|
|
435
|
-
|
|
484
|
+
try:
|
|
485
|
+
execute(**process_args(args))
|
|
486
|
+
except StopCodonValidationError as exc:
|
|
487
|
+
parser.error(str(exc))
|
|
436
488
|
|
|
437
489
|
|
|
438
490
|
if __name__ == "__main__":
|
|
@@ -6,7 +6,8 @@ import math
|
|
|
6
6
|
from typing import Union
|
|
7
7
|
from Bio.Phylo.BaseTree import Tree
|
|
8
8
|
|
|
9
|
-
from .modes import TrimmingMode
|
|
9
|
+
from .modes import StopCodonMode, TrimmingMode
|
|
10
|
+
|
|
10
11
|
# Always import the standard version for compatibility
|
|
11
12
|
from .site_classification import (
|
|
12
13
|
SiteClassificationType,
|
|
@@ -15,7 +16,7 @@ from .site_classification import (
|
|
|
15
16
|
|
|
16
17
|
from .settings import DEFAULT_AA_GAP_CHARS
|
|
17
18
|
from .stats import TrimmingStats
|
|
18
|
-
|
|
19
|
+
from .stop_codons import STOP_CODONS, StopCodonMaskingStats
|
|
19
20
|
|
|
20
21
|
# Counting a batch at a time bounds the temporary integer matrix while still
|
|
21
22
|
# letting np.bincount process many columns in one compiled operation.
|
|
@@ -46,17 +47,21 @@ def _column_character_counts(seq_array: np.ndarray) -> tuple[np.ndarray, np.ndar
|
|
|
46
47
|
|
|
47
48
|
if code_span <= _MAX_DENSE_CODE_SPAN:
|
|
48
49
|
counts = np.empty((code_span, n_cols), dtype=count_dtype)
|
|
49
|
-
offsets =
|
|
50
|
+
offsets = (
|
|
51
|
+
np.arange(_COLUMN_COUNT_BATCH_SIZE, dtype=np.int64) * code_span - min_code
|
|
52
|
+
)
|
|
50
53
|
|
|
51
54
|
for start_idx in range(0, n_cols, _COLUMN_COUNT_BATCH_SIZE):
|
|
52
55
|
end_idx = min(start_idx + _COLUMN_COUNT_BATCH_SIZE, n_cols)
|
|
53
56
|
width = end_idx - start_idx
|
|
54
|
-
encoded =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
counts[:, start_idx:end_idx] =
|
|
58
|
-
encoded.ravel(), minlength=width * code_span
|
|
59
|
-
|
|
57
|
+
encoded = np.add(
|
|
58
|
+
code_points[:, start_idx:end_idx], offsets[:width], dtype=np.int64
|
|
59
|
+
)
|
|
60
|
+
counts[:, start_idx:end_idx] = (
|
|
61
|
+
np.bincount(encoded.ravel(), minlength=width * code_span)
|
|
62
|
+
.reshape(width, code_span)
|
|
63
|
+
.T
|
|
64
|
+
)
|
|
60
65
|
|
|
61
66
|
present = np.any(counts, axis=1)
|
|
62
67
|
states = np.array(
|
|
@@ -75,9 +80,11 @@ def _column_character_counts(seq_array: np.ndarray) -> tuple[np.ndarray, np.ndar
|
|
|
75
80
|
width = end_idx - start_idx
|
|
76
81
|
encoded = np.searchsorted(states, seq_array[:, start_idx:end_idx])
|
|
77
82
|
encoded += offsets[:width]
|
|
78
|
-
counts[:, start_idx:end_idx] =
|
|
79
|
-
encoded.ravel(), minlength=width * len(states)
|
|
80
|
-
|
|
83
|
+
counts[:, start_idx:end_idx] = (
|
|
84
|
+
np.bincount(encoded.ravel(), minlength=width * len(states))
|
|
85
|
+
.reshape(width, len(states))
|
|
86
|
+
.T
|
|
87
|
+
)
|
|
81
88
|
return states, counts
|
|
82
89
|
|
|
83
90
|
|
|
@@ -108,7 +115,9 @@ class MSA:
|
|
|
108
115
|
self._site_composition_bias_cache = None
|
|
109
116
|
|
|
110
117
|
@staticmethod
|
|
111
|
-
def from_bio_msa(
|
|
118
|
+
def from_bio_msa(
|
|
119
|
+
alignment: MultipleSeqAlignment, gap_chars=None, threads=1
|
|
120
|
+
) -> "MSA":
|
|
112
121
|
header_info = []
|
|
113
122
|
sequences = []
|
|
114
123
|
requires_uppercase_normalization = False
|
|
@@ -144,11 +153,84 @@ class MSA:
|
|
|
144
153
|
def complement_to_bio_msa(self) -> MultipleSeqAlignment:
|
|
145
154
|
return self._to_bio_msa(self.sites_trimmed)
|
|
146
155
|
|
|
156
|
+
def mask_stop_codons(self, mode: StopCodonMode) -> StopCodonMaskingStats:
|
|
157
|
+
"""Replace selected in-frame stop codons with gap characters."""
|
|
158
|
+
if not isinstance(mode, StopCodonMode):
|
|
159
|
+
mode = StopCodonMode(mode)
|
|
160
|
+
|
|
161
|
+
if self._original_length % self._codon_size != 0:
|
|
162
|
+
raise ValueError(
|
|
163
|
+
"Stop codon masking requires an alignment length divisible by 3."
|
|
164
|
+
)
|
|
165
|
+
if self._original_length == 0:
|
|
166
|
+
return StopCodonMaskingStats(mode=mode)
|
|
167
|
+
|
|
168
|
+
if "-" not in self._gap_chars:
|
|
169
|
+
self._gap_chars = [*self._gap_chars, "-"]
|
|
170
|
+
|
|
171
|
+
normalized_records = (
|
|
172
|
+
np.char.upper(self.seq_records)
|
|
173
|
+
if self._requires_uppercase_normalization
|
|
174
|
+
# Keep the independent working array used by the original path,
|
|
175
|
+
# but avoid an expensive per-character Unicode operation.
|
|
176
|
+
else self.seq_records.copy()
|
|
177
|
+
)
|
|
178
|
+
codons = normalized_records.reshape(
|
|
179
|
+
self.seq_records.shape[0], -1, self._codon_size
|
|
180
|
+
)
|
|
181
|
+
gap_chars = np.char.upper(np.asarray(self._gap_chars, dtype="U1"))
|
|
182
|
+
complete_codons = ~np.any(np.isin(codons, gap_chars), axis=2)
|
|
183
|
+
codon_strings = (
|
|
184
|
+
np.ascontiguousarray(codons).view("U3").reshape(codons.shape[:2])
|
|
185
|
+
)
|
|
186
|
+
stop_codons = np.isin(codon_strings, tuple(STOP_CODONS)) & complete_codons
|
|
187
|
+
|
|
188
|
+
terminal_to_mask = np.zeros(stop_codons.shape, dtype=bool)
|
|
189
|
+
internal_to_mask = np.zeros(stop_codons.shape, dtype=bool)
|
|
190
|
+
|
|
191
|
+
for sequence_index in range(self.seq_records.shape[0]):
|
|
192
|
+
complete_positions = np.flatnonzero(complete_codons[sequence_index])
|
|
193
|
+
if complete_positions.size == 0:
|
|
194
|
+
continue
|
|
195
|
+
|
|
196
|
+
terminal_position = complete_positions[-1]
|
|
197
|
+
terminal_to_mask[sequence_index, terminal_position] = stop_codons[
|
|
198
|
+
sequence_index, terminal_position
|
|
199
|
+
]
|
|
200
|
+
internal_to_mask[sequence_index] = stop_codons[sequence_index]
|
|
201
|
+
internal_to_mask[sequence_index, terminal_position] = False
|
|
202
|
+
|
|
203
|
+
selected = np.zeros(stop_codons.shape, dtype=bool)
|
|
204
|
+
if mode in (StopCodonMode.terminal, StopCodonMode.all):
|
|
205
|
+
selected |= terminal_to_mask
|
|
206
|
+
if mode in (StopCodonMode.internal, StopCodonMode.all):
|
|
207
|
+
selected |= internal_to_mask
|
|
208
|
+
|
|
209
|
+
selected_sites = np.repeat(selected, self._codon_size, axis=1)
|
|
210
|
+
self.seq_records[selected_sites] = "-"
|
|
211
|
+
self._reset_analysis_caches()
|
|
212
|
+
|
|
213
|
+
return StopCodonMaskingStats(
|
|
214
|
+
mode=mode,
|
|
215
|
+
terminal_masked=int(np.count_nonzero(terminal_to_mask & selected)),
|
|
216
|
+
internal_masked=int(np.count_nonzero(internal_to_mask & selected)),
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
def _reset_analysis_caches(self) -> None:
|
|
220
|
+
self._site_classification_types = None
|
|
221
|
+
self._column_character_frequencies = None
|
|
222
|
+
self._column_character_count_cache = {}
|
|
223
|
+
self._site_gappyness_cache = None
|
|
224
|
+
self._site_entropy_cache = None
|
|
225
|
+
self._site_composition_bias_cache = None
|
|
226
|
+
|
|
147
227
|
def _to_bio_msa(self, sites) -> MultipleSeqAlignment:
|
|
148
228
|
# NOTE: we use the description as the id to preserve the full sequence description - see issue #20
|
|
149
229
|
if sites.shape[1] == 0:
|
|
150
230
|
sequence_rows = [""] * sites.shape[0]
|
|
151
|
-
elif
|
|
231
|
+
elif (
|
|
232
|
+
sites.dtype.kind == "U" and sites.dtype.itemsize == np.dtype("U1").itemsize
|
|
233
|
+
):
|
|
152
234
|
contiguous_sites = np.ascontiguousarray(sites)
|
|
153
235
|
sequence_rows = (
|
|
154
236
|
contiguous_sites.view(f"U{sites.shape[1]}").reshape(-1).tolist()
|
|
@@ -158,9 +240,7 @@ class MSA:
|
|
|
158
240
|
|
|
159
241
|
return MultipleSeqAlignment(
|
|
160
242
|
[
|
|
161
|
-
SeqRecord(
|
|
162
|
-
Seq(rec), id=str(info["description"]), description=""
|
|
163
|
-
)
|
|
243
|
+
SeqRecord(Seq(rec), id=str(info["description"]), description="")
|
|
164
244
|
for rec, info in zip(sequence_rows, self.header_info)
|
|
165
245
|
]
|
|
166
246
|
)
|
|
@@ -196,7 +276,19 @@ class MSA:
|
|
|
196
276
|
if self._site_gappyness_cache is not None:
|
|
197
277
|
return self._site_gappyness_cache
|
|
198
278
|
|
|
199
|
-
|
|
279
|
+
# KPI/KPIC classification already counts every uppercase character.
|
|
280
|
+
# Reuse those exact raw counts when possible instead of rescanning the
|
|
281
|
+
# alignment for a combined gap/classification mode.
|
|
282
|
+
shared_counts = (
|
|
283
|
+
self._column_character_count_cache.get(("frequencies", False))
|
|
284
|
+
if not self._requires_uppercase_normalization
|
|
285
|
+
else None
|
|
286
|
+
)
|
|
287
|
+
if shared_counts is not None:
|
|
288
|
+
states, counts = shared_counts
|
|
289
|
+
gap_counts = counts[np.isin(states, self._gap_chars)].sum(axis=0)
|
|
290
|
+
site_gappyness = gap_counts / self.seq_records.shape[0]
|
|
291
|
+
elif self.seq_records.size < _MIN_CELLS_FOR_COLUMN_COUNTING:
|
|
200
292
|
site_gappyness = np.isin(self.seq_records, self._gap_chars).mean(axis=0)
|
|
201
293
|
else:
|
|
202
294
|
states, counts = self._get_column_character_counts(
|
|
@@ -225,21 +317,23 @@ class MSA:
|
|
|
225
317
|
_, counts_by_state = self._get_non_gap_character_counts(
|
|
226
318
|
normalize_gap_chars=True, cache_key="entropy"
|
|
227
319
|
)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
320
|
+
total_counts = counts_by_state.sum(axis=0).astype(float)
|
|
321
|
+
observed_states = np.count_nonzero(counts_by_state, axis=0)
|
|
322
|
+
raw_entropy = np.zeros(counts_by_state.shape[1], dtype=float)
|
|
323
|
+
|
|
324
|
+
# Iterate over the small alphabet dimension while NumPy evaluates all
|
|
325
|
+
# alignment columns together. This preserves the original summation
|
|
326
|
+
# order without paying Python overhead once per column.
|
|
327
|
+
for state_counts in counts_by_state:
|
|
328
|
+
present = state_counts > 0
|
|
329
|
+
probabilities = state_counts[present] / total_counts[present]
|
|
330
|
+
raw_entropy[present] -= probabilities * np.log2(probabilities)
|
|
331
|
+
|
|
332
|
+
entropies = np.zeros(counts_by_state.shape[1], dtype=float)
|
|
333
|
+
variable_sites = observed_states > 1
|
|
334
|
+
entropies[variable_sites] = raw_entropy[variable_sites] / np.log2(
|
|
335
|
+
observed_states[variable_sites]
|
|
336
|
+
)
|
|
243
337
|
|
|
244
338
|
self._site_entropy_cache = np.around(entropies, decimals=4)
|
|
245
339
|
self._column_character_count_cache.pop(
|
|
@@ -257,26 +351,29 @@ class MSA:
|
|
|
257
351
|
return self._site_composition_bias_cache
|
|
258
352
|
|
|
259
353
|
_, counts_by_state = self._get_non_gap_character_counts()
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
354
|
+
total_counts = counts_by_state.sum(axis=0).astype(float)
|
|
355
|
+
observed_states = np.count_nonzero(counts_by_state, axis=0)
|
|
356
|
+
dominance = np.zeros(counts_by_state.shape[1], dtype=float)
|
|
357
|
+
|
|
358
|
+
# Group columns by the number of observed states so each compact row
|
|
359
|
+
# has the same values and reduction length as the original per-column
|
|
360
|
+
# calculation. This keeps scores identical at four-decimal boundaries.
|
|
361
|
+
for state_count in np.unique(observed_states[observed_states > 1]):
|
|
362
|
+
columns = np.flatnonzero(observed_states == state_count)
|
|
363
|
+
column_counts = counts_by_state[:, columns].T
|
|
364
|
+
present_counts = column_counts[column_counts > 0].reshape(
|
|
365
|
+
len(columns), state_count
|
|
366
|
+
)
|
|
367
|
+
probabilities = present_counts.astype(float) / total_counts[columns, None]
|
|
368
|
+
dominance[columns] = np.sum(np.square(probabilities), axis=1)
|
|
275
369
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
370
|
+
bias_scores = np.zeros(counts_by_state.shape[1], dtype=float)
|
|
371
|
+
bias_scores[observed_states == 1] = 1.0
|
|
372
|
+
variable_sites = observed_states > 1
|
|
373
|
+
min_dominance = 1.0 / observed_states[variable_sites]
|
|
374
|
+
bias_scores[variable_sites] = (dominance[variable_sites] - min_dominance) / (
|
|
375
|
+
1.0 - min_dominance
|
|
376
|
+
)
|
|
280
377
|
|
|
281
378
|
self._site_composition_bias_cache = np.around(bias_scores, decimals=4)
|
|
282
379
|
return self._site_composition_bias_cache
|
|
@@ -353,11 +450,11 @@ class MSA:
|
|
|
353
450
|
key = (cache_key, normalize_case)
|
|
354
451
|
if key not in self._column_character_count_cache:
|
|
355
452
|
seq_array = (
|
|
356
|
-
np.char.upper(self.seq_records)
|
|
357
|
-
|
|
358
|
-
|
|
453
|
+
np.char.upper(self.seq_records) if normalize_case else self.seq_records
|
|
454
|
+
)
|
|
455
|
+
self._column_character_count_cache[key] = _column_character_counts(
|
|
456
|
+
seq_array
|
|
359
457
|
)
|
|
360
|
-
self._column_character_count_cache[key] = _column_character_counts(seq_array)
|
|
361
458
|
return self._column_character_count_cache[key]
|
|
362
459
|
|
|
363
460
|
def _get_non_gap_character_counts(
|
|
@@ -387,9 +484,7 @@ class MSA:
|
|
|
387
484
|
|
|
388
485
|
_, counts_by_state = self._get_non_gap_character_counts()
|
|
389
486
|
observed_states = np.count_nonzero(counts_by_state, axis=0)
|
|
390
|
-
states_occurring_at_least_twice = np.count_nonzero(
|
|
391
|
-
counts_by_state >= 2, axis=0
|
|
392
|
-
)
|
|
487
|
+
states_occurring_at_least_twice = np.count_nonzero(counts_by_state >= 2, axis=0)
|
|
393
488
|
|
|
394
489
|
site_classification_types = np.empty(self._original_length, dtype=object)
|
|
395
490
|
site_classification_types.fill(SiteClassificationType.other)
|
|
@@ -418,7 +513,9 @@ class MSA:
|
|
|
418
513
|
sites_to_trim = np.where(self.site_gappyness >= gap_threshold)[0]
|
|
419
514
|
elif mode == TrimmingMode.block_gappy:
|
|
420
515
|
high_gap_sites = np.where(self.site_gappyness >= gap_threshold)[0]
|
|
421
|
-
sites_to_trim = self._retain_contiguous_sites(
|
|
516
|
+
sites_to_trim = self._retain_contiguous_sites(
|
|
517
|
+
high_gap_sites, min_block_size=2
|
|
518
|
+
)
|
|
422
519
|
elif mode == TrimmingMode.gappyout:
|
|
423
520
|
# Keep sites at the inferred boundary and trim strictly above it.
|
|
424
521
|
sites_to_trim = np.where(self.site_gappyness > gap_threshold)[0]
|
|
@@ -438,8 +535,16 @@ class MSA:
|
|
|
438
535
|
!= SiteClassificationType.parsimony_informative
|
|
439
536
|
)[0]
|
|
440
537
|
elif mode in (TrimmingMode.kpi_gappy, TrimmingMode.kpi_smart_gap):
|
|
441
|
-
|
|
442
|
-
|
|
538
|
+
if self._requires_uppercase_normalization:
|
|
539
|
+
sites_to_trim_gaps_based = np.where(
|
|
540
|
+
self.site_gappyness > gap_threshold
|
|
541
|
+
)[0]
|
|
542
|
+
site_classification_types = self.site_classification_types
|
|
543
|
+
else:
|
|
544
|
+
site_classification_types = self.site_classification_types
|
|
545
|
+
sites_to_trim_gaps_based = np.where(
|
|
546
|
+
self.site_gappyness > gap_threshold
|
|
547
|
+
)[0]
|
|
443
548
|
sites_to_trim_classification_based = np.where(
|
|
444
549
|
site_classification_types
|
|
445
550
|
!= SiteClassificationType.parsimony_informative
|
|
@@ -456,9 +561,16 @@ class MSA:
|
|
|
456
561
|
| (site_classification_types == SiteClassificationType.singleton)
|
|
457
562
|
)[0]
|
|
458
563
|
elif mode in (TrimmingMode.kpic_gappy, TrimmingMode.kpic_smart_gap):
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
564
|
+
if self._requires_uppercase_normalization:
|
|
565
|
+
sites_to_trim_gaps_based = np.where(
|
|
566
|
+
self.site_gappyness >= gap_threshold
|
|
567
|
+
)[0]
|
|
568
|
+
site_classification_types = self.site_classification_types
|
|
569
|
+
else:
|
|
570
|
+
site_classification_types = self.site_classification_types
|
|
571
|
+
sites_to_trim_gaps_based = np.where(
|
|
572
|
+
self.site_gappyness >= gap_threshold
|
|
573
|
+
)[0]
|
|
462
574
|
sites_to_trim_classification_based = np.where(
|
|
463
575
|
(site_classification_types == SiteClassificationType.other)
|
|
464
576
|
| (site_classification_types == SiteClassificationType.singleton)
|
|
@@ -525,7 +637,9 @@ class MSA:
|
|
|
525
637
|
if clade.is_terminal():
|
|
526
638
|
continue
|
|
527
639
|
|
|
528
|
-
taxa_names = [
|
|
640
|
+
taxa_names = [
|
|
641
|
+
str(t.name) for t in clade.get_terminals() if t.name is not None
|
|
642
|
+
]
|
|
529
643
|
indices = sorted(
|
|
530
644
|
terminal_to_index[name]
|
|
531
645
|
for name in taxa_names
|
|
@@ -649,16 +763,11 @@ class MSA:
|
|
|
649
763
|
return np.array([])
|
|
650
764
|
|
|
651
765
|
sites_to_trim = np.asarray(sites_to_trim)
|
|
652
|
-
blocks = sites_to_trim // self._codon_size
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
start = block * self._codon_size
|
|
658
|
-
positions = np.arange(start, min(start + self._codon_size, self._original_length))
|
|
659
|
-
triplets.extend(positions)
|
|
660
|
-
|
|
661
|
-
return np.unique(triplets)
|
|
766
|
+
blocks = np.unique(sites_to_trim // self._codon_size)
|
|
767
|
+
triplets = (
|
|
768
|
+
blocks[:, None] * self._codon_size + np.arange(self._codon_size)
|
|
769
|
+
).reshape(-1)
|
|
770
|
+
return triplets[triplets < self._original_length]
|
|
662
771
|
|
|
663
772
|
def determine_codon_triplet_positions(self, alignment_position):
|
|
664
773
|
"""
|
|
@@ -8,18 +8,18 @@ from argparse import (
|
|
|
8
8
|
|
|
9
9
|
from .helpers import SeqType
|
|
10
10
|
from .files import FileFormat
|
|
11
|
-
from .modes import TrimmingMode
|
|
11
|
+
from .modes import StopCodonMode, TrimmingMode
|
|
12
12
|
from .version import __version__
|
|
13
13
|
|
|
14
14
|
_MAIN_DESCRIPTION_TEMPLATE = r"""\
|
|
15
|
-
_____ _ _ _ _______ _______
|
|
15
|
+
_____ _ _ _ _______ _______
|
|
16
16
|
/ ____| (_) | |/ /_ _|__ __|
|
|
17
|
-
| | | |_ _ __ | ' / | | | |
|
|
18
|
-
| | | | | '_ \| < | | | |
|
|
19
|
-
| |____| | | |_) | . \ _| |_ | |
|
|
20
|
-
\_____|_|_| .__/|_|\_\_____| |_|
|
|
21
|
-
| |
|
|
22
|
-
|_|
|
|
17
|
+
| | | |_ _ __ | ' / | | | |
|
|
18
|
+
| | | | | '_ \| < | | | |
|
|
19
|
+
| |____| | | |_) | . \ _| |_ | |
|
|
20
|
+
\_____|_|_| .__/|_|\_\_____| |_|
|
|
21
|
+
| |
|
|
22
|
+
|_|
|
|
23
23
|
|
|
24
24
|
Version: {version}
|
|
25
25
|
Citation: Steenwyk et al. 2020, PLOS Biology. doi: 10.1371/journal.pbio.3001007
|
|
@@ -36,10 +36,10 @@ _REQUIRED_ARGUMENTS_DESCRIPTION = """\
|
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
38
|
_OPTIONAL_ARGUMENTS_DESCRIPTION = """\
|
|
39
|
-
-o, --output <output_file_name> output file name
|
|
39
|
+
-o, --output <output_file_name> output file name
|
|
40
40
|
(default: input file named with '.clipkit' suffix)
|
|
41
41
|
|
|
42
|
-
-m, --mode <smart-gap, trimming mode
|
|
42
|
+
-m, --mode <smart-gap, trimming mode
|
|
43
43
|
entropy,
|
|
44
44
|
gappy,
|
|
45
45
|
block-gappy,
|
|
@@ -47,14 +47,14 @@ _OPTIONAL_ARGUMENTS_DESCRIPTION = """\
|
|
|
47
47
|
composition-bias,
|
|
48
48
|
heterotachy,
|
|
49
49
|
kpic,
|
|
50
|
-
kpic-smart-gap,
|
|
51
|
-
kpic-gappy,
|
|
50
|
+
kpic-smart-gap,
|
|
51
|
+
kpic-gappy,
|
|
52
52
|
kpi,
|
|
53
53
|
kpi-smart-gap,
|
|
54
54
|
kpi-gappy,
|
|
55
55
|
cst,
|
|
56
|
-
c3>
|
|
57
|
-
|
|
56
|
+
c3>
|
|
57
|
+
|
|
58
58
|
-g, --gaps <threshold_of_gaps> specifies gaps threshold
|
|
59
59
|
(default: 0.9; entropy/composition-bias/heterotachy default: 0.8)
|
|
60
60
|
|
|
@@ -63,7 +63,7 @@ _OPTIONAL_ARGUMENTS_DESCRIPTION = """\
|
|
|
63
63
|
default for nt: XxNn-?*)
|
|
64
64
|
|
|
65
65
|
-if, --input_file_format <file_format> specifies input file format
|
|
66
|
-
(default: auto-detect)
|
|
66
|
+
(default: auto-detect)
|
|
67
67
|
|
|
68
68
|
-s, --sequence_type <nt, aa> specifies sequence type of input file
|
|
69
69
|
(default: auto-detect)
|
|
@@ -82,6 +82,10 @@ _OPTIONAL_ARGUMENTS_DESCRIPTION = """\
|
|
|
82
82
|
|
|
83
83
|
-co, --codon conduct trimming of codons
|
|
84
84
|
|
|
85
|
+
--remove_stop_codons <terminal, mask selected in-frame stop codons as gaps
|
|
86
|
+
internal,
|
|
87
|
+
all> (requires nucleotide input and --codon)
|
|
88
|
+
|
|
85
89
|
-eo, --ends_only trim only from the ends of the alignment
|
|
86
90
|
|
|
87
91
|
-t, --threads <number_of_threads> requested number of threads to use for parallel processing
|
|
@@ -104,7 +108,7 @@ _OPTIONAL_ARGUMENTS_DESCRIPTION = """\
|
|
|
104
108
|
|
|
105
109
|
|
|
106
110
|
-------------------------------------
|
|
107
|
-
| Detailed explanation of arguments |
|
|
111
|
+
| Detailed explanation of arguments |
|
|
108
112
|
-------------------------------------
|
|
109
113
|
Modes
|
|
110
114
|
smart-gap: dynamic determination of gaps threshold
|
|
@@ -163,7 +167,7 @@ Input and output file formats
|
|
|
163
167
|
Log
|
|
164
168
|
Creates a log file that summarizes the characteristics of each position.
|
|
165
169
|
The log file has four columns.
|
|
166
|
-
- Column 1 is the position in the alignment (starting at 1),
|
|
170
|
+
- Column 1 is the position in the alignment (starting at 1),
|
|
167
171
|
- Column 2 reports if the site was trimmed or kept (trim and keep, respectively),
|
|
168
172
|
- Column 3 reports if the site is a parsimony informative site or not (PI and nPI, respectively), or
|
|
169
173
|
a constant site or not (Const and nConst, respectively), or neither (nConst, nPI)
|
|
@@ -176,6 +180,13 @@ Codon
|
|
|
176
180
|
Trims codon-based alignments. If one position in a codon should be trimmed, the whole
|
|
177
181
|
codon will be trimmed.
|
|
178
182
|
|
|
183
|
+
Remove stop codons
|
|
184
|
+
Masks in-frame stop codons with "---" before gap statistics and trimming.
|
|
185
|
+
"terminal" masks only a stop at the final complete non-gap codon in each
|
|
186
|
+
sequence, "internal" masks all other stop codons, and "all" masks both.
|
|
187
|
+
DNA and RNA stops are recognized case-insensitively. This option requires
|
|
188
|
+
nucleotide input, --codon, and an alignment length divisible by three.
|
|
189
|
+
|
|
179
190
|
Threads
|
|
180
191
|
Requested number of threads to use for parallel processing.
|
|
181
192
|
For kpi/kpic family modes, ClipKIT may automatically use fewer
|
|
@@ -203,9 +214,7 @@ Plot trim report
|
|
|
203
214
|
|
|
204
215
|
|
|
205
216
|
def _main_description() -> str:
|
|
206
|
-
return textwrap.dedent(
|
|
207
|
-
_MAIN_DESCRIPTION_TEMPLATE.format(version=__version__)
|
|
208
|
-
)
|
|
217
|
+
return textwrap.dedent(_MAIN_DESCRIPTION_TEMPLATE.format(version=__version__))
|
|
209
218
|
|
|
210
219
|
|
|
211
220
|
def create_parser() -> ArgumentParser:
|
|
@@ -346,6 +355,13 @@ def create_parser() -> ArgumentParser:
|
|
|
346
355
|
help=SUPPRESS,
|
|
347
356
|
)
|
|
348
357
|
|
|
358
|
+
optional.add_argument(
|
|
359
|
+
"--remove_stop_codons",
|
|
360
|
+
choices=[mode.value for mode in StopCodonMode],
|
|
361
|
+
required=False,
|
|
362
|
+
help=SUPPRESS,
|
|
363
|
+
)
|
|
364
|
+
|
|
349
365
|
optional.add_argument(
|
|
350
366
|
"-eo",
|
|
351
367
|
"--ends_only",
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Optional, Union
|
|
3
|
+
|
|
4
|
+
from .exceptions import StopCodonValidationError
|
|
5
|
+
from .modes import StopCodonMode
|
|
6
|
+
|
|
7
|
+
STOP_CODONS = frozenset({"TAA", "TAG", "TGA", "UAA", "UAG", "UGA"})
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def normalize_stop_codon_mode(
|
|
11
|
+
mode: Union[StopCodonMode, str, None],
|
|
12
|
+
) -> Optional[StopCodonMode]:
|
|
13
|
+
if mode is None or isinstance(mode, StopCodonMode):
|
|
14
|
+
return mode
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
return StopCodonMode(mode)
|
|
18
|
+
except ValueError as exc:
|
|
19
|
+
choices = ", ".join(f"'{choice.value}'" for choice in StopCodonMode)
|
|
20
|
+
raise StopCodonValidationError(
|
|
21
|
+
f"remove_stop_codons must be one of: {choices}, or None."
|
|
22
|
+
) from exc
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def validate_stop_codon_configuration(
|
|
26
|
+
mode: Optional[StopCodonMode],
|
|
27
|
+
*,
|
|
28
|
+
codon: bool,
|
|
29
|
+
sequence_type,
|
|
30
|
+
alignment_length: int,
|
|
31
|
+
) -> None:
|
|
32
|
+
if mode is None:
|
|
33
|
+
return
|
|
34
|
+
if not codon:
|
|
35
|
+
raise StopCodonValidationError(
|
|
36
|
+
"Stop codon masking requires codon-aware trimming "
|
|
37
|
+
"(codon=True / --codon)."
|
|
38
|
+
)
|
|
39
|
+
if getattr(sequence_type, "value", sequence_type) != "nt":
|
|
40
|
+
raise StopCodonValidationError(
|
|
41
|
+
"Stop codon masking requires nucleotide input "
|
|
42
|
+
"(sequence_type='nt' / --sequence_type nt)."
|
|
43
|
+
)
|
|
44
|
+
if alignment_length % 3 != 0:
|
|
45
|
+
raise StopCodonValidationError(
|
|
46
|
+
"Stop codon masking requires an alignment length divisible by 3."
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class StopCodonMaskingStats:
|
|
52
|
+
mode: Optional[StopCodonMode] = None
|
|
53
|
+
terminal_masked: int = 0
|
|
54
|
+
internal_masked: int = 0
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def total_masked(self) -> int:
|
|
58
|
+
return self.terminal_masked + self.internal_masked
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def summary(self) -> dict:
|
|
62
|
+
return {
|
|
63
|
+
"mode": self.mode.value if self.mode is not None else None,
|
|
64
|
+
"terminal_masked": self.terminal_masked,
|
|
65
|
+
"internal_masked": self.internal_masked,
|
|
66
|
+
"total_masked": self.total_masked,
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.13.1"
|
|
@@ -3,12 +3,13 @@ import time
|
|
|
3
3
|
from .logger import logger
|
|
4
4
|
from .stats import TrimmingStats
|
|
5
5
|
|
|
6
|
-
from typing import TYPE_CHECKING
|
|
6
|
+
from typing import TYPE_CHECKING, Optional
|
|
7
7
|
|
|
8
8
|
if TYPE_CHECKING:
|
|
9
9
|
from .files import FileFormat
|
|
10
10
|
from .helpers import SeqType
|
|
11
11
|
from .modes import TrimmingMode
|
|
12
|
+
from .stop_codons import StopCodonMaskingStats
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
def write_user_args(
|
|
@@ -24,6 +25,7 @@ def write_user_args(
|
|
|
24
25
|
codon: bool,
|
|
25
26
|
use_log: bool,
|
|
26
27
|
ends_only: bool,
|
|
28
|
+
stop_codon_masking: "Optional[StopCodonMaskingStats]" = None,
|
|
27
29
|
) -> None:
|
|
28
30
|
if seq_type.value == "nt":
|
|
29
31
|
seq_type_name = "Nucleotides"
|
|
@@ -32,9 +34,13 @@ def write_user_args(
|
|
|
32
34
|
"""
|
|
33
35
|
Function to print user arguments to stdout
|
|
34
36
|
"""
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
stop_codon_summary = ""
|
|
38
|
+
if stop_codon_masking is not None and stop_codon_masking.mode is not None:
|
|
39
|
+
stop_codon_summary = (
|
|
40
|
+
f" Stop codon masking mode: {stop_codon_masking.mode.value}\n"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
logger.info(textwrap.dedent(f"""\
|
|
38
44
|
|
|
39
45
|
-------------
|
|
40
46
|
| Arguments |
|
|
@@ -47,11 +53,10 @@ def write_user_args(
|
|
|
47
53
|
Trimming mode: {mode.value}
|
|
48
54
|
Create complementary output: {complement}
|
|
49
55
|
Process as codons: {codon}
|
|
56
|
+
{stop_codon_summary}\
|
|
50
57
|
Trim ends only: {ends_only}
|
|
51
58
|
Create log file: {use_log}
|
|
52
|
-
""" # noqa
|
|
53
|
-
)
|
|
54
|
-
)
|
|
59
|
+
""")) # noqa
|
|
55
60
|
|
|
56
61
|
|
|
57
62
|
def write_output_files_message(
|
|
@@ -60,9 +65,7 @@ def write_output_files_message(
|
|
|
60
65
|
"""
|
|
61
66
|
Function to print out that the output files are being written
|
|
62
67
|
"""
|
|
63
|
-
logger.info(
|
|
64
|
-
textwrap.dedent(
|
|
65
|
-
f"""\
|
|
68
|
+
logger.info(textwrap.dedent(f"""\
|
|
66
69
|
|
|
67
70
|
------------------------
|
|
68
71
|
| Writing output files |
|
|
@@ -70,18 +73,29 @@ def write_output_files_message(
|
|
|
70
73
|
Trimmed alignment: {out_file_name}
|
|
71
74
|
Complement file: {out_file_name + '.complement' if complement else False}
|
|
72
75
|
Log file: {out_file_name + '.log' if use_log else False}
|
|
73
|
-
"""
|
|
74
|
-
)
|
|
75
|
-
)
|
|
76
|
+
"""))
|
|
76
77
|
|
|
77
78
|
|
|
78
|
-
def write_output_stats(
|
|
79
|
+
def write_output_stats(
|
|
80
|
+
stats: "TrimmingStats",
|
|
81
|
+
start_time: float,
|
|
82
|
+
stop_codon_masking: "Optional[StopCodonMaskingStats]" = None,
|
|
83
|
+
) -> None:
|
|
79
84
|
"""
|
|
80
85
|
Function to print out output statistics
|
|
81
86
|
"""
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
stop_codon_summary = ""
|
|
88
|
+
if stop_codon_masking is not None and stop_codon_masking.mode is not None:
|
|
89
|
+
stop_codon_summary = (
|
|
90
|
+
f" Stop codon masking mode: {stop_codon_masking.mode.value}\n"
|
|
91
|
+
" Terminal stop codons masked: "
|
|
92
|
+
f"{stop_codon_masking.terminal_masked}\n"
|
|
93
|
+
" Internal stop codons masked: "
|
|
94
|
+
f"{stop_codon_masking.internal_masked}\n"
|
|
95
|
+
f" Total stop codons masked: {stop_codon_masking.total_masked}\n\n"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
logger.info(textwrap.dedent(f"""\
|
|
85
99
|
|
|
86
100
|
---------------------
|
|
87
101
|
| Output Statistics |
|
|
@@ -91,7 +105,6 @@ def write_output_stats(stats: "TrimmingStats", start_time: float) -> None:
|
|
|
91
105
|
Number of sites trimmed: {stats.trimmed_length}
|
|
92
106
|
Percentage of alignment trimmed: {stats.trimmed_percentage}%
|
|
93
107
|
|
|
108
|
+
{stop_codon_summary}\
|
|
94
109
|
Execution time: {round(time.time() - start_time, 3)}s
|
|
95
|
-
"""
|
|
96
|
-
)
|
|
97
|
-
)
|
|
110
|
+
"""))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clipkit
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.13.1
|
|
4
4
|
Summary: Alignment trimming software for phylogenetics.
|
|
5
5
|
Home-page: https://github.com/jlsteenwyk/clipkit
|
|
6
6
|
Author: Jacob L. Steenwyk
|
|
@@ -101,6 +101,25 @@ Release automation details are documented in [RELEASE.md](RELEASE.md).
|
|
|
101
101
|
pip install clipkit
|
|
102
102
|
# run
|
|
103
103
|
clipkit input.fa
|
|
104
|
+
|
|
105
|
+
# mask all in-frame stops in a codon-aligned nucleotide MSA
|
|
106
|
+
clipkit coding.fa --codon --sequence_type nt --remove_stop_codons all
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The same operation is available through the Python API:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from clipkit import clipkit
|
|
113
|
+
|
|
114
|
+
trim_run, stats = clipkit(
|
|
115
|
+
input_file_path="coding.fa",
|
|
116
|
+
mode="gappy",
|
|
117
|
+
gaps=0.9,
|
|
118
|
+
sequence_type="nt",
|
|
119
|
+
codon=True,
|
|
120
|
+
remove_stop_codons="all",
|
|
121
|
+
)
|
|
122
|
+
print(trim_run.stop_codon_masking.summary)
|
|
104
123
|
```
|
|
105
124
|
|
|
106
125
|
**eComp archives**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.12.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|