-
Notifications
You must be signed in to change notification settings - Fork 16
/
itolup.go
86 lines (70 loc) · 2.48 KB
/
itolup.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
package cmd
import (
"fmt"
goio "io"
"os"
"time"
"github.com/evolbioinfo/gotree/io"
"github.com/evolbioinfo/gotree/tree"
"github.com/evolbioinfo/gotree/upload"
"github.com/spf13/cobra"
)
var itoluploadid string
var itolprojectname string
var itoltreename string
var itolannotationfile string
// itolCmd represents the itol command
var itolCmd = &cobra.Command{
Use: "itol",
Short: "Upload a tree to iTOL and display the access url",
Long: `Upload a tree to iTOL and display the access url.
If --id is given, it uploads the tree to the itol account corresponding to the user upload ID.
The upload id is accessible by enabling "Batch upload" option in iTOL user settings.
If --id is not given, it uploads the tree without account, and will be automatically deleted after 30 days.
If several trees are included in the input file, it will upload all of them, waiting 1 second between each upload
It is possible to give itol annotation files to the uploader:
gotree upload itol -i tree.tree --name tree --user-id uploadkey --project project annotation*.txt
Urls are written on stdout
Server responses are written on stderr
So:
gotree upload itol -i tree.tree --name tree --user-id uploadkey --project project annotation*.txt > urls
Will store only urls in the output file
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
var treefile goio.Closer
var treechan <-chan tree.Trees
var url, response string
// args: All annotation files to add to the upload
upld := upload.NewItolUploader(itoluploadid, itolprojectname, args...)
i := 0
if treefile, treechan, err = readTrees(intreefile); err != nil {
io.LogError(err)
return
}
defer treefile.Close()
for reftree := range treechan {
if reftree.Err != nil {
io.LogError(reftree.Err)
return reftree.Err
}
if url, response, err = upld.Upload(fmt.Sprintf("%s_%03d", itoltreename, i), reftree.Tree); err != nil {
io.LogError(err)
return
}
fmt.Println(url)
fmt.Fprintf(os.Stderr, "-------------------\n")
fmt.Fprintf(os.Stderr, "<Server response>\n")
fmt.Fprintf(os.Stderr, response)
fmt.Fprintf(os.Stderr, "-------------------\n")
time.Sleep(1 * time.Second)
i++
}
return
},
}
func init() {
uploadCmd.AddCommand(itolCmd)
itolCmd.Flags().StringVar(&itoluploadid, "user-id", "", "iTOL User upload id")
itolCmd.Flags().StringVar(&itolprojectname, "project", "", "iTOL project to upload the tree")
itolCmd.Flags().StringVar(&itoltreename, "name", "tree", "iTOL tree name prefix")
}