-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'features/v3.0.0/gohan-gene-api' into releases/v3.0.0
- Loading branch information
Showing
18 changed files
with
1,004 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,7 @@ bin/* | |
*/*/tmp | ||
|
||
*.vcf | ||
*.vcf.gz | ||
*.vcf.gz | ||
|
||
*/*/*.csv | ||
*/*/*.gtf* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package chromosome | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
func IsValidHumanChromosome(text string) bool { | ||
|
||
// Check if number can be represented as an int as is non-zero | ||
chromNumber, _ := strconv.Atoi(text) | ||
if chromNumber > 0 { | ||
// It can.. | ||
// Check if it in range 1-23 | ||
if chromNumber < 24 { | ||
return true | ||
} | ||
} else { | ||
// No it can't.. | ||
// Check if it is an X, Y.. | ||
loweredText := strings.ToLower(text) | ||
switch loweredText { | ||
case "x": | ||
return true | ||
case "y": | ||
return true | ||
} | ||
|
||
// ..or M (MT) | ||
switch strings.Contains(loweredText, "m") { | ||
case true: | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package structs | ||
|
||
import ( | ||
"api/models" | ||
"sync" | ||
) | ||
|
||
type IngestionQueueStructure struct { | ||
Variant *models.Variant | ||
WaitGroup *sync.WaitGroup | ||
} | ||
|
||
type GeneIngestionQueueStructure struct { | ||
Gene *models.Gene | ||
WaitGroup *sync.WaitGroup | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package mvc | ||
|
||
import ( | ||
"api/contexts" | ||
"api/models" | ||
assemblyId "api/models/constants/assembly-id" | ||
esRepo "api/repositories/elasticsearch" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"sync" | ||
|
||
"github.com/labstack/echo" | ||
"github.com/mitchellh/mapstructure" | ||
) | ||
|
||
func GenesGetByNomenclatureWildcard(c echo.Context) error { | ||
cfg := c.(*contexts.GohanContext).Config | ||
es := c.(*contexts.GohanContext).Es7Client | ||
|
||
// Chromosome search term | ||
chromosomeSearchTerm := c.QueryParam("chromosome") | ||
if len(chromosomeSearchTerm) == 0 { | ||
// if no chromosome is provided, assume "wildcard" search | ||
chromosomeSearchTerm = "*" | ||
} | ||
|
||
// Name search term | ||
term := c.QueryParam("term") | ||
|
||
// Assembly ID | ||
// perform wildcard search if empty/random parameter is passed | ||
// - set to Unknown to trigger it | ||
assId := assemblyId.Unknown | ||
if assemblyId.CastToAssemblyId(c.QueryParam("assemblyId")) != assemblyId.Unknown { | ||
// retrieve passed parameter if is valid | ||
assId = assemblyId.CastToAssemblyId(c.QueryParam("assemblyId")) | ||
} | ||
|
||
// Size | ||
var ( | ||
size int = 25 | ||
sizeCastErr error | ||
) | ||
if len(c.QueryParam("size")) > 0 { | ||
sizeQP := c.QueryParam("size") | ||
size, sizeCastErr = strconv.Atoi(sizeQP) | ||
if sizeCastErr != nil { | ||
size = 25 | ||
} | ||
} | ||
|
||
fmt.Printf("Executing wildcard genes search for term %s, assemblyId %s (max size: %d)\n", term, assId, size) | ||
|
||
// Execute | ||
docs := esRepo.GetGeneDocumentsByTermWildcard(cfg, es, chromosomeSearchTerm, term, assId, size) | ||
|
||
docsHits := docs["hits"].(map[string]interface{})["hits"] | ||
allDocHits := []map[string]interface{}{} | ||
mapstructure.Decode(docsHits, &allDocHits) | ||
|
||
// grab _source for each hit | ||
var allSources []models.Gene | ||
|
||
for _, r := range allDocHits { | ||
source := r["_source"].(map[string]interface{}) | ||
|
||
// cast map[string]interface{} to struct | ||
var resultingVariant models.Gene | ||
mapstructure.Decode(source, &resultingVariant) | ||
|
||
// accumulate structs | ||
allSources = append(allSources, resultingVariant) | ||
} | ||
|
||
fmt.Printf("Found %d docs!\n", len(allSources)) | ||
|
||
geneResponseDTO := models.GenesResponseDTO{ | ||
Term: term, | ||
Count: len(allSources), | ||
Results: allSources, | ||
Status: 200, | ||
Message: "Success", | ||
} | ||
|
||
return c.JSON(http.StatusOK, geneResponseDTO) | ||
} | ||
|
||
func GetGenesOverview(c echo.Context) error { | ||
|
||
resultsMap := map[string]interface{}{} | ||
resultsMux := sync.RWMutex{} | ||
|
||
es := c.(*contexts.GohanContext).Es7Client | ||
cfg := c.(*contexts.GohanContext).Config | ||
|
||
// retrieve aggregation of genes/chromosomes by assembly id | ||
results := esRepo.GetGeneBucketsByKeyword(cfg, es) | ||
|
||
// begin mapping results | ||
geneChromosomeGroupBucketsMapped := []map[string]interface{}{} | ||
|
||
// loop over top level aggregation and | ||
// accumulated nested aggregations | ||
if aggs, ok := results["aggregations"]; ok { | ||
aggsMapped := aggs.(map[string]interface{}) | ||
|
||
if items, ok := aggsMapped["genes_assembly_id_group"]; ok { | ||
itemsMapped := items.(map[string]interface{}) | ||
|
||
if buckets := itemsMapped["buckets"]; ok { | ||
arrayMappedBuckets := buckets.([]interface{}) | ||
|
||
for _, mappedBucket := range arrayMappedBuckets { | ||
geneChromosomeGroupBucketsMapped = append(geneChromosomeGroupBucketsMapped, mappedBucket.(map[string]interface{})) | ||
} | ||
} | ||
} | ||
} | ||
|
||
individualAssemblyIdKeyMap := map[string]interface{}{} | ||
|
||
// iterated over each assemblyId bucket | ||
for _, chromGroupBucketMap := range geneChromosomeGroupBucketsMapped { | ||
|
||
assemblyIdKey := fmt.Sprint(chromGroupBucketMap["key"]) | ||
|
||
numGenesPerChromMap := map[string]interface{}{} | ||
bucketsMapped := map[string]interface{}{} | ||
|
||
if chromGroupItem, ok := chromGroupBucketMap["genes_chromosome_group"]; ok { | ||
chromGroupItemMapped := chromGroupItem.(map[string]interface{}) | ||
|
||
for _, chromBucket := range chromGroupItemMapped["buckets"].([]interface{}) { | ||
doc_key := fmt.Sprint(chromBucket.(map[string]interface{})["key"]) // ensure strings and numbers are expressed as strings | ||
doc_count := chromBucket.(map[string]interface{})["doc_count"] | ||
|
||
// add to list of buckets by chromosome | ||
bucketsMapped[doc_key] = doc_count | ||
} | ||
} | ||
|
||
numGenesPerChromMap["numberOfGenesPerChromosome"] = bucketsMapped | ||
individualAssemblyIdKeyMap[assemblyIdKey] = numGenesPerChromMap | ||
} | ||
|
||
resultsMux.Lock() | ||
resultsMap["assemblyIDs"] = individualAssemblyIdKeyMap | ||
resultsMux.Unlock() | ||
|
||
return c.JSON(http.StatusOK, resultsMap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.