-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Batch Prokka Assemblies | ||
Batch Prokka can help you execute prokka batch assemblies. | ||
|
||
# Useage | ||
|
||
You only need to specify two parameters, dataPath and outPath. | ||
|
||
For example: | ||
|
||
``` | ||
./batch-prokka-linux-amd64 -dataPath=/path/to/data -outPath=/path/to/out | ||
``` | ||
|
||
The file name format example of the source file has been given in the [data directory](data). | ||
|
||
# Cross platform | ||
|
||
You can use this program directly on Linux, Windows and Mac, as long as your device has [Prokka](https://github.com/tseemann/prokka) installed. | ||
|
||
[window](batch-prokka-windows-amd64) | ||
|
||
[mac](batch-prokka-mac-amd64) | ||
|
||
[linux](batch-prokka-linux-amd64) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module gyy-prokka | ||
|
||
go 1.16 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2021/06/10 11:16:25 参数都要填噢!! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"sort" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func main() { | ||
var outPath string | ||
var dataPath string | ||
|
||
flag.StringVar(&outPath, "outPath", "", "prokka output file path") | ||
flag.StringVar(&dataPath, "dataPath", "", "prokka source file path") | ||
|
||
flag.Parse() | ||
if (len(outPath) == 0 || len(dataPath) == 0) { | ||
logger("missing params !!") | ||
return | ||
} | ||
|
||
var files []string | ||
files, err := GetAllFile(dataPath, files) | ||
if err != nil { | ||
logger("read file error") | ||
return | ||
} | ||
|
||
for _, file := range files { | ||
length := strings.Index(file, ".") | ||
outPutDirSeg := file[0:length] | ||
desPath := outPath + "/" + outPutDirSeg + "_prokka" | ||
_, err := os.Stat(desPath) | ||
|
||
if os.IsNotExist(err) { | ||
//ret := getGenArray(outPutDirSeg, files) | ||
//file1 := ret[0] | ||
//file2 := ret[1] | ||
|
||
cmd := "prokka --compliant " + dataPath + "/" + file + " --outdir " + desPath | ||
|
||
logger(cmd) | ||
Command(cmd) | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
func Command(cmd string) error { | ||
c := exec.Command("bash", "-c", cmd) | ||
stdout, err := c.StdoutPipe() | ||
if err != nil { | ||
return err | ||
} | ||
go func() { | ||
reader := bufio.NewReader(stdout) | ||
for { | ||
readString, err := reader.ReadString('\n') | ||
if err != nil || err == io.EOF { | ||
break | ||
} | ||
fmt.Print(readString) | ||
} | ||
}() | ||
return c.Run() | ||
} | ||
|
||
func getGenArray(seg string, files []string) ([]string) { | ||
var ret []string | ||
for _, file := range files { | ||
length := strings.Index(file, "_") | ||
outPutDirSeg := file[0:length] | ||
if seg == outPutDirSeg { | ||
ret = append(ret, file) | ||
} | ||
} | ||
|
||
sort.Sort(sort.StringSlice(ret)) | ||
|
||
return ret | ||
} | ||
|
||
func GetAllFile(pathname string, s []string) ([]string, error) { | ||
rd, err := ioutil.ReadDir(pathname) | ||
if err != nil { | ||
fmt.Println("read dir fail:", err) | ||
return s, err | ||
} | ||
for _, fi := range rd { | ||
if fi.IsDir() { | ||
fullDir := pathname + "/" + fi.Name() | ||
s, err = GetAllFile(fullDir, s) | ||
if err != nil { | ||
fmt.Println("read dir fail:", err) | ||
return s, err | ||
} | ||
} else { | ||
//仅返回文件名 | ||
//fullName := pathname + "/" + fi.Name() | ||
fullName := fi.Name() | ||
s = append(s, fullName) | ||
} | ||
} | ||
return s, nil | ||
} | ||
|
||
func logger(logthis string) { | ||
filePath := "logfile.log" | ||
fmt.Println(logthis) | ||
_, err := os.Stat(filePath) | ||
if os.IsNotExist(err) { | ||
_, err := os.Create(filePath) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
} | ||
file, err := os.OpenFile(filePath, os.O_WRONLY | os.O_TRUNC, 0666) | ||
// file, err := os.OpenFile(filePath, os.O_WRONLY | os.O_APPEND, 0666) | ||
if err != nil { | ||
fmt.Printf("open file err=%v\n", err) | ||
return | ||
} | ||
|
||
defer file.Close() | ||
|
||
now := time.Now() | ||
time := now.Format("2006/01/02 15:04:05") | ||
str := fmt.Sprintf("%v %v ", time, logthis) | ||
writer := bufio.NewWriter(file) | ||
writer.WriteString(str) | ||
|
||
writer.Flush() | ||
} |