1 // Copyright (C) The Lightning Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/sdk/go/arvados"
16 type pythonPlot struct{}
18 func (cmd *pythonPlot) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
22 fmt.Fprintf(stderr, "%s\n", err)
25 flags := flag.NewFlagSet("", flag.ContinueOnError)
26 flags.SetOutput(stderr)
27 projectUUID := flags.String("project", "", "project `UUID` for output data")
28 inputFilename := flags.String("i", "-", "input `file`")
29 sampleCSVFilename := flags.String("labels-csv", "", "use first two columns of `labels.csv` as id->color mapping")
30 sampleFastaDirname := flags.String("sample-fasta-dir", "", "`directory` containing fasta input files")
31 priority := flags.Int("priority", 500, "container request priority")
32 err = flags.Parse(args)
33 if err == flag.ErrHelp {
36 } else if err != nil {
40 runner := arvadosContainerRunner{
41 Name: "lightning plot",
42 Client: arvados.NewClientFromEnv(),
43 ProjectUUID: *projectUUID,
47 Mounts: map[string]map[string]interface{}{
48 "/plot.py": map[string]interface{}{
50 "content": plotscript,
54 err = runner.TranslatePaths(inputFilename, sampleCSVFilename, sampleFastaDirname)
58 runner.Prog = "python3"
59 runner.Args = []string{"/plot.py", *inputFilename, *sampleCSVFilename, *sampleFastaDirname, "/mnt/output/plot.png"}
61 output, err = runner.Run()
65 fmt.Fprintln(stdout, output+"/plot.png")
76 X = scipy.load(infile)
81 for fnm in os.listdir(sys.argv[3]):
82 if '.2.fasta' not in fnm:
84 if len(labels) != len(X):
85 raise "len(inputdir) != len(inputarray)"
86 with open(sys.argv[2], 'rt') as csvfile:
87 for row in csv.reader(csvfile):
122 for fnm in sorted(labels.keys()):
123 if labels[fnm] in labelcolors:
124 colors.append(labelcolors[labels[fnm]])
126 colors.append('black')
128 from matplotlib.figure import Figure
129 from matplotlib.patches import Polygon
130 from matplotlib.backends.backend_agg import FigureCanvasAgg
132 ax = fig.add_subplot(111)
133 ax.scatter(X[:,0], X[:,1], c=colors, s=60, marker='o', alpha=0.5)
134 canvas = FigureCanvasAgg(fig)
135 canvas.print_figure(sys.argv[4], dpi=80)