/
test_decomposition_view.js
273 lines (235 loc) · 9.18 KB
/
test_decomposition_view.js
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
requirejs([
'jquery',
'underscore',
'model',
'view'
], function($, _, model, DecompositionView) {
$(document).ready(function() {
var DecompositionModel = model.DecompositionModel;
module('Decomposition View', {
setup: function() {
// setup function
var data = {
name: 'pcoa',
sample_ids: ['PC.636', 'PC.635'],
coordinates: [
[-0.276542, -0.144964, 0.066647, -0.067711, 0.176070, 0.072969,
-0.229889, -0.046599],
[-0.237661, 0.046053, -0.138136, 0.159061, -0.247485, -0.115211,
-0.112864, 0.064794]],
percents_explained: [26.6887048633, 16.2563704022, 13.7754129161,
11.217215823, 10.024774995, 8.22835130237,
7.55971173665, 6.24945796136]};
var md_headers = ['SampleID', 'LinkerPrimerSequence', 'Treatment',
'DOB'];
var metadata = [['PC.636', 'YATGCTGCCTCCCGTAGGAGT', 'Control',
'20070314'],
['PC.635', 'YATGCTGCCTCCCGTAGGAGT', 'Fast',
'20071112']];
this.decomp = new DecompositionModel(data, md_headers, metadata);
},
teardown: function() {
// teardown function
this.decomp = null;
}
});
/**
*
* Test that the Decomposition View object is initialized correctly
*
*/
test('Test constructor', function() {
var obs;
var dv = new DecompositionView(this.decomp);
var data = {name: 'pcoa',
sample_ids: ['PC.636', 'PC.635'],
coordinates: [
[-0.276542, -0.144964, 0.066647, -0.067711, 0.176070, 0.072969,
-0.229889, -0.046599],
[-0.237661, 0.046053, -0.138136, 0.159061, -0.247485, -0.115211,
-0.112864, 0.064794]],
percents_explained: [26.6887048633, 16.2563704022,
13.7754129161, 11.217215823,
10.024774995, 8.22835130237,
7.55971173665, 6.24945796136]};
var _md_headers = ['SampleID', 'LinkerPrimerSequence', 'Treatment',
'DOB'];
var _metadata = [
['PC.636', 'YATGCTGCCTCCCGTAGGAGT', 'Control', '20070314'],
['PC.635', 'YATGCTGCCTCCCGTAGGAGT', 'Fast', '20071112']];
var exp = new DecompositionModel(data, _md_headers, _metadata);
deepEqual(dv.decomp, exp, 'decomp set correctly');
equal(dv.count, 2, 'count set correctly');
equal(dv.getVisibleCount(), 2, 'visibleCount set correctly');
deepEqual(dv.visibleDimensions, [0, 1, 2],
'visibleDimensions set correctly');
deepEqual(dv.tubes, [], 'tubes set correctly');
equal(dv.axesColor, '#FFFFFF');
equal(dv.backgroundColor, '#000000');
deepEqual(dv.axesOrientation, [1, 1, 1]);
/*
I'm unsure on how to test this, so right now just testing what I think
makes sense to test
*/
obs = [dv.markers[0].position.x,
dv.markers[0].position.y,
dv.markers[0].position.z];
exp = [-0.276542, -0.144964, 0.066647];
deepEqual(obs, exp, 'First marker position set correctly');
obs = [dv.markers[1].position.x,
dv.markers[1].position.y,
dv.markers[1].position.z];
exp = [-0.237661, 0.046053, -0.138136];
deepEqual(obs, exp, 'Second marker position set correctly');
deepEqual(dv.lines, [], 'lines set correctly');
/*
TODO: How do we test this?
*/
// deepEqual(dv._genericSphere, undefined,
// "_genericSphere set correctly");
});
/**
*
* Test that getVisibleCount is correctly updated
*
*/
test('Test getVisibleCount', function() {
var dv = new DecompositionView(this.decomp);
dv.markers[0].visible = false;
equal(dv.getVisibleCount(), 1);
dv.markers[1].visible = false;
equal(dv.getVisibleCount(), 0);
dv.markers[0].visible = true;
dv.markers[1].visible = true;
equal(dv.getVisibleCount(), 2);
});
/**
*
* Test that changeVisibleDimensions updates the meshes position
*
*/
test('Test changeVisibleDimensions', function() {
var dv = new DecompositionView(this.decomp);
dv.changeVisibleDimensions([2, 3, 4]);
obs = [dv.markers[0].position.x,
dv.markers[0].position.y,
dv.markers[0].position.z];
exp = [0.066647, -0.067711, 0.176070];
deepEqual(obs, exp, 'First marker position updated correctly');
obs = [dv.markers[1].position.x,
dv.markers[1].position.y,
dv.markers[1].position.z];
exp = [-0.138136, 0.159061, -0.247485];
deepEqual(obs, exp, 'Second marker position updated correctly');
deepEqual(dv.axesOrientation, [1, 1, 1]);
});
test('Test changeVisibleDimensions (2D)', function() {
var dv = new DecompositionView(this.decomp);
dv.changeVisibleDimensions([2, 3, null]);
obs = [dv.markers[0].position.x,
dv.markers[0].position.y,
dv.markers[0].position.z];
exp = [0.066647, -0.067711, 0];
deepEqual(obs, exp);
obs = [dv.markers[1].position.x,
dv.markers[1].position.y,
dv.markers[1].position.z];
exp = [-0.138136, 0.159061, 0];
deepEqual(obs, exp);
deepEqual(dv.axesOrientation, [1, 1, 1]);
});
/**
*
* Test the changeVisibleDimensions throws an error if the number of
* dimensions passes is different the 3
*
*/
test('Test changeVisibleDimensions excepts', function() {
throws(
function() {
var dv = new DecompositionView(this.decomp);
dv.changeVisibleDimensions([2, 3, 4, 5]);
},
Error,
'An error is raised if the number of dimensions is not 3'
);
});
/**
*
* Test that changeVisibleDimensions updates the meshes position
*
*/
test('Test change flip axes', function(assert) {
var dv = new DecompositionView(this.decomp);
// copy the arrays
expa = _.clone(dv.markers[0].position.toArray());
expb = _.clone(dv.markers[1].position.toArray());
// flip the orientation of the position
expb[1] = expb[1] * -1;
expa[1] = expa[1] * -1;
// change the position of the decomposition view and ...
dv.flipVisibleDimension(1);
// ... Check for the following things:
//
// 1.- The position themselves
// 2.- The ranges i.e. positions still fall within the dimensionRanges.
// 3.- The axis orientation vector
obs = dv.markers[0].position.toArray();
deepEqual(obs, expa, 'First marker position updated correctly');
assert.ok(obs[1] <= dv.decomp.dimensionRanges.max[1],
'Falls within range (max)');
assert.ok(obs[1] >= dv.decomp.dimensionRanges.min[1],
'Falls within range (min)');
obs = dv.markers[1].position.toArray();
deepEqual(obs, expb, 'Second marker position updated correctly');
assert.ok(obs[1] <= dv.decomp.dimensionRanges.max[1],
'Falls within range (max)');
assert.ok(obs[1] >= dv.decomp.dimensionRanges.min[1],
'Falls within range (min)');
deepEqual(dv.axesOrientation, [1, -1, 1]);
});
test('Test change flip axes (2D)', function(assert) {
var dv = new DecompositionView(this.decomp);
var expa = [-0.276542, 0.144964, 0], expb = [-0.237661, -0.046053, 0];
dv.changeVisibleDimensions([0, 1, null]);
// change the position of the decomposition view and ...
dv.flipVisibleDimension(1);
// ... Check for the following things:
//
// 1.- The position themselves
// 2.- The ranges i.e. positions still fall within the dimensionRanges.
// 3.- The axis orientation vector
obs = dv.markers[0].position.toArray();
deepEqual(obs, expa, 'First marker position updated correctly');
obs = dv.markers[1].position.toArray();
deepEqual(obs, expb, 'Second marker position updated correctly');
deepEqual(dv.axesOrientation, [1, -1, 1]);
});
/**
*
* Test that changeVisibleDimensions and flip axis
*
*/
test('Test changing the orientations and then flipping a dimension',
function() {
var dv = new DecompositionView(this.decomp);
deepEqual(dv.axesOrientation, [1, 1, 1]);
dv.changeVisibleDimensions([2, 3, 4]);
obs = dv.markers[0].position.toArray();
exp = [0.066647, -0.067711, 0.176070];
deepEqual(obs, exp, 'First marker position updated correctly');
obs = dv.markers[1].position.toArray();
exp = [-0.138136, 0.159061, -0.247485];
deepEqual(obs, exp, 'Second marker position updated correctly');
deepEqual(dv.axesOrientation, [1, 1, 1]);
dv.flipVisibleDimension(3);
obs = dv.markers[0].position.toArray();
exp = [0.066647, 0.067711, 0.176070];
deepEqual(obs, exp, 'First marker position updated correctly');
obs = dv.markers[1].position.toArray();
exp = [-0.138136, -0.159061, -0.247485];
deepEqual(obs, exp, 'Second marker position updated correctly');
deepEqual(dv.axesOrientation, [1, -1, 1]);
});
});
});