Metadata-Version: 2.4
Name: mimosa-tool
Version: 2.0.1
Summary: Model-independent motif similarity assessment tool
Author: Anton Tsukanov
Author-email: Anton Tsukanov <ubercomrade@gmail.com>
License-Expression: MIT
Requires-Dist: jax==0.10.0
Requires-Dist: numpy>=2.4.6
Requires-Python: >=3.12, <3.14
Project-URL: Homepage, https://github.com/ubercomrade/mimosa
Project-URL: Repository, https://github.com/ubercomrade/mimosa
Project-URL: Issues, https://github.com/ubercomrade/mimosa/issues
Description-Content-Type: text/markdown

# Mimosa

Mimosa is a Python package and command-line tool for DNA motif comparison.
It supports PWM/PFM, BaMM, Dimont, Slim, and precomputed score profiles.
Mimosa compares heterogeneous motif models through their behavior on the same
DNA sequences rather than by forcing their internal representations into a
common matrix.

## Background

Transcription factors (TFs) are key regulators of gene expression. They bind
specific DNA sequences, termed transcription factor binding sites (TFBSs),
located in gene regulatory regions. Because TFBSs are highly variable, they are
typically described using motifs, which capture the nucleotide preferences of a
TF across a range of binding sites. The position weight matrix (PWM) is the de
facto standard motif model, assuming independence between positions and
additive nucleotide contributions. However, numerous studies have demonstrated
the presence of dependencies between positions within TFBSs. To account for
such dependencies, alternative models have been proposed, including
Markov-based approaches (BaMM, InMoDe, Dimont, Slim, MODER2) and deep learning
models (DeepBind, DeepGRN, BERT-TFBS).
However, a mature ecosystem of databases and tools has been developed primarily
for PWMs, including motif comparison methods that are critical for result
interpretation. Comparison of alternative motif models usually requires their
conversion into PWMs, which inevitably leads to loss of information about
positional dependencies. At present, no universal tool exists for their direct
comparison. Mimosa (Model-Independent Motif Similarity Assessment) addresses
this gap by evaluating motif similarity based on functional behavior, namely
the scores models assign to DNA sequences rather than their internal parameters.

Mimosa uses the following profile comparison pipeline:

1. Scan the same DNA sequences with each model to obtain score profiles.
2. Normalize the scores to make different models comparable.
3. Identify positions with high scores in either profile.
4. Calculate weighted Jaccard similarity across profile alignments and strand
   orientations.
5. Return the best alignment and its similarity score.

See [Method and Statistics](docs/python/method.md) for the metric definition,
statistical significance, and references.

## Supported Models

| Model | Source formats | CLI type |
|---|---|---|
| PWM/PFM | MEME, plain PFM, model bundle | `pwm` |
| BaMM | `.ihbcp`, model bundle | `bamm` |
| Dimont | Jstacs XML, model bundle | `dimont` |
| Slim | Jstacs XML, model bundle | `slim` |
| Score profile | FASTA-like numeric rows | `scores` |

## Installation

