1 // Copyright (C) The Lightning Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.arvados.org/arvados.git/sdk/go/arvados"
18 type pythonPlot struct{}
20 //go:embed pca_plot.py
23 func (cmd *pythonPlot) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
27 fmt.Fprintf(stderr, "%s\n", err)
30 flags := flag.NewFlagSet("", flag.ContinueOnError)
31 flags.SetOutput(stderr)
32 projectUUID := flags.String("project", "", "project `UUID` for output data")
33 inputFilename := flags.String("i", "-", "input `file`")
34 outputFilename := flags.String("o", "", "output `filename` (e.g., './plot.png')")
35 sampleListFilename := flags.String("samples", "", "use second column of `samples.csv` as complete list of sample IDs")
36 phenotypeFilename := flags.String("phenotype", "", "use `phenotype.csv` as id->phenotype mapping (column 0 is sample id)")
37 cat1Column := flags.Int("phenotype-cat1-column", 1, "0-based column `index` of 1st category in phenotype.csv file")
38 cat2Column := flags.Int("phenotype-cat2-column", -1, "0-based column `index` of 2nd category in phenotype.csv file")
39 xComponent := flags.Int("x", 1, "1-based PCA component to plot on x axis")
40 yComponent := flags.Int("y", 2, "1-based PCA component to plot on y axis")
41 priority := flags.Int("priority", 500, "container request priority")
42 runlocal := flags.Bool("local", false, "run on local host (default: run in an arvados container)")
43 err = flags.Parse(args)
44 if err == flag.ErrHelp {
47 } else if err != nil {
49 } else if flags.NArg() > 0 {
50 err = fmt.Errorf("errant command line arguments after parsed flags: %v", flags.Args())
54 runner := arvadosContainerRunner{
55 Name: "lightning pca-plot",
56 Client: arvados.NewClientFromEnv(),
57 ProjectUUID: *projectUUID,
61 Mounts: map[string]map[string]interface{}{
62 "/pca_plot.py": map[string]interface{}{
69 err = runner.TranslatePaths(inputFilename, sampleListFilename, phenotypeFilename)
73 *outputFilename = "/mnt/output/plot.png"
77 fmt.Sprintf("%d", *xComponent),
78 fmt.Sprintf("%d", *yComponent),
81 fmt.Sprintf("%d", *cat1Column),
82 fmt.Sprintf("%d", *cat2Column),
86 if *outputFilename == "" {
87 fmt.Fprintln(stderr, "error: must specify -o filename.png in local mode (or try -help)")
90 cmd := exec.Command("python3", append([]string{"-"}, args...)...)
91 cmd.Stdin = strings.NewReader(pcaPlotPy)
100 runner.Prog = "python3"
101 runner.Args = append([]string{"/pca_plot.py"}, args...)
103 output, err = runner.Run()
107 fmt.Fprintln(stdout, output+"/plot.png")