タグ: mmp

After mishima.syk #4

Thank a lot for all attendance and presenters at mishima.syk #4 !
I enjoyed the event and party.
All presentations were very interesting and exciting. 😉
I made brief introduction about cytoscape.js, and up loaded my slide and sample code to slide share and git hub.
slide link
code link
My sample apps will need Flask, and Flask-Bootstrap. They can be installed using pip.
My mistake was that I forgot mention about my test environment.
Sample code does not work on Chrome…..
I couldn’t fix the bug. Firefox, and Safari may be work well.
But in chrome, run the app from terminal and access 127.0.0.1:5000 .
Then open javascript console in your browser and type following code , you can draw network.

cy.load(items)

Hmm, I want to study more and more.

今回のmishimasyl勉強会は次世代シーケンサの話に始まり、ネットワーク関連の話題でサンプルをいじりながらあれこれとやったり、事例紹介をしていただいたりと、勉強になりました。
 NGsの解析は最終的な解析に至るまでのステップがかなり大変そうな印象を持ちました。
データの解析というとだいたい最後のステップの可視化から何かをひもとく部分をイメージすることが多い気もしますがデータの準備超大事ですよね、その辺のプロセスが垣間見えたのはよかったです。
 ネットワーク関連の話もたのしく聞かせていただきました。igraph便利ですね。
画像を解析するっての思想がなかったんでおおって感じです。
 早速本はポチった。
今回もありがとうございました。

*ちなみにサンプルサイトのCOLAだけがmapDataを使っていて
*トップのページだけがノードをクリックすると画像をとるサイトに飛ぶようになっていて
*後のページはすべてアラートでsmilesが出ます
html部分は後から書き足ししたこともあり、ライブラリ全部毎回読んでいたりと冗長に思われるかもしれません。

Get min and max values.

I made some web apps in our lab.
I want to make mmp app. For make it, I need function that can set range like spotfire.
HTML5 range tag is not enough.
….
I found good JS library noUiSlier !
It’s easy to get min and max value from slid-bar.
I wrote code using flask.
Sample folder are….

iwatobipen$ tree
.
├── app.py
├── static
│   ├── jquery-1.11.1.min.js
│   └── noUiSlider.7.0.8
│       ├── README.md
│       ├── jquery.nouislider.all.js
│       ├── jquery.nouislider.all.min.js
│       ├── jquery.nouislider.css
│       ├── jquery.nouislider.js
│       ├── jquery.nouislider.min.css
│       ├── jquery.nouislider.min.js
│       ├── jquery.nouislider.pips.css
│       └── jquery.nouislider.pips.min.css
└── templates
    ├── index.html
    └── sample.html

app.py was simple.

from flask import Flask, url_for, jsonify, request
from flask import render_template
from flask_bootstrap import Bootstrap


app = Flask(__name__)
Bootstrap( app )

@app.route('/')
def top():
    return render_template('index.html')

@app.route('/testpage1')
def sample():
    return render_template('sample.html')

if __name__=="__main__":
    app.run(debug=True)

Next, wrote sample.html

{% extends 'bootstrap/base.html' %} 
{% block title %} samole {% endblock title %}
{% block styles %}
{{ super() }}
<link href="{{ url_for('static', filename="noUiSlider.7.0.8/jquery.nouislider.min.css") }}" rel="stylesheet">
<link href="{{ url_for('static', filename="noUiSlider.7.0.8/jquery.nouislider.pips.min.css") }}" rel="stylesheet">
{% endblock styles %}
{% block scripts %}
{{ super() }}
<script type=text/javascript src="{{ url_for('static', filename="jquery-1.11.1.min.js") }}"></script>
<script type=text/javascript src="{{ url_for('static', filename="noUiSlider.7.0.8/jquery.nouislider.all.min.js") }}"></script>
			
<script>
$('#testslider').noUiSlider({
		start: [ 0, 20 ],
		connect: true,
			range: {
						'min': -40,
						'max': 40
								}
});
</script>
 <script>
$("#read-button").click(function(){
		alert( $('#testslider').val());
		});
 </script>

<script>
function leftValue( value, handle, slider ){
	$(this).text( handle.parent()[0].style.left );
};
$("#testslider").Link("lower").to($("#lower-value"));
$("#testslider").Link("lower").to($("#lower-offset"), leftValue);

$("#testslider").Link("upper").to($("#upper-value"));
$("#testslider").Link("upper").to($("#upper-offset"), leftValue);
</script>

{% block head %}
{{ super() }}
<style>
div.example {
	padding: 20px;
}
</style>

{% endblock %}

{% endblock scripts %}

