Skip to content

Commit 0c115ca

Browse files
committed
t-SNE plot added.
1 parent 85b6b9c commit 0c115ca

File tree

14 files changed

+817
-343
lines changed

14 files changed

+817
-343
lines changed

NetExplorer/models.py

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,9 +1544,9 @@ class Document(models.Model):
15441544

15451545

15461546
# ------------------------------------------------------------------------------
1547-
class PlotlyPlot(object):
1547+
class GenExpPlot(object):
15481548
"""
1549-
Class for Plotly barplots.
1549+
Class for Plotly barplots and violins.
15501550
traces = [
15511551
0 : {
15521552
group1: [ values ],
@@ -1559,14 +1559,17 @@ class PlotlyPlot(object):
15591559
"""
15601560
def __init__(self):
15611561
self.traces = list()
1562+
self.traces_set = set()
15621563
self.groups = list()
1564+
self.groups_set = set()
15631565
self.title = str()
15641566
self.ylab = str()
15651567
self.trace_names = list()
15661568

15671569
def add_group(self, group):
1568-
if group not in self.groups:
1570+
if group not in self.groups_set:
15691571
self.groups.append(group)
1572+
self.groups_set.add(group)
15701573

15711574
for trace in self.traces:
15721575
if group not in trace:
@@ -1610,7 +1613,7 @@ def is_empty(self):
16101613

16111614

16121615
# ------------------------------------------------------------------------------
1613-
class BarPlot(PlotlyPlot):
1616+
class BarPlot(GenExpPlot):
16141617
"""
16151618
Class for Plotly bar plots.
16161619
Each bar (group) consists of only one value.
@@ -1648,7 +1651,7 @@ def plot(self):
16481651

16491652

16501653
# ------------------------------------------------------------------------------
1651-
class ViolinPlot(PlotlyPlot):
1654+
class ViolinPlot(GenExpPlot):
16521655
"""
16531656
Class for Plotly violinplots.
16541657
Each violin (group) is made of multiple values.
@@ -1711,6 +1714,79 @@ def plot(self):
17111714
return theplot
17121715

17131716

1717+
class ScatterPlot(object):
1718+
'''
1719+
Class for Plotly scatterplots
1720+
'''
1721+
def __init__(self):
1722+
self.traces = dict()
1723+
1724+
def add_trace(self, name):
1725+
if name not in self.traces:
1726+
self.traces[name] = PlotlyTrace(name)
1727+
self.traces[name].order = len(self.traces)
1728+
1729+
def add_x(self, trace_name, x):
1730+
if trace_name in self.traces:
1731+
self.traces[trace_name].x.append(x)
1732+
else:
1733+
raise(KeyError("Trace %s not found in ScatterPlot!" % trace_name))
1734+
1735+
def add_y(self, trace_name, y):
1736+
if trace_name in self.traces:
1737+
self.traces[trace_name].y.append(y)
1738+
1739+
def add_name(self, trace_name, name):
1740+
if trace_name in self.traces:
1741+
self.traces[trace_name].names.append(name)
1742+
1743+
def plot(self):
1744+
theplot = dict()
1745+
theplot['data'] = list()
1746+
theplot['layout'] = dict()
1747+
for trace_name in sorted(self.traces.keys(), key=lambda n: self.traces[n].order):
1748+
trace = self.traces[trace_name]
1749+
trace_data = dict()
1750+
if str(trace_name).isdigit():
1751+
trace_data['name'] = 'c' + str(trace.name)
1752+
else:
1753+
trace_data['name'] = str(trace.name)
1754+
trace_data['x'] = trace.x
1755+
trace_data['y'] = trace.y
1756+
trace_data['type'] = trace.type
1757+
trace_data['mode'] = trace.mode
1758+
if trace.color:
1759+
trace_data['marker'] = { 'color': list(trace.color) }
1760+
if trace.names:
1761+
trace_data['text'] = trace.names
1762+
theplot['data'].append(trace_data)
1763+
return theplot
1764+
1765+
def add_color_to_trace(self, trace_name, colors):
1766+
if trace_name in self.traces:
1767+
self.traces[trace_name].color = colors
1768+
else:
1769+
raise(KeyError("Trace %s not found in ScatterPlot!" % trace_name))
1770+
1771+
1772+
1773+
class PlotlyTrace(object):
1774+
'''
1775+
Class for plotly traces
1776+
'''
1777+
def __init__(self, name):
1778+
self.name = name
1779+
self.order = int()
1780+
self.x = list()
1781+
self.y = list()
1782+
self.names = list()
1783+
self.mode = 'markers'
1784+
self.type = 'scatter'
1785+
self.color = list()
1786+
1787+
1788+
1789+
17141790

17151791

17161792
# EXCEPTIONS
@@ -2002,6 +2078,13 @@ def __unicode__(self):
20022078
name_str += self.units
20032079
return name_str
20042080

2081+
2082+
class CellPlotPosition(models.Model):
2083+
experiment = models.ForeignKey(Experiment, on_delete=models.CASCADE)
2084+
sample = models.ForeignKey(Sample, on_delete=models.CASCADE)
2085+
dataset = models.ForeignKey(Dataset, on_delete=models.CASCADE)
2086+
x_position = models.FloatField()
2087+
y_position = models.FloatField()
20052088

20062089

20072090
# ------------------------------------------------------------------------------

NetExplorer/static/css/style.css

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ kbd {
20042004
#select-dataset { display: none; }
20052005
#planexp-gene-expression { display: none; }
20062006
.gene-expression-search-container { width: 50%; }
2007-
#expression-plot-container {
2007+
#plot-container {
20082008
width: 100%;
20092009
margin-top: 50px;
20102010
text-align: center;
@@ -2016,6 +2016,13 @@ kbd {
20162016
background-color: #f4f4f4;
20172017
}
20182018

2019+
#tsne-plot {
2020+
display: inline-block;
2021+
height: 500px;
2022+
min-width: 700px;
2023+
background-color: #f4f4f4;
2024+
}
2025+
20192026
#plot-genenotfound {
20202027
display: none;
20212028
margin: auto;
@@ -2025,6 +2032,15 @@ kbd {
20252032
background-color: #FDD4D4;
20262033
}
20272034

2035+
#tsneplot-genenotfound {
2036+
display: none;
2037+
margin: auto;
2038+
font-size: 18px;
2039+
padding: 8px;
2040+
width: 700px;
2041+
background-color: #FDD4D4;
2042+
}
2043+
20282044
#expression-plot-loading {
20292045
display: none;
20302046
position: absolute;
@@ -2033,10 +2049,27 @@ kbd {
20332049
margin-top: 175px;
20342050
}
20352051

2052+
#tsne-plot-loading {
2053+
display: none;
2054+
position: absolute;
2055+
z-index: 2;
2056+
left: calc(50% - 75px);
2057+
margin-top: 175px;
2058+
}
2059+
20362060
.planexp-loading-img {
20372061
width: 150px;
20382062
}
20392063

20402064
.input-grp-withlabel {
20412065
vertical-align: bottom !important;
2042-
}
2066+
}
2067+
2068+
#planexp-tsne { display: none; }
2069+
2070+
2071+
#planexp-tsne input[type=range]::-moz-range-track {
2072+
background: #E7E7E7;
2073+
}
2074+
2075+
#plot-tsne-btn { width: 125px; }

0 commit comments

Comments
 (0)