1 // Copyright (C) The Lightning Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
16 "git.arvados.org/arvados.git/sdk/go/arvados"
19 type pythonPlot struct{}
24 func (cmd *pythonPlot) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
28 fmt.Fprintf(stderr, "%s\n", err)
31 flags := flag.NewFlagSet("", flag.ContinueOnError)
32 flags.SetOutput(stderr)
33 projectUUID := flags.String("project", "", "project `UUID` for output data")
34 inputFilename := flags.String("i", "-", "input `file`")
35 outputFilename := flags.String("o", "", "output `filename` (e.g., './plot.png')")
36 sampleListFilename := flags.String("samples", "", "use second column of `samples.csv` as complete list of sample IDs")
37 phenotypeFilename := flags.String("phenotype", "", "use `phenotype.csv` as id->phenotype mapping (column 0 is sample id)")
38 phenotypeCategoryColumn := flags.Int("phenotype-category-column", -1, "0-based column `index` of 2nd category in phenotype.csv file")
39 phenotypeColumn := flags.Int("phenotype-column", 1, "0-based column `index` of phenotype in phenotype.csv file")
40 priority := flags.Int("priority", 500, "container request priority")
41 runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
42 err = flags.Parse(args)
43 if err == flag.ErrHelp {
46 } else if err != nil {
50 runner := arvadosContainerRunner{
51 Name: "lightning plot",
52 Client: arvados.NewClientFromEnv(),
53 ProjectUUID: *projectUUID,
57 Mounts: map[string]map[string]interface{}{
58 "/plot.py": map[string]interface{}{
60 "content": plotscript,
65 err = runner.TranslatePaths(inputFilename, sampleListFilename, phenotypeFilename)
69 *outputFilename = "/mnt/output/plot.png"
71 args = []string{*inputFilename, *sampleListFilename, *phenotypeFilename, fmt.Sprintf("%d", *phenotypeCategoryColumn), fmt.Sprintf("%d", *phenotypeColumn), *outputFilename}
73 if *outputFilename == "" {
74 fmt.Fprintln(stderr, "error: must specify -o filename.png in local mode (or try -help)")
77 cmd := exec.Command("python3", append([]string{"-"}, args...)...)
78 cmd.Stdin = strings.NewReader(plotscript)
87 runner.Prog = "python3"
88 runner.Args = append([]string{"/plot.py"}, args...)
90 output, err = runner.Run()
94 fmt.Fprintln(stdout, output+"/plot.png")