Skip to content

updating pattern clustering - #140

Merged
nkempynck merged 10 commits into
mainfrom
dev
Mar 28, 2026
Merged

nkempynck merged 10 commits into
mainfrom
dev

Conversation

@nkempynck

Copy link
Copy Markdown
Collaborator

Updating pattern clustering in the standard enhancer code analysis.

Faster tomtoms: not one vs one but one vs collection
Dual direction tomtom calculation
Updated default thresholds

To do: update notebook

@nkempynck

Copy link
Copy Markdown
Collaborator Author

still WIP

@nkempynck

Copy link
Copy Markdown
Collaborator Author

New feature: x_shift parameter for contribution scores plotting
Added an x_shift parameter to contribution_scores() in src/crested/pl/explain/_contribution_scores.py that allows shifting the viewing window left or right when zooming into specific subsets of a region. Includes bounds checking with a clear error message.

Bug fix: duplicate kwargs in clustermap_tf_motif
Fixed a bug in src/crested/pl/modisco/_modisco.py where aspect, cmap, and norm were passed both as explicit arguments and through **imshow_kws, causing a TypeError. All defaults are now handled through the imshow_kws dict. Also added a cbar_pad parameter for controlling colorbar positioning, and improved colorbar rendering with manual positioning, a custom light-centered colormap, and better label padding.

Modisco pattern matching improvements (_tfmodisco.py)

Changed default sim_threshold from 0.5 to 7.0 in match_to_patterns() and from 3.0 to 6.0 in process_patterns().
Changed default trim_ic_threshold from 0.05 to 0.025 in process_patterns().
Vectorized the pattern matching logic in match_to_patterns() using matrix operations instead of a loop, taking the element-wise maximum of both comparison orders to handle asymmetric similarity scores.
Added a new post_hoc_merging() function that iteratively merges similar patterns above a similarity threshold, with IC-based filtering and optional verbose output. The old implementation is preserved as post_hoc_merging_old().
Added a return_info parameter to post_hoc_merging() to optionally return merge metadata.

@nkempynck

Copy link
Copy Markdown
Collaborator Author

Also enhancer_code_analysis update

@nkempynck

Copy link
Copy Markdown
Collaborator Author

notebook that is

@nkempynck
nkempynck merged commit 25c0f9f into main Mar 28, 2026
11 checks passed
nkempynck added a commit that referenced this pull request Jun 17, 2026
### Features
- {func}`crested.tl.modisco.process_patterns` now defaults to deterministic,
  order-independent **agglomerative clustering** (full pairwise TOMTOM + single
  cut at `sim_threshold`) instead of greedy leader clustering. New `clustering`,
  `linkage_method`, `sort_by`, and `representative` parameters; pass
  `clustering="greedy"` to reproduce earlier analyses. (#140)
- {func}`crested.tl.modisco.create_tf_ct_matrix` now defaults to **NNLS-based TF
  selection** (`selection="nnls"`): a non-negative ridge deconvolution that
  competes down broadly-expressed binders, followed by an expression-relevance
  gate (`rel_keep_frac`). Replaces the name-based paralog collapse; pass
  `selection="threshold"` for the original per-column gates. (#140)
- {func}`crested.pl.modisco.clustermap_tf_motif` gains a categorical row-class
  color strip and a per-column species stack. (#140)
- `calculate_mean_expression_per_cell_type` computes per-cell-type means on
  sparse `X` directly, avoiding densification on atlas-scale inputs. (#140)

### Bugfixes
- Agglomerative cluster IC is now the best member's IC (not the representative's),
  fixing discard/sort under non-IC `representative`. (#140)
- `process_patterns` skips classes with no matched pattern file instead of raising. (#140)
- `create_tf_ct_matrix` skips constant-expression columns, avoiding divide-by-zero. (#140)
- `_trim_pattern_by_ic` no longer over-truncates/crashes on flat patterns. (#140)

### Documentation
- Enhancer code analysis notebook updated for the agglomerative + NNLS pipeline. (#140)
- Clarified `min_tf_gex` is applied to the (optionally log-transformed) expression. (#140)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant