12 "github.com/kshedden/gonpy"
15 type exportNumpy struct {
19 func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
23 fmt.Fprintf(stderr, "%s\n", err)
26 flags := flag.NewFlagSet("", flag.ContinueOnError)
27 flags.SetOutput(stderr)
28 pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
29 err = flags.Parse(args)
30 if err == flag.ErrHelp {
33 } else if err != nil {
40 log.Println(http.ListenAndServe(*pprof, nil))
44 cgs, err := ReadCompactGenomes(stdin)
49 for _, cg := range cgs {
50 if cols < len(cg.Variants) {
51 cols = len(cg.Variants)
55 out := make([]uint16, rows*cols)
56 for row, cg := range cgs {
57 for i, v := range cg.Variants {
58 out[row*cols+i] = uint16(v)
61 w := bufio.NewWriter(cmd.output)
62 npw, err := gonpy.NewWriter(nopCloser{w})
66 npw.Shape = []int{rows, cols}
75 type nopCloser struct {
79 func (nopCloser) Close() error { return nil }