diff --git a/src/api/models/indexes/main.go b/src/api/models/indexes/main.go index 12f94edd..7fb93e97 100644 --- a/src/api/models/indexes/main.go +++ b/src/api/models/indexes/main.go @@ -33,14 +33,10 @@ type Sample struct { } type Variation struct { - Genotype Genotype `json:"genotype"` - GenotypeProbability []float64 `json:"genotypeProbability"` // -1 = no call (equivalent to a '.') - PhredScaleLikelyhood []float64 `json:"phredScaleLikelyhood"` // -1 = no call (equivalent to a '.') - Alleles AllelePair `json:"alleles"` -} -type AllelePair struct { - Left string `json:"left"` - Right string `json:"right"` + Genotype Genotype `json:"genotype"` + GenotypeProbability []float64 `json:"genotypeProbability"` // -1 = no call (equivalent to a '.') + PhredScaleLikelyhood []float64 `json:"phredScaleLikelyhood"` // -1 = no call (equivalent to a '.') + Alleles []string `json:"alleles"` } type Genotype struct { diff --git a/src/api/mvc/variants/main.go b/src/api/mvc/variants/main.go index c10e12bf..7713de91 100644 --- a/src/api/mvc/variants/main.go +++ b/src/api/mvc/variants/main.go @@ -677,7 +677,7 @@ func executeGetByIds(c echo.Context, ids []string, isVariantIdQuery bool, isDocu SampleId: sampleId, GenotypeType: zygosity.ZygosityToString(variant.Sample.Variation.Genotype.Zygosity), - Alleles: []string{alleles.Left, alleles.Right}, + Alleles: alleles, AssemblyId: variant.AssemblyId, DocumentId: docId, diff --git a/src/api/repositories/elasticsearch/variants.go b/src/api/repositories/elasticsearch/variants.go index 90ebeec9..929aac42 100644 --- a/src/api/repositories/elasticsearch/variants.go +++ b/src/api/repositories/elasticsearch/variants.go @@ -658,61 +658,27 @@ func DeleteVariantsByTableId(es *es7.Client, cfg *models.Config, tableId string) // -- internal use only -- func addAllelesToShouldMap(alleles []string, genotype c.GenotypeQuery, allelesShouldMap []map[string]interface{}) ([]map[string]interface{}, int) { - minimumShouldMatch := 0 - - if len(alleles) > 0 { - switch len(alleles) { - case 1: - if genotype == gq.ALTERNATE || genotype == gq.REFERENCE { - // haploid case - - // queried allele should be present on the left side of the pair with an empty right side - allelesShouldMap = append(allelesShouldMap, map[string]interface{}{ - "query_string": map[string]interface{}{ - "query": "sample.variation.alleles.left.keyword:" + alleles[0] + " AND sample.variation.alleles.right.keyword:\"\"", - }}) - - } else { - // assume diploid-type of search as default - - // queried allele can be present on either side of the pair - allelesShouldMap = append(allelesShouldMap, map[string]interface{}{ - "query_string": map[string]interface{}{ - "query": "sample.variation.alleles.left.keyword:" + alleles[0] + " OR sample.variation.alleles.right.keyword:" + alleles[0], - }}) + minimumShouldMatch := 1 + + queryStrBuild := "" + for i, al := range alleles { + if i == 0 { + queryStrBuild += al + } else { + switch genotype { + case gq.ALTERNATE: // haploid + case gq.REFERENCE: + queryStrBuild = fmt.Sprintf("%s OR %s", queryStrBuild, al) + default: // diploid ++ + queryStrBuild = fmt.Sprintf("%s AND %s", queryStrBuild, al) } - case 2: - if genotype == gq.ALTERNATE || genotype == gq.REFERENCE { - // haploid case - - // either queried allele can be present on the left side of the pair with an empty right side - allelesShouldMap = append(allelesShouldMap, map[string]interface{}{ - "query_string": map[string]interface{}{ - "query": "sample.variation.alleles.left.keyword:" + alleles[0] + " AND sample.variation.alleles.right.keyword:\"\"", - }}) - allelesShouldMap = append(allelesShouldMap, map[string]interface{}{ - "query_string": map[string]interface{}{ - "query": "sample.variation.alleles.left.keyword:" + alleles[1] + " AND sample.variation.alleles.right.keyword:\"\"", - }}) - - } else { - // assume diploid-type of search as default - - // treat as a left/right pair - // either queried allele can be present on the left or right side of the pair - allelesShouldMap = append(allelesShouldMap, map[string]interface{}{ - "query_string": map[string]interface{}{ - "query": "sample.variation.alleles.left.keyword:" + alleles[0] + " AND sample.variation.alleles.right.keyword:" + alleles[1], - }}) - allelesShouldMap = append(allelesShouldMap, map[string]interface{}{ - "query_string": map[string]interface{}{ - "query": "sample.variation.alleles.left.keyword:" + alleles[1] + " AND sample.variation.alleles.right.keyword:" + alleles[0], - }}) - } - // TODO: triploid ? } - minimumShouldMatch = 1 } + allelesShouldMap = append(allelesShouldMap, map[string]interface{}{ + "query_string": map[string]interface{}{ + "default_field": "sample.variation.alleles", + "query": queryStrBuild, + }}) return allelesShouldMap, minimumShouldMatch } diff --git a/src/api/services/ingestion.go b/src/api/services/ingestion.go index 07e35551..8296f7d6 100644 --- a/src/api/services/ingestion.go +++ b/src/api/services/ingestion.go @@ -746,22 +746,22 @@ func (i *IngestionService) ProcessVcf( // ... REF ALT ... // ... G CT,CTT,CTTT - var alleles indexes.AllelePair + alleles := make([]string, 0) // hold a temporary pointer to the current state of this-variant's 'alt' and 'ref' for brevity tmpVariantAlt := tmpVariant["alt"].([]string) tmpVariantRef := tmpVariant["ref"].([]string) if alleleLeft > 0 { - alleles.Left = tmpVariantAlt[alleleLeft-1] + alleles = append(alleles, tmpVariantAlt[alleleLeft-1]) } else { - alleles.Left = tmpVariantRef[0] + alleles = append(alleles, tmpVariantRef[0]) } if ploidy == p.Diploid { if alleleRight > 0 { - alleles.Right = tmpVariantAlt[alleleRight-1] + alleles = append(alleles, tmpVariantAlt[alleleRight-1]) } else { - alleles.Right = tmpVariantRef[0] + alleles = append(alleles, tmpVariantRef[0]) } }