Mercurial > repos > thomaswollmann > detection_viz
annotate detection_viz.py @ 1:ff66bae1f7f8 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
author | thomaswollmann |
---|---|
date | Mon, 07 Jan 2019 05:36:36 -0500 |
parents | 629d9e8ca64c |
children |
rev | line source |
---|---|
0
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
1 import argparse |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
2 import sys |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
3 import os |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
4 import csv |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
5 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
6 import matplotlib |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
7 matplotlib.use('Agg') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
8 import matplotlib.pyplot as plt |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
9 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
10 import skimage.io |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
11 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
12 def plot_circles(file_name, ax, color, stroke_size, radius): |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
13 resfile = open(file_name, 'rb') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
14 rd = csv.reader(resfile, delimiter=',') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
15 for row in rd: |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
16 circ = plt.Circle((int(row[1]), int(row[0])), lw=stroke_size, radius=radius, color=color, fill=False) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
17 ax.add_patch(circ) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
18 resfile.close() |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
19 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
20 def detection_viz(input_file, output_file, tp=None, fn=None, fp=None, stroke_size=3, circle_radius=50): |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
21 img = skimage.io.imread(input_file) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
22 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
23 fig = plt.figure(figsize=(40, 40)) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
24 ax = fig.add_axes([0, 0, 1, 1]) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
25 ax.axis('off') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
26 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
27 plt.imshow(img) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
28 if tp is not None: |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
29 plot_circles(tp, ax, '#00FF00', stroke_size, circle_radius) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
30 if fn is not None: |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
31 plot_circles(fn, ax, 'red', stroke_size, circle_radius) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
32 if fp is not None: |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
33 plot_circles(fp, ax, 'darkorange', stroke_size, circle_radius) |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
34 |
1
ff66bae1f7f8
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
0
diff
changeset
|
35 fig.canvas.print_png(output_file, dpi=1800) |
0
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
36 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
37 if __name__ == "__main__": |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
38 parser = argparse.ArgumentParser() |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
39 parser.add_argument('input_file', type=argparse.FileType('r'), help='original file') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
40 # output file should not be of type argparse.FileType('w') sine it is created immediately in this case which leads to an error in renaming |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
41 parser.add_argument('out_file_str', type=str, help='string of output file name') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
42 parser.add_argument('--tp', dest='input_tp_file', type=argparse.FileType('r'), help='input TP file') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
43 parser.add_argument('--fn', dest='input_fn_file', type=argparse.FileType('r'), help='input FN file') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
44 parser.add_argument('--fp', dest='input_fp_file', type=argparse.FileType('r'), help='input FP file') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
45 parser.add_argument('--stroke_size', dest='thickness', default=3, type=float, help='stroke thickness') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
46 parser.add_argument('--circle_radius', dest='circle_radius', type=float, default=50, help='circle radius') |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
47 args = parser.parse_args() |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
48 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
49 tp=None |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
50 if args.input_tp_file: |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
51 tp=args.input_tp_file.name |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
52 fn=None |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
53 if args.input_fn_file: |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
54 fn=args.input_fn_file.name |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
55 fp=None |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
56 if args.input_fp_file: |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
57 fp=args.input_fp_file.name |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
58 |
629d9e8ca64c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff
changeset
|
59 detection_viz(args.input_file.name, args.out_file_str, tp=tp, fn=fn, fp=fp, stroke_size=args.thickness, circle_radius=args.circle_radius) |