Skip to content

Commit

Permalink
Merge pull request #8 from bento-platform/releases/v2.2.0
Browse files Browse the repository at this point in the history
releases/v2.2.0
  • Loading branch information
brouillette authored Sep 10, 2021
2 parents 46e5ddd + 3a44229 commit 7a64b6d
Show file tree
Hide file tree
Showing 16 changed files with 580 additions and 167 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,13 @@ Requests
> - chromosome : **number**
> - lowerBound : **number**
> - upperBound : **number**
> - reference : **string** `an allele ( "A" | "C" | "G" | "T" or some combination thereof)`
> - reference : **string** `an allele ( "A" | "C" | "G" | "T" or some combination thereof )`
> - alternative : **string** `an allele`
> - ids : **string** `(a comma-deliminated list of variant ID alphanumeric codes)`
> - size : **number** `(maximum number of results per id)`
> - sortByPosition : **string** `(<empty> | asc | desc)`
> - includeSamplesInResultSet : **boolean** `(true | false)`
> - genotype : **string** `( "HOMOZYGOUS" | "HETEROZYGOUS_REFERENCE" | "HETEROZYGOUS_ALTERNATE" )`
>
> &nbsp;&nbsp;**GET** `/variants/count/by/variantId`<br/>
> &nbsp;&nbsp;&nbsp;params:
Expand All @@ -225,6 +226,7 @@ Requests
> - reference : **string** `an allele`
> - alternative : **string** `an allele`
> - ids : **string** `(a comma-deliminated list of variant ID alphanumeric codes)`
> - genotype : **string** `( "HOMOZYGOUS" | "HETEROZYGOUS_REFERENCE" | "HETEROZYGOUS_ALTERNATE" )`
> &nbsp;&nbsp;**GET** `/variants/get/by/sampleId`<br/>
> &nbsp;&nbsp;&nbsp;params:
Expand All @@ -237,6 +239,7 @@ Requests
> - size : **number** `(maximum number of results per id)`
> - sortByPosition : **string** `(<empty> | asc | desc)`
> - includeSamplesInResultSet : **boolean** `(true | false)`
> - genotype : **string** `( "HOMOZYGOUS" | "HETEROZYGOUS_REFERENCE" | "HETEROZYGOUS_ALTERNATE" )`
>
> &nbsp;&nbsp;**GET** `/variants/count/by/sampleId`<br/>
> &nbsp;&nbsp;&nbsp;params:
Expand All @@ -246,6 +249,7 @@ Requests
> - reference : **string** `an allele`
> - alternative : **string** `an allele`
> - ids : **string** `(comma-deliminated list of sample ID alphanumeric codes)`
> - genotype : **string** `( "HOMOZYGOUS" | "HETEROZYGOUS_REFERENCE" | "HETEROZYGOUS_ALTERNATE" )`
>
<br />
Expand All @@ -265,12 +269,8 @@ Generalized Response Body Structure
> {
> "filter": `string`,
> "pos": `number`,
> "ref": [
> `string`, // an allele
> ],
> "alt": [
> `string`, // an allele
> ],
> "ref": `[]string`, // list of alleles
> "alt": `[]string`, // list of alleles
> "info": [
> {
> "id": `string`,
Expand All @@ -283,8 +283,17 @@ Generalized Response Body Structure
> "id": `string`,
> "samples": [
> {
> "sampleId": `string`,
> "variation": `string`,
> "id": `string`,
> "variation": {
> "genotype": {
> "phased": `boolean`,
> "alleleLeft": `number`,
> "alleleRight": `number`,
> "zygosity": `number` (0 : "Unknown" | 1 : "Homozygous" | 2 : "Heterozygous")
> },
> "genotypeProbability": `[]float` | null,
> "phredScaleLikelyhood": `[]float` | null,
> }
> },
> ...
> ]
Expand Down
15 changes: 11 additions & 4 deletions src/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,31 @@ func main() {

// -- Variants
e.GET("/variants/overview", mvc.GetVariantsOverview)

e.GET("/variants/get/by/variantId", mvc.VariantsGetByVariantId,
// middleware
gam.MandateChromosomeAttribute,
gam.MandateCalibratedBounds)
gam.MandateCalibratedBounds,
gam.ValidatePotentialGenotypeQueryParameter)
e.GET("/variants/get/by/sampleId", mvc.VariantsGetBySampleId,
// middleware
gam.MandateChromosomeAttribute,
gam.MandateCalibratedBounds,
gam.MandateSampleIdsPluralAttribute)
gam.MandateSampleIdsPluralAttribute,
gam.ValidatePotentialGenotypeQueryParameter)

e.GET("/variants/count/by/variantId", mvc.VariantsCountByVariantId,
// middleware
gam.MandateChromosomeAttribute,
gam.MandateCalibratedBounds)
gam.MandateCalibratedBounds,
gam.ValidatePotentialGenotypeQueryParameter)
e.GET("/variants/count/by/sampleId", mvc.VariantsCountBySampleId,
// middleware
gam.MandateChromosomeAttribute,
gam.MandateCalibratedBounds,
gam.MandateSampleIdsSingularAttribute)
gam.MandateSampleIdsSingularAttribute,
gam.ValidatePotentialGenotypeQueryParameter)

