Skip to content

Instantly share code, notes, and snippets.

@ElDeveloper
Created March 23, 2016 21:24
Show Gist options
  • Select an option

  • Save ElDeveloper/a50506fa7639a0198e5b to your computer and use it in GitHub Desktop.

Select an option

Save ElDeveloper/a50506fa7639a0198e5b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pandas as pd, numpy as np\n",
"from emperor import Emperor\n",
"from skbio.stats.ordination import OrdinationResults"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = [['PC.354', 'Control', '20061218', 'Control_mouse_I.D._354'],\n",
"['PC.355', 'Control', '20061218', 'Control_mouse_I.D._355'],\n",
"['PC.356', 'Control', '20061126', 'Control_mouse_I.D._356'],\n",
"['PC.481', 'Control', '20070314', 'Control_mouse_I.D._481'],\n",
"['PC.593', 'Control', '20071210', 'Control_mouse_I.D._593'],\n",
"['PC.607', 'Fast', '20071112', 'Fasting_mouse_I.D._607'],\n",
"['PC.634', 'Fast', '20080116', 'Fasting_mouse_I.D._634'],\n",
"['PC.635', 'Fast', '20080116', 'Fasting_mouse_I.D._635'],\n",
"['PC.636', 'Fast', '20080116', 'Fasting_mouse_I.D._636']]\n",
"columns = ['SampleID', 'Treatment', 'DOB', 'Description']\n",
"mf = pd.DataFrame(columns=columns, data=data)\n",
"\n",
"mf.set_index('SampleID', inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"eigvals = np.array([0.47941212, 0.29201496, 0.24744925,\n",
" 0.20149607, 0.18007613, 0.14780677,\n",
" 0.13579593, 0.1122597, 0.])\n",
"n = eigvals.shape[0]\n",
"site = np.random.randn(n, n)\n",
"site_ids = ('PC.636', 'PC.635', 'PC.356', 'PC.481', 'PC.354', 'PC.593',\n",
" 'PC.355', 'PC.607', 'PC.634')\n",
"p_explained = np.array([0.26688705, 0.1625637, 0.13775413, 0.11217216,\n",
" 0.10024775, 0.08228351, 0.07559712, 0.06249458,\n",
" 0.])\n",
"ores = OrdinationResults(eigvals, site=site, site_ids=site_ids,\n",
" proportion_explained=p_explained)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<script type=\"text/javascript\">\n",
"\n",
"if ($(\"#emperor-css\").length == 0){{\n",
" $(\"head\").append([\n",
"\n",
" '<link id=\"emperor-css\" rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.rawgit.com/biocore/emperor/new-api/emperor/support_files/css/emperor.css\">',\n",
" '<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.rawgit.com/biocore/emperor/new-api/emperor/support_files/vendor/css/jquery-ui.min.css\">',\n",
" '<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.rawgit.com/biocore/emperor/new-api/emperor/support_files/vendor/css/slick.grid.min.css\">',\n",
" '<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.rawgit.com/biocore/emperor/new-api/emperor/support_files/vendor/css/spectrum.min.css\">',\n",
" '<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.rawgit.com/biocore/emperor/new-api/emperor/support_files/vendor/css/chosen.min.css\">'\n",
" ]);\n",
"}}\n",
"</script>\n",
"<div id='python-penguin' style=\"position: relative; width:100%; height:500px;\"></div>\n",
"</div><script type=\"text/javascript\">\n",
"requirejs.config({\n",
"'baseUrl': 'https://cdn.rawgit.com/biocore/emperor/new-api/emperor/support_files/',\n",
"\n",
"// the left side is the module name, and the right side is the path\n",
"// relative to the baseUrl attribute, do NOT include the .js extension\n",
"'paths': {\n",
" /* jQuery */\n",
" 'jquery': './vendor/js/jquery-2.1.4.min',\n",
" 'jqueryui': './vendor/js/jquery-ui.min',\n",
" 'jquery_drag': './vendor/js/jquery.event.drag-2.2.min',\n",
"\n",
" /* jQuery plugins */\n",
" 'chosen': './vendor/js/chosen.jquery.min',\n",
" 'spectrum': './vendor/js/spectrum.min',\n",
"\n",
" /* other libraries */\n",
" 'underscore': './vendor/js/underscore-min',\n",
" 'chroma': './vendor/js/chroma.min',\n",
"\n",
"\n",
" /* THREE.js and plugins */\n",
" 'three': './vendor/js/three.min',\n",
" 'orbitcontrols': './vendor/js/three.js-plugins/OrbitControls',\n",
"\n",
" /* SlickGrid */\n",
" 'slickcore': './vendor/js/slick.core.min',\n",
" 'slickgrid': './vendor/js/slick.grid.min',\n",
" 'slickformatters': './vendor/js/slick.editors.min',\n",
" 'slickeditors': './vendor/js/slick.formatters.min',\n",
"\n",
" /* Emperor's objects */\n",
" 'model': './js/model',\n",
" 'view': './js/view',\n",
" 'controller': './js/controller',\n",
" 'draw': './js/draw',\n",
" 'scene3d': './js/sceneplotview3d',\n",
" 'viewcontroller': './js/view-controller',\n",
" 'colorviewcontroller': './js/color-view-controller',\n",
" 'visibilitycontroller': './js/visibility-controller',\n",
" 'color-editor': './js/color-editor',\n",
"},\n",
"/*\n",
" Libraries that are not AMD compatible need shim to declare their\n",
" dependencies.\n",
" */\n",
"'shim': {\n",
" 'jquery_drag': {\n",
" 'deps': ['jquery', 'jqueryui']\n",
" },\n",
" 'chosen': {\n",
" 'deps': ['jquery'],\n",
" 'exports': 'jQuery.fn.chosen'\n",
" },\n",
" 'orbitcontrols': {\n",
" 'deps': ['three']\n",
" },\n",
"'slickcore': ['jqueryui'],\n",
"'slickgrid': ['slickcore', 'jquery_drag', 'slickformatters',\n",
" 'slickeditors']\n",
"}\n",
"});\n",
"\n",
"requirejs(\n",
"[\"jquery\", \"model\", \"controller\"],\n",
"function($, model, EmperorController) {\n",
" var DecompositionModel = model.DecompositionModel;\n",
"\n",
" var div = $('#python-penguin');\n",
" console.log(div)\n",
"\n",
" var ids = ['PC.636', 'PC.635', 'PC.356', 'PC.481', 'PC.354', 'PC.593', 'PC.355', 'PC.607', 'PC.634'];\n",
" var coords = [[2.5565702979036593, -0.8780325229863559, 1.3574540094739298, 1.390929053066396, 1.4880208338434566, 0.6415455208551188, -0.11334068569791714, 0.6752527225964794, -1.025206278827291], [0.4258489518855303, 1.822638688676298, -1.5367199221085501, -0.6697243858936007, 0.5796155830196403, -1.7212585166451781, -0.2625140913393158, -0.47650526300534546, -0.5240203835655134], [0.26868481630291213, 0.7629412984495773, 0.19713042088290506, -0.2655397715175227, 1.1934176291918064, 1.778325925112435, -1.1211392301048755, 0.31878999434319644, -0.5439608491243837], [0.3274681601984497, -0.2563653120017135, -1.404584264180973, 0.5176311149223279, 0.889079623746385, -0.6501564261583433, 1.2511104684145693, 0.5484615416722257, 1.9131492129671699], [-1.0739810688522125, 0.29160486088954857, 0.6893691878709062, 0.9842987196822924, -0.3660630860842288, -1.7523386751445684, -0.41484974559752635, -0.8533229754455762, -2.3025783451330635], [0.7842322909391489, -0.1576114942491606, 0.2126063950939303, 0.6432399767313438, -0.23642040795622424, -0.7936041133202046, -0.09259398367516317, 1.4398034530613009, 0.6196270997592959], [-0.415110980490149, -0.019016213424139658, 1.0508242057901231, 0.7285765640617634, -1.5895560069952177, -0.9519302666898674, 0.5164629179146168, -0.6404089160137746, 1.2205021301789385], [-0.5891878704586315, 3.086068002372547, 0.06819552377095979, -0.4412047847031714, -1.5454960981981776, -0.6998657577764945, 0.28034579272920446, -0.670356919903373, 0.05059492128104446], [0.9568919681350673, -0.9630826756065411, -0.7399867321958497, 1.2960676823501607, 1.7123304238584443, -0.057040259070259294, 0.9642941595721573, -0.4655832756837728, 1.416816848205954]];\n",
" var pct_var = [0.26688705, 0.1625637, 0.13775413, 0.11217216, 0.10024775, 0.08228351, 0.07559712, 0.06249458, 0.0];\n",
" var md_headers = ['SampleID', 'Treatment', 'DOB', 'Description'];\n",
" var metadata = [['PC.636', 'Fast', '20080116', 'Fasting_mouse_I.D._636'], ['PC.635', 'Fast', '20080116', 'Fasting_mouse_I.D._635'], ['PC.356', 'Control', '20061126', 'Control_mouse_I.D._356'], ['PC.481', 'Control', '20070314', 'Control_mouse_I.D._481'], ['PC.354', 'Control', '20061218', 'Control_mouse_I.D._354'], ['PC.593', 'Control', '20071210', 'Control_mouse_I.D._593'], ['PC.355', 'Control', '20061218', 'Control_mouse_I.D._355'], ['PC.607', 'Fast', '20071112', 'Fasting_mouse_I.D._607'], ['PC.634', 'Fast', '20080116', 'Fasting_mouse_I.D._634']];\n",
"\n",
" var dm, ec;\n",
"\n",
" function init() {\n",
" // Initialize the DecompositionModel\n",
" dm = new DecompositionModel(name, ids, coords, pct_var,\n",
" md_headers, metadata);\n",
" // Initialize the EmperorController\n",
" ec = new EmperorController(dm, 'python-penguin');\n",
" lol = ec\n",
" }\n",
"\n",
" function animate() {\n",
" requestAnimationFrame(animate);\n",
" ec.render();\n",
" }\n",
" $(window).resize(function() {\n",
" ec.resize(window.innerWidth, window.innerHeight);\n",
" });\n",
" \n",
" $(function(){\n",
" init();\n",
" animate();\n",
" \n",
" });\n",
"\n",
"}); // END REQUIRE.JS block\n",
"</script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<emperor.core.Emperor at 0x10a906fd0>"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Emperor(ores, mf)"
]
},
{
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment