diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/gyy-shovill.iml b/.idea/gyy-shovill.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/gyy-shovill.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..31d4b53 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..e6e5ffa --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + direct + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4631e9a --- /dev/null +++ b/README.md @@ -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) + + diff --git a/batch-prokka-linux-amd64 b/batch-prokka-linux-amd64 new file mode 100755 index 0000000..f58b3d1 Binary files /dev/null and b/batch-prokka-linux-amd64 differ diff --git a/batch-prokka-mac-amd64 b/batch-prokka-mac-amd64 new file mode 100755 index 0000000..da27d31 Binary files /dev/null and b/batch-prokka-mac-amd64 differ diff --git a/batch-prokka-windows-amd64 b/batch-prokka-windows-amd64 new file mode 100755 index 0000000..5de7204 Binary files /dev/null and b/batch-prokka-windows-amd64 differ diff --git a/data/adv.fa b/data/adv.fa new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..172efb6 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gyy-prokka + +go 1.16 diff --git a/logfile.log b/logfile.log new file mode 100644 index 0000000..6a01650 --- /dev/null +++ b/logfile.log @@ -0,0 +1 @@ +2021/06/10 11:16:25 参数都要填噢!! \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..be77aca --- /dev/null +++ b/main.go @@ -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() +} diff --git a/test.php b/test.php new file mode 100644 index 0000000..e69de29