Skip to content

Commit 82bca1b

Browse files
author
akmorrow13
authored
Merge pull request #488 from akmorrow13/null_genes
fixed null gene name
2 parents e8817ec + fd7395c commit 82bca1b

File tree

5 files changed

+81
-77
lines changed

5 files changed

+81
-77
lines changed

src/main/sources/BigBedDataSource.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ function createFromBigBedFile(remoteSource: BigBed): BigBedSource {
126126
coveredRanges = ContigInterval.coalesce(coveredRanges);
127127
var genes = fb.rows.map(parseBedFeature);
128128
genes.forEach(gene => addGene(gene));
129-
//we have new data from our internal block range
130-
o.trigger('newdata', fb.range);
131129
});
130+
//we have new data from our internal block range
131+
o.trigger('newdata', interval);
132+
o.trigger('networkdone');
132133
});
133134
}
134135

src/main/utils.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ function computePercentile(xs: number[], percentile: number): number {
273273
}
274274
}
275275

276+
/**
277+
* Converts a string into a null, NaN, undefined, Inf or -Inf. Returns
278+
* original string if string is not a special case.
279+
* Returns string parsed to special case (null, NaN, undefined, Inf or -Inf)
280+
* or original string.
281+
*/
282+
function stringToLiteral(value: string): any {
283+
var maps = {
284+
"NaN": NaN,
285+
"null": null,
286+
"undefined": undefined,
287+
"Infinity": Infinity,
288+
"-Infinity": -Infinity
289+
};
290+
return ((value in maps) ? maps[value] : value);
291+
}
292+
276293
module.exports = {
277294
tupleLessOrEqual,
278295
tupleRangeOverlaps,
@@ -286,5 +303,6 @@ module.exports = {
286303
formatInterval,
287304
isChrMatch,
288305
flatMap,
289-
computePercentile
306+
computePercentile,
307+
stringToLiteral
290308
};

src/main/viz/GeneTrack.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import d3utils from './d3utils';
2424
import scale from '../scale';
2525
import ContigInterval from '../ContigInterval';
2626
import canvasUtils from './canvas-utils';
27+
import utils from '../utils';
2728
import dataCanvas from 'data-canvas';
2829
import style from '../style';
2930

@@ -61,7 +62,8 @@ function drawGeneName(ctx: CanvasRenderingContext2D,
6162
textIntervals: Interval[]) {
6263
var p = gene.position,
6364
centerX = 0.5 * (clampedScale(1 + p.start()) + clampedScale(1 + p.stop()));
64-
var name = gene.name || gene.id;
65+
// do not use gene name if it is null or empty
66+
var name = !_.isEmpty(utils.stringToLiteral(gene.name)) ? gene.name : gene.id;
6567
var textWidth = ctx.measureText(name).width;
6668
var textInterval = new Interval(centerX - 0.5 * textWidth,
6769
centerX + 0.5 * textWidth);
@@ -79,6 +81,9 @@ class GeneTrack extends React.Component<VizProps<BigBedSource>, State> {
7981

8082
constructor(props: VizProps<BigBedSource>) {
8183
super(props);
84+
this.state = {
85+
networkStatus: null
86+
};
8287
}
8388

8489
render(): any {

src/test/viz/FeatureTrack-test.js

Lines changed: 20 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ describe('FeatureTrack', function() {
120120
});
121121

122122
it('should render features with bigBed file', function(): any {
123-
var featureClickedData = null;
124-
var featureClicked = function(data) {
125-
featureClickedData = data;
126-
};
127123

128124
var p = pileup.create(testDiv, {
129125
range: {contig: 'chr17', start: 10000, stop: 16500},
@@ -140,91 +136,42 @@ describe('FeatureTrack', function() {
140136
data: pileup.formats.bigBed({
141137
url: '/test-data/chr17.22.10000-21000.bb',
142138
}),
143-
options: {onFeatureClicked: featureClicked},
144139
name: 'Features'
145140
}
146141
]
147142
});
148143

149144

150-
return waitFor(ready, 2000)
151-
.then(() => {
145+
return waitFor(ready, 2000).then(() => {
152146
var features = drawnObjects(testDiv, '.features');
153147
// there can be duplicates in the case where features are
154148
// overlapping more than one section of the canvas
155149
features = _.uniq(features, false, function(x) {
156150
return x.position.start();
157151
});
158152

159-
expect(features).to.have.length(5);
160-
expect(features.map(f => f.position.start())).to.deep.equal(
161-
[10000, 10150, 10400, 16000, 16180]);
162-
163-
// canvas height should be height of features that are overlapping
164-
var height = yForRow(2) * window.devicePixelRatio; // should be 2 rows
165-
166-
features = testDiv.querySelector('.features');
167-
expect(features).to.not.be.null;
168-
if (features != null) {
169-
expect(features.style.height).to.equal(`${height}px`);
170-
}
171-
// check clicking on feature in row 0
172-
var canvasList = testDiv.getElementsByTagName('canvas');
173-
var canvas = canvasList[1];
174-
expect(featureClickedData).to.be.null;
175-
ReactTestUtils.Simulate.click(canvas,{nativeEvent: {offsetX: 0, offsetY: 10}});
176-
expect(featureClickedData).to.not.be.null;
177-
178-
// check clicking on feature in row 1
179-
featureClickedData = null;
180-
ReactTestUtils.Simulate.click(canvas,{nativeEvent: {offsetX: 55, offsetY: 10}});
181-
expect(featureClickedData).to.not.be.null;
182-
183-
p.destroy();
153+
expect(features).to.have.length.at.least(2);
154+
155+
p.setRange({contig: 'chr22', start: 20000, stop: 21000});
156+
}).delay(300).then(() => {
157+
var features = drawnObjects(testDiv, '.features');
158+
// there can be duplicates in the case where features are
159+
// overlapping more than one section of the canvas
160+
features = _.uniq(features, false, function(x) {
161+
return x.position.start();
184162
});
185-
});
186-
187-
it('should not exceed parent height limits', function(): any {
188-
var p = pileup.create(testDiv, {
189-
range: {contig: 'chr22', start: 20000, stop: 21000},
190-
tracks: [
191-
{
192-
viz: pileup.viz.genome(),
193-
data: pileup.formats.twoBit({
194-
url: '/test-data/test.2bit'
195-
}),
196-
isReference: true
197-
},
198-
{
199-
viz: pileup.viz.features(),
200-
data: pileup.formats.bigBed({
201-
url: '/test-data/chr17.22.10000-21000.bb',
202-
}),
203-
name: 'Features'
204-
}
205-
]
206-
});
207-
208-
return waitFor(ready, 2000)
209-
.then(() => {
210-
var features = drawnObjects(testDiv, '.features');
211-
// there can be duplicates in the case where features are
212-
// overlapping more than one section of the canvas
213-
features = _.uniq(features, false, function(x) {
214-
return x.position.start();
215-
});
216163

217-
expect(features).to.have.length(10);
164+
expect(features).to.have.length(10);
218165

219-
// canvas height should be maxed out
220-
var expectedHeight = 150 * window.devicePixelRatio;
221-
var featureCanvas = testDiv.querySelector('.features');
222-
expect(featureCanvas).to.not.be.null;
223-
if (featureCanvas != null) {
224-
expect(featureCanvas.style.height).to.equal(`${expectedHeight}px`);
225-
}
226-
p.destroy();
227-
});
166+
// canvas height should be maxed out, should not exceed parent height limits
167+
var expectedHeight = 150 * window.devicePixelRatio;
168+
var featureCanvas = testDiv.querySelector('.features');
169+
expect(featureCanvas).to.not.be.null;
170+
if (featureCanvas != null) {
171+
expect(featureCanvas.style.height).to.equal(`${expectedHeight}px`);
172+
}
173+
p.destroy();
174+
});
228175
});
229176
});
230177
});

src/test/viz/GeneTrack-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,37 @@ describe('GeneTrack', function() {
6868
});
6969
});
7070

71+
it('should not print null gene name', function(): any {
72+
var p = pileup.create(testDiv, {
73+
range: {contig: '17', start: 1156459, stop: 1156529},
74+
tracks: [
75+
{
76+
viz: pileup.viz.genome(),
77+
data: pileup.formats.twoBit({
78+
url: '/test-data/test.2bit'
79+
}),
80+
isReference: true
81+
},
82+
{
83+
data: pileup.formats.bigBed({
84+
url: '/test-data/ensembl.chr17.bb'
85+
}),
86+
viz: pileup.viz.genes(),
87+
}
88+
]
89+
});
90+
91+
return waitFor(ready, 2000)
92+
.then(() => {
93+
var genes = drawnObjects(testDiv, '.genes');
94+
expect(genes).to.have.length(1);
95+
expect(genes.map(g => g.name)).to.deep.equal(
96+
[ 'null']); // null gene name
97+
98+
// Do not draw null gene name. Default to gene id.
99+
var texts = callsOf(testDiv, '.genes', 'fillText');
100+
expect(texts.map(t => t[1])).to.deep.equal(['ENST00000386721']);
101+
p.destroy();
102+
});
103+
});
71104
});

0 commit comments

Comments
 (0)