pynteractive package¶
Submodules¶
pynteractive.datastruct module¶
-
class
pynteractive.datastruct.
DataStruct
(name=None)¶ DataStruct is the basic data structure aimed to abstract any data set that will be represented in Pynteractive Web GUI. All different dataset inherit from DataStruct class, and datastruct class implements the basic mechanisms to communicate with the Pynteractive web server
-
addAction
(name, func)¶ Actions can be added to each visualization
An action consists of a label (name) shown in the web interface plus a callback method (func) called then the button associated to the label is clicked. The callback function must accept one parameter that depending on the visualization can be defferent (eg. list of nodes, sample id, etc...)
example:
a=Graph() def myfunc(nodes): print 'these are the selected nodes',nodes a.addAction('Print selected nodes',myfunc) a.view() # Now you can select some nodes in the GUI and click your action on the left side bar
-
clearLog
()¶ Clears the contents of the log box in the web GUI
-
closeView
()¶ Closes the browser window/tab containing the dataset GUI
-
log
(log)¶ Dumps HTML code in the Log section in the web GUI
-
static
readCsv
(csvfile)¶ readsCsv and returns the output as a vector of vectors. Detects delimiter automatically
-
selectionHandler
(func)¶ Sets a hook method that will be fired every time a selection is performed
-
setDoubleClick
(f)¶ Sets a callback as a response to a double click event on a graph node
-
view
()¶ This method opens the default web browser in the system showing the web visualization associated to the data
-
pynteractive.Network module¶
-
class
pynteractive.Network.
Network
(name=None, directed=False)¶ Bases:
pynteractive.datastruct.DataStruct
This class implements basic methods and datastructures to represent a Newtork. IT is used for either Graphs or trees
-
addEdge
(n1, n2, label, **kwargs)¶ Adds an edge from node n1 to node n2, if it is not directed the order does not matter. The edge id will be a combination of n1,n2 and label (eg: addEdge(‘node1’,’node2’,’connection_node1_node2’) –> edge_id = ‘node1~node2~connection_node1_node2’)
-
addNode
(node_id=None, label=None, **kwargs)¶ Ads a node into the network, you can specify a cwnode_id and a label, if no node_id is specified, it will be randomly generated (autoincremental id) and if label is None it will get the same value as the node_id
Random parameters can be assigned to the node via **kargs.
It returns the tuple node_id,label.
-
delEdge
(_id)¶ Deletes a connection between two given nodes
-
delNode
(node_id)¶ Deletes a node from the network as well as the edges
-
getEdges
()¶ Returns the edges of the Network –> ([edge_ids])
-
getNodes
()¶ Returns the nodes of the Network –> ([node_ids])
-
updateNode
(node_id, **kwargs)¶ Updates parameters related to node node_id updating those parameters specified via **kwargs
-
pynteractive.visNetwork module¶
-
class
pynteractive.visNetwork.
VisNetwork
(name=None, directed=False)¶ Bases:
pynteractive.Network.Network
-
addEdge
(n1, n2, label=None, title=None, width=None, style=None, length=None)¶ Adds an edge to a node, if it is not directed the order does not matter:
- label: label on the edge
- title: text shown when hovering the edge
- width: width in pixeld of the edge
- style: line style -> line, arrow, arrow-center, dash-line
- length: length of the edge
-
addNode
(node_id=None, label=None, title=None, group=None, shape='ellipse', color=None, radius=None, image=None)¶ Adds a node to the network:
- node_id: identification of the node, if not specified it will be randomly generated
- label: Text that will be shown within the node
- title: Tooltip shown when hovering the node
- group: color group (numeric, eg: 1,2,3,4) used for clusterings
- shape: any of ellipse, circle, box, database, image, circularImage, label, dot, star, triangle, triangleDown, square
- color: color name or html code (eg: red, #FF0000)
- radius: radius of the shape
- image: Image in case the shape is image or circularImage
-
clear
()¶ Clears the GUI by removing every node and edge in the network
-
delEdge
(ed_id)¶ Deletes a connection between two given nodes
-
delNode
(node_id)¶ Deletes a node from the network as well as the edges
-
focusNode
(id)¶ Forces the GUI to zoom in into the specified node
-
updateNode
(node_id, label=None, title=None, group=None, shape=None, color=None, radius=None, image=None)¶ Updates a node in the network
-
pynteractive.graph module¶
-
class
pynteractive.graph.
Graph
(name=None, directed=False)¶ Bases:
pynteractive.visNetwork.VisNetwork
-
fromCsv
(fil, matrix=False, distances=False)¶ Draws a network given a csv file
The format for the CSV can be:¶ n1 n2 a b a c c d ¶ n1 n2 a b d e b c e e f a d e ¶ a b c d e f a 1 0 0 0 0 0 b 1 0 0 0 0 0 c 0 1 1 1 0 0 d 0 1 0 0 1 0 e 1 0 0 0 1 1 f 0 0 0 0 1 1 ¶ a b c d e f a 54 0 0 0 0 0 b 23 0 0 0 0 0 c 0 10 2 1 0 0 d 0 10 0 0 13 0 e 56 0 0 0 1 1 f 0 0 0 0 3 1
-
random
(nn, ne)¶ Creates a random Graph containing nn nodes and ne edges
-
pynteractive.map module¶
-
class
pynteractive.map.
Map
(name=None)¶ Bases:
pynteractive.Network.Network
The Map class allows to plot data in an OpenStreet Map. The user can plot points of different sizes and colors as well as linking them with edges. In order to specify the location coordinates or places (eg. postcode) can be used.
-
CACHE
= {}¶
-
LOCK
= <thread.lock object>¶
-
MAXTHREADS
= 15¶
-
RUNNINGTHREADS
= <threading._Semaphore object>¶
-
THREADS
= []¶
-
addEdge
(n1, n2, color='red', width=2)¶ Ads and edge between two points given a color tag
-
addNode
(*args, **kwargs)¶
-
clear
()¶ Deletes all the information plotted in the map
-
delEdge
(eid)¶ Deletes an edge given an egde ID
-
delNode
(node_id)¶ Deletes a node from the map
-
focusNode
(node_id)¶ Zooms into a given node
-
updateNode
(node_id, radius=None, color=None, lng=None, lat=None, place=None, country=None)¶ Updates a node in the Map
-
pynteractive.tree module¶
-
class
pynteractive.tree.
Tree
(name=None, directed=None)¶ Bases:
pynteractive.Network.Network
-
getName
(name)¶
-
readNewick
(newick)¶
-
pynteractive.chart module¶
-
class
pynteractive.chart.
Chart
(name=None, type='line')¶ Bases:
pynteractive.datastruct.DataStruct
-
SHAPES
= set(['triangle-down', 'diamond', 'cross', 'triangle-up', 'square', 'circle'])¶
-
TYPES
= {'line': 'Line', 'bar': 'Bar', 'scatter': 'Scatter', 'stack': 'Stack'}¶
-
addSeries
(seriesName, x=[], y=[], sizes=[], shapes=[], data=[], csv=None)¶ - Adds a series of data. A series of data has to have a name and a collection of (x,y) pairs that can be either integers or floats
if the chart is a scatter you can add as well sizes and or shapes.
The available shapes are: ‘circle’, ‘cross’, ‘triangle-up’, ‘triangle-down’, ‘diamond’, ‘square’
There are several ways of adding data:
a=Chart() a.addSeries('dataset1',[1,2,3],[4,5,6]) a.addSeries('dataset2',[1,2,3],[4,5,6],sizes=[.5,.5,.2],shapes=['circle','cross','square']) a.addSeries('dataset3',data=[[1,4],[2,5],[3,6]]) a.addSeries('dataset4',data=[[1,4,.5,'circle'],[2,5,.5,'cross'],[3,6,.2,'square']]) a.addSeries('dataset5',csv='file.csv') # The format has to the same as we pass it to data parameter
-
addValue
(idSeries, x, y, **kwargs)¶ Ads a value into a series, extra parameters can be size=N and shape=’XXX’
-
changeType
(type)¶ Changes the chart type in the view, the following types are available: ‘bar’,’scatter’,’line’,’stack’
-
delSeries
(seriesName)¶ Deletes a series from the graph
-
delValue
(idSeries, x)¶ Deletes a value from a series
-
pynteractive.phylotree module¶
-
class
pynteractive.phylotree.
PhyloTree
(name=None)¶ Bases:
pynteractive.datastruct.DataStruct
-
addBar
(description, color, minval, maxval)¶ Outside the tracks, bars can be drawn showing extra information. You can have as many bars you want per sector (tip) (eg: if you want two bars in a barplot per tip, you call addBar twice and then you populate them with data
description: Text description for the legend
color: color used for the bar
minval: minimum value of the data that the bars will show
maxval: maximum value of the data that the bars will show
Returns the Bar identifier to be used to add data to it (See example below)
-
addGradientTrack
(description, color, minval, maxval)¶ A gradient Track is a track where tips in the tree can have a continuous value, and the color will be shown as a gradient color. You must specify minval and maxval of the track so that the gradient can be calculated
description: Text used for the legend
color: color used for the gradient on track
minval: Minimum value of the range of values this track will have
maxval: Minimum value of the range of values this track will have
Returns the track ID that you will have to use to add data to it
-
addMultiColorTrack
(description, colordict)¶ A Multicolor track is a track that can have random colors given a color dictionary eg: {“uk”:’red’,”france”:’green’,”germany”:”#a2a2a2”} - description: Text used for the legend - colordict: Dictionary mapping values to colors
Returns the track ID that you will have to use to add data to it
-
addTrack
(description, color)¶ Ads a track as an external ring. This is a BOOLEAN track, where any tip can be flagged in the track. When clicking a coloured tip on the track, all the tips flagged in the track will automatically be selected
description: Text used for the legend
color: color used for the flagged tips on the track
Returns the track ID that you will have to use to add data to it
-
addTrackBar
(nbar, tipname, value)¶ Adds data to a bar
- nbar: bar ID provided by addBar function
- tipname: name of the tip you will add data to
- value: Value the the bar will show
p=PhyloTree() p.setData("file.newick") contaminationBars=p.addBar('contamination','green',0,28) p.addTrackBar(contaminationBars,'sample1',4) p.addTrackBar(contaminationBars,'sample2',22) p.addTrackBar(contaminationBars,'sample3',17)
-
addTrackFeature
(trackn, tipname, value=False, title=None)¶ Adds a data to a track:
- trackn: Track number to add data to
- tipname: The tip you want to add the feature to
- value: Only required/necessary if it’s a gradient track
- title: Tooltip shown when hovering with the mouse
p=PhyloTree() p.setData("file.newick") resistanteTrack=p.addTrack('Antibiotic resistante','red') coverageTrack=p.addTrack('Avg Depth coverage','blue',0,344) p.addTrackFeature(resistanceTrack,'sample1') p.addTrackFeature(resistanceTrack,'sample3') p.addTrackFeature(coverageTrack,'sampler1',25) p.addTrackFeature(coverageTrack,'sampler2',221) p.addTrackFeature(coverageTrack,'sampler3',344)
-
clearBars
()¶ Clears all bars around the tracks
-
clearCladeColor
(clade)¶ Clears tree color given a clade
-
clearCladeMarks
()¶ Removes all clade marks
-
clearSelection
()¶ Method to clear the current selection in the tree
-
clearTracks
()¶ Clears all information in tracks
-
delTrackFeature
(trackn, tipname)¶ Deletes a feature present on a track
-
getTips
()¶ Returns a set containing all the tip names found in the tree
-
markClade
(nodes, color)¶ Marks the region of a clade given a fill color
- nodes: Is a list of tips/internalnodes
- color: HTML compatible color
-
nodeClick
(nid)¶ Method called when a node is clicked
-
recolor
= <_sre.SRE_Pattern object>¶
-
selectClade
(tips)¶ Select the clade containing a set of given tips
-
selectTips
(tips)¶ Method usd to select nodes in the view (tree tips), you must provide tip labels
-
setCladeColor
(nodes, color)¶ Sets tree color for a clade
- nodes: Is a list of tips/internalnodes
- color: HTML compatible color
-
setData
(newick=None)¶ Draws the specified newick tree, It can be either a string containing the newick string or a path to a file
-
unMarkClade
(clade)¶ Removes a mark for a clade
-