> ## Documentation Index
> Fetch the complete documentation index at: https://proto.evodesign.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sequence Motif Match

> Score DNA sequences against motifs using MEME FIMO

<div class="page-hero">
  <img class="page-hero-banner" src="https://proto-bio.github.io/proto-assets/images/constraint/seq-motif/hero.png" alt="Sequence Motif Match" />
</div>

<Note>
  **License:** MEME Suite (FIMO) is licensed under Custom (MEME Suite Academic License) and has restrictions around commercial use and may require explicit attribution when utilized. Please refer to [the license](https://github.com/althonos/pymemesuite/blob/main/vendor/meme/COPYING) for full terms.
</Note>

<p class="entity-disclaimer">This constraint is open source. Any third-party models, product names, or trademarks referenced are the property of their respective owners, and Proto is not affiliated with them.</p>

<hr class="entity-rule" />

<input type="radio" name="tab-constraint-seq-motif" id="none-constraint-seq-motif" class="tab-radio-input" />

<input type="radio" name="tab-constraint-seq-motif" id="tools-constraint-seq-motif" class="tab-radio-input" defaultChecked />

<input type="radio" name="tab-constraint-seq-motif" id="source-constraint-seq-motif" class="tab-radio-input" />

<input type="radio" name="tab-constraint-seq-motif" id="cite-constraint-seq-motif" class="tab-radio-input" />

<div class="tool-tab-bar"><span class="tool-tab-wrap"><label for="tools-constraint-seq-motif" class="tool-tab tab-open badge-tools"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="7" x="3" y="3" rx="1" /><rect width="7" height="7" x="14" y="3" rx="1" /><rect width="7" height="7" x="14" y="14" rx="1" /><rect width="7" height="7" x="3" y="14" rx="1" /></svg> Tools Used</label><label for="none-constraint-seq-motif" class="tool-tab tab-close badge-tools"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="7" x="3" y="3" rx="1" /><rect width="7" height="7" x="14" y="3" rx="1" /><rect width="7" height="7" x="14" y="14" rx="1" /><rect width="7" height="7" x="3" y="14" rx="1" /></svg> Tools Used</label></span> <span class="tool-tab-wrap"><label for="source-constraint-seq-motif" class="tool-tab tab-open badge-source"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" /></svg> Source</label><label for="none-constraint-seq-motif" class="tool-tab tab-close badge-source"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" /></svg> Source</label></span> <span class="tool-tab-wrap"><label for="cite-constraint-seq-motif" class="tool-tab tab-open badge-cite"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z" /><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z" /></svg> Cite</label><label for="none-constraint-seq-motif" class="tool-tab tab-close badge-cite"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z" /><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z" /></svg> Cite</label></span></div>

<a href="/docs/tools/gene-annotation/meme" class="tab-panel tools-panel tools-panel-single" data-tab="tools-constraint-seq-motif">
  <div class="tools-single-card">
    <img noZoom src="https://proto-bio.github.io/proto-assets/images/tool/meme/social.png" alt="" loading="lazy" />
  </div>

  <span class="panel-goto-btn tools-goto-btn"><span><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14" /><path d="m12 5 7 7-7 7" /></svg> Go to Tool Page</span></span>
</a>

<a href="https://github.com/evo-design/proto-language/blob/d3b7822f74ea64747cc751a3b2ab1aa6b799ac47/proto_language/constraint/sequence_annotation/seq_motif_constraint.py#L159" target="_blank" class="tab-panel source-panel" data-tab="source-constraint-seq-motif">
  <div class="source-info">
    <img noZoom src="https://github.com/evo-design.png?size=40" class="source-avatar" width="36" height="36" />

    <span class="source-path">evo-design/proto-language<span class="source-subpath">/proto\_language/constraint/sequence\_annotation/seq\_motif\_constraint.py</span></span>
  </div>

  <span class="panel-goto-btn source-goto-btn"><span><svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" /></svg> View source</span></span>
</a>

<div class="tab-panel cite-panel" data-tab="cite-constraint-seq-motif">
  <div class="cite-code-wrap">
    ```bibtex theme={null}
    @article{grant2011fimo,
      title={FIMO: scanning for occurrences of a given motif},
      author={Grant, Charles E. and Bailey, Timothy L. and Noble, William Stafford},
      journal={Bioinformatics},
      volume={27},
      number={7},
      pages={1017--1018},
      year={2011},
      publisher={Oxford University Press},
      doi={10.1093/bioinformatics/btr064}
    }
    ```
  </div>

  <span class="panel-goto-btn cite-copy-btn"><span><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1z" /><path d="M15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z" /></svg> Copy citation</span></span>
</div>

<div class="entity-contributors"><span class="entity-contributors-label">Constraint contributors</span><span class="entity-contributors-people"><a class="entity-contributor" href="https://github.com/dguo8412" target="_blank" rel="noopener" title="dguo8412: 4 commits"><img noZoom class="entity-contributor-avatar" src="https://avatars.githubusercontent.com/u/46211285?v=4&s=64" alt="" loading="lazy" /><span class="entity-contributor-login">dguo8412</span></a><a class="entity-contributor" href="https://github.com/bviggiano" target="_blank" rel="noopener" title="bviggiano: 1 commit"><img noZoom class="entity-contributor-avatar" src="https://avatars.githubusercontent.com/u/21143637?v=4&s=64" alt="" loading="lazy" /><span class="entity-contributor-login">bviggiano</span></a></span></div>
Score DNA sequences against sequence motifs using MEME.

This constraint function uses MEME Suite's Find Individual Motif
Occurrences tool to search for sequence  motifs represented as position weight matrices
in DNA sequences. It evaluates whether sequences contain desired motifs (wanted)
or unwanted motifs (not\_wanted).

The scoring strategy penalizes sequences based on motif presence:

* **Unwanted motifs**: Strong matches (low p-values) result in high penalties,
  encouraging sequences without these binding sites
* **Wanted motifs**: Strong matches result in low penalties (rewards), while
  missing wanted motifs result in high penalties
* **No motif specification**: Any motif matches are penalized (novelty constraint)

## API Reference

<div class="api-model-section api-model-static api-config-section">
  <div class="api-model-header"><span class="api-model-badge api-config-badge">Config</span><span class="api-model-name">SeqMotifConfig</span><a href="https://github.com/evo-design/proto-language/blob/d3b7822f74ea64747cc751a3b2ab1aa6b799ac47/proto_language/constraint/sequence_annotation/seq_motif_constraint.py#L14" target="_blank" class="func-table-btn func-source-btn api-model-source"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6" /><polyline points="8 6 2 12 8 18" /></svg> Source</a></div>

  Configuration for sequence motif constraint using MEME.

  This class defines configuration parameters for evaluating DNA sequences against
  known transcription factor binding motifs using MEME Suite's Find Individual
  Motif Occurrences tool. The constraint searches for position weight matrix
  motifs in sequences and can either encourage specific motifs (wanted) or discourage
  them (not\_wanted), enabling design of sequences with controlled sites.

  <Note>
    Motif names must match exactly with the names in the MEME file (case-sensitive).
    Use the MOTIF lines in the .meme file to identify available motif names.
  </Note>

  <ParamField path="motifs_path" type="string" required>
    Path to MEME format motif file (.meme) containing PWMs.
  </ParamField>

  <ParamField path="fimo_config" type="MEMEFimoScanConfig">
    FIMO scan parameters (p-value threshold, both-strands); defaults match FIMO's nucleotide behavior.
  </ParamField>

  <ParamField path="wanted" type="array">
    Motifs that should be present: 'all' (all motifs), 'none' (no requirement), or list of motif names.
  </ParamField>

  <ParamField path="not_wanted" type="array">
    Motifs that should NOT be present: 'all' (reject all), 'none' (allow all), or list of motif names.
  </ParamField>

  <ParamField path="scale" type="number" default="1.0">
    Scaling factor to adjust penalty magnitude (>1 = stricter, \<1 = more lenient). Example: 1.0
  </ParamField>

  <ParamField path="exclusive" type="boolean" default="True">
    If True, automatically sets unwanted motifs as complement of wanted motifs
  </ParamField>

  <ParamField path="aggregation" type="enum" default="smart">
    How to aggregate penalties: 'smart' (adaptive), 'average', 'max' (strictest), 'percentile'

    Options: `smart`, `average`, `max`, `percentile`
  </ParamField>

  <ParamField path="percentile_value" type="number" default="95.0">
    Which percentile to use when aggregation='percentile' (0-100)
  </ParamField>

  <ParamField path="unwanted_focus" type="boolean" default="True">
    When both wanted and unwanted motifs exist, weight unwanted motifs more heavily in final score
  </ParamField>
</div>

<div class="api-model-section api-model-static api-output-section">
  <div class="api-model-header"><span class="api-model-badge api-output-badge">Returns</span><span class="api-model-name">ConstraintOutput</span></div>

  One result per sequence. Score ranges from 0.0
  (all criteria satisfied) to 1.0 (severe violations). `metadata`
  carries a single `motif_constraint` dict:

  * `penalty`: Float overall penalty score (0.0-1.0)

  * `wanted`: Sorted list of wanted motif names

  * `not_wanted`: Sorted list of unwanted motif names

  * `found`: Dictionary mapping motif names to their best (lowest) FIMO p-values

  * `details`: Dictionary with per-motif scoring details including:

    * `penalty`: Individual motif penalty
    * `status`: "wanted\_found", "wanted\_missing", "unwanted", or "unwanted\_absent"
    * `p_value`: FIMO p-value if motif was found

  * `aggregation_info`: Dictionary with aggregation statistics:

    * `method`: Aggregation method used
    * `unwanted_count`: Number of unwanted motif evaluations
    * `wanted_count`: Number of wanted motif evaluations
    * `unwanted_matches`: Number of unwanted motifs found
    * `wanted_matches`: Number of wanted motifs found
</div>

## Usage

Requiring specific transcription factor binding sites:

```python python icon="python" theme={null}
>>> from proto_language.core import Sequence, SequenceType
>>> promoter_seq = Sequence("ATCGGCGGGATCGTAATATAGCATGC", "dna")
>>> config = SeqMotifConfig(
...     motifs_path="/data/jaspar_vertebrates.meme",
...     wanted=["SP1", "lacI"],
...     aggregation="average",
... )
>>> results = seq_motif_constraint([(promoter_seq,)], config)
>>> print(results[0].score)  # e.g., 0.15
>>> print(results[0].metadata["motif_constraint"]["found"])  # e.g., {"SP1": 1e-8}
```

## Metadata

| Property        | Value                  |
| --------------- | ---------------------- |
| Key             | `seq-motif`            |
| Function        | `seq_motif_constraint` |
| Category        | `sequence_annotation`  |
| Mode            | `discrete`             |
| Uses GPU        | `False`                |
| Supported Types | `dna`                  |
