相关疑难解决方法(0)

如何为DNA序列生成一个热编码?

我想为一组DNA序列生成一个热编码.例如,序列ACGTCCA可以以转置方式如下表示.但是下面的代码将以水平方式生成一个热编码,我希望它以垂直形式.谁能帮我?

ACGTCCA 
1000001 - A
0100110 - C 
0010000 - G
0001000 - T
Run Code Online (Sandbox Code Playgroud)

示例代码:

from sklearn.preprocessing import OneHotEncoder
import itertools

# two example sequences
seqs = ["ACGTCCA","CGGATTG"]


# split sequences to tokens
tokens_seqs = [seq.split("\\") for seq in seqs]

# convert list of of token-lists to one flat list of tokens
# and then create a dictionary that maps word to id of word,
# like {A: 1, B: 2} here
all_tokens = itertools.chain.from_iterable(tokens_seqs)
word_to_id = {token: idx for …
Run Code Online (Sandbox Code Playgroud)

python arrays python-itertools scikit-learn one-hot-encoding

5
推荐指数
2
解决办法
2024
查看次数