9 "git.arvados.org/arvados.git/sdk/go/arvados"
12 type pythonPlot struct{}
14 func (cmd *pythonPlot) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
18 fmt.Fprintf(stderr, "%s\n", err)
21 flags := flag.NewFlagSet("", flag.ContinueOnError)
22 flags.SetOutput(stderr)
23 projectUUID := flags.String("project", "", "project `UUID` for output data")
24 inputFilename := flags.String("i", "-", "input `file`")
25 sampleCSVFilename := flags.String("labels-csv", "", "use first two columns of `labels.csv` as id->color mapping")
26 sampleFastaDirname := flags.String("sample-fasta-dir", "", "`directory` containing fasta input files")
27 priority := flags.Int("priority", 500, "container request priority")
28 err = flags.Parse(args)
29 if err == flag.ErrHelp {
32 } else if err != nil {
36 runner := arvadosContainerRunner{
37 Name: "lightning plot",
38 Client: arvados.NewClientFromEnv(),
39 ProjectUUID: *projectUUID,
43 Mounts: map[string]map[string]interface{}{
44 "/plot.py": map[string]interface{}{
46 "content": plotscript,
50 err = runner.TranslatePaths(inputFilename, sampleCSVFilename, sampleFastaDirname)
54 runner.Prog = "python3"
55 runner.Args = []string{"/plot.py", *inputFilename, *sampleCSVFilename, *sampleFastaDirname, "/mnt/output/plot.png"}
57 output, err = runner.Run()
61 fmt.Fprintln(stdout, output+"/plot.png")
72 X = scipy.load(infile)
77 for fnm in os.listdir(sys.argv[3]):
78 if '.2.fasta' not in fnm:
80 if len(labels) != len(X):
81 raise "len(inputdir) != len(inputarray)"
82 with open(sys.argv[2], 'rt') as csvfile:
83 for row in csv.reader(csvfile):
118 for fnm in sorted(labels.keys()):
119 if labels[fnm] in labelcolors:
120 colors.append(labelcolors[labels[fnm]])
122 colors.append('black')
124 from matplotlib.figure import Figure
125 from matplotlib.patches import Polygon
126 from matplotlib.backends.backend_agg import FigureCanvasAgg
128 ax = fig.add_subplot(111)
129 ax.scatter(X[:,0], X[:,1], c=colors, s=60, marker='o', alpha=0.5)
130 canvas = FigureCanvasAgg(fig)
131 canvas.print_figure(sys.argv[4], dpi=80)