annotate qupath_roi_splitter.py @ 4:9f136ebf73ac draft

planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
author galaxyp
date Fri, 19 Jul 2024 14:33:40 +0000
parents 24ccdcfbabac
children 17c54a716a5b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
1 import argparse
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
2
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
3 import cv2
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
4 import geojson
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
5 import numpy as np
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
6 import pandas as pd
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
7
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
8
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
9 def collect_coords(input_coords, feature_index, coord_index=0):
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
10 coords_with_index = []
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
11 for coord in input_coords:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
12 coords_with_index.append((coord[0], coord[1], feature_index, coord_index))
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
13 coord_index += 1
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
14 return coords_with_index
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
15
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
16
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
17 def collect_roi_coords(input_roi, feature_index):
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
18 all_coords = []
2
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
19 if len(input_roi["geometry"]["coordinates"]) == 1:
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
20 # Polygon w/o holes
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
21 all_coords.extend(collect_coords(input_roi["geometry"]["coordinates"][0], feature_index))
2
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
22 else:
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
23 coord_index = 0
2
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
24 for sub_roi in input_roi["geometry"]["coordinates"]:
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
25 # Polygon with holes or MultiPolygon
2
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
26 if not isinstance(sub_roi[0][0], list):
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
27 all_coords.extend(collect_coords(sub_roi, feature_index, coord_index))
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
28 coord_index += len(sub_roi)
2
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
29 else:
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
30 # MultiPolygon with holes
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
31 for sub_coord in sub_roi:
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
32 all_coords.extend(collect_coords(sub_coord, feature_index, coord_index))
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
33 coord_index += len(sub_coord)
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
34 return all_coords
2
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
35
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
36
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
37 def split_qupath_roi(in_roi):
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
38 with open(in_roi) as file:
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
39 qupath_roi = geojson.load(file)
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
40
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
41 # HE dimensions
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
42 dim_plt = [int(qupath_roi["dim"]["width"]), int(qupath_roi["dim"]["height"])]
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
43
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
44 tma_name = qupath_roi["name"]
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
45 cell_types = [ct.rsplit(" - ", 1)[-1] for ct in qupath_roi["featureNames"]]
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
46
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
47 coords_by_cell_type = {ct: [] for ct in cell_types}
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
48 coords_by_cell_type['all'] = [] # For storing all coordinates if args.all is True
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
49
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
50 for feature_index, roi in enumerate(qupath_roi["features"]):
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
51 feature_coords = collect_roi_coords(roi, feature_index)
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
52
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
53 if args.all:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
54 coords_by_cell_type['all'].extend(feature_coords)
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
55 elif "classification" in roi["properties"]:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
56 cell_type = roi["properties"]["classification"]["name"]
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
57 if cell_type in cell_types:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
58 coords_by_cell_type[cell_type].extend(feature_coords)
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
59
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
60 for cell_type, coords in coords_by_cell_type.items():
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
61 if coords:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
62 # Generate image (white background)
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
63 img = np.ones((dim_plt[1], dim_plt[0]), dtype="uint8") * 255
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
64
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
65 # Convert to numpy array and ensure integer coordinates
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
66 coords_arr = np.array(coords).astype(int)
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
67
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
68 # Sort by feature_index first, then by coord_index
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
69 coords_arr = coords_arr[np.lexsort((coords_arr[:, 3], coords_arr[:, 2]))]
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
70
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
71 # Get filled pixel coordinates
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
72 if args.fill:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
73 filled_coords = np.column_stack(np.where(img == 0))
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
74 all_coords = np.unique(np.vstack((coords_arr[:, :2], filled_coords[:, ::-1])), axis=0)
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
75 else:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
76 all_coords = coords_arr[:, :2]
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
77
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
78 # Save all coordinates to CSV
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
79 coords_df = pd.DataFrame(all_coords, columns=['x', 'y'], dtype=int)
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
80 coords_df.to_csv("{}_{}.txt".format(tma_name, cell_type), sep='\t', index=False)
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
81
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
82 # Generate image for visualization if --img is specified
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
83 if args.img:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
84 # Group coordinates by feature_index
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
85 features = {}
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
86 for x, y, feature_index, coord_index in coords_arr:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
87 if feature_index not in features:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
88 features[feature_index] = []
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
89 features[feature_index].append((x, y))
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
90
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
91 # Draw each feature separately
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
92 for feature_coords in features.values():
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
93 pts = np.array(feature_coords, dtype=np.int32)
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
94 if args.fill:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
95 cv2.fillPoly(img, [pts], color=0) # Black fill
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
96 else:
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
97 cv2.polylines(img, [pts], isClosed=True, color=0, thickness=1) # Black outline
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
98
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
99 cv2.imwrite("{}_{}.png".format(tma_name, cell_type), img)
3
24ccdcfbabac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 00029e8a3ee400f69a6dbe9e556ec9c27c6979cb
galaxyp
parents: 2
diff changeset
100
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
101
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
102 if __name__ == "__main__":
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
103 parser = argparse.ArgumentParser(description="Split ROI coordinates of QuPath TMA annotation by cell type (classification)")
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
104 parser.add_argument("--qupath_roi", default=False, help="Input QuPath annotation (GeoJSON file)")
4
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
105 parser.add_argument("--fill", action="store_true", required=False, help="Fill pixels in ROIs (order of coordinates will be lost)")
9f136ebf73ac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 918ae25f84e7042ed36461219ff068633c1c2427
galaxyp
parents: 3
diff changeset
106 parser.add_argument('--version', action='version', version='%(prog)s 0.3.0')
2
7bee859bbd11 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 7391296e0c7c8d48b42a129d154b50b29fd41737
galaxyp
parents: 1
diff changeset
107 parser.add_argument("--all", action="store_true", required=False, help="Extracts all ROIs")
3
24ccdcfbabac planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 00029e8a3ee400f69a6dbe9e556ec9c27c6979cb
galaxyp
parents: 2
diff changeset
108 parser.add_argument("--img", action="store_true", required=False, help="Generates image of ROIs")
0
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
109 args = parser.parse_args()
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
110
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
111 if args.qupath_roi:
b5e9cebb27e3 planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit cdf3e9652b10c7a0b179202129a797e32fd95909
galaxyp
parents:
diff changeset
112 split_qupath_roi(args.qupath_roi)