Fix input arg in export.
authorTom Clegg <tom@tomclegg.ca>
Wed, 4 Mar 2020 01:54:03 +0000 (20:54 -0500)
committerTom Clegg <tom@tomclegg.ca>
Wed, 4 Mar 2020 01:54:03 +0000 (20:54 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

exportnumpy.go
filter.go
import.go
pca.go

index 78d87af796c4252f0029404f4fa3572c713b6b3a..2c902239f037bb94703ea19851ec6355359c3bc2 100644 (file)
@@ -6,6 +6,7 @@ import (
        "flag"
        "fmt"
        "io"
+       "io/ioutil"
        "log"
        "net/http"
        _ "net/http/pprof"
@@ -29,8 +30,8 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
        pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
        runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
        projectUUID := flags.String("project", "", "project `UUID` for output data")
-       inputFilename := flags.String("i", "", "input `file`")
-       outputFilename := flags.String("o", "", "output `file`")
+       inputFilename := flags.String("i", "-", "input `file`")
+       outputFilename := flags.String("o", "-", "output `file`")
        err = flags.Parse(args)
        if err == flag.ErrHelp {
                err = nil
@@ -46,7 +47,7 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
        }
 
        if !*runlocal {
-               if *outputFilename != "" {
+               if *outputFilename != "-" {
                        err = errors.New("cannot specify output file in container mode: not implemented")
                        return 1
                }
@@ -69,7 +70,21 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
                return 0
        }
 
-       cgs, err := ReadCompactGenomes(stdin)
+       var input io.ReadCloser
+       if *inputFilename == "-" {
+               input = ioutil.NopCloser(stdin)
+       } else {
+               input, err = os.Open(*inputFilename)
+               if err != nil {
+                       return 1
+               }
+               defer input.Close()
+       }
+       cgs, err := ReadCompactGenomes(input)
+       if err != nil {
+               return 1
+       }
+       err = input.Close()
        if err != nil {
                return 1
        }
@@ -88,7 +103,7 @@ func (cmd *exportNumpy) RunCommand(prog string, args []string, stdin io.Reader,
        }
 
        var output io.WriteCloser
-       if *outputFilename == "" {
+       if *outputFilename == "-" {
                output = nopCloser{stdout}
        } else {
                output, err = os.OpenFile(*outputFilename, os.O_CREATE|os.O_WRONLY, 0777)
index 87d94ef62c9b0817af27e729aa6018ef3384ca20..26e55bafa4efea47cb8ffda6c41ca45587272869 100644 (file)
--- a/filter.go
+++ b/filter.go
@@ -32,8 +32,8 @@ func (cmd *filterer) RunCommand(prog string, args []string, stdin io.Reader, std
        pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
        runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
        projectUUID := flags.String("project", "", "project `UUID` for output data")
-       inputFilename := flags.String("i", "", "input `file`")
-       outputFilename := flags.String("o", "", "output `file`")
+       inputFilename := flags.String("i", "-", "input `file`")
+       outputFilename := flags.String("o", "-", "output `file`")
        maxvariants := flags.Int("max-variants", -1, "drop tiles with more than `N` variants")
        mincoverage := flags.Float64("min-coverage", 1, "drop tiles with coverage less than `P` across all haplotypes (0 < P ≤ 1)")
        maxtag := flags.Int("max-tag", -1, "drop tiles with tag ID > `N`")
@@ -53,7 +53,7 @@ func (cmd *filterer) RunCommand(prog string, args []string, stdin io.Reader, std
        }
 
        if !*runlocal {
-               if *outputFilename != "" {
+               if *outputFilename != "-" {
                        err = errors.New("cannot specify output file in container mode: not implemented")
                        return 1
                }
@@ -83,7 +83,7 @@ func (cmd *filterer) RunCommand(prog string, args []string, stdin io.Reader, std
        }
 
        var infile io.ReadCloser
-       if *inputFilename == "" {
+       if *inputFilename == "-" {
                infile = ioutil.NopCloser(stdin)
        } else {
                infile, err = os.Open(*inputFilename)
@@ -159,7 +159,7 @@ func (cmd *filterer) RunCommand(prog string, args []string, stdin io.Reader, std
        log.Print("filtering done")
 
        var outfile io.WriteCloser
-       if *outputFilename == "" {
+       if *outputFilename == "-" {
                outfile = nopCloser{cmd.output}
        } else {
                outfile, err = os.OpenFile(*outputFilename, os.O_CREATE|os.O_WRONLY, 0777)
index 14b3667ed7fec34df0c75a4ef5504b4dc356d838..e6a4b3a5cb8961afd73a7177d04b83f23dcda632 100644 (file)
--- a/import.go
+++ b/import.go
@@ -45,7 +45,7 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
        flags.SetOutput(stderr)
        flags.StringVar(&cmd.tagLibraryFile, "tag-library", "", "tag library fasta `file`")
        flags.StringVar(&cmd.refFile, "ref", "", "reference fasta `file`")
-       flags.StringVar(&cmd.outputFile, "o", "", "output `file`")
+       flags.StringVar(&cmd.outputFile, "o", "-", "output `file`")
        flags.StringVar(&cmd.projectUUID, "project", "", "project `UUID` for output data")
        flags.BoolVar(&cmd.runLocal, "local", false, "run on local host (default: run in an arvados container)")
        pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
@@ -88,7 +88,7 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
                                return 1
                        }
                }
-               if cmd.outputFile == "" {
+               if cmd.outputFile == "-" {
                        cmd.outputFile = "/mnt/output/library.gob"
                } else {
                        // Not yet implemented, but this should write
@@ -121,7 +121,7 @@ func (cmd *importer) RunCommand(prog string, args []string, stdin io.Reader, std
        }()
 
        var output io.WriteCloser
-       if cmd.outputFile == "" {
+       if cmd.outputFile == "-" {
                output = nopCloser{stdout}
        } else {
                output, err = os.OpenFile(cmd.outputFile, os.O_CREATE|os.O_WRONLY, 0777)
diff --git a/pca.go b/pca.go
index 0073823c6cb82de5d0f8376577124f1fc2687db6..cd68eeb897e7fefda071f97c1d2eb26142de12ad 100644 (file)
--- a/pca.go
+++ b/pca.go
@@ -21,7 +21,7 @@ func (cmd *pythonPCA) RunCommand(prog string, args []string, stdin io.Reader, st
        flags := flag.NewFlagSet("", flag.ContinueOnError)
        flags.SetOutput(stderr)
        projectUUID := flags.String("project", "", "project `UUID` for output data")
-       inputFilename := flags.String("i", "", "input `file`")
+       inputFilename := flags.String("i", "-", "input `file`")
        err = flags.Parse(args)
        if err == flag.ErrHelp {
                err = nil