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 cat1Column := flags.Int("phenotype-cat1-column", 1, "0-based column `index` of 1st category in phenotype.csv file")
39 cat2Column := flags.Int("phenotype-cat2-column", -1, "0-based column `index` of 2nd category in phenotype.csv file")
40 xComponent := flags.Int("x", 1, "1-based PCA component to plot on x axis")
41 yComponent := flags.Int("y", 2, "1-based PCA component to plot on y axis")
42 priority := flags.Int("priority", 500, "container request priority")
43 runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
44 err = flags.Parse(args)
45 if err == flag.ErrHelp {
48 } else if err != nil {
52 runner := arvadosContainerRunner{
53 Name: "lightning plot",
54 Client: arvados.NewClientFromEnv(),
55 ProjectUUID: *projectUUID,
59 Mounts: map[string]map[string]interface{}{
60 "/plot.py": map[string]interface{}{
62 "content": plotscript,
67 err = runner.TranslatePaths(inputFilename, sampleListFilename, phenotypeFilename)
71 *outputFilename = "/mnt/output/plot.png"
75 fmt.Sprintf("%d", *xComponent),
76 fmt.Sprintf("%d", *yComponent),
79 fmt.Sprintf("%d", *cat1Column),
80 fmt.Sprintf("%d", *cat2Column),
84 if *outputFilename == "" {
85 fmt.Fprintln(stderr, "error: must specify -o filename.png in local mode (or try -help)")
88 cmd := exec.Command("python3", append([]string{"-"}, args...)...)
89 cmd.Stdin = strings.NewReader(plotscript)
98 runner.Prog = "python3"
99 runner.Args = append([]string{"/plot.py"}, args...)
101 output, err = runner.Run()
105 fmt.Fprintln(stdout, output+"/plot.png")