-
Notifications
You must be signed in to change notification settings - Fork 57
/
3rd-gc.go
87 lines (69 loc) · 1.82 KB
/
3rd-gc.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
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
)
// from https://stackoverflow.com/questions/24999079/reading-csv-file-in-go
func readCsvFile(filePath string) [][]string {
f, err := os.Open(filePath)
if err != nil {
log.Fatal("Unable to read input file " + filePath, err)
}
defer f.Close()
csvReader := csv.NewReader(f)
records, err := csvReader.ReadAll()
if err != nil {
log.Fatal("Unable to parse file as CSV for " + filePath, err)
}
return records
}
func main() {
// Read the codon/amino acid table
codons := readCsvFile("codon-table-grouped.csv")[1:]
c2s:= make(map[string]string)
for _, element := range codons {
c2s[element[1]]=element[0]
}
// read the codons
virvac := readCsvFile("side-by-side.csv")[1:]
matches := 0.0
for _, element := range virvac {
vir:=element[1]
vac:=element[2]
var our string
var prop string
fmt.Printf("%s v %s, amino: %s == %s. ",
vir, vac,
c2s[vir], c2s[vac])
// base case, don't do anything
our = vir
// don't do anything if codon ends on G or C already
if(vir[2] == 'G' || vir[2] =='C') {
fmt.Printf("Codon ended on G or C already, not doing anything.")
} else {
prop = vir[:2]+"G"
fmt.Printf("Attempting G substitution, new candidate '%s'. ", prop)
if(c2s[vir] == c2s[prop]) {
fmt.Printf("Amino acid still the same, done!")
our = prop
} else {
fmt.Printf("Oops, amino acid changed. Trying C, new candidate '%s'. ", prop)
prop = vir[:2]+"C"
if(c2s[vir] == c2s[prop]) {
fmt.Printf("Amino acid still the same, done!")
our=prop
}
}
}
fmt.Printf(" ")
if(vac == our) {
fmt.Printf("Matched the vaccine!\n")
matches++
} else {
fmt.Printf("No match.\n")
}
}
fmt.Printf("%.1f%%\n", 100.0*matches/float64(len(virvac)))
}