Up load throttle to gomaxprocs.
[lightning.git] / flake.go
1 package lightning
2
3 import (
4         "context"
5         "flag"
6         "fmt"
7         "io"
8         "net/http"
9         _ "net/http/pprof"
10
11         "git.arvados.org/arvados.git/sdk/go/arvados"
12         log "github.com/sirupsen/logrus"
13 )
14
15 type flakecmd struct {
16         filter filter
17 }
18
19 func (cmd *flakecmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
20         var err error
21         defer func() {
22                 if err != nil {
23                         fmt.Fprintf(stderr, "%s\n", err)
24                 }
25         }()
26         flags := flag.NewFlagSet("", flag.ContinueOnError)
27         flags.SetOutput(stderr)
28         pprof := flags.String("pprof", "", "serve Go profile data at http://`[addr]:port`")
29         runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
30         projectUUID := flags.String("project", "", "project `UUID` for output data")
31         priority := flags.Int("priority", 500, "container request priority")
32         inputDir := flags.String("input-dir", "./in", "input `directory`")
33         outputDir := flags.String("output-dir", "./out", "output `directory`")
34         cmd.filter.Flags(flags)
35         err = flags.Parse(args)
36         if err == flag.ErrHelp {
37                 err = nil
38                 return 0
39         } else if err != nil {
40                 return 2
41         }
42
43         if *pprof != "" {
44                 go func() {
45                         log.Println(http.ListenAndServe(*pprof, nil))
46                 }()
47         }
48
49         if !*runlocal {
50                 runner := arvadosContainerRunner{
51                         Name:        "lightning flake",
52                         Client:      arvados.NewClientFromEnv(),
53                         ProjectUUID: *projectUUID,
54                         RAM:         700000000000,
55                         VCPUs:       96,
56                         Priority:    *priority,
57                         KeepCache:   2,
58                         APIAccess:   true,
59                 }
60                 err = runner.TranslatePaths(inputDir)
61                 if err != nil {
62                         return 1
63                 }
64                 runner.Args = []string{"flake", "-local=true",
65                         "-pprof", ":6060",
66                         "-input-dir", *inputDir,
67                         "-output-dir", "/mnt/output",
68                         "-max-variants", fmt.Sprintf("%d", cmd.filter.MaxVariants),
69                         "-min-coverage", fmt.Sprintf("%f", cmd.filter.MinCoverage),
70                         "-max-tag", fmt.Sprintf("%d", cmd.filter.MaxTag),
71                 }
72                 var output string
73                 output, err = runner.Run()
74                 if err != nil {
75                         return 1
76                 }
77                 fmt.Fprintln(stdout, output)
78                 return 0
79         }
80
81         tilelib := &tileLibrary{
82                 retainNoCalls:       true,
83                 retainTileSequences: true,
84                 compactGenomes:      map[string][]tileVariantID{},
85         }
86         err = tilelib.LoadDir(context.Background(), *inputDir, nil)
87         if err != nil {
88                 return 1
89         }
90
91         log.Info("filtering")
92         cmd.filter.Apply(tilelib)
93         log.Info("tidying")
94         tilelib.Tidy()
95         err = tilelib.WriteDir(*outputDir)
96         if err != nil {
97                 return 1
98         }
99         return 0
100 }