{% block content %}
<div class="example">
 <div class="view">
	 <p> noUiSliderber test </p><br><br>
 <div id="testslider" style="width:200px;"></div>
 <br>
 <button id="read-button">read min-max</button>
 <br><br>
 minvalue<br>
 <span id="lower-value"></span><br>
 <span id="lower-offset"></span><br>
 maxvalue<br>
 <span id="upper-value"></span><br>
 <span id="upper-offset"></span><br>
{% endblock %}

This code is very simple, only slider bar and that bar can get min and max value.
So, integrate ajax, it’s easy to generate SQL with some data range.
Screen Shot 2014-10-04 at 9.57.09 PM

MMP using predict

I’m still thinking about how to use mmp data in our lab.
Inspired following nice presentation, I challenged to make predictive model from MMPA.
One of ipython notebook about rdkit. link
And another is Greg’s nice presentation about reaction finger print . link2
To make predictive model from mmps, I think, I need to convert molecular transformation to fingerprint .
So, I tried to use atompair fingerprint about pair.
Data preparation is almost same as link.
In following code, TID_CHEMBL240.txt was get from chembl19, and mmp_herg.txt was made by using rdkit mmp codes.
Steps are…
1st. Merge MMPs and herg_pKi.
2nd. Calculate delta pKi.
3rd. Calculate AtomPairFingerprint.
4th. Classify delta pKi is over 1 (10 hold increase pKi) or not.

import math
from rdkit import Chem
from rdkit.Chem import AllChem
import pandas as pd
from rdkit.Chem import PandasTools
from sklearn import feature_extraction
from sklearn.svm import SVR, SVC
from sklearn import svm
from sklearn.cross_validation import train_test_split
from sklearn.metrics import confusion_matrix

df = pd.read_table("TID_CHEMBL240.txt")
mmps = pd.read_csv("mmp_herg.txt", header=None, names=["smiles1", "smiles2","molregno1","molregno2","tform","core"])
PandasTools.AddMoleculeColumnToFrame(mmps,"smiles1","mol1")
PandasTools.AddMoleculeColumnToFrame(mmps,"smiles2","mol2")
mmps = mmps[["mol1","mol2","molregno1","molregno2","tform","core"]]


#make activity table
t1 = df[["MOLREGNO", "STANDARD_VALUE"]]
#1st step merge data
mmpdds=mmps.merge(t1,left_on="molregno1",right_on="MOLREGNO",suffixes=("_1","_2")).merge(t1,left_on="molregno2", right_on="MOLREGNO",suffixes=("_1","_2"))
mmpdds["pKi_1"]=mmpdds.apply(lambda row:-1*math.log10(float(row["STANDARD_VALUE_1"])*1e-9),axis=1)
mmpdds["pKi_2"]=mmpdds.apply(lambda row:-1*math.log10(float(row["STANDARD_VALUE_2"])*1e-9),axis=1)

#2nd step calc delta pKi
mmpdds["delta"]=mmpdds.pKi_1-mmpdds.pKi_2
mmpdds = mmpdds[["mol1","mol2","molregno1", "molregno2", "pKi_1", "pKi_2", "delta", "tform", "core"]]

#3rd Calc AtompairFingerprint
mmpdds["afp_1"]=mmpdds.apply(lambda row:AllChem.GetAtomPairFingerprint(row["mol1"]) ,axis=1)
mmpdds["afp_2"]=mmpdds.apply(lambda row:AllChem.GetAtomPairFingerprint(row["mol2"]) ,axis=1)
mmpdds["deltafp"]=mmpdds.afp_2-mmpdds.afp_1
mmpdds = mmpdds.dropna()
#classify delta pKi is >1 or not.
mmpdds["ov10"] = mmpdds.delta > 1

Hmm. maybe work fine.
Go next Step.
Next, I got NonzeroElements from AtomPairFingerprint and make sparse matrix from it.
Scikit-learn has good module DictVectrizer.
So, used tha method to handle sparse matrix.
And split dataset using train_test_split.
OK, read to go.
First, build SVR classification module.
Then apply to test set.

nzf = [fp.GetNonzeroElements() for fp in mmpdds.deltafp]
v=feature_extraction.DictVectorizer(sparse=True)
sparse_mat=v.fit_transform(nzf)
x_train, x_test, y_train, y_test = train_test_split(
    sparse_mat, mmpdds.ov10, test_size=0.3, random_state=42)
clf=svm.SVC()
clf.fit(x_train,y_train)
pred=clf.predict(x_test)

cm = confusion_matrix(y_test, pred)
print(cm)

confusion matrix was…
[[359 0]
[ 5 64]]
Fine !

文章が文章になっているのか不明ですね、、、
とりあえず動作は確認できたのでベースはよしということで。