"bufio"
"compress/gzip"
"encoding/gob"
+ "errors"
"flag"
"fmt"
"io"
"sync"
"sync/atomic"
"time"
+
+ "git.arvados.org/arvados.git/sdk/go/arvados"
)
type importer struct {
tagLibraryFile string
refFile string
+ outputFile string
+ projectUUID string
+ runLocal bool
encoder *gob.Encoder
}
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.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`")
err = flags.Parse(args)
if err == flag.ErrHelp {
return 0
} else if err != nil {
return 2
- } else if cmd.refFile == "" || cmd.tagLibraryFile == "" {
- fmt.Fprintln(os.Stderr, "cannot run without -tag-library and -ref arguments")
+ } else if cmd.tagLibraryFile == "" {
+ fmt.Fprintln(os.Stderr, "cannot import without -tag-library argument")
return 2
} else if flags.NArg() == 0 {
flags.Usage()
}()
}
+ if !cmd.runLocal {
+ runner := arvadosContainerRunner{
+ Name: "lightning import",
+ Client: arvados.NewClientFromEnv(),
+ ProjectUUID: cmd.projectUUID,
+ RAM: 30000000000,
+ VCPUs: 16,
+ }
+ err = runner.TranslatePaths(&cmd.tagLibraryFile, &cmd.refFile, &cmd.outputFile)
+ if err != nil {
+ return 1
+ }
+ inputs := flags.Args()
+ for i := range inputs {
+ err = runner.TranslatePaths(&inputs[i])
+ if err != nil {
+ return 1
+ }
+ }
+ if cmd.outputFile == "-" {
+ cmd.outputFile = "/mnt/output/library.gob"
+ } else {
+ // Not yet implemented, but this should write
+ // the collection to an existing collection,
+ // possibly even an in-place update.
+ err = errors.New("cannot specify output file in container mode: not implemented")
+ return 1
+ }
+ runner.Args = append([]string{"import", "-local=true", "-tag-library", cmd.tagLibraryFile, "-ref", cmd.refFile, "-o", cmd.outputFile}, inputs...)
+ var output string
+ output, err = runner.Run()
+ if err != nil {
+ return 1
+ }
+ fmt.Fprintln(stdout, output+"/library.gob")
+ return 0
+ }
+
infiles, err := listInputFiles(flags.Args())
if err != nil {
return 1
log.Printf("tilelib.Len() == %d", tilelib.Len())
}
}()
- w := bufio.NewWriter(stdout)
- cmd.encoder = gob.NewEncoder(w)
- err = cmd.tileGVCFs(tilelib, infiles)
+
+ var output io.WriteCloser
+ if cmd.outputFile == "-" {
+ output = nopCloser{stdout}
+ } else {
+ output, err = os.OpenFile(cmd.outputFile, os.O_CREATE|os.O_WRONLY, 0777)
+ if err != nil {
+ return 1
+ }
+ defer output.Close()
+ }
+ bufw := bufio.NewWriter(output)
+ cmd.encoder = gob.NewEncoder(bufw)
+
+ err = cmd.tileInputs(tilelib, infiles)
+ if err != nil {
+ return 1
+ }
+ err = bufw.Flush()
if err != nil {
return 1
}
- err = w.Flush()
+ err = output.Close()
if err != nil {
return 1
}
return
}
-func (cmd *importer) tileGVCFs(tilelib *tileLibrary, infiles []string) error {
+func (cmd *importer) tileInputs(tilelib *tileLibrary, infiles []string) error {
starttime := time.Now()
errs := make(chan error, 1)
todo := make(chan func() error, len(infiles)*2)
}
func (cmd *importer) tileGVCF(tilelib *tileLibrary, infile string, phase int) (tileseq tileSeq, err error) {
+ if cmd.refFile == "" {
+ err = errors.New("cannot import vcf: reference data (-ref) not specified")
+ return
+ }
args := []string{"bcftools", "consensus", "--fasta-ref", cmd.refFile, "-H", fmt.Sprint(phase + 1), infile}
indexsuffix := ".tbi"
if _, err := os.Stat(infile + ".csi"); err == nil {