Skip to content

Commit bdbd68b

Browse files
committed
Faster implementation of cell order/sort for t-SNE plot.
1 parent 1d4deca commit bdbd68b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

NetExplorer/views/plot_gene_expression.py

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def plot_gene_expression(request):
107107

108108
if theplot is not None and not theplot.is_empty():
109109
response = theplot.plot()
110-
print("PLOTTING")
111110
else:
112111
response = None
113112

NetExplorer/views/plot_tsne.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ def do_tsne(experiment, dataset, conditions, gene_symbol, ctype, with_color):
2222
theplot.add_y(trace_name, float(cell.y_position))
2323
cell_name = cell.sample.sample_name
2424
theplot.add_name(trace_name, cell_name)
25-
cell_order.append(cell_name)
25+
cell_order.append(cell.sample.id)
2626

2727
if with_color is True:
2828
# Get Gene expression for cells
2929
cell_expression = ExpressionAbsolute.objects.filter(
3030
experiment=experiment, dataset=dataset,
3131
sample__in=samples, gene_symbol=gene_symbol
3232
)
33-
cell_expression = list(cell_expression)
34-
cell_expression.sort(key=lambda cell: cell_order.index(cell.sample.sample_name))
35-
cell_expression = [ cell.expression_value for cell in cell_expression ]
33+
# We need a dictionary with {cell_id : cell_expression}
34+
# so we can keep the same order as cell positions (in cell_order)
35+
thedict = dict()
36+
for cellexp in cell_expression:
37+
thedict[cellexp.sample.id] = cellexp.expression_value
38+
cell_expression = [ thedict[cell_idx] for cell_idx in cell_order ]
3639
theplot.add_color_to_trace(trace_name, cell_expression)
3740
return theplot
3841

0 commit comments

Comments
 (0)