{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# * Visualizing of genetic similarity with Lightning + GraphX *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup lightning" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [] } ], "source": [ "%libraryDependencies += \"org.viz.lightning\" %% \"lightning-scala\" % \"0.1.6\"" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [] } ], "source": [ "%update" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [] } ], "source": [ "import org.viz.lightning._\n", "import org.apache.spark.graphx._" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [] }, { "data": { "text/plain": [ "org.viz.lightning.Lightning@7cd4a5c1" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val lgn = Lightning(host=\"https://lightning-spark-summit.herokuapp.com\" )\n", "lgn.enableNotebook()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load structure similarity data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Public data from http://www.brain-map.org/" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [] }, { "data": { "text/plain": [ "org.apache.spark.graphx.impl.GraphImpl@36afd257" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val source = \"/Users/mathisonian/projects/spark-summit/notebooks/data/allen-connectivity.txt\"\n", "val g = GraphLoader.edgeListFile(sc, source)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show the network (unlabeled)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [] }, { "data": { "text/plain": [ "org.viz.lightning.Visualization@7a4932cd" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val links = g.edges.collect().map(e => Array(e.srcId.toInt, e.dstId.toInt))\n", "\n", "lgn.force(links)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show the network colored by degree" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [] }, { "data": { "text/plain": [ "org.viz.lightning.Visualization@417fda19" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val links = g.edges.collect().map(e => Array(e.srcId.toInt, e.dstId.toInt))\n", "val degrees = g.degrees.sortBy(_._1).collect().map(x => Math.log(x._2))\n", "\n", "lgn.force(links, value=degrees, colormap=\"Lightning\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show the network colored by connected components" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [] }, { "data": { "text/plain": [ "org.viz.lightning.Visualization@74ca5c41" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val links = g.edges.collect().map(e => Array(e.srcId.toInt, e.dstId.toInt))\n", "val connectedComponents = g.connectedComponents().vertices.sortBy(_._1).map(_._2.toInt).collect()\n", "\n", "lgn.force(links, label=connectedComponents)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "name": "scala", "version": "2.10.4" } }, "nbformat": 4, "nbformat_minor": 0 }