Mimosa supports Python 3.12 and 3.13. The package is published on
[PyPI](https://pypi.org/project/mimosa-tool/) as `mimosa-tool`.

```bash
python -m pip install mimosa-tool
```

To install from source with uv, run from the repository root:

```bash
uv sync --locked --group dev
uv run mimosa --version
```

Alternatively, install this checkout with `python -m pip install .`.
Paths under `examples/` below refer to files in the repository, not files
installed beside the CLI. With the uv environment, prefix CLI commands with
`uv run`.

Mimosa uses JAX for computation. The default installation supports CPU
execution; GPU execution requires a compatible JAX
CUDA or ROCm plugin and driver as described in the
[JAX installation guide](https://docs.jax.dev/en/latest/installation.html).
The project currently requires `jax==0.10.0`; any GPU plugin must be compatible
with that version. JAX selects the compute device automatically. Inspect the
selected backend and its available devices with:

```bash
uv run python -c "import jax; print(jax.default_backend(), jax.devices())"
```

## CLI

Compare two PWM models on generated sequences with the default settings:

```bash
mimosa compare examples/foxa2.meme examples/gata2.meme \
  --query-type pwm --target-type pwm
```

Compare them on a FASTA batch:

```bash
mimosa compare examples/foxa2.meme examples/gata2.meme \
  --query-type pwm --target-type pwm \
  --fasta examples/foreground.fa --min-logerr 2
```

Compare precomputed score profiles:

```bash
mimosa compare examples/scores_1.fasta examples/scores_2.fasta \
  --query-type scores --target-type scores --min-logerr 2
```

Compare one query against multiple targets:

```bash
mimosa compare-many examples/foxa2.meme examples/gata2.meme examples/gata4.meme \
  --query-type pwm --target-type pwm --fasta examples/foreground.fa \
  --min-logerr 2
```

Compute pair-specific Monte Carlo significance:

```bash
mimosa compare examples/foxa2.meme examples/gata2.meme \
  --query-type pwm --target-type pwm \
  --fasta examples/foreground.fa --background examples/background.fa \
  --min-logerr 2 \
  --pvalue --mc-replicates 2000 --mc-seed 127
```

Monte Carlo randomizes the query while keeping targets fixed. This option
requires motif models, not precomputed score profiles. See
[Method and statistics](docs/python/method.md) for assumptions and settings.

Manage the optional prepared-profile cache:

```bash
mimosa cache clear --cache-dir .mimosa-cache
```

Successful `compare` results are one JSON object; `compare-many` results are an
ordered JSON array on `stdout`. Diagnostics and errors are
written to `stderr`. Run `mimosa --help` to list commands.

Command-specific options are listed by `mimosa compare --help`,
`mimosa compare-many --help`, and `mimosa cache --help`. In particular:

- `--fasta` supplies the shared comparison sequences.
- `--background` supplies separate sequences for score calibration; without it,
  calibration uses the comparison sequences.
- `--background-freq` is the per-base frequency used for PFM-to-PWM conversion
  (uniform `0.25`), not a sequence-generation or calibration-file option.
- `--cache-dir` enables persistent normalized-profile caching across runs;
  caching is disabled if omitted.

## Python API

```python
from mimosa import compare, read_fasta, read_model

query = read_model("examples/foxa2.meme")
target = read_model("examples/gata2.meme")
sequences, names = read_fasta("examples/foreground.fa")

result = compare(query, target, sequences, min_logerr=2.0)
print(result.to_dict())
```

Compare one query against multiple targets:

```python
from mimosa import compare_many

targets = [target, read_model("examples/gata4.meme")]
results = compare_many(query, targets, sequences, min_logerr=2.0)
```

The [quickstart](docs/python/quickstart.md) and [API reference](docs/python/api.md)
cover profile reuse, site selection, PFM reconstruction, and Monte Carlo.
See [custom models](docs/python/extending.md) to integrate another scorer.

## Documentation

- [Python Documentation](docs/python/index.md)
- [Python Quickstart](docs/python/quickstart.md)
- [Python API](docs/python/api.md)
- [CLI Reference](docs/python/cli.md)
- [Supported Models and Formats](docs/python/models.md)
- [Comparison Method and Statistics](docs/python/method.md)
- [Custom Models and Readers](docs/python/extending.md)
- [Storage and Cache](docs/python/storage.md)
- [Data Layout and Coordinates](docs/python/data_layout.md)
- [Migrating to JAX](docs/python/migration.md)

## Development

Run the code checks, tests, and example commands:

```bash
uv run ruff check .
uv run pytest -q tests
uv run bash examples/run.sh
```

Run the production-path performance benchmark with:

```bash
uv run python benchmarks/benchmark_performance.py --output /tmp/mimosa-performance.json
```

The default run uses 10 000 sequences, 1/64/128/256 targets and three repeats;
it can require substantial memory and temporary disk space. For a smaller check:

```bash
uv run python benchmarks/benchmark_performance.py \
  --sequence-count 100 --target-counts 1 --repeats 1 --min-logerr 2 \
  --output /tmp/mimosa-performance-small.json
```

Run the benchmark with `--help` for detailed options. Report the selected JAX
device and distinguish compilation time from warmed execution when sharing
performance measurements.

## License

MIT. See [LICENSE](LICENSE).
