This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·155 lines (111 loc) · 3.47 KB
/
main.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
//##### package & import
package main
import (
"os"
"fmt"
"log"
"time"
"os/exec"
"net/http"
"io/ioutil"
"encoding/hex"
"crypto/sha256"
"html/template"
"path/filepath"
)
//##### Struct & Const
var numParrell int
var dirData, dirAFPG, dirAFDB, endDate string
const (
PROGRAM = "Alphafold Web Server "
VERSION = "1.0 "
PRGDATE = "2022.02 "
AUTHORS = "LI,YAN-JIE "
)
//##### Functions
//### Error Report
func ExportError(funcName string, err error) {
if err != nil {
log.Fatal("\n# Error - ", funcName," :\n< ", err, " >\n")
} //if
} //func ExportError
//### Router
func routePage(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(16)
switch r.Method {
case "GET" :
t, _ := template.ParseFiles("user.html")
t.Execute(w, nil)
case "POST" :
if len(r.Form["UserSequ"]) == 0 { return }
userTime := time.Now().Format("2006-01-02_15-04-05")
userSequ := r.Form["UserSequ"][0]
sessionID := Sha256Encoding(userTime + userSequ)
dirSession := filepath.Join(dirData, sessionID)
CreateDirIfNotExist(dirSession)
http.Redirect(w, r, "http://120.126.17.200:8082/" + sessionID, 302)
pathFasta := filepath.Join(dirSession, "querySeq.fasta")
fileConts := ">" + userTime + "\n" + userSequ + "\n"
ioutil.WriteFile(pathFasta, []byte(fileConts), 0777)
RunAlphaFold(dirSession)
} //switch r.Method
} //func routePage
//### System
func CreateDirIfNotExist(dirName string) {
if _, err := os.Stat(dirName); os.IsNotExist(err) {
err = os.MkdirAll(dirName, 0777)
ExportError("os.MkdirAll", err)
} //if
} //func CreateDirIfNotExist
func Sha256Encoding(src string) string {
m := sha256.New()
m.Write([]byte(src))
return hex.EncodeToString(m.Sum(nil))
} //func Sha256Encoding
func InitialProgram(Argvs []string, lenArgs int) {
if len(Argvs) < lenArgs {
log.Fatal("\n# Usage :\n " + Argvs[0] + " dir_data")
} //if
CreateDirIfNotExist(Argvs[1])
dirData = Argvs[1]
dirAFPG = "/SSD_Intel/dir_ssd/AFserver/alphafold/docker/run_docker.py"
dirAFDB = "/SSD_Intel/dir_ssd/AFserver/AFDB"
endDate = "--max_template_date=2021-12-31"
} //func IniPrg
func RunAlphaFold(dirSession string) bool {
pathFasta := "--fasta_paths=" + filepath.Join(dirSession, "querySeq.fasta")
pathData := "--data_dir=" + dirAFDB
pathOutput := "--output_dir=" + dirSession
for true {
if numParrell == 0 {
fmt.Println(dirSession, "Start")
numParrell = 1
cmd := exec.Command("python3", dirAFPG, pathFasta, pathData, pathOutput, endDate)
cmd.Start()
cmd.Wait()
numParrell = 0
fmt.Println(dirSession, "End")
break
} else {
time.Sleep(30 * time.Second)
}
}
return true
}
//##### Main
func main() {
//### Start Servers
fmt.Println("┌---------- Program Information ------------┐")
fmt.Println("| Name : ", PROGRAM, "|")
fmt.Println("| Version : ", VERSION, "|")
fmt.Println("| Date : ", PRGDATE, "|")
fmt.Println("| Authors : ", AUTHORS, "|")
fmt.Println("└-------------------------------------------┘")
//### Setup
InitialProgram(os.Args, 2)
//### Routers
http.HandleFunc("/", routePage)
//### Listen at TCL Port
err := http.ListenAndServe(":8081", nil)
ExportError("http.ListenAndServe", err)
} //func main()