<p>Motifs are not designed to be variable length in general since PSSMs/PVMs don't support insertions/deletions (indels). Instead, I suggest profile HMMs, such as those offered by HMMER3, which do support indels. You can parse HMMER3 output with Biopython via <code>Bio.SearchIO.HmmerIO</code></p>

CC BY-SA 4.0
2021-01-04T21:39:59.880Z
2021-01-04T21:39:59.880Z
Chris_Rands
<p>All sequences represented in a <a href="https://biopython.org/docs/1.75/api/Bio.motifs.html" rel="nofollow noreferrer">Biopython motif object</a> must be the same length. For example, a motif has a <code>__len__</code> property, which has to consist of a single value.</p>
<p>There are <a href="https://www.nature.com/articles/s41598-019-38746-w" rel="nofollow noreferrer">other methods</a> that <em>do</em> support variable-length motifs, I suggest that you look into them, but unfortunately biopython seems to be limited to fixed-length motifs.</p>

CC BY-SA 4.0
2021-01-04T18:05:16.053Z
2021-01-04T18:05:16.053Z
Maximilian Press
<p>I want to create motif of different length kmers.
Following code works for kmers of same length but not different length.What to do ?</p>
<pre class="lang-py prettyprint-override"><code>from Bio import motifs

sequences = SeqIO.parse(&quot;myfile.fasta&quot;,&quot;fasta&quot;)
    instances = []
    for data in sequences:
      instance = data.seq
      instances.append(instance)
    
motif = motifs.create(instances)
</code></pre>

CC BY-SA 4.0
2021-01-04T10:54:35.903Z
Thank you for the edit @finswimmer
Lipsa
<python><motifs>
biopython-motifs , How can I create motif from sequences of different length?
# biopython-motifs , How can I create motif from sequences of different length?

(Asked by: username_0 on 2021-01-03)

I want to create motif of different length kmers.
Following code works for kmers of same length but not different length.What to do ?
from Bio import motifs

sequences = SeqIO.parse("myfile.fasta","fasta")
    instances = []
    for data in sequences:
      instance = data.seq
      instances.append(instance)
    
motif = motifs.create(instances)

**Tags:** python, motifs
> **Comments:**
> **username_0**: Thank you for the edit @finswimmer  

---

## 2 answers

### Answer by username_1 on 2021-01-04. Score: 3

Motifs are not designed to be variable length in general since PSSMs/PVMs don't support insertions/deletions (indels). Instead, I suggest profile HMMs, such as those offered by HMMER3, which do support indels. You can parse HMMER3 output with Biopython via `Bio.SearchIO.HmmerIO`


---

### Answer by username_2 on 2021-01-04. Score: 1

All sequences represented in a [Biopython motif object](https://biopython.org/docs/1.75/api/Bio.motifs.html) must be the same length. For example, a motif has a `__len__` property, which has to consist of a single value.

There are [other methods](https://www.nature.com/articles/s41598-019-38746-w) that *do* support variable-length motifs, I suggest that you look into them, but unfortunately biopython seems to be limited to fixed-length motifs.


---

