clipkit 2.12.1__tar.gz → 2.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {clipkit-2.12.1 → clipkit-2.13.0}/PKG-INFO +20 -1
  2. {clipkit-2.12.1 → clipkit-2.13.0}/README.md +19 -0
  3. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/api.py +4 -4
  4. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/args_processing.py +17 -2
  5. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/clipkit.py +61 -14
  6. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/exceptions.py +4 -0
  7. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/modes.py +6 -0
  8. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/msa.py +238 -158
  9. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/parser.py +36 -20
  10. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/smart_gap_helper.py +5 -3
  11. clipkit-2.13.0/clipkit/stop_codons.py +67 -0
  12. clipkit-2.13.0/clipkit/version.py +1 -0
  13. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/write.py +33 -20
  14. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit.egg-info/PKG-INFO +20 -1
  15. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit.egg-info/SOURCES.txt +1 -0
  16. clipkit-2.12.1/clipkit/version.py +0 -1
  17. {clipkit-2.12.1 → clipkit-2.13.0}/LICENSE.md +0 -0
  18. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/__init__.py +0 -0
  19. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/__main__.py +0 -0
  20. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/ecomp/__init__.py +0 -0
  21. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/ecomp/reader.py +0 -0
  22. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/ecomp/writer.py +0 -0
  23. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/files.py +0 -0
  24. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/guide_tree.py +0 -0
  25. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/helpers.py +0 -0
  26. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/logger.py +0 -0
  27. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/plot_report.py +0 -0
  28. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/settings.py +0 -0
  29. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/site_classification.py +0 -0
  30. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/stats.py +0 -0
  31. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit/warnings.py +0 -0
  32. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit.egg-info/dependency_links.txt +0 -0
  33. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit.egg-info/entry_points.txt +0 -0
  34. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit.egg-info/requires.txt +0 -0
  35. {clipkit-2.12.1 → clipkit-2.13.0}/clipkit.egg-info/top_level.txt +0 -0
  36. {clipkit-2.12.1 → clipkit-2.13.0}/pyproject.toml +0 -0
  37. {clipkit-2.12.1 → clipkit-2.13.0}/setup.cfg +0 -0
  38. {clipkit-2.12.1 → clipkit-2.13.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clipkit
3
- Version: 2.12.1
3
+ Version: 2.13.0
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 .modes import TrimmingMode
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("CST mode requires an auxiliary file via -a/--auxiliary_file.")
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(input_file, input_file_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 {
@@ -182,6 +206,7 @@ def run(
182
206
  alignment,
183
207
  gap_characters,
184
208
  seq_records=msa.seq_records,
209
+ gaps_dist=msa.site_gappyness,
185
210
  )
186
211
  elif mode == TrimmingMode.gappyout:
187
212
  gaps = msa.determine_gappyout_gap_threshold()
@@ -196,14 +221,15 @@ def run(
196
221
  )
197
222
 
198
223
  trim_run = TrimRun(
199
- alignment,
200
- msa,
201
- gap_characters,
202
- sequence_type,
203
- input_file_format,
204
- output_file_format,
205
- gaps,
206
- codon,
224
+ alignment=alignment,
225
+ msa=msa,
226
+ gap_characters=gap_characters,
227
+ sequence_type=sequence_type,
228
+ input_file_format=input_file_format,
229
+ output_file_format=output_file_format,
230
+ gaps=gaps,
231
+ codon=codon,
232
+ stop_codon_masking=stop_codon_masking,
207
233
  )
208
234
 
209
235
  return trim_run, msa.stats
@@ -229,6 +255,7 @@ def execute(
229
255
  plot_trim_report: Union[str, None] = None,
230
256
  auxiliary_file: str = None,
231
257
  threads: int = 1,
258
+ remove_stop_codons: Union[StopCodonMode, str, None] = None,
232
259
  **kwargs,
233
260
  ) -> None:
234
261
  fh = None
@@ -247,6 +274,7 @@ def execute(
247
274
  logger.disabled = True
248
275
 
249
276
  start_time = time.time()
277
+ remove_stop_codons = normalize_stop_codon_mode(remove_stop_codons)
250
278
 
251
279
  if validate_only:
252
280
  try:
@@ -260,6 +288,12 @@ def execute(
260
288
  return
261
289
 
262
290
  validated_sequence_type = sequence_type or get_seq_type(alignment)
291
+ validate_stop_codon_configuration(
292
+ remove_stop_codons,
293
+ codon=codon,
294
+ sequence_type=validated_sequence_type,
295
+ alignment_length=alignment.get_alignment_length(),
296
+ )
263
297
  validated_gap_characters = gap_characters or get_gap_chars(
264
298
  validated_sequence_type
265
299
  )
@@ -291,6 +325,9 @@ def execute(
291
325
  gap_characters=validated_gap_characters,
292
326
  mode=mode.value,
293
327
  codon=codon,
328
+ stop_codon_masking=StopCodonMaskingStats(
329
+ mode=remove_stop_codons
330
+ ).summary,
294
331
  complement=complement,
295
332
  ends_only=ends_only,
296
333
  threads_requested=threads,
@@ -316,6 +353,7 @@ def execute(
316
353
  quiet,
317
354
  ends_only,
318
355
  threads,
356
+ remove_stop_codons,
319
357
  )
320
358
  except InvalidInputFileFormat:
321
359
  logger.error(
@@ -337,6 +375,7 @@ def execute(
337
375
  codon,
338
376
  use_log,
339
377
  ends_only,
378
+ trim_run.stop_codon_masking,
340
379
  )
341
380
 
342
381
  if dry_run:
@@ -384,6 +423,7 @@ def execute(
384
423
  gap_characters=trim_run.gap_characters,
385
424
  mode=mode.value,
386
425
  codon=codon,
426
+ stop_codon_masking=trim_run.stop_codon_masking.summary,
387
427
  complement=complement,
388
428
  ends_only=ends_only,
389
429
  threads_requested=threads,
@@ -403,7 +443,11 @@ def execute(
403
443
  )
404
444
  logger.info(f"Wrote trim plot report to {plot_trim_report}")
405
445
 
406
- write_output_stats(stats, start_time)
446
+ write_output_stats(
447
+ stats,
448
+ start_time,
449
+ stop_codon_masking=trim_run.stop_codon_masking,
450
+ )
407
451
  finally:
408
452
  if fh is not None:
409
453
  log_file_logger.removeHandler(fh)
@@ -431,7 +475,10 @@ def main(argv=None):
431
475
 
432
476
  args = parser.parse_args(argv)
433
477
 
434
- execute(**process_args(args))
478
+ try:
479
+ execute(**process_args(args))
480
+ except StopCodonValidationError as exc:
481
+ parser.error(str(exc))
435
482
 
436
483
 
437
484
  if __name__ == "__main__":
@@ -4,3 +4,7 @@ class ClipKITException(Exception):
4
4
 
5
5
  class InvalidInputFileFormat(ClipKITException):
6
6
  pass
7
+
8
+
9
+ class StopCodonValidationError(ValueError):
10
+ pass
@@ -23,3 +23,9 @@ class TrimmingMode(Enum):
23
23
  kpic_smart_gap = "kpic-smart-gap"
24
24
  cst = "cst" # custom site trimming
25
25
  c3 = "c3"
26
+
27
+
28
+ class StopCodonMode(Enum):
29
+ terminal = "terminal"
30
+ internal = "internal"
31
+ all = "all"