-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions_test.go
269 lines (225 loc) · 9.41 KB
/
functions_test.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package main
import (
"fmt"
"io/ioutil"
"strconv"
"strings"
"testing"
)
// test ReadProteinsFASTA function
func TestReadProteinsFASTA(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/ReadProteinsFASTA/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/ReadProteinsFASTA/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
reader := GenerateFASTAReader(filePath)
functionToString := strings.TrimSpace(fmt.Sprint(ReadProteinsFASTA(reader)))
if outputFile != functionToString {
t.Errorf("ReadProteinsFASTA() = %v, want %v", strings.TrimSpace(outputFile), functionToString)
}
}
}
// test TranslateDNA function
func TestTranslateDNA(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/TranslateDNA/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/TranslateDNA/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
reader := GenerateDNAReader(filePath)
functionToString := fmt.Sprint(TranslateDNA(reader))
if outputFile != functionToString {
t.Errorf("TranslateDNA() = %v, want %v", outputFile, functionToString)
}
}
}
// test ReadParameters function
func TestReadParameters(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/ReadParameters/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/ReadParameters/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
reader := ReadParameters(filePath)
if outputFile != fmt.Sprint(reader) {
t.Errorf("ReadParameters() = %v, want %v", outputFile, fmt.Sprint(reader))
}
}
}
// test ReadAAIndexMap function
func TestReadAAIndexMap(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/ReadAAIndexMap/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/ReadAAIndexMap/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
reader := ReadAAIndexMap(filePath)
if outputFile != fmt.Sprint(reader) {
t.Errorf("ReadAAIndexMap() = %v, want %v", outputFile, fmt.Sprint(reader))
}
}
}
// test NamesToChar function
func TestNamesToChar(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/NamesToChar/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/NamesToChar/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
reader := NameToChar(filePath)
if outputFile != fmt.Sprint(reader) {
t.Errorf("NamesToChar() = %v, want %v", outputFile, fmt.Sprint(reader))
}
}
}
// test TranslateCodon function
func TestTranslateCodon(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/TranslateCodon/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/TranslateCodon/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
inputString, _ := readFileToString(filePath)
reader := TranslateCodon(inputString)
if reader.Identifier != outputFile {
t.Errorf("TranslateCodon() = %v, want %v", outputFile, reader)
}
}
}
// test TranscribeDNA function
func TestTranscribeDNA(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/TranscribeDNA/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/TranscribeDNA/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
inputString, _ := readFileToString(filePath)
reader := TranscribeDNA(inputString)
//fmt.Println("\n", reader)
if reader != outputFile {
t.Errorf("TranscribeDNA() = %v, want %v", outputFile, reader)
}
}
}
// test ReadCIFToFasta function
func TestReadCIFToFasta(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/ReadCIFToFasta/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/ReadCIFToFasta/output_%d.txt", i)
// Compare the expected result with the actual result from checkIfInBounds function
outputFile, _ := readFileToString(outputFilePath)
reader := GenerateCIFReader(filePath)
protein, _ := ReadCIFToFasta(reader)
if outputFile != fmt.Sprint(protein) {
t.Errorf("ReadProteinsFASTA() = %v, want %v", outputFile, fmt.Sprint(protein))
}
}
}
// TestIdentifyHelicies tests the IdentifyHelicies function
func TestIdentifyHelicies(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/IdentifyHelicies/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/IdentifyHelicies/output_%d.txt", i)
// Read the expected output file
outputFile, _ := readFileToString(outputFilePath)
// Read the input file and parse it into CFScoreArray
inputString, _ := readFileToString(filePath)
CFScoreArray, _ := parseProteinPredArray(inputString)
// Run the IdentifyHelicies function and get the result
reader := IdentifyHelicies(CFScoreArray)
// Compare the result with the expected output
if fmt.Sprint(reader) != outputFile {
t.Errorf("IdentifyHelicies() = %v, want %v", outputFile, fmt.Sprint(reader))
}
}
}
// TestIdentifySheets2 tests the IdentifySheets2 function
func TestIdentifySheets2(t *testing.T) {
// Loop through test cases, using indices from 0 to 3
for i := 0; i <= 3; i++ {
// Generate a file path for the input of each test case
filePath := fmt.Sprintf("Tests/input/IdentifySheets2/input_%d.txt", i)
// Generate a file path for the expected output of each test case
outputFilePath := fmt.Sprintf("Tests/output/IdentifySheets2/output_%d.txt", i)
// Read the expected output file
outputFile, _ := readFileToString(outputFilePath)
// Read the input file and parse it into CFScoreArray
inputString, _ := readFileToString(filePath)
CFScoreArray, _ := parseProteinPredArray(inputString)
// Run the IdentifySheets2 function and get the result
reader := IdentifySheets2(CFScoreArray)
// Compare the result with the expected output
if fmt.Sprint(reader) != outputFile {
t.Errorf("IdentifyHelicies() = %v, want %v", outputFile, fmt.Sprint(reader))
}
}
}
func readFileToString(filePath string) (string, error) {
// Read the file
data, err := ioutil.ReadFile(filePath)
if err != nil {
// If there's an error, return the empty string and the error
return "", err
}
// Convert the byte slice to a string and return it
return string(data), nil
}
// parseProteinPredArray parses a string into a slice of CFScore structs.
func parseProteinPredArray(input string) ([]CFScore, error) {
// Trim the leading and trailing brackets and split the string by '} {'
trimmedInput := strings.Trim(input, "[]")
splitInput := strings.Split(trimmedInput, "} {")
var scores []CFScore
for _, s := range splitInput {
// Remove any leading or trailing braces or spaces
trimmedScore := strings.Trim(s, "{} ")
// Split the trimmed string by space to get individual scores
scoreParts := strings.Fields(trimmedScore)
if len(scoreParts) != 3 {
return nil, fmt.Errorf("invalid score format: %s", s)
}
// Convert the string scores to float64 and create a CFScore struct
helix, err := strconv.ParseFloat(scoreParts[0], 64)
if err != nil {
return nil, err
}
sheet, err := strconv.ParseFloat(scoreParts[1], 64)
if err != nil {
return nil, err
}
loop, err := strconv.ParseFloat(scoreParts[2], 64)
if err != nil {
return nil, err
}
scores = append(scores, CFScore{Helix: helix, Sheet: sheet, Loop: loop})
}
return scores, nil
}