Skip to content
Snippets Groups Projects
Commit 27e1e420 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

change(annotatet): move annotation script to bin

parent 0265d006
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,9 @@ for i, k in enumerate((*essential, *param_values.keys())): ...@@ -74,7 +74,9 @@ for i, k in enumerate((*essential, *param_values.keys())):
for k, suffix in essential.items(): # Autocomplete if fullpath not provided for k, suffix in essential.items(): # Autocomplete if fullpath not provided
if not str(param_values[k]).endswith(suffix): if not str(param_values[k]).endswith(suffix):
param_values[k] = Path(param_values[k]) / f"{ param_values['pos'] }.{suffix}" param_values[k] = (
Path(param_values[k]) / f"{ param_values['pos'] }.{suffix}"
)
# Functions # Functions
...@@ -100,7 +102,9 @@ def annotate_image(current_key=None, valid_values: t.Tuple[int] = (1, 2)): ...@@ -100,7 +102,9 @@ def annotate_image(current_key=None, valid_values: t.Tuple[int] = (1, 2)):
# Show image to annotate # Show image to annotate
while current_key is None or current_key not in valid_values: while current_key is None or current_key not in valid_values:
if current_key is not None: if current_key is not None:
print(f"Invalid value. Please try with valid values {valid_values}") print(
f"Invalid value. Please try with valid values {valid_values}"
)
if (current_key := readchar.readkey()) in "qsu": if (current_key := readchar.readkey()) in "qsu":
# if (current_key := input()) in "qsu": # if (current_key := input()) in "qsu":
...@@ -112,7 +116,8 @@ def annotate_image(current_key=None, valid_values: t.Tuple[int] = (1, 2)): ...@@ -112,7 +116,8 @@ def annotate_image(current_key=None, valid_values: t.Tuple[int] = (1, 2)):
async def generate_image( async def generate_image(
generator, location_stack: t.List[t.Tuple[np.ndarray, t.Tuple[int, int, int]]] generator,
location_stack: t.List[t.Tuple[np.ndarray, t.Tuple[int, int, int]]],
): ):
new_location_image = next(generator) new_location_image = next(generator)
location_stack.append((new_location_image[0], new_location_image[1])) location_stack.append((new_location_image[0], new_location_image[1]))
...@@ -122,7 +127,9 @@ def _parse_input(value: str, valid_values: t.Tuple[int]): ...@@ -122,7 +127,9 @@ def _parse_input(value: str, valid_values: t.Tuple[int]):
try: try:
return int(value) return int(value)
except: except:
print(f"Non-parsable value. Please try again with valid values {valid_values}") print(
f"Non-parsable value. Please try again with valid values {valid_values}"
)
return None return None
...@@ -151,7 +158,9 @@ def write_into_file(file_path: str, line: str): ...@@ -151,7 +158,9 @@ def write_into_file(file_path: str, line: str):
f.write(str(line)) f.write(str(line))
async def parent(image_path, results_path, out_dir, ncells, seed, interval): async def annotate_images(
image_path, results_path, out_dir, ncells, seed, interval
):
preemptive_cache = 3 preemptive_cache = 3
...@@ -190,7 +199,14 @@ async def parent(image_path, results_path, out_dir, ncells, seed, interval): ...@@ -190,7 +199,14 @@ async def parent(image_path, results_path, out_dir, ncells, seed, interval):
write_into_file( write_into_file(
out_annot_file, out_annot_file,
",".join( ",".join(
("experiment", "position", "tile", "cell_label", "tp", "annotation") (
"experiment",
"position",
"tile",
"cell_label",
"tp",
"annotation",
)
) )
+ "\n", + "\n",
) )
...@@ -225,7 +241,8 @@ async def parent(image_path, results_path, out_dir, ncells, seed, interval): ...@@ -225,7 +241,8 @@ async def parent(image_path, results_path, out_dir, ncells, seed, interval):
print("Annotation done!") print("Annotation done!")
if __name__ == "__main__": # if __name__ == "__main__":
def annotate():
if any([param_values.get(k) is None for k in ("min_tp", "max_tp")]): if any([param_values.get(k) is None for k in ("min_tp", "max_tp")]):
interval = None interval = None
else: else:
...@@ -233,7 +250,7 @@ if __name__ == "__main__": ...@@ -233,7 +250,7 @@ if __name__ == "__main__":
print(param_values) print(param_values)
trio.run( trio.run(
parent, annotate_images,
param_values["image_path"], param_values["image_path"],
param_values["results_path"], param_values["results_path"],
param_values["out_dir"], param_values["out_dir"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment