Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple jupyter widget to parse urls using clustal
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"from traitlets import Unicode, List\n",
"from IPython.display import display\n",
"\n",
"class MsaParseUrl(widgets.DOMWidget):\n",
" _view_name = Unicode('MsaParseUrlView').tag(sync=True)\n",
" _view_module = Unicode('MsaParseURL').tag(sync=True)\n",
" parse_url = Unicode('').tag(sync=True)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"require.config({\n",
" paths: {\n",
" biojs: \"https://cdn.biojs.net/msa/0.4/msa.min.gz.js\",\n",
" }\n",
"});\n",
"\n",
"require(['biojs'], function(){\n",
" console.log(\"biojs loaded\");\n",
"});\n",
"\n",
"require([\"nbextensions/widgets/widgets/js/widget\",\n",
" \"nbextensions/widgets/widgets/js/manager\",\n",
" \"biojs\"],\n",
" function(widgets, manager, biojs){\n",
"});\n",
"\n",
"define('MsaParseURL', ['jquery', 'jupyter-js-widgets'], function($, widgets) {\n",
" var MsaParseUrlView = widgets.DOMWidgetView.extend({\n",
" render: function(){\n",
" var clustal = require(\"biojs-io-clustal\");\n",
" if(clustal){\n",
" console.log(clustal);\n",
" }\n",
" var m = new msa({\n",
" el:this.$el.append(\"<div>\", {id:\"seqDiv\"}),\n",
" });\n",
" if(m){\n",
" console.log(m);\n",
" }\n",
" clustal.read(this.model.get(\"parse_url\"), function(err, seqs){\n",
" m.seqs.reset(seqs);\n",
" m.render();\n",
" });\n",
" },\n",
" });\n",
" manager.WidgetManager.register_widget_view('MsaParseUrlView', MsaParseUrlView);\n",
" return {\n",
" MsaParseUrlView: MsaParseUrlView\n",
" }\n",
"});"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%javascript\n",
"require.config({\n",
" paths: {\n",
" biojs: \"https://cdn.biojs.net/msa/0.4/msa.min.gz.js\",\n",
" }\n",
"});\n",
"\n",
"require(['biojs'], function(){\n",
" console.log(\"biojs loaded\");\n",
"});\n",
"\n",
"require([\"nbextensions/widgets/widgets/js/widget\",\n",
" \"nbextensions/widgets/widgets/js/manager\",\n",
" \"biojs\"],\n",
" function(widgets, manager, biojs){\n",
"});\n",
"\n",
"define('MsaParseURL', ['jquery', 'jupyter-js-widgets'], function($, widgets) {\n",
" var MsaParseUrlView = widgets.DOMWidgetView.extend({\n",
" render: function(){\n",
" var clustal = require(\"biojs-io-clustal\");\n",
" if(clustal){\n",
" console.log(clustal);\n",
" }\n",
" var m = new msa({\n",
" el:this.$el.append(\"<div>\", {id:\"seqDiv\"}),\n",
" });\n",
" if(m){\n",
" console.log(m);\n",
" }\n",
" clustal.read(this.model.get(\"parse_url\"), function(err, seqs){\n",
" m.seqs.reset(seqs);\n",
" m.render();\n",
" });\n",
" },\n",
" });\n",
" manager.WidgetManager.register_widget_view('MsaParseUrlView', MsaParseUrlView);\n",
" return {\n",
" MsaParseUrlView: MsaParseUrlView\n",
" }\n",
"});"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"w = MsaParseUrl()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"w.parse_url = \"https://raw.githubusercontent.com/greenify/msa/master/test/dummy/samples/p53.clustalo.clustal\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"display(w)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
},
"widgets": {
"state": {},
"version": "1.1.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment