Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Alleles remodeling #46

Draft
wants to merge 2 commits into
base: features/1448
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/api/models/indexes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/api/mvc/variants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
70 changes: 18 additions & 52 deletions src/api/repositories/elasticsearch/variants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions src/api/services/ingestion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down