-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
68 lines (57 loc) · 1.79 KB
/
output.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
61
62
63
64
65
66
67
68
package main
import (
"bytes"
"compress/gzip"
"fmt"
"io/ioutil"
"log"
jsoniter "github.com/json-iterator/go"
)
// PanelCoverage contains all gene coverages
type PanelCoverage struct {
Identifier string
GitVersion string
GlobalTotalBases int
GlobalCoveredBases5x int
GlobalCoveredBases10x int
GlobalCoveredBases20x int
GlobalCoveredBases30x int
PerGeneCoverage map[string]Coverage
}
// Coverage data
type Coverage struct {
ENSG string
Symbol string
TotalBases int // total targeted bases
CoveredBases int // copy of BasesCovered10x for backwards compatibility
BasesCovered5x int
BasesCovered10x int
BasesCovered20x int
BasesCovered30x int
}
// outputToJSON outputs coverage to JSON file
func outputToJSON(sample string, geneCoverageMap map[string]Coverage, globalTotalBases, globalCoveredBases5x, globalCoveredBases10x, globalCoveredBases20x, globalCoveredBases30x int) {
var json = jsoniter.ConfigCompatibleWithStandardLibrary
var b bytes.Buffer
w := gzip.NewWriter(&b)
outputFilePath := fmt.Sprintf("%s_coverage.json.gz", sample)
export := PanelCoverage{
Identifier: sample,
PerGeneCoverage: geneCoverageMap,
GlobalTotalBases: globalTotalBases,
GlobalCoveredBases5x: globalCoveredBases5x,
GlobalCoveredBases10x: globalCoveredBases10x,
GlobalCoveredBases20x: globalCoveredBases20x,
GlobalCoveredBases30x: globalCoveredBases30x,
}
toWriteJSON, err := json.Marshal(export)
if err != nil {
log.Fatalf("failed convert struct FileRepresentation of sample %s into json; got %v", sample, err)
}
w.Write(toWriteJSON)
w.Close() // You must close this first to flush the bytes to the buffer.
err = ioutil.WriteFile(outputFilePath, b.Bytes(), 0644)
if err != nil {
log.Fatalf(err.Error())
}
}