Skip to content

Commit

Permalink
feat: first round of annotation cli
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed Nov 21, 2023
1 parent 1567f07 commit f5373bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
19 changes: 19 additions & 0 deletions src/cryo_et_neuroglancer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional

from .write_segmentation import main as segmentation_encode
from .write_annotations import main as annotations_encode


def encode_segmentation(
Expand Down Expand Up @@ -75,6 +76,24 @@ def parse_args(args):
)
subcommand.set_defaults(func=encode_segmentation)

# annotations
subcommand = subparsers.add_parser(
"encode-annotations", help="Encode annotations file"
)
subcommand.add_argument(
"zarr_paths",
help="Path towards your segmentation ZARR folders",
nargs="+",
type=Path,
)
subcommand.add_argument(
"-o", "--output", required=False, help="Output folder to produce", type=Path
)
subcommand.add_argument(
"-r", "--resolution", required=False, help="Resolution", type=float
)
subcommand.set_defaults(func=annotations_encode)

return parser.parse_args(args)


Expand Down
30 changes: 9 additions & 21 deletions src/cryo_et_neuroglancer/write_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,20 @@ def view_data(coordinate_space: neuroglancer.CoordinateSpace, output_dir: Path)
print(viewer)


def main(paths: list[tuple[Path, Path]], output_dir: Path, should_view: bool) -> None:
def main(zarr_paths: list[Path], output: Path, resolution: float) -> None:
"""For each path set, load the data and write the combined annotations."""
annotations = []
for path_set in paths:
input_metadata_path, input_annotations_path = path_set
for path_set in zarr_paths:
input_metadata_path = path_set
input_annotations_path = path_set.parent / (path_set.stem + ".ndjson")
metadata, data = load_data(input_metadata_path, input_annotations_path)
annotations.append({"metadata": metadata, "data": data})

coordinate_space = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units=["", "", ""], scales=[1, 1, 1]
names=["x", "y", "z"],
units=["nm", "nm", "nm"],
scales=[resolution, resolution, resolution],
)
colors = [(255, 0, 0, 255), (0, 255, 0, 255)]
write_annotations(output_dir, annotations, coordinate_space, colors)
print("Wrote annotations to", output_dir)

if should_view:
view_data(coordinate_space, output_dir)


if __name__ == "__main__":
base_dir = Path("/media/starfish/LargeSSD/data/cryoET/data")
input_metadata_path = base_dir / "sara_goetz-ribosome-1.0.json"
input_annotations_path = base_dir / "sara_goetz-ribosome-1.0.ndjson"
paths = [(input_metadata_path, input_annotations_path)]
input_metadata_path = base_dir / "sara_goetz-fatty_acid_synthase-1.0.json"
input_annotations_path = base_dir / "sara_goetz-fatty_acid_synthase-1.0.ndjson"
paths.append((input_metadata_path, input_annotations_path))
should_view = False
main(paths, base_dir / "annotations", should_view)
write_annotations(output, annotations, coordinate_space, colors)
print("Wrote annotations to", output)

0 comments on commit f5373bb

Please sign in to comment.