-
Notifications
You must be signed in to change notification settings - Fork 4
/
getvariantsdata.go
60 lines (50 loc) · 1.67 KB
/
getvariantsdata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package htsserver
import (
"net/http"
"github.com/ga4gh/htsget-refserver/internal/htscli"
"github.com/ga4gh/htsget-refserver/internal/htsconfig"
"github.com/ga4gh/htsget-refserver/internal/htsconstants"
"github.com/ga4gh/htsget-refserver/internal/htsrequest"
)
func getVariantsData(writer http.ResponseWriter, request *http.Request) {
newRequestHandler(
htsconstants.GetMethod,
htsconstants.APIEndpointVariantsData,
addRegionFromQueryString,
getVariantsDataHandler,
).handleRequest(writer, request)
}
// getVariantsData serves the actual data from AWS back to client
func getVariantsDataHandler(handler *requestHandler) {
fileURL, err := htsconfig.GetObjectPath(handler.HtsReq.GetEndpoint(), handler.HtsReq.GetID())
if err != nil {
return
}
commandChain := htscli.NewCommandChain()
removedHeadBytes := 0
removedTailBytes := 0
if handler.HtsReq.IsHeaderBlock() {
// only get the header for header blocks
commandChain.AddCommand(bcftoolsViewHeaderOnlyVCF(fileURL))
} else {
// body-based requests
commandChain.AddCommand(bcftoolsViewBodyVCF(handler.HtsReq, fileURL))
}
// execute command chain and stream output
commandWriteStream(commandChain, removedHeadBytes, removedTailBytes, handler.Writer)
}
func bcftoolsViewHeaderOnlyVCF(fileURL string) *htscli.Command {
cmd := htscli.BcftoolsView()
cmd.SetFilePath(fileURL)
cmd.SetHeaderOnly(true)
return cmd.GetCommand()
}
func bcftoolsViewBodyVCF(htsgetReq *htsrequest.HtsgetRequest, fileURL string) *htscli.Command {
cmd := htscli.BcftoolsView()
cmd.SetFilePath(fileURL)
cmd.SetHeaderOnly(false)
if !htsgetReq.AllRegionsRequested() {
cmd.SetRegion(htsgetReq.GetRegions()[0])
}
return cmd.GetCommand()
}