16 "git.arvados.org/arvados.git/sdk/go/arvados"
17 log "github.com/sirupsen/logrus"
20 type ref2genome struct {
27 func (cmd *ref2genome) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
31 fmt.Fprintf(stderr, "%s\n", err)
34 flags := flag.NewFlagSet("", flag.ContinueOnError)
35 flags.SetOutput(stderr)
36 flags.StringVar(&cmd.refFile, "ref", "", "reference fasta `file`")
37 flags.StringVar(&cmd.projectUUID, "project", "", "project `UUID` for containers and output data")
38 flags.StringVar(&cmd.outputFilename, "o", "", "output filename")
39 flags.BoolVar(&cmd.runLocal, "local", false, "run on local host (default: run in an arvados container)")
40 priority := flags.Int("priority", 500, "container request priority")
41 pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
42 err = flags.Parse(args)
43 if err == flag.ErrHelp {
46 } else if err != nil {
48 } else if cmd.refFile == "" {
49 err = errors.New("reference data (-ref) not specified")
55 log.Println(http.ListenAndServe(*pprof, nil))
60 if cmd.outputFilename != "" {
61 err = errors.New("cannot specify output filename in non-local mode")
64 runner := arvadosContainerRunner{
65 Name: "lightning ref2genome",
66 Client: arvados.NewClientFromEnv(),
67 ProjectUUID: cmd.projectUUID,
72 err = runner.TranslatePaths(&cmd.refFile)
76 runner.Args = []string{"ref2genome", "-local=true", "-ref", cmd.refFile, "-o", "/mnt/output/ref.genome"}
78 output, err = runner.Run()
82 fmt.Fprintln(stdout, output+"/ref.genome")
86 var out io.WriteCloser
87 if cmd.outputFilename == "" {
88 out = nopCloser{stdout}
90 out, err = os.OpenFile(cmd.outputFilename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
95 f, err := os.Open(cmd.refFile)
101 if strings.HasSuffix(cmd.refFile, ".gz") {
102 in, err = gzip.NewReader(f)
109 label, seqlen := "", 0
110 scanner := bufio.NewScanner(in)
112 buf := scanner.Bytes()
113 if len(buf) > 0 && buf[0] == '>' {
115 fmt.Fprintf(out, "%s\t%d\n", label, seqlen)
117 label = strings.TrimSpace(string(buf[1:]))
120 seqlen += len(bytes.TrimSpace(buf))
124 fmt.Fprintf(out, "%s\t%d\n", label, seqlen)
126 if err = scanner.Err(); err != nil {
129 if err = out.Close(); err != nil {