Skip to content

Instantly share code, notes, and snippets.

@ElDeveloper
Last active August 29, 2015 13:57
Show Gist options
  • Save ElDeveloper/9797907 to your computer and use it in GitHub Desktop.
Save ElDeveloper/9797907 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"# using the formatters in Emperor\n",
"from emperor.format import (format_mapping_file_to_js, format_pcoa_to_js,\n",
" format_taxa_to_js, format_vectors_to_js,\n",
" format_comparison_bars_to_js, EMPEROR_HEADER_HTML_STRING,\n",
" format_emperor_html_footer_string)\n",
"\n",
"# we are going to use this remote location to load resources\n",
"resources_url = 'http://emperor.colorado.edu/master/make_emperor/emperor_output/emperor_required_resources'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from skbio.maths.stats.ordination import PCoA\n",
"from skbio.core.distance import SymmetricDistanceMatrix, DistanceMatrix\n",
"import numpy as np"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from qiime.parse import parse_mapping_file\n",
"data, headers, _ = parse_mapping_file(open('Fasting_Map.txt', 'U'))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"dm = SymmetricDistanceMatrix.from_file(open('unweighted_unifrac_dm.txt', 'U'))\n",
"pcoa = PCoA(dm)\n",
"\n",
"# grab the things we need for the plot\n",
"coords = pcoa.scores().species\n",
"eigvals = pcoa.scores().eigvals\n",
"pcts = np.ones(len(eigvals))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# i am assuming the order from the dm to the PCoA object is preserved\n",
"pcoa_string = format_pcoa_to_js(dm.ids, coords, eigvals, pcts)\n",
"mf_string = format_mapping_file_to_js(data, headers, headers)\n",
"\n",
"# A lot of this is going to be empty because we don't really need any of it\n",
"footer = format_emperor_html_footer_string(False, False, False, False)\n",
"taxa = format_taxa_to_js([], [], [])\n",
"bars = format_comparison_bars_to_js([], [], 0)\n",
"vectors = format_vectors_to_js([], [], [], [], None)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import HTML, IFrame"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# build the HTML string\n",
"output = [EMPEROR_HEADER_HTML_STRING,\n",
" mf_string,\n",
" pcoa_string,\n",
" taxa,\n",
" bars,\n",
" vectors,\n",
" footer]\n",
"# add the remote resources\n",
"output = '\\n'.join(output).replace('emperor_required_resources', resources_url)\n",
"\n",
"fd = open('d.html', 'w')\n",
"fd.write(output)\n",
"fd.close()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"IFrame('files/d.html', 800, 400)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
" <iframe\n",
" width=\"800\"\n",
" height=400\"\n",
" src=\"files/d.html\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" ></iframe>\n",
" "
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
"<IPython.lib.display.IFrame at 0x10820bb90>"
]
}
],
"prompt_number": 9
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment