Metadata-Version: 2.4
Name: tfmindi
Version: 1.0.0
Summary: A very interesting piece of code
Project-URL: Documentation, https://tfmindi.readthedocs.io/
Project-URL: Homepage, https://github.com/aertslab/TF-MInDi
Project-URL: Source, https://github.com/aertslab/TF-MInDi
Author: Seppe De Winter
Maintainer-email: Seppe De Winter <seppe.dewinter@kuleuven.be>, Lukas Mahieu <lukas.mahieu@kuleuven.be>
License: MIT License
        
        Copyright (c) 2025, Stein Aerts Lab
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: <3.13,>=3.10
Requires-Dist: anndata
Requires-Dist: igraph
Requires-Dist: lda
Requires-Dist: logomaker
Requires-Dist: matplotlib
Requires-Dist: memelite
Requires-Dist: numba
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: pooch
Requires-Dist: pybigwig
Requires-Dist: scanpy
Requires-Dist: scipy
Requires-Dist: seaborn
Requires-Dist: session-info2
Provides-Extra: dev
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: twine>=4.0.2; extra == 'dev'
Provides-Extra: doc
Requires-Dist: docutils!=0.18.*,!=0.19.*,>=0.8; extra == 'doc'
Requires-Dist: ipykernel; extra == 'doc'
Requires-Dist: ipython; extra == 'doc'
Requires-Dist: myst-nb>=1.1; extra == 'doc'
Requires-Dist: pandas; extra == 'doc'
Requires-Dist: setuptools; extra == 'doc'
Requires-Dist: sphinx-autodoc-typehints; extra == 'doc'
Requires-Dist: sphinx-book-theme>=1; extra == 'doc'
Requires-Dist: sphinx-copybutton; extra == 'doc'
Requires-Dist: sphinx-tabs; extra == 'doc'
Requires-Dist: sphinx>=8.1; extra == 'doc'
Requires-Dist: sphinxcontrib-bibtex>=1; extra == 'doc'
Requires-Dist: sphinxext-opengraph; extra == 'doc'
Provides-Extra: gpu
Requires-Dist: cudf-cu12==25.8.*; extra == 'gpu'
Requires-Dist: cugraph-cu12==25.8.*; extra == 'gpu'
Requires-Dist: cuml-cu12==25.8.*; extra == 'gpu'
Requires-Dist: cupy-cuda12x; extra == 'gpu'
Requires-Dist: rapids-singlecell; extra == 'gpu'
Provides-Extra: test
Requires-Dist: coverage; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

# TF-MInDi: Transcription Factor Motifs and Instances Discovery

[![Tests][badge-tests]][tests]
[![Documentation][badge-docs]][documentation]

[badge-tests]: https://img.shields.io/github/actions/workflow/status/aertslab/TF-MInDi/test.yaml?branch=main
[badge-docs]: https://img.shields.io/readthedocs/tf-mindi

**TF-MInDi** is a Python package for analyzing transcription factor binding patterns from deep learning model attribution scores. It identifies and clusters sequence motifs from contribution scores, maps them to DNA-binding domains, and provides comprehensive visualization tools for regulatory genomics analysis.

## Getting Started

Please refer to the [documentation](https://tf-mindi.readthedocs.io/en/latest/index.html) for detailed tutorials and examples,
in particular, the [API documentation](https://tf-mindi.readthedocs.io/en/latest/api.html) and [Tutorials](https://tf-mindi.readthedocs.io/en/latest/tutorials.html)

## Key Features

- **Seqlet Extraction**: Identifies important sequence regions from contribution scores using recursive seqlet calling from `tangermeme`
- **Motif Similarity Analysis**: Compares extracted seqlets to known motif databases using TomTom
- **Clustering & Dimensionality Reduction**: Groups similar seqlets using Leiden clustering and t-SNE visualization
- **DNA-Binding Domain Annotation**: Maps seqlet clusters to transcription factor families
- **Pattern Generation**: Creates consensus motifs from clustered seqlets with alignment
- **Comprehensive Visualization**: Region-level contribution plots, t-SNE embeddings, motif logos, and heatmaps

## Installation

tfmindi is compatible with python version 3.10-3.12.

### CPU Version (Default)
```bash
pip install tfmindi
```

### GPU-Accelerated Version (Recommended for large datasets)
```bash
# Requires CUDA-compatible GPU (CUDA 12.X)
pip install tfmindi[gpu]
```

The GPU version provides significant speedups for:
- PCA computation
- Neighborhood graph construction
- t-SNE embedding
- Leiden clustering

We're still working on making the tfmindi package as GPU-compatible as possible.
If `tfmindi` can't find the GPU, try importing `rapids_singlecell` directly in python and see what errors you get.
You might have to explicitly set your LD_LIBRARY_PATH for cuml as described [here](https://github.com/rapidsai/cuml/issues/404).

## Quick Start

TF-MInDi follows a scanpy-inspired workflow:

1. **Preprocessing (`tm.pp`)**: Extract seqlets, calculate motif similarities, and create an Anndata object
2. **Tools (`tm.tl`)**: Cluster seqlets and create consensus patterns
3. **Plotting (`tm.pl`)**: Visualize results


```python
import tfmindi as tm

# Optional: Check GPU availability and set backend
print(f"GPU available: {tm.is_gpu_available()}")
print(f"Current backend: {tm.get_backend()}")
# tm.set_backend('gpu')  # Force GPU backend
# tm.set_backend('cpu')  # Swap back to CPU backend

# Extract seqlets from contribution scores
seqlets_df, seqlet_matrices = tm.pp.extract_seqlets(
    contrib=contrib_scores,  # (n_examples, 4, length)
    oh=one_hot_sequences,    # (n_examples, 4, length)
    threshold=0.05
)

# Calculate motif similarity
motif_collection = tm.load_motif_collection(
    tm.fetch_motif_collection()
)
similarity_matrix = tm.pp.calculate_motif_similarity(
    seqlet_matrices,
    motif_collection,
    chunk_size=10000
)

# Create AnnData object for analysis
adata = tm.pp.create_seqlet_adata(
    similarity_matrix,
    seqlets_df,
    seqlet_matrices=seqlet_matrices,
    oh_sequences=one_hot_sequences,
    contrib_scores=contrib_scores,
    motif_collection=motif_collection
)

# Cluster seqlets and annotate with DNA-binding domains
tm.tl.cluster_seqlets(adata, resolution=3.0)

# Generate consensus logos for each cluster
patterns = tm.tl.create_patterns(adata)

# Visualize results
tm.pl.tsne(adata, color_by="cluster_dbd")
tm.pl.region_contributions(adata, example_idx=0)
tm.pl.dbd_heatmap(adata)
```

## Release Notes

See the [changelog](https://tf-mindi.readthedocs.io/en/latest/changelog.html).

## Contact

If you found a bug, please use the [issue tracker](https://github.com/aertslab/TF-MInDi/issues).

## Citation

> t.b.a

[uv]: https://github.com/astral-sh/uv
[issue tracker]: https://github.com/aertslab/TF-MInDi/issues
[tests]: https://github.com/aertslab/TF-MInDi/actions/workflows/test.yaml
[documentation]: https://tf-mindi.readthedocs.io
[changelog]: https://tf-mindi.readthedocs.io/en/latest/changelog.html
[api documentation]: https://tf-mindi.readthedocs.io/en/latest/api.html
[pypi]: https://pypi.org/project/tfmindi
