-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgene.go
More file actions
207 lines (189 loc) · 5.54 KB
/
Copy pathgene.go
File metadata and controls
207 lines (189 loc) · 5.54 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* gene.go specifies the Gene struct for the phageLog project
* Author: Elizabeth Koning
* Written in 2017
*/
package main
import (
"strconv"
)
type Gene struct {
// Strings: name, codingPot, blast, function, functionSource, notes
// int: num, start, stop, sdRank, altGeneMark, altGlimer, lastEnd, lengthRank, stStart
// bool: forward, geneMark, glimmer
// float: sdScore
name string
num int
start int
stop int
forward bool
codingPot string
sdScore float64
sdRank int
blast string
geneMark bool
glimmer bool
altGeneMark int
altGlimmer int
function string
functionSource string
notes string
lastEnd int
lengthRank int
stStart int
}
func (g *Gene) getOutput() string {
result := g.title() + "\n"
result += g.SSC() + "\n"
result += g.CP() + "\n"
result += g.SD() + "\n"
result += g.SCS() + "\n"
result += g.gap() + "\n"
result += g.BLAST() + "\n"
result += g.LO() + "\n"
result += g.ST() + "\n"
result += g.F() + "\n"
result += g.FS() + "\n"
result += g.other() + "\n"
return result
}
func (g *Gene) getCSV() string {
return g.name +"," + strconv.Itoa(g.num) + "," + g.SSC() + "," + g.CP() + "," + g.SD() + "," + g.SCS() + ","+ g.gap() + "," + g.BLAST() + "," + g.LO() + "," + g.ST() + "," + g.F() + "," + g.FS() + "\n"
}
// generates the title of the output
func (g *Gene) title() string {
return "Phage " + g.name + ", Gene #" + strconv.Itoa(g.num) + ":";
}
// generates the start and stop (SSC) description
func (g *Gene) SSC() string {
result := "SSC: Start: " + strconv.Itoa(g.start) + " Stop: " + strconv.Itoa(g.stop);
if g.forward {
result += " (forward).";
} else {
result += " (reverse).";
}
return result;
}
// adds label to output describing CP coverage
func (g *Gene) CP() string {
if g.codingPot == "all" {
g.codingPot = "ORF includes all coding potential shown in GeneMark-CP output."
}
return "CP: " + g.codingPot
}
// generate the output describing the SD score and its rank
func (g *Gene) SD() string {
var rank string
if g.sdRank == 1 {
rank = ""
} else {
rank = findRank(g.sdRank) + " "
}
return "SD: " + strconv.FormatFloat(g.sdScore, 'g', -1, 64) + "; " + rank + "best score."
}
// calculate length of gene
func (g * Gene) length() int {
if g.stop-g.start > 0 {
return g.stop-g.start+1
} else {
return g.start-g.stop+1
}
}
// generate the output describing the length and rank of the length
func (g *Gene) LO() string {
//result := "LO: ";
//if g.stop-g.start > 0 {
// result += strconv.Itoa(g.stop-g.start+1) + " bp; "
//} else {
// result += strconv.Itoa(g.start-g.stop+1) + " bp; "
//}
//if (g.lengthRank != 1) {
// result += findRank(g.lengthRank) + " "
//}
//result += "longest possible ORF."
//return result
result := "LO: " + strconv.Itoa( g.length() ) + " bp; "
if (g.lengthRank != 1) {
result += findRank(g.lengthRank) + " "
}
result += "longest possible ORF."
return result
}
// generate the output describing Starterator results
func (g *Gene) ST() string {
if g.stStart == 0 {
return "ST: Starterator not available."
} else if g.start == g.stStart {
return "ST: Starterator agrees with start at bp " + strconv.Itoa(g.stStart)
} else {
return "ST: Starterator suggested start at bp " + strconv.Itoa(g.stStart)
}
}
// generate the ouptut describing the gap or overlap
func (g *Gene) gap() string {
result := "Gap: ";
// if first gene, there is no previous gene
if g.num == 1 {
result += "No previous gene for first gene."
} else {
// if forward, take difference between endLast and start,
if g.start < g.stop {
if g.lastEnd >= g.start { // overlap, add one for including both ends
result += strconv.Itoa( g.lastEnd - g.start + 1 ) + " overlap"
} else { // gap, subtract one to not include ends
result += strconv.Itoa( g.start - g.lastEnd - 1 ) + " gap"
}
} else {
// if reverse, take the difference between endLast and start,
if g.lastEnd >= g.stop { // overlap
result += strconv.Itoa( g.lastEnd - g.stop + 1 ) + " overlap"
} else { // gap
result += strconv.Itoa( g.stop - g.lastEnd - 1 ) + " gap"
}
}
result += " with previous gene."
}
return result
}
// generate the output describing the BLAST results
func (g *Gene) BLAST() string {
// TODO make this more elegant, and different possibilities
return "BLAST: " + g.blast
}
// generates function description with a label for output
func (g *Gene) F() string {
// TODO make more elegant, more checks
return "F: " + g.function
}
// generates function source description with label for output
func (g *Gene) FS() string {
if g.functionSource == "all" {
g.functionSource = "Consulted BLAST, Phamerator, and HHpred."
}
return "FS: " + g.functionSource
}
// generates the description of the source of the start choice
func (g *Gene) SCS() string {
if g.glimmer {
if g.geneMark {
return "SCS: Glimmer and GeneMark."
} else if g.altGeneMark == 0 {
return "SCS: Called by Glimmer, not GeneMark."
} else {
return "SCS: Called by Glimmer, GeneMark suggested start at " + strconv.Itoa(g.altGeneMark)
}
} else {
if g.geneMark {
if g.altGlimmer == 0 {
return "SCS: Called by GeneMark, not Glimmer."
} else {
return "SCS: Called by GeneMark, Glimmer suggested start at " + strconv.Itoa(g.altGlimmer) + "."
}
} else {
return "SCS: No source."
}
}
}
// generates notes with the "Other notes: " label for output
func (g *Gene) other() string {
return "Other notes: " + g.notes;
}