From 7a10b6304a4f9b1da1da747edde187a914c88039 Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 13:16:19 -0400 Subject: [PATCH 1/9] patched elasticsearch repo (must/match maps): - reference/alternative queries --- src/api/repositories/elasticsearch/main.go | 92 ++++++++++++++-------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/src/api/repositories/elasticsearch/main.go b/src/api/repositories/elasticsearch/main.go index c5ef287f..417474ea 100644 --- a/src/api/repositories/elasticsearch/main.go +++ b/src/api/repositories/elasticsearch/main.go @@ -35,30 +35,45 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli // 'complexifying' the query // TODO: refactor common code between 'Get' and 'Count'-DocumentsContainerVariantOrSampleIdInPositionRange - matchMap := make(map[string]interface{}) - if variantId != "" { - matchMap["id"] = map[string]interface{}{ - "query": variantId, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "id": map[string]interface{}{ + "query": variantId, + }, + }, + }) + } if sampleId != "" { - matchMap["samples.id"] = map[string]interface{}{ - "query": sampleId, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "samples.id": map[string]interface{}{ + "query": sampleId, + }, + }, + }) } if alternative != "" { - matchMap["alt"] = map[string]interface{}{ - "query": alternative, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "alt": map[string]interface{}{ + "query": alternative, + }, + }, + }) } if reference != "" { - matchMap["ref"] = map[string]interface{}{ - "query": reference, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "ref": map[string]interface{}{ + "query": reference, + }, + }, + }) } if assemblyId != "" { @@ -135,13 +150,6 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli }) } - // append the match components to the must map - if len(matchMap) > 0 { - mustMap = append(mustMap, map[string]interface{}{ - "match": matchMap, - }) - } - // individually append each range components to the must map if len(rangeMapSlice) > 0 { for _, rms := range rangeMapSlice { @@ -253,27 +261,44 @@ func CountDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.C matchMap := make(map[string]interface{}) if variantId != "" { - matchMap["id"] = map[string]interface{}{ - "query": variantId, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "id": map[string]interface{}{ + "query": variantId, + }, + }, + }) + } if sampleId != "" { - matchMap["samples.id"] = map[string]interface{}{ - "query": sampleId, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "samples.id": map[string]interface{}{ + "query": sampleId, + }, + }, + }) } if alternative != "" { - matchMap["alt"] = map[string]interface{}{ - "query": alternative, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "alt": map[string]interface{}{ + "query": alternative, + }, + }, + }) } if reference != "" { - matchMap["ref"] = map[string]interface{}{ - "query": reference, - } + mustMap = append(mustMap, map[string]interface{}{ + "match": map[string]interface{}{ + "ref": map[string]interface{}{ + "query": reference, + }, + }, + }) } if assemblyId != "" { @@ -285,6 +310,7 @@ func CountDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.C }, }) } + rangeMapSlice := []map[string]interface{}{} // TODO: make upperbound and lowerbound nilable, somehow? From 936c5b209f1018983e833dbf177238d517a1d7e2 Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 14:00:01 -0400 Subject: [PATCH 2/9] reference query testing --- src/tests/integration/api/api_test.go | 127 ++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 10 deletions(-) diff --git a/src/tests/integration/api/api_test.go b/src/tests/integration/api/api_test.go index 113d81aa..af0db793 100644 --- a/src/tests/integration/api/api_test.go +++ b/src/tests/integration/api/api_test.go @@ -90,7 +90,7 @@ func TestGetIngestionRequests(t *testing.T) { func TestCanGetVariantsWithoutSamplesInResultset(t *testing.T) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Undefined, string(gq.UNCALLED)) + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Undefined, string(gq.UNCALLED), "") // assert that all responses from all combinations have no results for _, dtoResponse := range allDtoResponses { @@ -101,7 +101,7 @@ func TestCanGetVariantsWithoutSamplesInResultset(t *testing.T) { func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, true, s.Undefined, string(gq.UNCALLED)) + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, true, s.Undefined, string(gq.UNCALLED), "") // assert that all of the responses include valid sample sets // - * accumulate all samples into a single list using the set of @@ -124,7 +124,7 @@ func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { func TestCanGetVariantsInAscendingPositionOrder(t *testing.T) { // retrieve responses in ascending order - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Ascending, string(gq.UNCALLED)) + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Ascending, string(gq.UNCALLED), "") // assert the dto response slice is plentiful assert.NotNil(t, allDtoResponses) @@ -153,7 +153,7 @@ func TestCanGetVariantsInAscendingPositionOrder(t *testing.T) { func TestCanGetVariantsInDescendingPositionOrder(t *testing.T) { // retrieve responses in descending order - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Descending, string(gq.UNCALLED)) + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Descending, string(gq.UNCALLED), "") // assert the dto response slice is plentiful assert.NotNil(t, allDtoResponses) @@ -213,10 +213,105 @@ func TestCanGetHomozygousAlternateSamples(t *testing.T) { runAndValidateGenotypeQueryResults(t, gq.HOMOZYGOUS_ALTERNATE, specificValidation) } +func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { + + specificValidation := func(__t *testing.T, variant models.Variant, allelePattern string) { + assert.Contains(__t, variant.Ref, allelePattern) + + for _, sample := range variant.Samples { + assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) + assert.True(__t, + sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && + sample.Variation.Genotype.AlleleLeft > 0) + } + } + + patterns := []string{"A", "C", "T", "G"} + var patWg sync.WaitGroup + for _, pat := range patterns { + patWg.Add(1) + go func(_pat string, _patWg *sync.WaitGroup) { + defer _patWg.Done() + runAndValidateReferenceQueryResults(t, gq.HOMOZYGOUS_ALTERNATE, _pat, specificValidation) + }(pat, &patWg) + } + patWg.Wait() +} + +func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { + + specificValidation := func(__t *testing.T, variant models.Variant, allelePattern string) { + assert.Contains(__t, variant.Ref, allelePattern) + + for _, sample := range variant.Samples { + assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) + assert.True(__t, + sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && + sample.Variation.Genotype.AlleleLeft == 0) + } + } + + patterns := []string{"A", "C", "T", "G"} + var patWg sync.WaitGroup + for _, pat := range patterns { + patWg.Add(1) + go func(_pat string, _patWg *sync.WaitGroup) { + defer _patWg.Done() + runAndValidateReferenceQueryResults(t, gq.HOMOZYGOUS_REFERENCE, _pat, specificValidation) + }(pat, &patWg) + } + patWg.Wait() +} + +func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { + + specificValidation := func(__t *testing.T, variant models.Variant, allelePattern string) { + assert.Contains(__t, variant.Ref, allelePattern) + + for _, sample := range variant.Samples { + assert.True(t, sample.Variation.Genotype.Zygosity == z.Heterozygous) + assert.True(t, sample.Variation.Genotype.AlleleLeft != sample.Variation.Genotype.AlleleRight) + } + } + + patterns := []string{"A", "C", "T", "G"} + var patWg sync.WaitGroup + for _, pat := range patterns { + patWg.Add(1) + go func(_pat string, _patWg *sync.WaitGroup) { + defer _patWg.Done() + runAndValidateReferenceQueryResults(t, gq.HETEROZYGOUS, _pat, specificValidation) + }(pat, &patWg) + } + patWg.Wait() +} + // -- Common utility functions for api tests +func runAndValidateReferenceQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, allelePattern string, specificValidation func(__t *testing.T, variant models.Variant, allelePattern string)) { + + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), allelePattern) + + // assert that all of the responses include heterozygous sample sets + // - * accumulate all variants into a single list using the set of + // SelectManyT's and the SelectT + // - ** iterate over each variant in the ForEachT + + From(allDtoResponses).SelectManyT(func(resp models.VariantsResponseDTO) Query { // * + return From(resp.Data) + }).SelectManyT(func(data models.VariantResponseDataModel) Query { + return From(data.Results) + }).SelectT(func(variant models.Variant) models.Variant { + return variant + }).ForEachT(func(variant models.Variant) { // ** + assert.NotNil(_t, variant.Id) + + specificValidation(_t, variant, allelePattern) + }) +} + func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, specificValidation func(__t *testing.T, sample models.Sample)) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery)) + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), "") // assert that all of the responses include heterozygous sample sets // - * accumulate all samples into a single list using the set of @@ -241,9 +336,9 @@ func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQ }) } -func buildQueryAndMakeGetVariantsCall(chromosome string, sampleId string, includeSamples bool, sortByPosition c.SortDirection, genotype string, assemblyId c.AssemblyId, _t *testing.T, _cfg *models.Config) models.VariantsResponseDTO { +func buildQueryAndMakeGetVariantsCall(chromosome string, sampleId string, includeSamples bool, sortByPosition c.SortDirection, genotype string, assemblyId c.AssemblyId, referenceAllelePattern string, _t *testing.T, _cfg *models.Config) models.VariantsResponseDTO { - queryString := fmt.Sprintf("?chromosome=%s&ids=%s&includeSamplesInResultSet=%t&sortByPosition=%s&genotype=%s&assemblyId=%s", chromosome, sampleId, includeSamples, sortByPosition, genotype, assemblyId) + queryString := fmt.Sprintf("?chromosome=%s&ids=%s&includeSamplesInResultSet=%t&sortByPosition=%s&genotype=%s&assemblyId=%s&reference=%s", chromosome, sampleId, includeSamples, sortByPosition, genotype, assemblyId, referenceAllelePattern) url := fmt.Sprintf(VariantsGetBySampleIdsPathWithQueryString, _cfg.Api.Url, queryString) return makeGetVariantsCall(url, _t) @@ -304,15 +399,22 @@ func getOverviewResultCombinations(chromosomeStruct interface{}, sampleIdsStruct return allCombinations } -func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, includeSamples bool, sortByPosition c.SortDirection, genotype string) []models.VariantsResponseDTO { +func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, includeSamples bool, sortByPosition c.SortDirection, genotype string, referenceAllelePattern string) []models.VariantsResponseDTO { cfg := common.InitConfig() - // todo: deduplicate + // retrieve the overview overviewJson := getVariantsOverview(_t, cfg) + + // ensure the response is valid + // TODO: error check instead of nil check assert.NotNil(_t, overviewJson) + // generate all possible combinations of + // available samples, assemblys, and chromosomes overviewCombinations := getOverviewResultCombinations(overviewJson["chromosomes"], overviewJson["sampleIDs"], overviewJson["assemblyIDs"]) + // initialize a common slice in which to + // accumulate al responses asynchronously allDtoResponses := []models.VariantsResponseDTO{} allDtoResponsesMux := sync.RWMutex{} @@ -326,9 +428,14 @@ func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, inc sampleId := _combination[1] assemblyId := a.CastToAssemblyId(_combination[2]) - dto := buildQueryAndMakeGetVariantsCall(chrom, sampleId, includeSamples, sortByPosition, genotype, assemblyId, _t, cfg) + // make the call + dto := buildQueryAndMakeGetVariantsCall(chrom, sampleId, includeSamples, sortByPosition, genotype, assemblyId, referenceAllelePattern, _t, cfg) + assert.Equal(_t, 1, len(dto.Data)) + // accumulate all response objects + // to a common slice in an + // asynchronous-safe manner allDtoResponsesMux.Lock() allDtoResponses = append(allDtoResponses, dto) allDtoResponsesMux.Unlock() From 542101e268179b449fed23c0c2d27e82bf2a39c9 Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 15:45:01 -0400 Subject: [PATCH 3/9] refactored reference query tests --- src/tests/integration/api/api_test.go | 34 +++++++++------------------ 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/tests/integration/api/api_test.go b/src/tests/integration/api/api_test.go index af0db793..fd0c47af 100644 --- a/src/tests/integration/api/api_test.go +++ b/src/tests/integration/api/api_test.go @@ -226,16 +226,7 @@ func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { } } - patterns := []string{"A", "C", "T", "G"} - var patWg sync.WaitGroup - for _, pat := range patterns { - patWg.Add(1) - go func(_pat string, _patWg *sync.WaitGroup) { - defer _patWg.Done() - runAndValidateReferenceQueryResults(t, gq.HOMOZYGOUS_ALTERNATE, _pat, specificValidation) - }(pat, &patWg) - } - patWg.Wait() + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_ALTERNATE, specificValidation) } func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { @@ -251,16 +242,7 @@ func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { } } - patterns := []string{"A", "C", "T", "G"} - var patWg sync.WaitGroup - for _, pat := range patterns { - patWg.Add(1) - go func(_pat string, _patWg *sync.WaitGroup) { - defer _patWg.Done() - runAndValidateReferenceQueryResults(t, gq.HOMOZYGOUS_REFERENCE, _pat, specificValidation) - }(pat, &patWg) - } - patWg.Wait() + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_REFERENCE, specificValidation) } func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { @@ -274,20 +256,26 @@ func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { } } + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HETEROZYGOUS, specificValidation) +} + +// -- Common utility functions for api tests +func executeReferenceOrAlternativeQueryTestsOfVariousPatterns(_t *testing.T, genotypeQuery c.GenotypeQuery, specificValidation func(__t *testing.T, variant models.Variant, allelePattern string)) { + + // TODO: use some kind of Allele Enum patterns := []string{"A", "C", "T", "G"} var patWg sync.WaitGroup for _, pat := range patterns { patWg.Add(1) go func(_pat string, _patWg *sync.WaitGroup) { defer _patWg.Done() - runAndValidateReferenceQueryResults(t, gq.HETEROZYGOUS, _pat, specificValidation) + runAndValidateReferenceOrAlternativeQueryResults(_t, genotypeQuery, _pat, specificValidation) }(pat, &patWg) } patWg.Wait() } -// -- Common utility functions for api tests -func runAndValidateReferenceQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, allelePattern string, specificValidation func(__t *testing.T, variant models.Variant, allelePattern string)) { +func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, allelePattern string, specificValidation func(__t *testing.T, variant models.Variant, allelePattern string)) { allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), allelePattern) From 1d838f14053d5b44a49b1aa1546445ba00a900e6 Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 16:35:14 -0400 Subject: [PATCH 4/9] - refactoring - added alternative allele query tests --- src/tests/common/constants/main.go | 10 ++ .../referenceAlternativeTestType/main.go | 12 ++ src/tests/integration/api/api_test.go | 151 ++++++++++++++---- 3 files changed, 142 insertions(+), 31 deletions(-) create mode 100644 src/tests/common/constants/main.go create mode 100644 src/tests/common/constants/referenceAlternativeTestType/main.go diff --git a/src/tests/common/constants/main.go b/src/tests/common/constants/main.go new file mode 100644 index 00000000..6cd0f551 --- /dev/null +++ b/src/tests/common/constants/main.go @@ -0,0 +1,10 @@ +package constants + +/* + Defines a set of base level + constants and enums to be used + throughout Gohan tests. +*/ +type TestType int + +type ReferenceAlternativeTestType TestType diff --git a/src/tests/common/constants/referenceAlternativeTestType/main.go b/src/tests/common/constants/referenceAlternativeTestType/main.go new file mode 100644 index 00000000..42c44234 --- /dev/null +++ b/src/tests/common/constants/referenceAlternativeTestType/main.go @@ -0,0 +1,12 @@ +package referenceAlternativeTestType + +import ( + "tests/common/constants" +) + +const ( + Neither constants.ReferenceAlternativeTestType = iota + Reference + Alternative + Both +) diff --git a/src/tests/integration/api/api_test.go b/src/tests/integration/api/api_test.go index fd0c47af..c706ecf7 100644 --- a/src/tests/integration/api/api_test.go +++ b/src/tests/integration/api/api_test.go @@ -14,6 +14,8 @@ import ( "sync" "testing" common "tests/common" + testConsts "tests/common/constants" + ratt "tests/common/constants/referenceAlternativeTestType" . "github.com/ahmetb/go-linq" @@ -90,7 +92,7 @@ func TestGetIngestionRequests(t *testing.T) { func TestCanGetVariantsWithoutSamplesInResultset(t *testing.T) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Undefined, string(gq.UNCALLED), "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Undefined, string(gq.UNCALLED), "", "") // assert that all responses from all combinations have no results for _, dtoResponse := range allDtoResponses { @@ -101,7 +103,7 @@ func TestCanGetVariantsWithoutSamplesInResultset(t *testing.T) { func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, true, s.Undefined, string(gq.UNCALLED), "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, true, s.Undefined, string(gq.UNCALLED), "", "") // assert that all of the responses include valid sample sets // - * accumulate all samples into a single list using the set of @@ -124,7 +126,7 @@ func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { func TestCanGetVariantsInAscendingPositionOrder(t *testing.T) { // retrieve responses in ascending order - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Ascending, string(gq.UNCALLED), "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Ascending, string(gq.UNCALLED), "", "") // assert the dto response slice is plentiful assert.NotNil(t, allDtoResponses) @@ -153,7 +155,7 @@ func TestCanGetVariantsInAscendingPositionOrder(t *testing.T) { func TestCanGetVariantsInDescendingPositionOrder(t *testing.T) { // retrieve responses in descending order - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Descending, string(gq.UNCALLED), "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Descending, string(gq.UNCALLED), "", "") // assert the dto response slice is plentiful assert.NotNil(t, allDtoResponses) @@ -215,8 +217,12 @@ func TestCanGetHomozygousAlternateSamples(t *testing.T) { func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { - specificValidation := func(__t *testing.T, variant models.Variant, allelePattern string) { - assert.Contains(__t, variant.Ref, allelePattern) + specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + // ensure test is formatted correctly + assert.True(__t, alternativeAllelePattern == "") + + // validate variant + assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) @@ -226,13 +232,17 @@ func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { } } - executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_ALTERNATE, specificValidation) + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_ALTERNATE, ratt.Reference, specificValidation) } func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { - specificValidation := func(__t *testing.T, variant models.Variant, allelePattern string) { - assert.Contains(__t, variant.Ref, allelePattern) + specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + // ensure test is formatted correctly + assert.True(__t, alternativeAllelePattern == "") + + // validate variant + assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) @@ -242,13 +252,75 @@ func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { } } - executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_REFERENCE, specificValidation) + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_REFERENCE, ratt.Reference, specificValidation) } func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { - specificValidation := func(__t *testing.T, variant models.Variant, allelePattern string) { - assert.Contains(__t, variant.Ref, allelePattern) + specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + // ensure test is formatted correctly + assert.True(__t, alternativeAllelePattern == "") + + // validate variant + assert.Contains(__t, variant.Ref, referenceAllelePattern) + + for _, sample := range variant.Samples { + assert.True(t, sample.Variation.Genotype.Zygosity == z.Heterozygous) + assert.True(t, sample.Variation.Genotype.AlleleLeft != sample.Variation.Genotype.AlleleRight) + } + } + + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HETEROZYGOUS, ratt.Reference, specificValidation) +} + +func TestCanGetHomozygousAlternateVariantsWithVariousAlternatives(t *testing.T) { + + specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + // ensure test is formatted correctly + assert.True(__t, referenceAllelePattern == "") + + // validate variant + assert.Contains(__t, variant.Alt, alternativeAllelePattern) + + for _, sample := range variant.Samples { + assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) + assert.True(__t, + sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && + sample.Variation.Genotype.AlleleLeft > 0) + } + } + + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_ALTERNATE, ratt.Alternative, specificValidation) +} + +func TestCanGetHomozygousReferenceVariantsWithVariousAlternatives(t *testing.T) { + + specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + // ensure test is formatted correctly + assert.True(__t, referenceAllelePattern == "") + + // validate variant + assert.Contains(__t, variant.Alt, alternativeAllelePattern) + + for _, sample := range variant.Samples { + assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) + assert.True(__t, + sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && + sample.Variation.Genotype.AlleleLeft == 0) + } + } + + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_REFERENCE, ratt.Alternative, specificValidation) +} + +func TestCanGetHeterozygousVariantsWithVariousAlternatives(t *testing.T) { + + specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + // ensure test is formatted correctly + assert.True(__t, referenceAllelePattern == "") + + // validate variant + assert.Contains(__t, variant.Alt, alternativeAllelePattern) for _, sample := range variant.Samples { assert.True(t, sample.Variation.Genotype.Zygosity == z.Heterozygous) @@ -256,11 +328,13 @@ func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { } } - executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HETEROZYGOUS, specificValidation) + executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HETEROZYGOUS, ratt.Alternative, specificValidation) } // -- Common utility functions for api tests -func executeReferenceOrAlternativeQueryTestsOfVariousPatterns(_t *testing.T, genotypeQuery c.GenotypeQuery, specificValidation func(__t *testing.T, variant models.Variant, allelePattern string)) { +func executeReferenceOrAlternativeQueryTestsOfVariousPatterns(_t *testing.T, + genotypeQuery c.GenotypeQuery, refAltTestType testConsts.ReferenceAlternativeTestType, + specificValidation func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string)) { // TODO: use some kind of Allele Enum patterns := []string{"A", "C", "T", "G"} @@ -269,21 +343,31 @@ func executeReferenceOrAlternativeQueryTestsOfVariousPatterns(_t *testing.T, gen patWg.Add(1) go func(_pat string, _patWg *sync.WaitGroup) { defer _patWg.Done() - runAndValidateReferenceOrAlternativeQueryResults(_t, genotypeQuery, _pat, specificValidation) + + switch refAltTestType { + case ratt.Reference: + runAndValidateReferenceOrAlternativeQueryResults(_t, genotypeQuery, _pat, "", specificValidation) + case ratt.Alternative: + runAndValidateReferenceOrAlternativeQueryResults(_t, genotypeQuery, "", _pat, specificValidation) + default: + println("Skipping Test -- no Ref/Alt Test Type provided") + } + }(pat, &patWg) } patWg.Wait() } -func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, allelePattern string, specificValidation func(__t *testing.T, variant models.Variant, allelePattern string)) { +func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, + genotypeQuery c.GenotypeQuery, + referenceAllelePattern string, alternativeAllelePattern string, + specificValidation func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string)) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), allelePattern) + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), referenceAllelePattern, alternativeAllelePattern) - // assert that all of the responses include heterozygous sample sets - // - * accumulate all variants into a single list using the set of - // SelectManyT's and the SelectT + // assert that all of the responses include sample sets with the appropriate zygosity + // - * accumulate all variants into a single list using the set of SelectManyT's and the SelectT // - ** iterate over each variant in the ForEachT - From(allDtoResponses).SelectManyT(func(resp models.VariantsResponseDTO) Query { // * return From(resp.Data) }).SelectManyT(func(data models.VariantResponseDataModel) Query { @@ -292,20 +376,17 @@ func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, genotypeQue return variant }).ForEachT(func(variant models.Variant) { // ** assert.NotNil(_t, variant.Id) - - specificValidation(_t, variant, allelePattern) + specificValidation(_t, variant, referenceAllelePattern, alternativeAllelePattern) }) } func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, specificValidation func(__t *testing.T, sample models.Sample)) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), "", "") // assert that all of the responses include heterozygous sample sets - // - * accumulate all samples into a single list using the set of - // SelectManyT's and the SelectT + // - * accumulate all samples into a single list using the set of SelectManyT's and the SelectT // - ** iterate over each sample in the ForEachT - From(allDtoResponses).SelectManyT(func(resp models.VariantsResponseDTO) Query { // * return From(resp.Data) }).SelectManyT(func(data models.VariantResponseDataModel) Query { @@ -324,9 +405,17 @@ func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQ }) } -func buildQueryAndMakeGetVariantsCall(chromosome string, sampleId string, includeSamples bool, sortByPosition c.SortDirection, genotype string, assemblyId c.AssemblyId, referenceAllelePattern string, _t *testing.T, _cfg *models.Config) models.VariantsResponseDTO { +func buildQueryAndMakeGetVariantsCall(chromosome string, sampleId string, includeSamples bool, sortByPosition c.SortDirection, genotype string, assemblyId c.AssemblyId, referenceAllelePattern string, alternativeAllelePattern string, _t *testing.T, _cfg *models.Config) models.VariantsResponseDTO { + + queryString := fmt.Sprintf("?chromosome=%s&ids=%s&includeSamplesInResultSet=%t&sortByPosition=%s&genotype=%s&assemblyId=%s", chromosome, sampleId, includeSamples, sortByPosition, genotype, assemblyId) + + if referenceAllelePattern != "" { + queryString = fmt.Sprintf("%s%s", queryString, fmt.Sprintf("&reference=%s", referenceAllelePattern)) + } + if alternativeAllelePattern != "" { + queryString = fmt.Sprintf("%s%s", queryString, fmt.Sprintf("&alternative=%s", alternativeAllelePattern)) + } - queryString := fmt.Sprintf("?chromosome=%s&ids=%s&includeSamplesInResultSet=%t&sortByPosition=%s&genotype=%s&assemblyId=%s&reference=%s", chromosome, sampleId, includeSamples, sortByPosition, genotype, assemblyId, referenceAllelePattern) url := fmt.Sprintf(VariantsGetBySampleIdsPathWithQueryString, _cfg.Api.Url, queryString) return makeGetVariantsCall(url, _t) @@ -387,7 +476,7 @@ func getOverviewResultCombinations(chromosomeStruct interface{}, sampleIdsStruct return allCombinations } -func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, includeSamples bool, sortByPosition c.SortDirection, genotype string, referenceAllelePattern string) []models.VariantsResponseDTO { +func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, includeSamples bool, sortByPosition c.SortDirection, genotype string, referenceAllelePattern string, alternativeAllelePattern string) []models.VariantsResponseDTO { cfg := common.InitConfig() // retrieve the overview @@ -417,7 +506,7 @@ func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, inc assemblyId := a.CastToAssemblyId(_combination[2]) // make the call - dto := buildQueryAndMakeGetVariantsCall(chrom, sampleId, includeSamples, sortByPosition, genotype, assemblyId, referenceAllelePattern, _t, cfg) + dto := buildQueryAndMakeGetVariantsCall(chrom, sampleId, includeSamples, sortByPosition, genotype, assemblyId, referenceAllelePattern, alternativeAllelePattern, _t, cfg) assert.Equal(_t, 1, len(dto.Data)) From 3d9d232db48aa77d2afca796fec72bd8fac6a081 Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 16:52:40 -0400 Subject: [PATCH 5/9] sample validation refactoring --- src/tests/integration/api/api_test.go | 93 ++++++++++++--------------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/src/tests/integration/api/api_test.go b/src/tests/integration/api/api_test.go index c706ecf7..dfff039c 100644 --- a/src/tests/integration/api/api_test.go +++ b/src/tests/integration/api/api_test.go @@ -182,41 +182,22 @@ func TestCanGetVariantsInDescendingPositionOrder(t *testing.T) { } func TestCanGetHeterozygousSamples(t *testing.T) { - - specificValidation := func(__t *testing.T, sample models.Sample) { - assert.True(t, sample.Variation.Genotype.Zygosity == z.Heterozygous) - assert.True(t, sample.Variation.Genotype.AlleleLeft != sample.Variation.Genotype.AlleleRight) - } - - runAndValidateGenotypeQueryResults(t, gq.HOMOZYGOUS_REFERENCE, specificValidation) + // trigger + runAndValidateGenotypeQueryResults(t, gq.HETEROZYGOUS, validateHeterozygousSample) } func TestCanGetHomozygousReferenceSamples(t *testing.T) { - - specificValidation := func(__t *testing.T, sample models.Sample) { - assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) - assert.True(__t, - sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && - sample.Variation.Genotype.AlleleLeft == 0) - } - - runAndValidateGenotypeQueryResults(t, gq.HOMOZYGOUS_REFERENCE, specificValidation) + // trigger + runAndValidateGenotypeQueryResults(t, gq.HOMOZYGOUS_REFERENCE, validateHomozygousReferenceSample) } func TestCanGetHomozygousAlternateSamples(t *testing.T) { - - specificValidation := func(__t *testing.T, sample models.Sample) { - assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) - assert.True(__t, - sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && - sample.Variation.Genotype.AlleleLeft > 0) - } - - runAndValidateGenotypeQueryResults(t, gq.HOMOZYGOUS_ALTERNATE, specificValidation) + // trigger + runAndValidateGenotypeQueryResults(t, gq.HOMOZYGOUS_ALTERNATE, validateHomozygousAlternateSample) } func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { - + // setup specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, alternativeAllelePattern == "") @@ -225,10 +206,7 @@ func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { - assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) - assert.True(__t, - sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && - sample.Variation.Genotype.AlleleLeft > 0) + validateHomozygousAlternateSample(__t, sample) } } @@ -236,7 +214,7 @@ func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { } func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { - + // setup specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, alternativeAllelePattern == "") @@ -245,10 +223,7 @@ func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { - assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) - assert.True(__t, - sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && - sample.Variation.Genotype.AlleleLeft == 0) + validateHomozygousReferenceSample(__t, sample) } } @@ -256,7 +231,7 @@ func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { } func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { - + // setup specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, alternativeAllelePattern == "") @@ -265,16 +240,16 @@ func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { - assert.True(t, sample.Variation.Genotype.Zygosity == z.Heterozygous) - assert.True(t, sample.Variation.Genotype.AlleleLeft != sample.Variation.Genotype.AlleleRight) + validateHeterozygousSample(__t, sample) } } + // trigger executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HETEROZYGOUS, ratt.Reference, specificValidation) } func TestCanGetHomozygousAlternateVariantsWithVariousAlternatives(t *testing.T) { - + // setup specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, referenceAllelePattern == "") @@ -283,18 +258,16 @@ func TestCanGetHomozygousAlternateVariantsWithVariousAlternatives(t *testing.T) assert.Contains(__t, variant.Alt, alternativeAllelePattern) for _, sample := range variant.Samples { - assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) - assert.True(__t, - sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && - sample.Variation.Genotype.AlleleLeft > 0) + validateHomozygousAlternateSample(__t, sample) } } + // trigger executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_ALTERNATE, ratt.Alternative, specificValidation) } func TestCanGetHomozygousReferenceVariantsWithVariousAlternatives(t *testing.T) { - + // setup specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, referenceAllelePattern == "") @@ -303,18 +276,16 @@ func TestCanGetHomozygousReferenceVariantsWithVariousAlternatives(t *testing.T) assert.Contains(__t, variant.Alt, alternativeAllelePattern) for _, sample := range variant.Samples { - assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) - assert.True(__t, - sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && - sample.Variation.Genotype.AlleleLeft == 0) + validateHomozygousReferenceSample(__t, sample) } } + // trigger executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HOMOZYGOUS_REFERENCE, ratt.Alternative, specificValidation) } func TestCanGetHeterozygousVariantsWithVariousAlternatives(t *testing.T) { - + // setup specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, referenceAllelePattern == "") @@ -323,11 +294,11 @@ func TestCanGetHeterozygousVariantsWithVariousAlternatives(t *testing.T) { assert.Contains(__t, variant.Alt, alternativeAllelePattern) for _, sample := range variant.Samples { - assert.True(t, sample.Variation.Genotype.Zygosity == z.Heterozygous) - assert.True(t, sample.Variation.Genotype.AlleleLeft != sample.Variation.Genotype.AlleleRight) + validateHeterozygousSample(__t, sample) } } + // trigger executeReferenceOrAlternativeQueryTestsOfVariousPatterns(t, gq.HETEROZYGOUS, ratt.Alternative, specificValidation) } @@ -552,4 +523,24 @@ func makeGetVariantsCall(url string, _t *testing.T) models.VariantsResponseDTO { return respDto } +// --- sample validation +func validateHeterozygousSample(__t *testing.T, sample models.Sample) { + assert.True(__t, sample.Variation.Genotype.Zygosity == z.Heterozygous) + assert.True(__t, sample.Variation.Genotype.AlleleLeft != sample.Variation.Genotype.AlleleRight) +} + +func validateHomozygousReferenceSample(__t *testing.T, sample models.Sample) { + assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) + assert.True(__t, + sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && + sample.Variation.Genotype.AlleleLeft == 0) +} + +func validateHomozygousAlternateSample(__t *testing.T, sample models.Sample) { + assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) + assert.True(__t, + sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && + sample.Variation.Genotype.AlleleLeft > 0) +} + // -- From 7c1e2af0a776a417f5af93b64b9dc7ab8ae112fe Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 17:38:21 -0400 Subject: [PATCH 6/9] more accurate testing: - skips test when necessary --- Makefile | 2 +- src/tests/integration/api/api_test.go | 86 ++++++++++++++++++--------- 2 files changed, 59 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 33da8fa4..2d03a672 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ clean-drs-data: ## Tests test-api-dev: prepare-test-config @# Run the tests - go test tests/integration/... + go test tests/integration/... -v prepare-test-config: @# Prepare environment variables dynamically via a JSON file diff --git a/src/tests/integration/api/api_test.go b/src/tests/integration/api/api_test.go index dfff039c..30ce1cd4 100644 --- a/src/tests/integration/api/api_test.go +++ b/src/tests/integration/api/api_test.go @@ -109,6 +109,7 @@ func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { // - * accumulate all samples into a single list using the set of // SelectManyT's and the SelectT // - ** iterate over each sample in the ForEachT + var accumulatedSamples []*models.Sample From(allDtoResponses).SelectManyT(func(resp models.VariantsResponseDTO) Query { // * return From(resp.Data) @@ -119,9 +120,17 @@ func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { }).SelectT(func(sample models.Sample) models.Sample { return sample }).ForEachT(func(sample models.Sample) { // ** - assert.NotEmpty(t, sample.Id) - assert.NotEmpty(t, sample.Variation) + accumulatedSamples = append(accumulatedSamples, &sample) }) + + if len(accumulatedSamples) == 0 { + t.Skip("No samples returned! Skipping --") + } + + for _, s := range accumulatedSamples { + assert.NotEmpty(t, s.Id) + assert.NotEmpty(t, s.Variation) + } } func TestCanGetVariantsInAscendingPositionOrder(t *testing.T) { @@ -198,7 +207,7 @@ func TestCanGetHomozygousAlternateSamples(t *testing.T) { func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { // setup - specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + specificValidation := func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, alternativeAllelePattern == "") @@ -206,7 +215,7 @@ func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { - validateHomozygousAlternateSample(__t, sample) + validateHomozygousAlternateSample(__t, &sample) } } @@ -215,7 +224,7 @@ func TestCanGetHomozygousAlternateVariantsWithVariousReferences(t *testing.T) { func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { // setup - specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + specificValidation := func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, alternativeAllelePattern == "") @@ -223,7 +232,7 @@ func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { - validateHomozygousReferenceSample(__t, sample) + validateHomozygousReferenceSample(__t, &sample) } } @@ -232,7 +241,7 @@ func TestCanGetHomozygousReferenceVariantsWithVariousReferences(t *testing.T) { func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { // setup - specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + specificValidation := func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, alternativeAllelePattern == "") @@ -240,7 +249,7 @@ func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { assert.Contains(__t, variant.Ref, referenceAllelePattern) for _, sample := range variant.Samples { - validateHeterozygousSample(__t, sample) + validateHeterozygousSample(__t, &sample) } } @@ -250,7 +259,7 @@ func TestCanGetHeterozygousVariantsWithVariousReferences(t *testing.T) { func TestCanGetHomozygousAlternateVariantsWithVariousAlternatives(t *testing.T) { // setup - specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + specificValidation := func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, referenceAllelePattern == "") @@ -258,7 +267,7 @@ func TestCanGetHomozygousAlternateVariantsWithVariousAlternatives(t *testing.T) assert.Contains(__t, variant.Alt, alternativeAllelePattern) for _, sample := range variant.Samples { - validateHomozygousAlternateSample(__t, sample) + validateHomozygousAlternateSample(__t, &sample) } } @@ -268,7 +277,7 @@ func TestCanGetHomozygousAlternateVariantsWithVariousAlternatives(t *testing.T) func TestCanGetHomozygousReferenceVariantsWithVariousAlternatives(t *testing.T) { // setup - specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + specificValidation := func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, referenceAllelePattern == "") @@ -276,7 +285,7 @@ func TestCanGetHomozygousReferenceVariantsWithVariousAlternatives(t *testing.T) assert.Contains(__t, variant.Alt, alternativeAllelePattern) for _, sample := range variant.Samples { - validateHomozygousReferenceSample(__t, sample) + validateHomozygousReferenceSample(__t, &sample) } } @@ -286,7 +295,7 @@ func TestCanGetHomozygousReferenceVariantsWithVariousAlternatives(t *testing.T) func TestCanGetHeterozygousVariantsWithVariousAlternatives(t *testing.T) { // setup - specificValidation := func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { + specificValidation := func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string) { // ensure test is formatted correctly assert.True(__t, referenceAllelePattern == "") @@ -294,7 +303,7 @@ func TestCanGetHeterozygousVariantsWithVariousAlternatives(t *testing.T) { assert.Contains(__t, variant.Alt, alternativeAllelePattern) for _, sample := range variant.Samples { - validateHeterozygousSample(__t, sample) + validateHeterozygousSample(__t, &sample) } } @@ -305,7 +314,7 @@ func TestCanGetHeterozygousVariantsWithVariousAlternatives(t *testing.T) { // -- Common utility functions for api tests func executeReferenceOrAlternativeQueryTestsOfVariousPatterns(_t *testing.T, genotypeQuery c.GenotypeQuery, refAltTestType testConsts.ReferenceAlternativeTestType, - specificValidation func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string)) { + specificValidation func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string)) { // TODO: use some kind of Allele Enum patterns := []string{"A", "C", "T", "G"} @@ -332,13 +341,15 @@ func executeReferenceOrAlternativeQueryTestsOfVariousPatterns(_t *testing.T, func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, referenceAllelePattern string, alternativeAllelePattern string, - specificValidation func(__t *testing.T, variant models.Variant, referenceAllelePattern string, alternativeAllelePattern string)) { + specificValidation func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string)) { allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), referenceAllelePattern, alternativeAllelePattern) // assert that all of the responses include sample sets with the appropriate zygosity // - * accumulate all variants into a single list using the set of SelectManyT's and the SelectT // - ** iterate over each variant in the ForEachT + var accumulatedVariants []*models.Variant + From(allDtoResponses).SelectManyT(func(resp models.VariantsResponseDTO) Query { // * return From(resp.Data) }).SelectManyT(func(data models.VariantResponseDataModel) Query { @@ -346,18 +357,29 @@ func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, }).SelectT(func(variant models.Variant) models.Variant { return variant }).ForEachT(func(variant models.Variant) { // ** - assert.NotNil(_t, variant.Id) - specificValidation(_t, variant, referenceAllelePattern, alternativeAllelePattern) + accumulatedVariants = append(accumulatedVariants, &variant) }) + + if len(accumulatedVariants) == 0 { + _t.Skip(fmt.Sprintf("No variants returned for patterns ref: '%s', alt: '%s'! Skipping --", referenceAllelePattern, alternativeAllelePattern)) + } + + for _, v := range accumulatedVariants { + assert.NotNil(_t, v.Id) + specificValidation(_t, v, referenceAllelePattern, alternativeAllelePattern) + } + } -func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, specificValidation func(__t *testing.T, sample models.Sample)) { +func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, specificValidation func(__t *testing.T, sample *models.Sample)) { allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), "", "") // assert that all of the responses include heterozygous sample sets // - * accumulate all samples into a single list using the set of SelectManyT's and the SelectT // - ** iterate over each sample in the ForEachT + var accumulatedSamples []*models.Sample + From(allDtoResponses).SelectManyT(func(resp models.VariantsResponseDTO) Query { // * return From(resp.Data) }).SelectManyT(func(data models.VariantResponseDataModel) Query { @@ -367,13 +389,21 @@ func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQ }).SelectT(func(sample models.Sample) models.Sample { return sample }).ForEachT(func(sample models.Sample) { // ** - assert.NotEmpty(_t, sample.Id) - assert.NotEmpty(_t, sample.Variation) - assert.NotEmpty(_t, sample.Variation.Genotype) - assert.NotEmpty(_t, sample.Variation.Genotype.Zygosity) - - specificValidation(_t, sample) + accumulatedSamples = append(accumulatedSamples, &sample) }) + + if len(accumulatedSamples) == 0 { + _t.Skip("No samples returned! Skipping --") + } + + for _, s := range accumulatedSamples { + assert.NotEmpty(_t, s.Id) + assert.NotEmpty(_t, s.Variation) + assert.NotEmpty(_t, s.Variation.Genotype) + assert.NotEmpty(_t, s.Variation.Genotype.Zygosity) + + specificValidation(_t, s) + } } func buildQueryAndMakeGetVariantsCall(chromosome string, sampleId string, includeSamples bool, sortByPosition c.SortDirection, genotype string, assemblyId c.AssemblyId, referenceAllelePattern string, alternativeAllelePattern string, _t *testing.T, _cfg *models.Config) models.VariantsResponseDTO { @@ -524,19 +554,19 @@ func makeGetVariantsCall(url string, _t *testing.T) models.VariantsResponseDTO { } // --- sample validation -func validateHeterozygousSample(__t *testing.T, sample models.Sample) { +func validateHeterozygousSample(__t *testing.T, sample *models.Sample) { assert.True(__t, sample.Variation.Genotype.Zygosity == z.Heterozygous) assert.True(__t, sample.Variation.Genotype.AlleleLeft != sample.Variation.Genotype.AlleleRight) } -func validateHomozygousReferenceSample(__t *testing.T, sample models.Sample) { +func validateHomozygousReferenceSample(__t *testing.T, sample *models.Sample) { assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) assert.True(__t, sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && sample.Variation.Genotype.AlleleLeft == 0) } -func validateHomozygousAlternateSample(__t *testing.T, sample models.Sample) { +func validateHomozygousAlternateSample(__t *testing.T, sample *models.Sample) { assert.True(__t, sample.Variation.Genotype.Zygosity == z.Homozygous) assert.True(__t, sample.Variation.Genotype.AlleleLeft == sample.Variation.Genotype.AlleleRight && From 8b82cd519336a77883729cc98010c953a7e54b0e Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 17:45:53 -0400 Subject: [PATCH 7/9] readme touchup --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a102ce05..b8da9843 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,9 @@ Generalized Response Body Structure > } > }, > ... -> ] +> ], +> "fileId": `string` (UUID), +> "assemblyId": `string` ("GRCh38" | "GRCh37" | "NCBI36" | "Other"), > }, > ... > ] From 114896acb378ae095a972051ce4ed6effe7856ce Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 18:07:36 -0400 Subject: [PATCH 8/9] genotype test refactoring --- src/tests/integration/api/api_test.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/tests/integration/api/api_test.go b/src/tests/integration/api/api_test.go index 30ce1cd4..6e9c2f43 100644 --- a/src/tests/integration/api/api_test.go +++ b/src/tests/integration/api/api_test.go @@ -92,7 +92,7 @@ func TestGetIngestionRequests(t *testing.T) { func TestCanGetVariantsWithoutSamplesInResultset(t *testing.T) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Undefined, string(gq.UNCALLED), "", "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Undefined, gq.UNCALLED, "", "") // assert that all responses from all combinations have no results for _, dtoResponse := range allDtoResponses { @@ -103,7 +103,7 @@ func TestCanGetVariantsWithoutSamplesInResultset(t *testing.T) { func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, true, s.Undefined, string(gq.UNCALLED), "", "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, true, s.Undefined, gq.UNCALLED, "", "") // assert that all of the responses include valid sample sets // - * accumulate all samples into a single list using the set of @@ -135,7 +135,7 @@ func TestCanGetVariantsWithSamplesInResultset(t *testing.T) { func TestCanGetVariantsInAscendingPositionOrder(t *testing.T) { // retrieve responses in ascending order - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Ascending, string(gq.UNCALLED), "", "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Ascending, gq.UNCALLED, "", "") // assert the dto response slice is plentiful assert.NotNil(t, allDtoResponses) @@ -164,7 +164,7 @@ func TestCanGetVariantsInAscendingPositionOrder(t *testing.T) { func TestCanGetVariantsInDescendingPositionOrder(t *testing.T) { // retrieve responses in descending order - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Descending, string(gq.UNCALLED), "", "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(t, false, s.Descending, gq.UNCALLED, "", "") // assert the dto response slice is plentiful assert.NotNil(t, allDtoResponses) @@ -343,7 +343,7 @@ func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, referenceAllelePattern string, alternativeAllelePattern string, specificValidation func(__t *testing.T, variant *models.Variant, referenceAllelePattern string, alternativeAllelePattern string)) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), referenceAllelePattern, alternativeAllelePattern) + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, genotypeQuery, referenceAllelePattern, alternativeAllelePattern) // assert that all of the responses include sample sets with the appropriate zygosity // - * accumulate all variants into a single list using the set of SelectManyT's and the SelectT @@ -373,7 +373,7 @@ func runAndValidateReferenceOrAlternativeQueryResults(_t *testing.T, func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQuery, specificValidation func(__t *testing.T, sample *models.Sample)) { - allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, string(genotypeQuery), "", "") + allDtoResponses := getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t, true, s.Undefined, genotypeQuery, "", "") // assert that all of the responses include heterozygous sample sets // - * accumulate all samples into a single list using the set of SelectManyT's and the SelectT @@ -406,9 +406,13 @@ func runAndValidateGenotypeQueryResults(_t *testing.T, genotypeQuery c.GenotypeQ } } -func buildQueryAndMakeGetVariantsCall(chromosome string, sampleId string, includeSamples bool, sortByPosition c.SortDirection, genotype string, assemblyId c.AssemblyId, referenceAllelePattern string, alternativeAllelePattern string, _t *testing.T, _cfg *models.Config) models.VariantsResponseDTO { +func buildQueryAndMakeGetVariantsCall(chromosome string, sampleId string, includeSamples bool, sortByPosition c.SortDirection, genotype c.GenotypeQuery, assemblyId c.AssemblyId, referenceAllelePattern string, alternativeAllelePattern string, _t *testing.T, _cfg *models.Config) models.VariantsResponseDTO { - queryString := fmt.Sprintf("?chromosome=%s&ids=%s&includeSamplesInResultSet=%t&sortByPosition=%s&genotype=%s&assemblyId=%s", chromosome, sampleId, includeSamples, sortByPosition, genotype, assemblyId) + queryString := fmt.Sprintf("?chromosome=%s&ids=%s&includeSamplesInResultSet=%t&sortByPosition=%s&assemblyId=%s", chromosome, sampleId, includeSamples, sortByPosition, assemblyId) + + if genotype != gq.UNCALLED { + queryString = fmt.Sprintf("%s%s", queryString, fmt.Sprintf("&genotype=%s", string(genotype))) + } if referenceAllelePattern != "" { queryString = fmt.Sprintf("%s%s", queryString, fmt.Sprintf("&reference=%s", referenceAllelePattern)) @@ -477,7 +481,7 @@ func getOverviewResultCombinations(chromosomeStruct interface{}, sampleIdsStruct return allCombinations } -func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, includeSamples bool, sortByPosition c.SortDirection, genotype string, referenceAllelePattern string, alternativeAllelePattern string) []models.VariantsResponseDTO { +func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, includeSamples bool, sortByPosition c.SortDirection, genotype c.GenotypeQuery, referenceAllelePattern string, alternativeAllelePattern string) []models.VariantsResponseDTO { cfg := common.InitConfig() // retrieve the overview @@ -526,6 +530,7 @@ func getAllDtosOfVariousCombinationsOfChromosomesAndSampleIds(_t *testing.T, inc } func makeGetVariantsCall(url string, _t *testing.T) models.VariantsResponseDTO { + fmt.Printf("Calling %s\n", url) request, _ := http.NewRequest("GET", url, nil) client := &http.Client{} From b9a2fdfe51d9ccd30b6b6172bf7a30b35f6b2ccf Mon Sep 17 00:00:00 2001 From: brouillette Date: Tue, 21 Sep 2021 18:41:51 -0400 Subject: [PATCH 9/9] better api debugging --- docker-compose.yaml | 1 + etc/example.env | 1 + etc/test.config.yml.tpl | 1 + src/api/main.go | 4 ++ src/api/models/config.go | 5 ++ src/api/mvc/variants.go | 13 +++-- src/api/repositories/elasticsearch/main.go | 61 ++++++++++++---------- 7 files changed, 53 insertions(+), 33 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 66769845..102ba8b5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -31,6 +31,7 @@ services: - bridge-net environment: # API + - GOHAN_DEBUG=${GOHAN_DEBUG} - GOHAN_API_VCF_PATH=${GOHAN_API_CONTAINERIZED_VCF_PATH} # Elasticsearch diff --git a/etc/example.env b/etc/example.env index f79d4f3d..a8dcbb1c 100644 --- a/etc/example.env +++ b/etc/example.env @@ -1,5 +1,6 @@ ## Gohan Environment Variables +GOHAN_DEBUG=false GOHAN_SERVICES=gateway api elasticsearch kibana drs authorization # Host diff --git a/etc/test.config.yml.tpl b/etc/test.config.yml.tpl index f77e0e31..7d35d243 100644 --- a/etc/test.config.yml.tpl +++ b/etc/test.config.yml.tpl @@ -1,3 +1,4 @@ +debug: ${GOHAN_DEBUG} api: url: "${GOHAN_PUBLIC_URL}" port: "${GOHAN_API_INTERNAL_PORT}" diff --git a/src/api/main.go b/src/api/main.go index adbaabe6..74763465 100644 --- a/src/api/main.go +++ b/src/api/main.go @@ -29,6 +29,9 @@ func main() { } fmt.Printf("Using : \n"+ + + "\tDebug : %t \n\n"+ + "\tVCF Directory Path : %s \n"+ "\tElasticsearch Url : %s \n"+ "\tElasticsearch Username : %s\n\n"+ @@ -43,6 +46,7 @@ func main() { "Running on Port : %s\n", + cfg.Debug, cfg.Api.VcfPath, cfg.Elasticsearch.Url, cfg.Elasticsearch.Username, cfg.Drs.Url, cfg.Drs.Username, diff --git a/src/api/models/config.go b/src/api/models/config.go index 73236a97..d701b6a8 100644 --- a/src/api/models/config.go +++ b/src/api/models/config.go @@ -1,21 +1,26 @@ package models type Config struct { + Debug bool `yaml:"debug" envconfig:"GOHAN_DEBUG"` + Api struct { Url string `yaml:"url" envconfig:"GOHAN_PUBLIC_URL"` Port string `yaml:"port" envconfig:"GOHAN_API_INTERNAL_PORT"` VcfPath string `yaml:"vcfPath" envconfig:"GOHAN_API_VCF_PATH"` } `yaml:"api"` + Elasticsearch struct { Url string `yaml:"url" envconfig:"GOHAN_ES_URL"` Username string `yaml:"username" envconfig:"GOHAN_ES_USERNAME"` Password string `yaml:"password" envconfig:"GOHAN_ES_PASSWORD"` } `yaml:"elasticsearch"` + Drs struct { Url string `yaml:"url" envconfig:"GOHAN_DRS_URL"` Username string `yaml:"username" envconfig:"GOHAN_DRS_BASIC_AUTH_USERNAME"` Password string `yaml:"password" envconfig:"GOHAN_DRS_BASIC_AUTH_PASSWORD"` } `yaml:"drs"` + AuthX struct { IsAuthorizationEnabled bool `yaml:"isAuthorizationEnabled" envconfig:"GOHAN_AUTHZ_ENABLED"` OidcPublicJwksUrl string `yaml:"oidcPublicJwksUrl" envconfig:"GOHAN_PUBLIC_AUTHN_JWKS_URL"` diff --git a/src/api/mvc/variants.go b/src/api/mvc/variants.go index d2411ecb..6ffe7045 100644 --- a/src/api/mvc/variants.go +++ b/src/api/mvc/variants.go @@ -244,11 +244,12 @@ func GetVariantsOverview(c echo.Context) error { var wg sync.WaitGroup es := c.(*contexts.GohanContext).Es7Client + cfg := c.(*contexts.GohanContext).Config callGetBucketsByKeyword := func(key string, keyword string, _wg *sync.WaitGroup) { defer _wg.Done() - results := esRepo.GetBucketsByKeyword(es, keyword) + results := esRepo.GetBucketsByKeyword(cfg, es, keyword) // retrieve aggregations.items.buckets bucketsMapped := []interface{}{} @@ -311,6 +312,7 @@ func GetAllVariantIngestionRequests(c echo.Context) error { } func executeGetByIds(c echo.Context, ids []string, isVariantIdQuery bool) error { + cfg := c.(*contexts.GohanContext).Config var es, chromosome, lowerBound, upperBound, reference, alternative, genotype, assemblyId = retrieveCommonElements(c) @@ -365,7 +367,7 @@ func executeGetByIds(c echo.Context, ids []string, isVariantIdQuery bool) error fmt.Printf("Executing Get-Variants for VariantId %s\n", _id) - docs = esRepo.GetDocumentsContainerVariantOrSampleIdInPositionRange(es, + docs = esRepo.GetDocumentsContainerVariantOrSampleIdInPositionRange(cfg, es, chromosome, lowerBound, upperBound, _id, "", // note : "" is for sampleId reference, alternative, @@ -377,7 +379,7 @@ func executeGetByIds(c echo.Context, ids []string, isVariantIdQuery bool) error fmt.Printf("Executing Get-Samples for SampleId %s\n", _id) - docs = esRepo.GetDocumentsContainerVariantOrSampleIdInPositionRange(es, + docs = esRepo.GetDocumentsContainerVariantOrSampleIdInPositionRange(cfg, es, chromosome, lowerBound, upperBound, "", _id, // note : "" is for variantId reference, alternative, @@ -426,6 +428,7 @@ func executeGetByIds(c echo.Context, ids []string, isVariantIdQuery bool) error } func executeCountByIds(c echo.Context, ids []string, isVariantIdQuery bool) error { + cfg := c.(*contexts.GohanContext).Config var es, chromosome, lowerBound, upperBound, reference, alternative, genotype, assemblyId = retrieveCommonElements(c) @@ -448,7 +451,7 @@ func executeCountByIds(c echo.Context, ids []string, isVariantIdQuery bool) erro fmt.Printf("Executing Count-Variants for VariantId %s\n", _id) - docs = esRepo.CountDocumentsContainerVariantOrSampleIdInPositionRange(es, + docs = esRepo.CountDocumentsContainerVariantOrSampleIdInPositionRange(cfg, es, chromosome, lowerBound, upperBound, _id, "", // note : "" is for sampleId reference, alternative, genotype, assemblyId) @@ -458,7 +461,7 @@ func executeCountByIds(c echo.Context, ids []string, isVariantIdQuery bool) erro fmt.Printf("Executing Count-Samples for SampleId %s\n", _id) - docs = esRepo.CountDocumentsContainerVariantOrSampleIdInPositionRange(es, + docs = esRepo.CountDocumentsContainerVariantOrSampleIdInPositionRange(cfg, es, chromosome, lowerBound, upperBound, "", _id, // note : "" is for variantId reference, alternative, genotype, assemblyId) diff --git a/src/api/repositories/elasticsearch/main.go b/src/api/repositories/elasticsearch/main.go index 417474ea..41cd120c 100644 --- a/src/api/repositories/elasticsearch/main.go +++ b/src/api/repositories/elasticsearch/main.go @@ -10,6 +10,7 @@ import ( "net/http" "time" + "api/models" c "api/models/constants" gq "api/models/constants/genotype-query" s "api/models/constants/sort" @@ -18,7 +19,7 @@ import ( "github.com/elastic/go-elasticsearch" ) -func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Client, +func GetDocumentsContainerVariantOrSampleIdInPositionRange(cfg *models.Config, es *elasticsearch.Client, chromosome string, lowerBound int, upperBound int, variantId string, sampleId string, reference string, alternative string, @@ -159,7 +160,7 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli // exclude samples from result? var excludesSlice []string = make([]string, 0) - if includeSamplesInResultSet == false { + if !includeSamplesInResultSet { excludesSlice = append(excludesSlice, "samples") } @@ -198,11 +199,11 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli log.Fatalf("Error encoding query: %s\n", err) } - // DEBUG-- - // Unmarshal or Decode the JSON to the interface. - // myString := string(buf.Bytes()[:]) - // fmt.Println(myString) - // -- + if cfg.Debug { + // view the outbound elasticsearch query + myString := string(buf.Bytes()[:]) + fmt.Println(myString) + } fmt.Printf("Query Start: %s\n", time.Now()) @@ -223,16 +224,16 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli defer res.Body.Close() - // Temp resultString := res.String() - //fmt.Println(resultString) - // -- + if cfg.Debug { + fmt.Println(resultString) + } // Declared an empty interface result := make(map[string]interface{}) // Unmarshal or Decode the JSON to the interface. - // Known bug: response comes back with a preceing '[200 OK] ' which needs trimming (hence the [9:]) + // Known bug: response comes back with a preceding '[200 OK] ' which needs trimming (hence the [9:]) umErr := json.Unmarshal([]byte(resultString[9:]), &result) if umErr != nil { fmt.Printf("Error unmarshalling response: %s\n", umErr) @@ -243,7 +244,7 @@ func GetDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Cli return result } -func CountDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.Client, +func CountDocumentsContainerVariantOrSampleIdInPositionRange(cfg *models.Config, es *elasticsearch.Client, chromosome string, lowerBound int, upperBound int, variantId string, sampleId string, reference string, alternative string, @@ -389,8 +390,6 @@ func CountDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.C } } - // exclude samples from result? - // overall query structure var buf bytes.Buffer query := map[string]interface{}{ @@ -410,11 +409,11 @@ func CountDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.C log.Fatalf("Error encoding query: %s\n", err) } - // DEBUG-- - // Unmarshal or Decode the JSON to the interface. - // myString := string(buf.Bytes()[:]) - // fmt.Println(myString) - // -- + if cfg.Debug { + // view the outbound elasticsearch query + myString := string(buf.Bytes()[:]) + fmt.Println(myString) + } fmt.Printf("Query Start: %s\n", time.Now()) @@ -434,16 +433,16 @@ func CountDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.C defer res.Body.Close() - // Temp resultString := res.String() - // fmt.Println(resultString) - // -- + if cfg.Debug { + fmt.Println(resultString) + } // Declared an empty interface result := make(map[string]interface{}) // Unmarshal or Decode the JSON to the interface. - // Known bug: response comes back with a preceing '[200 OK] ' which needs trimming (hence the [9:]) + // Known bug: response comes back with a preceding '[200 OK] ' which needs trimming (hence the [9:]) umErr := json.Unmarshal([]byte(resultString[9:]), &result) if umErr != nil { fmt.Printf("Error unmarshalling response: %s\n", umErr) @@ -454,7 +453,7 @@ func CountDocumentsContainerVariantOrSampleIdInPositionRange(es *elasticsearch.C return result } -func GetBucketsByKeyword(es *elasticsearch.Client, keyword string) map[string]interface{} { +func GetBucketsByKeyword(cfg *models.Config, es *elasticsearch.Client, keyword string) map[string]interface{} { // begin building the request body. var buf bytes.Buffer @@ -475,6 +474,12 @@ func GetBucketsByKeyword(es *elasticsearch.Client, keyword string) map[string]in log.Fatalf("Error encoding aggMap: %s\n", err) } + if cfg.Debug { + // view the outbound elasticsearch query + myString := string(buf.Bytes()[:]) + fmt.Println(myString) + } + // TEMP: SECURITY RISK http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} // @@ -492,16 +497,16 @@ func GetBucketsByKeyword(es *elasticsearch.Client, keyword string) map[string]in defer res.Body.Close() - // Temp resultString := res.String() - fmt.Println(resultString) - // -- + if cfg.Debug { + fmt.Println(resultString) + } // Declared an empty interface result := make(map[string]interface{}) // Unmarshal or Decode the JSON to the interface. - // Known bug: response comes back with a preceing '[200 OK] ' which needs trimming (hence the [9:]) + // Known bug: response comes back with a preceding '[200 OK] ' which needs trimming (hence the [9:]) umErr := json.Unmarshal([]byte(resultString[9:]), &result) if umErr != nil { fmt.Printf("Error unmarshalling response: %s\n", umErr)