comparison qupath_roi_splitter.py @ 5:17c54a716a5b draft

planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit e3d24f3dc7a9812f8fa4447c9391e5bd3b5d4dc6
author galaxyp
date Tue, 30 Jul 2024 12:59:11 +0000
parents 9f136ebf73ac
children 6a8cf86fd3b7
comparison
equal deleted inserted replaced
4:9f136ebf73ac 5:17c54a716a5b
20 # Polygon w/o holes 20 # Polygon w/o holes
21 all_coords.extend(collect_coords(input_roi["geometry"]["coordinates"][0], feature_index)) 21 all_coords.extend(collect_coords(input_roi["geometry"]["coordinates"][0], feature_index))
22 else: 22 else:
23 coord_index = 0 23 coord_index = 0
24 for sub_roi in input_roi["geometry"]["coordinates"]: 24 for sub_roi in input_roi["geometry"]["coordinates"]:
25 # Polygon with holes or MultiPolygon 25 if len(sub_roi) == 2:
26 if not isinstance(sub_roi[0][0], list): 26 # Special case: LMD data
27 all_coords.extend(collect_coords(sub_roi, feature_index, coord_index)) 27 all_coords.extend(collect_coords([sub_roi], feature_index, coord_index))
28 coord_index += len(sub_roi) 28 coord_index += 1
29 else: 29 else:
30 # MultiPolygon with holes 30 # Polygon with holes or MultiPolygon
31 for sub_coord in sub_roi: 31 if not isinstance(sub_roi[0][0], list):
32 all_coords.extend(collect_coords(sub_coord, feature_index, coord_index)) 32 all_coords.extend(collect_coords(sub_roi, feature_index, coord_index))
33 coord_index += len(sub_coord) 33 coord_index += len(sub_roi)
34 else:
35 # MultiPolygon with holes
36 for sub_coord in sub_roi:
37 all_coords.extend(collect_coords(sub_coord, feature_index, coord_index))
38 coord_index += len(sub_coord)
34 return all_coords 39 return all_coords
35 40
36 41
37 def split_qupath_roi(in_roi): 42 def split_qupath_roi(in_roi):
38 with open(in_roi) as file: 43 with open(in_roi) as file:
101 106
102 if __name__ == "__main__": 107 if __name__ == "__main__":
103 parser = argparse.ArgumentParser(description="Split ROI coordinates of QuPath TMA annotation by cell type (classification)") 108 parser = argparse.ArgumentParser(description="Split ROI coordinates of QuPath TMA annotation by cell type (classification)")
104 parser.add_argument("--qupath_roi", default=False, help="Input QuPath annotation (GeoJSON file)") 109 parser.add_argument("--qupath_roi", default=False, help="Input QuPath annotation (GeoJSON file)")
105 parser.add_argument("--fill", action="store_true", required=False, help="Fill pixels in ROIs (order of coordinates will be lost)") 110 parser.add_argument("--fill", action="store_true", required=False, help="Fill pixels in ROIs (order of coordinates will be lost)")
106 parser.add_argument('--version', action='version', version='%(prog)s 0.3.0') 111 parser.add_argument('--version', action='version', version='%(prog)s 0.3.1')
107 parser.add_argument("--all", action="store_true", required=False, help="Extracts all ROIs") 112 parser.add_argument("--all", action="store_true", required=False, help="Extracts all ROIs")
108 parser.add_argument("--img", action="store_true", required=False, help="Generates image of ROIs") 113 parser.add_argument("--img", action="store_true", required=False, help="Generates image of ROIs")
109 args = parser.parse_args() 114 args = parser.parse_args()
110 115
111 if args.qupath_roi: 116 if args.qupath_roi: