From fb298592de70a759f561bdcbd2a081d036d4a4cd Mon Sep 17 00:00:00 2001 From: Alyssa Morrow Date: Thu, 20 Jun 2019 19:31:07 -0700 Subject: [PATCH] Variant json works when length is 0 --- src/main/json/GA4GHVariantJson.js | 4 +++- src/test/json/GA4GHVariantJson-test.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/json/GA4GHVariantJson.js b/src/main/json/GA4GHVariantJson.js index 1ac736f8..d2763b07 100644 --- a/src/main/json/GA4GHVariantJson.js +++ b/src/main/json/GA4GHVariantJson.js @@ -24,7 +24,9 @@ function create(json: string): VcfDataSource { // fill variants with json if (!_.isEmpty(parsedJson)) { variants = _.values(parsedJson.variants).map(variant => new VariantContext(Variant.fromGA4GH(variant),variant.calls)); - callSetNames = _.map(variants[0].calls, c => c.callSetName); + if (variants.length > 0) { // only call variants if non-empty + callSetNames = _.map(variants[0].calls, c => c.callSetName); + } } function rangeChanged(newRange: GenomeRange) { diff --git a/src/test/json/GA4GHVariantJson-test.js b/src/test/json/GA4GHVariantJson-test.js index c211033b..d18cb275 100644 --- a/src/test/json/GA4GHVariantJson-test.js +++ b/src/test/json/GA4GHVariantJson-test.js @@ -17,7 +17,7 @@ describe('GA4GHVariantJson', function() { }); it('should filter variants from json', function(done) { - + var source = GA4GHVariantJson.create(json); var requestInterval = new ContigInterval('1', 10000, 10500); @@ -62,4 +62,16 @@ describe('GA4GHVariantJson', function() { }); + it('should not fail when there are no variants', function(done) { + + var source = GA4GHVariantJson.create("{\"variants\": []}"); + + var requestInterval = new ContigInterval('1', 10, 20); + + var variants = source.getVariantsInRange(requestInterval); + expect(variants).to.have.length(0); + done(); + + }); + });