1 // Copyright (C) The Lightning Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
20 "git.arvados.org/arvados.git/sdk/go/arvados"
21 log "github.com/sirupsen/logrus"
24 type ref2genome struct {
31 func (cmd *ref2genome) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
35 fmt.Fprintf(stderr, "%s\n", err)
38 flags := flag.NewFlagSet("", flag.ContinueOnError)
39 flags.SetOutput(stderr)
40 flags.StringVar(&cmd.refFile, "ref", "", "reference fasta `file`")
41 flags.StringVar(&cmd.projectUUID, "project", "", "project `UUID` for containers and output data")
42 flags.StringVar(&cmd.outputFilename, "o", "", "output filename")
43 flags.BoolVar(&cmd.runLocal, "local", false, "run on local host (default: run in an arvados container)")
44 priority := flags.Int("priority", 500, "container request priority")
45 pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
46 err = flags.Parse(args)
47 if err == flag.ErrHelp {
50 } else if err != nil {
52 } else if cmd.refFile == "" {
53 err = errors.New("reference data (-ref) not specified")
59 log.Println(http.ListenAndServe(*pprof, nil))
64 if cmd.outputFilename != "" {
65 err = errors.New("cannot specify output filename in non-local mode")
68 runner := arvadosContainerRunner{
69 Name: "lightning ref2genome",
70 Client: arvados.NewClientFromEnv(),
71 ProjectUUID: cmd.projectUUID,
76 err = runner.TranslatePaths(&cmd.refFile)
80 runner.Args = []string{"ref2genome", "-local=true", "-ref", cmd.refFile, "-o", "/mnt/output/ref.genome"}
82 output, err = runner.Run()
86 fmt.Fprintln(stdout, output+"/ref.genome")
90 var out io.WriteCloser
91 if cmd.outputFilename == "" {
92 out = nopCloser{stdout}
94 out, err = os.OpenFile(cmd.outputFilename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
99 f, err := os.Open(cmd.refFile)
105 if strings.HasSuffix(cmd.refFile, ".gz") {
106 in, err = gzip.NewReader(f)
113 label, seqlen := "", 0
114 scanner := bufio.NewScanner(in)
116 buf := scanner.Bytes()
117 if len(buf) > 0 && buf[0] == '>' {
119 fmt.Fprintf(out, "%s\t%d\n", label, seqlen)
121 label = strings.TrimSpace(string(buf[1:]))
122 label = strings.SplitN(label, " ", 2)[0]
125 seqlen += len(bytes.TrimSpace(buf))
129 fmt.Fprintf(out, "%s\t%d\n", label, seqlen)
131 if err = scanner.Err(); err != nil {
134 if err = out.Close(); err != nil {