WholeSlideAnnotation#

from wholeslidedata import WholeSlideAnnotation
from wholeslidedata.visualization.plotting import plot_annotations
from colour import Color
from matplotlib import pyplot as plt
wsa = WholeSlideAnnotation('/tmp/TCGA-21-5784-01Z-00-DX1.xml')
print(len(wsa.annotations))
print(wsa.labels.names)
color_map = {label_name: Color(pick_for=label_name).hex_l for label_name in wsa.labels.names}
10
['lymphocytes', 'stroma', 'tumor']
plot_annotations(wsa.annotations, color_map=color_map)
../../../_images/7b5a8e0eb09d0ba2b28c10602d4a76571e7373be734feec46ceb7ad4debc8c0f.png
selected_annotations = wsa.select_annotations(center_x=7500, center_y=15000, width=5000, height=10000)
lymphocyte_annotations = [annotation for annotation in wsa.annotations if annotation.label.name == "lymphocytes"]
fig, axes = plt.subplots(1,2)
plot_annotations(selected_annotations, ax=axes[0], color_map=color_map)
plot_annotations(lymphocyte_annotations, ax=axes[1], color_map=color_map)
plt.show()
../../../_images/2327bea0856201116a5f85cc267be628e72b03b7d2a37679afa3055cc55605b2.png

Label names#

wsa = WholeSlideAnnotation('/tmp/TCGA-21-5784-01Z-00-DX1.xml', labels={'tumor':1, 'stroma': 2, 'lymphocytes':2}, renamed_labels={'tumor':1, 'other':2})
print(wsa.labels.names)
color_map = {label_name: Color(pick_for=label_name).hex_l for label_name in wsa.labels.names}
plot_annotations(wsa.annotations, color_map=color_map)
['other', 'tumor']
../../../_images/55f23ce39bbab6f88e66ff4a26ec088caf1523178d2b7419a277b86ece9a4303.png

Callbacks#

from wholeslidedata.annotation.hooks import ScalingAnnotationHook, TiledAnnotationHook
wsa = WholeSlideAnnotation('/tmp/TCGA-21-5784-01Z-00-DX1.xml', hooks=(ScalingAnnotationHook(0.5),))
color_map = {label_name: Color(pick_for=label_name).hex_l for label_name in wsa.labels.names}
plot_annotations(wsa.annotations, color_map=color_map)
../../../_images/7f155cae046ea6f7463de3575152604b34f9a1b42bbf711c3dc034b90dc678b3.png
labels={'tumor':1, 'stroma': 2, 'lymphocytes':2}
wsa = WholeSlideAnnotation('/tmp/TCGA-21-5784-01Z-00-DX1.xml', labels=labels, hooks=(TiledAnnotationHook(tile_size=256, label_names=list(labels)),))
color_map = {label_name: Color(pick_for=label_name).hex_l for label_name in wsa.labels.names}
plot_annotations(wsa.annotations, color_map=color_map)
../../../_images/a691aa689a762efd48eaff2472b78c9a7d55d81ab92452742e96c08e7dc48006.png
selected_annotations = wsa.select_annotations(center_x=7500, center_y=15000, width=5000, height=10000)
plot_annotations(selected_annotations, color_map=color_map)
../../../_images/ca33034d0cb7185b9509657da9a5617d8db76d88565f2d7c04600cac627a78d1.png