e.GET("/variants/ingestion/run", mvc.VariantsIngest)
e.GET("/variants/ingestion/requests", mvc.GetAllVariantIngestionRequests)

Expand Down
25 changes: 25 additions & 0 deletions src/api/middleware/genotypeMiddleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package middleware

import (
"fmt"
"net/http"

gq "api/models/constants/genotype-query"

"github.com/labstack/echo"
)

func ValidatePotentialGenotypeQueryParameter(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
genotypeQP := c.QueryParam("genotype")

if len(genotypeQP) > 0 {
_, genotypeErr := gq.CastToGenoType(genotypeQP)
if genotypeErr != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid genotype query %s, %s", genotypeQP, genotypeErr))
}
}

return next(c)
}
}
39 changes: 39 additions & 0 deletions src/api/models/constants/genotype-query/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package genotypeQuery

import (
"api/models/constants"
"errors"
"strings"
)

const (
UNCALLED constants.GenotypeQuery = ""

// # Haploid
REFERENCE constants.GenotypeQuery = "REFERENCE"
ALTERNATE constants.GenotypeQuery = "ALTERNATE"

// # Diploid or higher
HOMOZYGOUS_REFERENCE constants.GenotypeQuery = "HOMOZYGOUS_REFERENCE"
HETEROZYGOUS constants.GenotypeQuery = "HETEROZYGOUS"
HOMOZYGOUS_ALTERNATE constants.GenotypeQuery = "HOMOZYGOUS_ALTERNATE"
)

func CastToGenoType(text string) (constants.GenotypeQuery, error) {
switch strings.ToLower(text) {
case "":
return UNCALLED, nil
case "reference":
return REFERENCE, nil
case "alternate":
return ALTERNATE, nil
case "homozygous_reference":
return HOMOZYGOUS_REFERENCE, nil
case "heterozygous":
return HETEROZYGOUS, nil
case "homozygous_alternate":
return HOMOZYGOUS_ALTERNATE, nil
default:
return UNCALLED, errors.New("unable to parse genotype query")
}
}
16 changes: 0 additions & 16 deletions src/api/models/constants/genotypes.go

This file was deleted.

9 changes: 9 additions & 0 deletions src/api/models/constants/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package constants

type enumString string
type enumInt int

type GenotypeQuery enumString
type SearchOperation enumString

type Zygosity enumInt
13 changes: 0 additions & 13 deletions src/api/models/constants/search.go

This file was deleted.

15 changes: 15 additions & 0 deletions src/api/models/constants/search/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package search

import (
"api/models/constants"
)

const (
SEARCH_OP_EQ constants.SearchOperation = "eq"
SEARCH_OP_LT constants.SearchOperation = "lt"
SEARCH_OP_LE constants.SearchOperation = "le"
SEARCH_OP_GT constants.SearchOperation = "gt"
SEARCH_OP_GE constants.SearchOperation = "ge"

SEARCH_OP_CO constants.SearchOperation = "co"
)
20 changes: 20 additions & 0 deletions src/api/models/constants/zygosity/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package zygosity

import (
"api/models/constants"
)

const (
Empty constants.Zygosity = iota - 1
Unknown
Homozygous
Heterozygous
)

func IsValid(value int) bool {
return value <= int(Heterozygous)
}

func IsValidQuery(value int) bool {
return value > int(Empty) && IsValid(value)
}
23 changes: 20 additions & 3 deletions src/api/models/elasticsearch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package models

import (
c "api/models/constants"
)

var VcfHeaders = []string{"chrom", "pos", "id", "ref", "alt", "qual", "filter", "info", "format"}

type Variant struct {
Expand All @@ -8,7 +12,7 @@ type Variant struct {
Id string `json:"id"`
Ref []string `json:"ref"`
Alt []string `json:"alt"`
Format string `json:"format"`
Format []string `json:"format"`
Qual int `json:"qual"`
Filter string `json:"filter"`
Info []Info `json:"info"`
Expand All @@ -23,6 +27,19 @@ type Info struct {
}

type Sample struct {
SampleId string `json:"sampleId"`
Variation string `json:"variation"`
Id string `json:"id"`
Variation Variation `json:"variation"`
}

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 '.')
}

type Genotype struct {
Phased bool `json:"phased"`
AlleleLeft int `json:"alleleLeft"` // -1 = no call (equivalent to a '.')
AlleleRight int `json:"alleleRight"` // -1 = no call (equivalent to a '.')
Zygosity c.Zygosity `json:"zygosity"`
}
Loading

0 comments on commit 7a64b6d

Please sign in to comment.