Skip to content

Instantly share code, notes, and snippets.

@mpkocher
Created June 23, 2016 15:01
Show Gist options
  • Save mpkocher/3b041a5ab0a5e71d6bcf5611d91d6d2f to your computer and use it in GitHub Desktop.
Save mpkocher/3b041a5ab0a5e71d6bcf5611d91d6d2f to your computer and use it in GitHub Desktop.
PacBio Report Example
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import os\n",
"import logging\n",
"import random\n",
"\n",
"from pbcommand.models.report import Report, Attribute, PlotGroup, Table, Column, Plot\n",
"\n",
"log = logging.getLogger(__name__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create a Report Attribute "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def example_attributes():\n",
" a = Attribute('alpha', 1234, name='Alpha')\n",
" b = Attribute('beta', \"b-value\", name=\"Beta Display Name\")\n",
" return [a, b]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<Attribute id:alpha value:1234 name:Alpha >,\n",
" <Attribute id:beta value:b-value name:Beta Display Name >]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"example_attributes()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example Report Table"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def example_tables():\n",
" \"\"\"Return a table with 2 columns\"\"\"\n",
" columns = [Column( 'c1id', header='C1 header'),\n",
" Column('c2id', header='C2 header')]\n",
"\n",
" t = Table('myid', title='My Table', columns=columns)\n",
"\n",
" #Now append data to the columns\n",
" #Assume data is a list of tuples of len == 2\n",
" datum = [(c.id, random.random()) for c in columns]\n",
" for column_id, value in datum:\n",
" t.add_data_by_column_id(column_id, value)\n",
"\n",
" # Alternatively\n",
" cx = Column(\"cx\", header=\"X\", values=[1,2,3,4])\n",
" cy = Column(\"cy\", header=\"Y\", values=[1,4,9,16])\n",
" t2 = Table(\"xy\", title=\"X vs Y\", columns=[cx, cy])\n",
" return [t, t2]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<Table myid title:My Table ncolumns:2 >, <Table xy title:X vs Y ncolumns:2 >]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"example_tables()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plot Group"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def example_plotgroup():\n",
" \"\"\"Return a PlotGroup with 1 plot\"\"\"\n",
" # Image paths must be relative to the dir where the final Report is written\n",
"\n",
" plot = Plot('plot_id', image='image.png', caption='this is a plot a description')\n",
" p = PlotGroup('pg_id', title='some title', thumbnail='image_thumb.png', plots=[plot])\n",
"\n",
" return p"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<PlotGroup id:pg_id title:some title nplots:1 >"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"example_plotgroup()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example Report"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def example_report():\n",
"\n",
" tables = example_tables()\n",
" attributes = example_attributes()\n",
" plotgroup = example_plotgroup()\n",
" plotgroups = [plotgroup]\n",
"\n",
" # Id must match ^[a-z0-9_]+$\n",
" r = Report('loading', title=\"Loading Report\",\n",
" attributes=attributes,\n",
" plotgroups=plotgroups,\n",
" tables=tables)\n",
" return r"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"r = example_report()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<Report id:loading title:Loading Report uuid:b1f7f60e-dbf4-43a8-b49e-d7c36582fa29 nattributes:2 nplot_groups:1 ntables:2 >"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Table id:myid\n",
"--------------------------------\n",
"C1 header C2 header \n",
"--------------------------------\n",
"0.258159525326 0.999834193855 \n",
"\n",
"Table id:xy\n",
"-------\n",
"X Y \n",
"-------\n",
"1 1 \n",
"2 4 \n",
"3 9 \n",
"4 16 \n"
]
}
],
"source": [
"for t in r.tables:\n",
" print t"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<Attribute id:alpha value:1234 name:Alpha >\n",
"<Attribute id:beta value:b-value name:Beta Display Name >\n"
]
}
],
"source": [
"for a in r.attributes:\n",
" print a"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'b1f7f60e-dbf4-43a8-b49e-d7c36582fa29'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r.uuid"
]
},
{
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment