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 err = flags.Parse(args)
28 if err == flag.ErrHelp {
31 } else if err != nil {
35 runner := arvadosContainerRunner{
36 Name: "lightning plot",
37 Client: arvados.NewClientFromEnv(),
38 ProjectUUID: *projectUUID,
41 Mounts: map[string]map[string]interface{}{
42 "/plot.py": map[string]interface{}{
44 "content": plotscript,
48 err = runner.TranslatePaths(inputFilename, sampleCSVFilename, sampleFastaDirname)
52 runner.Prog = "python3"
53 runner.Args = []string{"/plot.py", *inputFilename, *sampleCSVFilename, *sampleFastaDirname, "/mnt/output/plot.png"}
55 output, err = runner.Run()
59 fmt.Fprintln(stdout, output+"/plot.png")
70 X = scipy.load(infile)
75 for fnm in os.listdir(sys.argv[3]):
76 if '.2.fasta' not in fnm:
78 if len(labels) != len(X):
79 raise "len(inputdir) != len(inputarray)"
80 with open(sys.argv[2], 'rt') as csvfile:
81 for row in csv.reader(csvfile):
116 for fnm in sorted(labels.keys()):
117 colors.append(labelcolors[labels[fnm]])
119 from matplotlib.figure import Figure
120 from matplotlib.patches import Polygon
121 from matplotlib.backends.backend_agg import FigureCanvasAgg
123 ax = fig.add_subplot(111)
124 ax.scatter(X[:,0], X[:,1], c=colors, s=60, marker='o', alpha=0.5)
125 canvas = FigureCanvasAgg(fig)
126 canvas.print_figure(sys.argv[4], dpi=80)