-
Notifications
You must be signed in to change notification settings - Fork 6
/
Cell.cs
204 lines (182 loc) · 7.63 KB
/
Cell.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System.Collections.Generic;
using System;
using UnityEngine;
using CellexalVR.AnalysisObjects;
using CellexalVR.Extensions;
namespace CellexalVR.AnalysisLogic
{
/// <summary>
/// Represents one cell. A cell may be present in multiple graphs.
/// </summary>
public class Cell
{
public List<Graph.GraphPoint> GraphPoints;
public Dictionary<string, float> Facs { get; private set; }
public Dictionary<string, string> FacsValue { get; private set; }
public Dictionary<string, float> NumericalAttributes { get; private set; }
public int ExpressionLevel { get; internal set; }
public float ExpressionValue { get; set; }
public string Label { get; set; }
private GraphManager graphManager;
private Dictionary<string, int> lastExpressions = new Dictionary<string, int>(16);
private Dictionary<string, int[]> flashingExpressions = new Dictionary<string, int[]>();
/// <summary>
/// Creates a new cell.
/// </summary>
/// <param name="label"> A string that differentiates this cell from other cells. </param>
/// <param name="graphManager"> The graphmanager that this cell has graphpoints in. </param>
public Cell(string label, GraphManager graphManager)
{
this.graphManager = graphManager;
this.Label = label;
GraphPoints = new List<Graph.GraphPoint>();
Facs = new Dictionary<string, float>();
FacsValue = new Dictionary<string, string>();
NumericalAttributes = new Dictionary<string, float>();
}
/// <summary>
/// Tell this cell that it is now represented by a graphpoint.
/// A cell may be represented by many graphpoints (typically one in each graph).
/// </summary>
/// <param name="g"> The graphpoint representing this cell. </param>
public void AddGraphPoint(Graph.GraphPoint g)
{
GraphPoints.Add(g);
}
public void ColorByCluster(int cluster, bool color)
{
foreach (Graph.GraphPoint g in GraphPoints)
{
if (color)
{
g.ColorSelectionColor(cluster, false);
}
else
{
g.ResetColor();
}
}
}
/// <summary>
/// Saves the current gene expression of this cell is colored by
/// </summary>
/// <param name="saveGeneName"> The genename to save </param>
/// <param name="removeGeneName"> The name of a gene to remove or an empty string to not remove anything. Gene expressions can use up quite some memory so only 10 are saved at a time. </param>
public void SaveExpression(string saveGeneName, string removeGeneName)
{
if (removeGeneName != null && removeGeneName != "")
{
lastExpressions.Remove(removeGeneName);
}
lastExpressions[saveGeneName] = ExpressionLevel;
}
/// <summary>
/// Color all graphpoints that represents this cell by an index.
/// I don't know enough biology to know what this actually is.
/// </summary>
/// <param name="facsName"> The index. </param>
public void ColorByIndex(string facsName)
{
//foreach (Graph.GraphPoint g in GraphPoints)
//{
// g.RecolorGeneExpression(, false);
//}
}
/// <summary>
/// Colors this cell by a gene expression color.
/// </summary>
/// <param name="i">A number between 0 and <see cref="CellexalVR.General.CellexalConfig.Config.GraphNumberOfExpressionColors"/></param>
public void ColorByGeneExpression(int i)
{
foreach (Graph.GraphPoint g in GraphPoints)
{
g.ColorGeneExpression(i);
}
}
/// <summary>
/// Adds a .facs bin index to this cell.
/// </summary>
/// <param name="facsName"> The thing's name. </param>
/// <param name="value"> The value of the thing. </param>
internal void AddFacs(string facsName, float value)
{
Facs[facsName.ToLower()] = value;
}
/// <summary>
/// Other numerical attribute that is not facs value or gene expression.
/// </summary>
public void AddNumericalAttribute(string attributeType, float value)
{
NumericalAttributes[attributeType.ToLower()] = value;
}
/// <summary>
/// Adds a .facs original value to this cell.
/// </summary>
/// <param name="facsName"> The thing's name. </param>
/// <param name="index"> The value of the thing. </param>
internal void AddFacsValue(string facsName, string value)
{
FacsValue[facsName.ToLower()] = value;
}
/// <summary>
/// Sets the group and color of all graphpoints that are representing this cell.
/// </summary>
/// <param name="group"> The new group. </param>
public void SetGroup(int group, bool changeColor)
{
foreach (var g in GraphPoints)
{
g.ColorSelectionColor(group, false);
}
}
/// <summary>
/// Initializes the cell for saving genee expressions for flashing.
/// Should be called before <see cref="SaveSingleFlashingGenesExpression(string, int, int)"/>
/// </summary>
/// <param name="category">The name of a category that should be initialized</param>
/// <param name="length">The number of genes in that category</param>
public void InitSaveSingleFlashingGenesExpression(string category, int length)
{
flashingExpressions[category] = new int[length];
}
/// <summary>
/// Saves a gene expression that can be flashed later.
/// </summary>
/// <param name="category">The name of the category that this gene is in</param>
/// <param name="index">Which index it should be put on</param>
/// <param name="expression">A value between 0 and <see cref="CellexalConfig.Config.GraphNumberOfExpressionColors"/></param>
public void SaveSingleFlashingGenesExpression(string category, int index, int expression)
{
flashingExpressions[category][index] = expression;
}
/// <summary>
/// Saves gene expressions so they can be flashed quickly later.
/// </summary>
/// <param name="category"> The category the gene expressions are in </param>
/// <param name="expression"> An array containing indices corresponding to <see cref="GraphManager.GeneExpressionMaterials"/>. </param>
public void SaveFlashingExpression(string category, int[] expression)
{
flashingExpressions[category] = expression;
}
/// <summary>
/// Gets the lengths of each category.
/// </summary>
/// <returns> A Dictionary with the categories as keys and their lengths as values. </returns>
internal Dictionary<string, int> GetCategoryLengths()
{
Dictionary<string, int> lengths = new Dictionary<string, int>();
foreach (KeyValuePair<string, int[]> pair in flashingExpressions)
{
lengths[pair.Key] = pair.Value.Length;
}
return lengths;
}
/// <summary>
/// Clears the saved flashing expressions.
/// </summary>
public void ClearFlashingExpressions()
{
flashingExpressions.Clear();
}
}
}