Skip to content

Commit 3135bd5

Browse files
edyoshikunziw-liu
andauthored
Adding annotation typings (#300)
* Adding annotation typings This PR takes a first stab at standardizing the labels and annotation columns for our datasets with the hope to merge annotations across datasets easily. * ruff format * changing the labels to dicts * format * distinction between cell cycle and cell division labels * ruff format --------- Co-authored-by: Ziwen Liu <[email protected]>
1 parent 1e5381d commit 3135bd5

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

viscy/data/cell_classification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from viscy.data.hcs import _read_norm_meta
1313
from viscy.data.triplet import INDEX_COLUMNS
14+
from viscy.data.typing import AnnotationColumns
1415

1516

1617
class ClassificationDataset(Dataset):
@@ -23,7 +24,7 @@ def __init__(
2324
transform: Callable | None,
2425
initial_yx_patch_size: tuple[int, int],
2526
return_indices: bool = False,
26-
label_column: str = "infection_state",
27+
label_column: AnnotationColumns = "infection_state",
2728
):
2829
self.plate = plate
2930
self.z_range = z_range

viscy/data/typing.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, NamedTuple, Sequence, TypedDict, TypeVar
1+
from typing import Callable, Literal, NamedTuple, Sequence, TypedDict, TypeVar
22

33
from torch import ShortTensor, Tensor
44

@@ -88,3 +88,39 @@ class TripletSample(TypedDict):
8888
positive: NotRequired[Tensor]
8989
negative: NotRequired[Tensor]
9090
index: NotRequired[TrackingIndex]
91+
92+
93+
# NOTE: these are the only columns that are allowed for the annotation dataframe.
94+
AnnotationColumns = Literal[
95+
"infection_state",
96+
"cell_division_state",
97+
"cell_remodeling_state",
98+
"cell_cycle_state",
99+
]
100+
101+
102+
# NOTE: The following labels are not mutable. They are used to map the labels to the integer values.
103+
LABEL_INFECTION_STATE = {"uninfected": 0, "infected": 1, "unknown": -1}
104+
105+
LABEL_CELL_DIVISION_STATE = {
106+
"interphase": 0,
107+
"mitosis": 1,
108+
"unknown": -1,
109+
}
110+
111+
LABEL_CELL_CYCLE_STATE = {
112+
"G1": 0,
113+
"S": 1,
114+
"G2": 2,
115+
"prophase": 3,
116+
"metaphase": 4,
117+
"anaphase": 5,
118+
"telophase": 6,
119+
"unknown": -1,
120+
}
121+
122+
LABEL_CELL_REMODELING_STATE = {
123+
"no_remodel": 0,
124+
"remodeling": 1,
125+
"unknown": -1,
126+
}

0 commit comments

Comments
 (0)