-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexternal_example_test.go
133 lines (119 loc) · 4.94 KB
/
external_example_test.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
// Copyright ©2011-2012 The bíogo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package external
import (
"fmt"
)
func ExampleBuild_1() {
// samtools sort [-n] [-m maxMem] <in.bam> <out.prefix>
type SamToolsSort struct {
Name string
Comment string
Cmd string `buildarg:"{{if .}}{{.}}{{else}}samtools{{end}}"` // samtools
SubCmd struct{} `buildarg:"sort"` // sort
SortNames bool `buildarg:"{{if .}}-n{{end}}"` // [-n]
MaxMem int `buildarg:"{{if .}}-m{{split}}{{.}}{{end}}"` // [-m maxMem]
InFile string `buildarg:"{{.}}"` // "<in.bam>"
OutFile string `buildarg:"{{.}}"` // "<out.prefix>"
CommandBuilder
}
s := SamToolsSort{
Name: "Sort",
SortNames: true,
MaxMem: 1e8,
InFile: "infile",
OutFile: "outfile",
}
args := Must(Build(s))
fmt.Printf("%#v\n", args)
// Output:
// []string{"samtools", "sort", "-n", "-m", "100000000", "infile", "outfile"}
}
func ExampleBuild_2() {
// samtools merge [-h inh.sam] [-n] <out.bam> <in1.bam> <in2.bam> [...]
type SamToolsMerge struct {
Name string
Comment string
Cmd string `buildarg:"{{if .}}{{.}}{{else}}samtools{{end}}"` // samtools
SubCmd struct{} `buildarg:"merge"` // merge
HeaderFile string `buildarg:"{{if .}}-h{{split}}{{.}}{{end}}"` // [-h inh.sam]
SortNames bool `buildarg:"{{if .}}-n{{end}}"` // [-n]
OutFile string `buildarg:"{{.}}"` // <out.bam>
InFiles []string `buildarg:"{{args .}}"` // <in.bam>...
CommandBuilder
}
s := &SamToolsMerge{
Name: "Merge",
Cmd: "samtools",
HeaderFile: "header",
InFiles: []string{"infile1", "infile2"},
OutFile: "outfile",
}
args := Must(Build(s))
fmt.Printf("%#v\n", args)
// Output:
// []string{"samtools", "merge", "-h", "header", "outfile", "infile1", "infile2"}
}
func ExampleBuild_3() {
// sed [-n] [-e <exp>]... [-f <file>]... [--follow-symlinks] [-i[suf]] [-l <len>] [--posix] [-r] [-s] [-s] <in>... > <out>
type InPlace struct {
Yes bool
Suf string
}
type Sed struct {
Name string
Comment string
Cmd string `buildarg:"{{if .}}{{.}}{{else}}sed{{end}}"` // sed
Quiet bool `buildarg:"{{if .}}-n{{end}}"` // [-n]
Script []string `buildarg:"{{if .}}{{mprintf \"-e\x00'%s'\" . | args}}{{end}}"` // [-e '<exp>']...
ScriptFile []string `buildarg:"{{if .}}{{mprintf \"-f\x00%s\" . | args}}{{end}}"` // [-f "<file>"]...
Follow bool `buildarg:"{{if .}}--follow-symlinks{{end}}"` // [--follow-symlinks]
InPlace InPlace `buildarg:"{{if .Yes}}-i{{with .Suf}}{{.}}{{end}}{{end}}"` // [-i[suf]]
WrapAt int `buildarg:"{{if .}}-l{{split}}{{.}}{{end}}"` // [-l <len>]
Posix bool `buildarg:"{{if .}}--posix{{end}}"` // [--posix]
ExtendRE bool `buildarg:"{{if .}}-r{{end}}"` // [-r]
Separate bool `buildarg:"{{if .}}-s{{end}}"` // [-s]
Unbuffered bool `buildarg:"{{if .}}-u{{end}}"` // [-u]
InFiles []string `buildarg:"{{args .}}"` // "<in>"...
CommandBuilder
}
s := &Sed{
Name: "Sed",
Cmd: "sed",
WrapAt: 76,
Script: []string{`s/\<hi\>/lo/g`, `s/\<left\>/right/g`},
InPlace: InPlace{true, "bottomright"},
InFiles: []string{"infile1", "infile2"},
}
args := Must(Build(s))
fmt.Printf("%#v\n", args)
// Output:
// []string{"sed", "-e", "'s/\\<hi\\>/lo/g'", "-e", "'s/\\<left\\>/right/g'", "-ibottomright", "-l", "76", "infile1", "infile2"}
}
func ExampleBuild_4() {
// bowtie [options]* <ebwt> {-1 <m1> -2 <m2> | --12 <r> | <s>} [<hit>]
type Bowtie struct {
Name string
Comment string
Cmd string `buildarg:"{{if .}}{{.}}{{else}}bowtie{{end}}"` // bowtie
Index string `buildarg:"{{.}}"` // <ebwt>
One []string `buildarg:"{{if .}}-1{{join \",\" .}}{{end}}"` // -1 <m1>
Two []string `buildarg:"{{if .}}-2{{join \",\" .}}{{end}}"` // -2 <m2>
Mixed []string `buildarg:"{{if .}}--12{{join \",\" .}}{{end}}"` // --12 <r>
Unpaired []string `buildarg:"{{if .}}{{join \",\" .}}{{end}}"` // <s>
OutFile string `buildarg:"{{if .}}{{.}}{{end}}"` // <hit>
CommandBuilder
}
b := &Bowtie{
Name: "Bowtie",
Cmd: "bowtie",
Index: "ebwt",
Unpaired: []string{"a.fa", "b.fa", "c.fa", "d.fa", "e.fa"},
OutFile: "oufile",
}
args := Must(Build(b))
fmt.Printf("%#v\n", args)
// Output:
// []string{"bowtie", "ebwt", "a.fa,b.fa,c.fa,d.fa,e.fa", "oufile"}
}