Workflow tutorial
Import the subsetmask
package
[1]:
import pandas as pd
import subsetmask as sm
Load the metadata as a pandas
data frame
[ ]:
# Load the metadata CSV file
meta = pd.read_csv("test/metadata.csv", index_col=0, header=0)
We use the Image
class
[ ]:
image = sm.Image(metadata_df=meta,
images_col='slide',
image_name='slide_1',
x_col='x_slide_mm',
y_col='y_slide_mm')
# addd store image method
image.store_image(group_col=None, figsize=(30, 50), dpi=300, dot_size=5, cmap='tab20')
# launches napari with the generated image
image.draw_labels()
[ ]:
# without closing napari we run this line to save the annotations
image.save_annotations(ann_col_name="new_col")
# we change our annotations for something more meaningful
map = {
"label_1": "sample_1",
"label_2": "sample_2"
}
image.rename_annotations(ann_col_name="new_col", mapping_dict=map)
# we extract the annotated df from the object
annotated_meta = image.annotated_metadata_df
[ ]:
# we verify the value counts of the new column
print(annotated_meta[["new_col"]].value_counts())
new_col
not_assigned 205211
sample_2 75815
sample_1 64059
Name: count, dtype: int64
[ ]:
# now just save the annotated metadata
annotated_meta.to_csv("test/metadata_annotated.csv")