cc-mapping 0.2.1__tar.gz → 0.2.5__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 (23) hide show
  1. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/PKG-INFO +1 -1
  2. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/pyproject.toml +1 -1
  3. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/plot.py +11 -4
  4. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/thresholding/sequential.py +36 -21
  5. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/LICENSE +0 -0
  6. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/README.md +0 -0
  7. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/__init__.py +0 -0
  8. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/core.py +0 -0
  9. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/feature_selection/__init__.py +0 -0
  10. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/feature_selection/_base.py +0 -0
  11. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/feature_selection/_persistence.py +0 -0
  12. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/feature_selection/_plotting.py +0 -0
  13. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/feature_selection/_preprocessing.py +0 -0
  14. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/feature_selection/_random_forest.py +0 -0
  15. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/feature_selection/_training.py +0 -0
  16. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/manifold.py +0 -0
  17. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/preprocess.py +0 -0
  18. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/pseudotime.py +0 -0
  19. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/thresholding/__init__.py +0 -0
  20. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/thresholding/base.py +0 -0
  21. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/thresholding/single.py +0 -0
  22. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/utils.py +0 -0
  23. {cc_mapping-0.2.1 → cc_mapping-0.2.5}/src/cc_mapping/utils_v0.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cc-mapping
3
- Version: 0.2.1
3
+ Version: 0.2.5
4
4
  Summary: Gaussian Mixture Model-based thresholding for single-cell gene expression analysis
5
5
  Home-page: https://github.com/StallaertLab/cc_mapping
6
6
  License: BSD-3-Clause
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cc-mapping"
3
- version = "0.2.1"
3
+ version = "0.2.5"
4
4
  description = "Gaussian Mixture Model-based thresholding for single-cell gene expression analysis"
5
5
  authors = ["ddpoe <dap182@pitt.edu>"]
6
6
  readme = "README.md"
@@ -531,14 +531,21 @@ def combine_figures_with_gridspec(
531
531
  if fig.axes:
532
532
  source_ax = fig.axes[0]
533
533
 
534
- # Copy images, collections, lines, etc.
535
- for collection in source_ax.collections:
534
+ # Move artists from the source axes into the combined axes.
535
+ # Each Artist may belong to only ONE figure; calling add_*() on a
536
+ # second figure raises "Can not put single artist in more than one
537
+ # figure". Detach via .remove() first, then re-attach. list(...)
538
+ # snapshots so we don't mutate while iterating.
539
+ for collection in list(source_ax.collections):
540
+ collection.remove()
536
541
  ax_combined.add_collection(collection)
537
542
 
538
- for line in source_ax.lines:
543
+ for line in list(source_ax.lines):
544
+ line.remove()
539
545
  ax_combined.add_line(line)
540
546
 
541
- for patch in source_ax.patches:
547
+ for patch in list(source_ax.patches):
548
+ patch.remove()
542
549
  ax_combined.add_patch(patch)
543
550
 
544
551
  # Copy limits and properties
@@ -418,15 +418,26 @@ class SequentialGMM(GaussianMixtureModelBase):
418
418
  **gmm_kwargs
419
419
  )
420
420
  gmm.fit(subset_data.reshape(-1, 1))
421
-
421
+
422
+ # Sort GMM components by mean (low -> high) so column index matches the
423
+ # caller's ordered_labels convention (e.g. ['G1','S','G2'] = ascending
424
+ # DNA content). sklearn does NOT order components by mean, so without
425
+ # this sort, argmax(predict_proba) returns raw component indices that
426
+ # don't line up with the user-provided label order.
427
+ sort_order = np.argsort(gmm.means_.flatten())
428
+ sorted_means = gmm.means_.flatten()[sort_order]
429
+ sorted_covs = gmm.covariances_.flatten()[sort_order]
430
+ sorted_weights = gmm.weights_[sort_order]
431
+ sorted_data_probs = gmm.predict_proba(subset_data.reshape(-1, 1))[:, sort_order]
432
+
422
433
  # Extract GMM info
423
434
  gmm_info = _GaussianMixtureModelInfo(
424
435
  gmm_kwargs=gmm_kwargs,
425
- means=gmm.means_.flatten(),
426
- covs=gmm.covariances_.flatten(),
427
- weights=gmm.weights_,
436
+ means=sorted_means,
437
+ covs=sorted_covs,
438
+ weights=sorted_weights,
428
439
  n_components=n_components,
429
- data_probs=gmm.predict_proba(subset_data.reshape(-1, 1)),
440
+ data_probs=sorted_data_probs,
430
441
  )
431
442
 
432
443
  # Handle duplicate labels if needed.
@@ -451,12 +462,17 @@ class SequentialGMM(GaussianMixtureModelBase):
451
462
  ordered_labels=ordered_labels_processed,
452
463
  )
453
464
 
454
- # Assign new labels to subset cells
455
- new_labels = self._assign_labels_from_thresholds(
456
- data=subset_data,
457
- thresholds=decision_boundaries.thresholds,
458
- ordered_labels=ordered_labels_processed,
459
- )
465
+ # Assign new labels via per-cell argmax of the (possibly condensed)
466
+ # probability matrix. This is robust to overlapping components: when
467
+ # the threshold-derivation walk produces fewer than N-1 forward
468
+ # transitions (because backward transitions in the sorted-cell
469
+ # sequence get filtered), label assignment used to error out with
470
+ # "labels must equal thresholds + 1". decision_boundaries are still
471
+ # computed above and stored in internal_data for plotting / .uns
472
+ # introspection; only the cell-label assignment switches to argmax.
473
+ class_idx = np.argmax(probs_array, axis=1)
474
+ labels_arr = np.asarray(ordered_labels_processed)
475
+ new_labels = labels_arr[class_idx]
460
476
 
461
477
  # Update labels in-place
462
478
  self._update_labels_in_place(
@@ -1239,18 +1255,17 @@ class SequentialGMM(GaussianMixtureModelBase):
1239
1255
  )
1240
1256
 
1241
1257
  # Filter adata to only include cells with labels from this operation
1242
- # For refinement operations, we need to include all descendant labels
1243
- # since subsequent operations may have further refined the labels
1244
- if 'refined_from_labels' in op_data and op_data['refined_from_labels']:
1245
- # This was a refinement operation - find all labels that descended from it
1246
- labels_to_plot = self._get_descendant_labels(operation_name, ordered_labels)
1247
- else:
1248
- # This was an initial threshold operation - use ordered_labels directly
1249
- labels_to_plot = ordered_labels
1250
-
1258
+ # (or any of its descendants). Initial-threshold operations also need
1259
+ # the descendant lookup: by the time we plot, subsequent refinement
1260
+ # stages may have replaced this op's labels with finer-grained ones,
1261
+ # leaving zero cells under the original label strings.
1262
+ # _get_descendant_labels gracefully handles the no-descendants case
1263
+ # by returning the input labels unchanged.
1264
+ labels_to_plot = self._get_descendant_labels(operation_name, ordered_labels)
1265
+
1251
1266
  mask = self.adata.obs[obs_label].isin(labels_to_plot)
1252
1267
  adata_subset = self.adata[mask, :]
1253
-
1268
+
1254
1269
  # Call base class plotting method with explicit parameters
1255
1270
  ax = super()._plot_hist_base(
1256
1271
  adata=adata_subset,
File without changes
File without changes