clipkit 2.13.0__tar.gz → 2.13.2__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.13.0 → clipkit-2.13.2}/PKG-INFO +4 -1
  2. {clipkit-2.13.0 → clipkit-2.13.2}/README.md +3 -0
  3. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/clipkit.py +6 -0
  4. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/msa.py +91 -57
  5. clipkit-2.13.2/clipkit/version.py +1 -0
  6. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit.egg-info/PKG-INFO +4 -1
  7. clipkit-2.13.0/clipkit/version.py +0 -1
  8. {clipkit-2.13.0 → clipkit-2.13.2}/LICENSE.md +0 -0
  9. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/__init__.py +0 -0
  10. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/__main__.py +0 -0
  11. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/api.py +0 -0
  12. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/args_processing.py +0 -0
  13. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/ecomp/__init__.py +0 -0
  14. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/ecomp/reader.py +0 -0
  15. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/ecomp/writer.py +0 -0
  16. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/exceptions.py +0 -0
  17. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/files.py +0 -0
  18. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/guide_tree.py +0 -0
  19. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/helpers.py +0 -0
  20. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/logger.py +0 -0
  21. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/modes.py +0 -0
  22. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/parser.py +0 -0
  23. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/plot_report.py +0 -0
  24. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/settings.py +0 -0
  25. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/site_classification.py +0 -0
  26. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/smart_gap_helper.py +0 -0
  27. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/stats.py +0 -0
  28. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/stop_codons.py +0 -0
  29. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/warnings.py +0 -0
  30. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit/write.py +0 -0
  31. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit.egg-info/SOURCES.txt +0 -0
  32. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit.egg-info/dependency_links.txt +0 -0
  33. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit.egg-info/entry_points.txt +0 -0
  34. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit.egg-info/requires.txt +0 -0
  35. {clipkit-2.13.0 → clipkit-2.13.2}/clipkit.egg-info/top_level.txt +0 -0
  36. {clipkit-2.13.0 → clipkit-2.13.2}/pyproject.toml +0 -0
  37. {clipkit-2.13.0 → clipkit-2.13.2}/setup.cfg +0 -0
  38. {clipkit-2.13.0 → clipkit-2.13.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clipkit
3
- Version: 2.13.0
3
+ Version: 2.13.2
4
4
  Summary: Alignment trimming software for phylogenetics.
5
5
  Home-page: https://github.com/jlsteenwyk/clipkit
6
6
  Author: Jacob L. Steenwyk
@@ -63,6 +63,9 @@ Dynamic: summary
63
63
  <a href="https://anaconda.org/bioconda/clipkit">
64
64
  <img src="https://img.shields.io/conda/dn/bioconda/clipkit?label=bioconda%20downloads" alt="Bioconda Downloads">
65
65
  </a>
66
+ <a href="https://usegalaxy.eu/root?tool_id=clipkit">
67
+ <img src="https://img.shields.io/badge/usegalaxy-.eu-brightgreen" alt="Run ClipKIT on the European Galaxy server">
68
+ </a>
66
69
  <a href="https://lbesson.mit-license.org/" alt="License">
67
70
  <img src="https://img.shields.io/badge/License-MIT-blue.svg">
68
71
  </a>
@@ -29,6 +29,9 @@
29
29
  <a href="https://anaconda.org/bioconda/clipkit">
30
30
  <img src="https://img.shields.io/conda/dn/bioconda/clipkit?label=bioconda%20downloads" alt="Bioconda Downloads">
31
31
  </a>
32
+ <a href="https://usegalaxy.eu/root?tool_id=clipkit">
33
+ <img src="https://img.shields.io/badge/usegalaxy-.eu-brightgreen" alt="Run ClipKIT on the European Galaxy server">
34
+ </a>
32
35
  <a href="https://lbesson.mit-license.org/" alt="License">
33
36
  <img src="https://img.shields.io/badge/License-MIT-blue.svg">
34
37
  </a>
@@ -202,6 +202,12 @@ def run(
202
202
  TrimmingMode.kpi_smart_gap,
203
203
  TrimmingMode.kpic_smart_gap,
204
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
205
211
  gaps = smart_gap_threshold_determination(
206
212
  alignment,
207
213
  gap_characters,
@@ -47,14 +47,16 @@ def _column_character_counts(seq_array: np.ndarray) -> tuple[np.ndarray, np.ndar
47
47
 
48
48
  if code_span <= _MAX_DENSE_CODE_SPAN:
49
49
  counts = np.empty((code_span, n_cols), dtype=count_dtype)
50
- offsets = np.arange(_COLUMN_COUNT_BATCH_SIZE, dtype=np.int64) * code_span
50
+ offsets = (
51
+ np.arange(_COLUMN_COUNT_BATCH_SIZE, dtype=np.int64) * code_span - min_code
52
+ )
51
53
 
52
54
  for start_idx in range(0, n_cols, _COLUMN_COUNT_BATCH_SIZE):
53
55
  end_idx = min(start_idx + _COLUMN_COUNT_BATCH_SIZE, n_cols)
54
56
  width = end_idx - start_idx
55
- encoded = code_points[:, start_idx:end_idx].astype(np.int64)
56
- encoded -= min_code
57
- encoded += offsets[:width]
57
+ encoded = np.add(
58
+ code_points[:, start_idx:end_idx], offsets[:width], dtype=np.int64
59
+ )
58
60
  counts[:, start_idx:end_idx] = (
59
61
  np.bincount(encoded.ravel(), minlength=width * code_span)
60
62
  .reshape(width, code_span)
@@ -166,7 +168,14 @@ class MSA:
166
168
  if "-" not in self._gap_chars:
167
169
  self._gap_chars = [*self._gap_chars, "-"]
168
170
 
169
- codons = np.char.upper(self.seq_records).reshape(
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(
170
179
  self.seq_records.shape[0], -1, self._codon_size
171
180
  )
172
181
  gap_chars = np.char.upper(np.asarray(self._gap_chars, dtype="U1"))
@@ -267,7 +276,19 @@ class MSA:
267
276
  if self._site_gappyness_cache is not None:
268
277
  return self._site_gappyness_cache
269
278
 
270
- if self.seq_records.size < _MIN_CELLS_FOR_COLUMN_COUNTING:
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:
271
292
  site_gappyness = np.isin(self.seq_records, self._gap_chars).mean(axis=0)
272
293
  else:
273
294
  states, counts = self._get_column_character_counts(
@@ -296,21 +317,23 @@ class MSA:
296
317
  _, counts_by_state = self._get_non_gap_character_counts(
297
318
  normalize_gap_chars=True, cache_key="entropy"
298
319
  )
299
- n_cols = counts_by_state.shape[1]
300
- entropies = np.zeros(n_cols, dtype=float)
301
-
302
- for col_idx in range(n_cols):
303
- non_gap_counts = counts_by_state[:, col_idx]
304
- non_gap_counts = non_gap_counts[non_gap_counts > 0]
305
-
306
- if len(non_gap_counts) <= 1:
307
- continue
308
-
309
- total = float(sum(non_gap_counts))
310
- probs = [count / total for count in non_gap_counts]
311
- raw_entropy = -sum(p * math.log2(p) for p in probs if p > 0.0)
312
- max_entropy = math.log2(len(non_gap_counts))
313
- entropies[col_idx] = raw_entropy / max_entropy if max_entropy > 0 else 0.0
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
+ )
314
337
 
315
338
  self._site_entropy_cache = np.around(entropies, decimals=4)
316
339
  self._column_character_count_cache.pop(
@@ -328,26 +351,29 @@ class MSA:
328
351
  return self._site_composition_bias_cache
329
352
 
330
353
  _, counts_by_state = self._get_non_gap_character_counts()
331
- bias_scores = np.zeros(counts_by_state.shape[1], dtype=float)
332
-
333
- for idx in range(counts_by_state.shape[1]):
334
- counts = counts_by_state[:, idx]
335
- counts = counts[counts > 0].astype(float)
336
- total = counts.sum()
337
-
338
- if total == 0:
339
- bias_scores[idx] = 0.0
340
- continue
341
-
342
- n_states = len(counts)
343
- if n_states == 1:
344
- bias_scores[idx] = 1.0
345
- continue
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)
346
369
 
347
- probs = counts / total
348
- dominance = float(np.sum(np.square(probs)))
349
- min_dominance = 1.0 / float(n_states)
350
- bias_scores[idx] = (dominance - min_dominance) / (1.0 - min_dominance)
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
+ )
351
377
 
352
378
  self._site_composition_bias_cache = np.around(bias_scores, decimals=4)
353
379
  return self._site_composition_bias_cache
@@ -509,8 +535,16 @@ class MSA:
509
535
  != SiteClassificationType.parsimony_informative
510
536
  )[0]
511
537
  elif mode in (TrimmingMode.kpi_gappy, TrimmingMode.kpi_smart_gap):
512
- sites_to_trim_gaps_based = np.where(self.site_gappyness > gap_threshold)[0]
513
- site_classification_types = self.site_classification_types
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]
514
548
  sites_to_trim_classification_based = np.where(
515
549
  site_classification_types
516
550
  != SiteClassificationType.parsimony_informative
@@ -527,9 +561,16 @@ class MSA:
527
561
  | (site_classification_types == SiteClassificationType.singleton)
528
562
  )[0]
529
563
  elif mode in (TrimmingMode.kpic_gappy, TrimmingMode.kpic_smart_gap):
530
- sites_to_trim_gaps_based = np.where(self.site_gappyness >= gap_threshold)[0]
531
-
532
- site_classification_types = self.site_classification_types
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]
533
574
  sites_to_trim_classification_based = np.where(
534
575
  (site_classification_types == SiteClassificationType.other)
535
576
  | (site_classification_types == SiteClassificationType.singleton)
@@ -722,18 +763,11 @@ class MSA:
722
763
  return np.array([])
723
764
 
724
765
  sites_to_trim = np.asarray(sites_to_trim)
725
- blocks = sites_to_trim // self._codon_size
726
-
727
- # Create all triplet positions for each block
728
- triplets = []
729
- for block in np.unique(blocks):
730
- start = block * self._codon_size
731
- positions = np.arange(
732
- start, min(start + self._codon_size, self._original_length)
733
- )
734
- triplets.extend(positions)
735
-
736
- 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]
737
771
 
738
772
  def determine_codon_triplet_positions(self, alignment_position):
739
773
  """
@@ -0,0 +1 @@
1
+ __version__ = "2.13.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clipkit
3
- Version: 2.13.0
3
+ Version: 2.13.2
4
4
  Summary: Alignment trimming software for phylogenetics.
5
5
  Home-page: https://github.com/jlsteenwyk/clipkit
6
6
  Author: Jacob L. Steenwyk
@@ -63,6 +63,9 @@ Dynamic: summary
63
63
  <a href="https://anaconda.org/bioconda/clipkit">
64
64
  <img src="https://img.shields.io/conda/dn/bioconda/clipkit?label=bioconda%20downloads" alt="Bioconda Downloads">
65
65
  </a>
66
+ <a href="https://usegalaxy.eu/root?tool_id=clipkit">
67
+ <img src="https://img.shields.io/badge/usegalaxy-.eu-brightgreen" alt="Run ClipKIT on the European Galaxy server">
68
+ </a>
66
69
  <a href="https://lbesson.mit-license.org/" alt="License">
67
70
  <img src="https://img.shields.io/badge/License-MIT-blue.svg">
68
71
  </a>
@@ -1 +0,0 @@
1
- __version__ = "2.13.0"
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