-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalculateCytoMethylationPerc.go
77 lines (69 loc) · 1.99 KB
/
CalculateCytoMethylationPerc.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
69
70
71
72
73
74
75
76
77
package goio
import (
"fmt"
"log"
"strconv"
)
type CalulateCytoMethylationPerc struct {
*Mapper
MinCov int
CytoContext string
}
func (m *CalulateCytoMethylationPerc) HandleDataRow(dataRow *[]string) int {
if dataRow != nil {
locusCytoContext := (*dataRow)[5]
if m.CytoContext != "" && m.CytoContext != locusCytoContext {
return 0
}
methylCountStr := (*dataRow)[3]
methylCount, err := strconv.ParseInt(methylCountStr, 10, 32)
if err != nil {
log.Fatal(err)
}
unMethylCount, err := strconv.ParseInt((*dataRow)[4], 10, 32)
if err != nil {
log.Fatal(err)
}
var coverage int64 = methylCount + unMethylCount
if coverage < int64(m.MinCov) {
return 0
}
startPosStr := (*dataRow)[1]
startPos, err := strconv.ParseInt(startPosStr, 10, 32)
zeroBasedStartPos := startPos - 1
if err != nil {
log.Fatal(err)
}
strand := (*dataRow)[2]
var methylFraction float64
if coverage > 0 {
methylFraction = float64(methylCount) / float64(methylCount+unMethylCount)
} else {
methylFraction = -1.0
}
newDataRow := []string{(*dataRow)[0], strconv.FormatInt(zeroBasedStartPos, 10),
startPosStr,
strand,
methylCountStr,
strconv.FormatInt(coverage, 10),
strconv.FormatFloat(methylFraction, 'f', 5, 64),
locusCytoContext,
(*dataRow)[6]}
//*dataRow = append(*dataRow, strconv.FormatInt(coverage, 10), strconv.FormatFloat(methylFraction, 'f', 5, 64))
m.OutputRowChannel <- newDataRow
//fmt.Fprintln(m.gzipWriter, strings.Join(newDataRow, "\t"))
return 1
} else {
return 0
}
}
func (m *CalulateCytoMethylationPerc) HandleHeader(header *[]string) int {
fmt.Println("Handling header ...")
//fmt.Fprintln(m.gzipWriter, strings.Join(*header, "\t"))
newHeader := []string{"#Chromosome|str", "0BasedStart|int", "Stop|int",
"Strand|str", "MethylCount|int", "TotalCount|int", "MethylFraction|float",
"CytoContext|str", "CytoTriNucleotide|str"}
m.OutputRowChannel <- newHeader
//fmt.Fprintln(m.gzipWriter, strings.Join(newHeader, "\t"))
return 1
}