Drkcore

02 09 2009 chemoinformatics R Tweet

openbabelのフィンガープリントを使ってSVMの予測モデルを作る

久々にケモインフォクックブックを更新した。

で、このフィンガープリント使って予測モデルを作ってみる。

Benchmark Data Set for in Silico Prediction of Ames Mutagenicity のSupporting InformationにAmes試験のデータセットがあるのでこれを使ってcsvを用意する。

babel -ismi ci900161g_si_001/smiles_cas_N6512.smi -ofpt ci900161g.fpt -xh -xfFP2

これでfptファイルを用意してクックブックので変換。

f2b.py ci900161g.fpt > fingerprint.txt

さらにフィンガープリントをcsvにするのは下のやっつけスクリプトで。

file = "ci900161g_si_001/smiles_cas_N6512.smi"

dic = {"0":"negative","1":"positive"}
act = {}
for l in open(file,"r"):
   smi,id,num = l.split()
   act[id] = dic[num]


fingerprints_file = "fingerprint.txt"

header = "ID,"

for i in range(1,1025):
   header += "bit" + str(i) + ","

header += "act"
print header

for l in open(fingerprints_file, "r"):
   col = ""
   id, fp = l.split()
   col += "\"" +id + "\","
   for c in fp:
       col += c + ","
   col += "\"" + act[id] + "\""
   print col

実行

python fconv.py > ci900161g.csv

でRで解析してみる。

ames <- read.csv("/Users/kzfm/ci900161g.csv")
set.seed(50)
tr.num <- sample(6512,2500)
ames.train <- ames[tr.num,]
ames.test <- ames[-tr.num,]
ames.svm <- ksvm(act ~.,data=ames.train[,-1])
ames.pre <- predict(ames.svm, ames.test[,c(-1,-1026)])
ames.tab <- table(ames.test[,1026],ames.pre)
sum(diag(ames.tab))/sum(ames.tab)

結果

>     sum(diag(ames.tab))/sum(ames.tab)
[1] 0.7771685
> ames.tab
          ames.pre
           negative positive
  negative     1424      425
  positive      469     1694

まぁまあかなぁ。フィンガープリントとかカーネルを考えればもうちょっと精度が上がる気もするが。

参考

  • [連載]フリーソフトによるデータ解析・マイニング第 31 回. Rとカーネル法・サポートベクターマシン.

ProductName マシンラーニング (Rで学ぶデータサイエンス 6)
辻谷 将明,竹澤 邦夫
共立出版 / ¥ 3,675 ()
通常1~2か月以内に発送

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021