-
Notifications
You must be signed in to change notification settings - Fork 2
/
uploadSample.go
67 lines (56 loc) · 1.51 KB
/
uploadSample.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
package metagenomics
import (
"errors"
"fmt"
"github.com/chanzuckerberg/czid-cli/pkg/czid"
"github.com/spf13/cobra"
)
var sampleName string
// uploadSampleCmd represents the uploadSample command
var uploadSampleCmd = &cobra.Command{
Use: "upload-sample [r1path] [r2path]?",
Short: "Upload a single sample",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validateCommonArgs(); err != nil {
return err
}
if len(args) == 0 {
return errors.New("missing required argument: r1path")
}
r1path := args[0]
r2path := ""
if sampleName == "" {
sampleName = czid.ToSampleName(r1path)
}
sampleFiles := map[string]czid.SampleFiles{
sampleName: {Single: []string{r1path}},
}
if len(args) > 1 {
r2path = args[1]
sampleFiles[sampleName] = czid.SampleFiles{R1: []string{r1path}, R2: []string{r2path}}
}
if len(args) > 2 {
return fmt.Errorf("too many positional arguments (maximum 2), args: %v", args)
}
if r1path == r2path {
return errors.New("r1 and r2 cannot be the same file")
}
return czid.UploadSamplesFlow(
sampleFiles,
stringMetadata,
projectName,
metadataCSVPath,
workflow,
czid.SampleOptions{
Technology: Technologies[technology],
},
disableBuffer,
)
},
}
func init() {
MetagenomicsCmd.AddCommand(uploadSampleCmd)
loadSharedFlags(uploadSampleCmd)
uploadSampleCmd.Flags().StringVarP(&sampleName, "sample-name", "s", "", "Sample name. Optional, defaults to the base file name of r1path with extensions and _R1 removed")
}