diff --git a/src/main/data/feature.js b/src/main/data/feature.js index 55f90605..04b72bea 100644 --- a/src/main/data/feature.js +++ b/src/main/data/feature.js @@ -18,8 +18,8 @@ class Feature { this.id = feature.id; this.featureType = feature.featureType; this.contig = feature.contig; - this.start = feature.start; - this.stop = feature.stop; + this.start = parseInt(feature.start); + this.stop = parseInt(feature.stop); this.score = feature.score; } @@ -29,8 +29,8 @@ class Feature { id: ga4ghFeature.id, featureType: ga4ghFeature.featureType, contig: ga4ghFeature.referenceName, - start: ga4ghFeature.start, - stop: ga4ghFeature.end, + start: parseInt(ga4ghFeature.start), + stop: parseInt(ga4ghFeature.end), score: 1000 }); } diff --git a/src/main/data/variant.js b/src/main/data/variant.js index f0a47c88..c8177af6 100644 --- a/src/main/data/variant.js +++ b/src/main/data/variant.js @@ -23,7 +23,7 @@ class Variant { constructor(variant: Object) { this.contig = variant.contig; - this.position = variant.position; + this.position = parseInt(variant.position); this.ref = variant.ref; this.alt = variant.alt; this.id = variant.id; @@ -36,7 +36,7 @@ class Variant { return new Variant( { contig: ga4ghVariant.referenceName, - position: ga4ghVariant.start, + position: parseInt(ga4ghVariant.start), id: ga4ghVariant.id, ref: ga4ghVariant.referenceBases, alt: ga4ghVariant.alternateBases, diff --git a/src/main/json/GA4GHVariantJson.js b/src/main/json/GA4GHVariantJson.js index 400485ea..b93519f6 100644 --- a/src/main/json/GA4GHVariantJson.js +++ b/src/main/json/GA4GHVariantJson.js @@ -21,7 +21,7 @@ function create(json: string): VcfDataSource { // fill variants with json if (!_.isEmpty(parsedJson)) { - variants = _.values(parsedJson.variants).map(feature => Variant.fromGA4GH(feature)); + variants = _.values(parsedJson.variants).map(variant => Variant.fromGA4GH(variant)); } function rangeChanged(newRange: GenomeRange) { diff --git a/src/test/data/feature-test.js b/src/test/data/feature-test.js new file mode 100644 index 00000000..f1e9295e --- /dev/null +++ b/src/test/data/feature-test.js @@ -0,0 +1,32 @@ +/* @flow */ +'use strict'; + +import {expect} from 'chai'; +import Feature from '../../main/data/feature'; +import _ from 'underscore'; +import RemoteFile from '../../main/RemoteFile'; + +describe('Feature', function() { + var json; + + before(function () { + return new RemoteFile('/test-data/features.ga4gh.chr1.120000-125000.json').getAllString().then(data => { + json = data; + }); + }); + + it('should parse features from GA4GH', function(done) { + + // parse json + var parsedJson = JSON.parse(json); + var features = _.values(parsedJson.features).map(feature => Feature.fromGA4GH(feature)); + + expect(features).to.have.length(9); + expect(features[0].contig).to.equal("chr1"); + expect(features[0].start).to.equal(89295); + expect(features[0].stop).to.equal(120932); + expect(features[0].id).to.equal("WyIxa2dlbm9tZXMiLCJnZW5jb2RlX3YyNGxpZnQzNyIsIjE0MDUwOTE3MjM1NDE5MiJd"); + expect(features[0].score).to.equal(1000); + done(); + }); +}); diff --git a/src/test/data/variant-test.js b/src/test/data/variant-test.js new file mode 100644 index 00000000..a09c302f --- /dev/null +++ b/src/test/data/variant-test.js @@ -0,0 +1,31 @@ +/* @flow */ +'use strict'; + +import {expect} from 'chai'; +import {Variant} from '../../main/data/variant'; +import _ from 'underscore'; +import RemoteFile from '../../main/RemoteFile'; + +describe('Variant', function() { + var json; + + before(function () { + return new RemoteFile('/test-data/variants.ga4gh.chr1.10000-11000.json').getAllString().then(data => { + json = data; + }); + }); + + it('should parse variants from GA4GH', function(done) { + + // parse json + var parsedJson = JSON.parse(json); + var variants = _.values(parsedJson.variants).map(variant => Variant.fromGA4GH(variant)); + + expect(variants).to.have.length(11); + expect(variants[0].contig).to.equal("1"); + expect(variants[0].position).to.equal(10176); + expect(variants[0].ref).to.equal("A"); + expect(variants[0].alt[0]).to.equal("AC"); + done(); + }); +}); diff --git a/src/test/viz/FeatureTrack-test.js b/src/test/viz/FeatureTrack-test.js index c510b2db..319fc2b5 100644 --- a/src/test/viz/FeatureTrack-test.js +++ b/src/test/viz/FeatureTrack-test.js @@ -72,7 +72,7 @@ describe('FeatureTrack', function() { expect(features).to.have.length(4); expect(features.map(f => f.start)).to.deep.equal( - ["89295", "92230", "110953", "120725"]); + [89295, 92230, 110953, 120725]); p.destroy(); }); }); diff --git a/src/test/viz/VariantTrack.js b/src/test/viz/VariantTrack-test.js similarity index 100% rename from src/test/viz/VariantTrack.js rename to src/test/viz/VariantTrack-test.js