14 "git.arvados.org/arvados.git/sdk/go/arvados"
15 "github.com/kshedden/gonpy"
16 log "github.com/sirupsen/logrus"
19 type exportNumpy struct{}
21 func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
25 fmt.Fprintf(stderr, "%s\n", err)
28 flags := flag.NewFlagSet("", flag.ContinueOnError)
29 flags.SetOutput(stderr)
30 pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
31 runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
32 projectUUID := flags.String("project", "", "project `UUID` for output data")
33 priority := flags.Int("priority", 500, "container request priority")
34 inputFilename := flags.String("i", "-", "input `file`")
35 outputFilename := flags.String("o", "-", "output `file`")
36 err = flags.Parse(args)
37 if err == flag.ErrHelp {
40 } else if err != nil {
46 log.Println(http.ListenAndServe(*pprof, nil))
51 if *outputFilename != "-" {
52 err = errors.New("cannot specify output file in container mode: not implemented")
55 runner := arvadosContainerRunner{
56 Name: "lightning export-numpy",
57 Client: arvados.NewClientFromEnv(),
58 ProjectUUID: *projectUUID,
63 err = runner.TranslatePaths(inputFilename)
67 runner.Args = []string{"export-numpy", "-local=true", "-i", *inputFilename, "-o", "/mnt/output/library.npy"}
69 output, err = runner.Run()
73 fmt.Fprintln(stdout, output+"/library.npy")
77 var input io.ReadCloser
78 if *inputFilename == "-" {
79 input = ioutil.NopCloser(stdin)
81 input, err = os.Open(*inputFilename)
87 cgs, err := ReadCompactGenomes(input)
96 for _, cg := range cgs {
97 if cols < len(cg.Variants) {
98 cols = len(cg.Variants)
102 out := make([]uint16, rows*cols)
103 for row, cg := range cgs {
104 for i, v := range cg.Variants {
105 out[row*cols+i] = uint16(v)
109 var output io.WriteCloser
110 if *outputFilename == "-" {
111 output = nopCloser{stdout}
113 output, err = os.OpenFile(*outputFilename, os.O_CREATE|os.O_WRONLY, 0777)
119 bufw := bufio.NewWriter(output)
120 npw, err := gonpy.NewWriter(nopCloser{bufw})
124 npw.Shape = []int{rows, cols}
137 type nopCloser struct {
141 func (nopCloser) Close() error { return nil }