<p>The next line in the manual speaks of a python function they provide that can get k-mers from your sequence, so you don't need to worry about doing this a different way. The function slices the sequence starting from the first base with a sliding window of k to obtain k-sized pieces of the sequence and then space-separates these pieces into a single string.</p>
<pre class="lang-py prettyprint-override"><code>seq=&quot;ATGCCGTA&quot;
k=2
[seq[x:x+k] for x in range(len(seq)+1-k)]
['AT', 'TG', 'GC', 'CC', 'CG', 'GT', 'TA']

&quot; &quot;.join([seq[x:x+k] for x in range(len(seq)+1-k)])
'AT TG GC CC CG GT TA'

k=3
&quot; &quot;.join([seq[x:x+k] for x in range(len(seq)+1-k)])
'ATG TGC GCC CCG CGT GTA'
</code></pre>

CC BY-SA 4.0
2023-11-03T14:44:20.943Z
2023-11-03T14:44:20.943Z
Ram RS
<p>I'm trying to use DNABERT to predict promoter regions. Right now, I have a df with 500k rows, 1st column is the DNA sequence (all different lengths), 2nd column says &quot;promoter&quot; vs. &quot;non-promoter&quot;. I'm trying to understand the GitHub, read the paper, as well as other background reading, but I'm still confused.</p>
<p>If I want to get started, they said it's optional to pre-train (so you can skip to step 3). This is where I got tripped up: &quot;Note that the sequences are in kmer format, so you will need to convert your sequences into that.&quot; From what I understand, you need to do this so that all of the sequences are the same length? So kmer=6 means all of the sequences are length 6? Someone suggested that I take the first nucleotide in the promoter and grab 3 nucleotides before and 3 nucleotides after (+/-3 bases). I don't think that's how the kmer thing works though? I tried replicating how I think it works down below (I got confused on the last row of the 'after' df). Please correct me if I'm wrong!
Also, if there is a good package that does this for me, please let me know!</p>
<p>Before:</p>
<pre><code>seq                          label 
AAAGAGGT                      1 [promoter]
</code></pre>
<p>After:</p>
<pre><code>seq                          label 
AAAGAG                         1
AAGAGG                         1
AGAGGT                         1
??[GAGGT]??                    1
</code></pre>

CC BY-SA 4.0
2023-11-02T19:05:31.603Z
Edit the post and add the exact command you used.
Ram RS
CC BY-SA 4.0
2023-11-03T05:16:32.420Z
I didn't use any command to get the 'after' rows. I just did this by hand.
user18482
<python>
New to DNABERT confused about kmers input
# New to DNABERT confused about kmers input

(Asked by: username_0 on 2023-11-02)

I'm trying to use DNABERT to predict promoter regions. Right now, I have a df with 500k rows, 1st column is the DNA sequence (all different lengths), 2nd column says "promoter" vs. "non-promoter". I'm trying to understand the GitHub, read the paper, as well as other background reading, but I'm still confused.
If I want to get started, they said it's optional to pre-train (so you can skip to step 3). This is where I got tripped up: "Note that the sequences are in kmer format, so you will need to convert your sequences into that." From what I understand, you need to do this so that all of the sequences are the same length? So kmer=6 means all of the sequences are length 6? Someone suggested that I take the first nucleotide in the promoter and grab 3 nucleotides before and 3 nucleotides after (+/-3 bases). I don't think that's how the kmer thing works though? I tried replicating how I think it works down below (I got confused on the last row of the 'after' df). Please correct me if I'm wrong!
Also, if there is a good package that does this for me, please let me know!
Before:
seq                          label 
AAAGAGGT                      1 [promoter]

After:
seq                          label 
AAAGAG                         1
AAGAGG                         1
AGAGGT                         1
??[GAGGT]??                    1

**Tags:** python
> **Comments:**
> **username_1**: Edit the post and add the exact command you used.  
> **username_0**: I didn't use any command to get the 'after' rows. I just did this by hand.  

---

## 1 answers

### Answer by username_1 on 2023-11-03. Score: 0

The next line in the manual speaks of a python function they provide that can get k-mers from your sequence, so you don't need to worry about doing this a different way. The function slices the sequence starting from the first base with a sliding window of k to obtain k-sized pieces of the sequence and then space-separates these pieces into a single string.
seq="ATGCCGTA"
k=2
[seq[x:x+k] for x in range(len(seq)+1-k)]
['AT', 'TG', 'GC', 'CC', 'CG', 'GT', 'TA']

" ".join([seq[x:x+k] for x in range(len(seq)+1-k)])
'AT TG GC CC CG GT TA'

k=3
" ".join([seq[x:x+k] for x in range(len(seq)+1-k)])
'ATG TGC GCC CCG CGT GTA'


---

