Skip to content

Commit

Permalink
Fix Jaccard Calculation (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffquinn-msk authored Dec 2, 2024
1 parent 54e433c commit a13a7d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 1 addition & 7 deletions src/nuc2seg/cli/calculate_benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import argparse
import logging

import numpy as np
import torch
import tqdm
import os

from nuc2seg import log_config
from nuc2seg.data import Nuc2SegDataset, TiledDataset
from nuc2seg.segment import stitch_predictions
from nuc2seg.xenium import load_vertex_file, load_and_filter_transcripts_as_points
from nuc2seg.postprocess import (
calculate_average_intersection_over_union,
calculate_segmentation_jaccard_index,
)
from nuc2seg.xenium import load_vertex_file, load_and_filter_transcripts_as_points

logger = logging.getLogger(__name__)

Expand Down
9 changes: 4 additions & 5 deletions src/nuc2seg/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,19 @@ def calculate_segmentation_jaccard_index(
sjoined_gdf.reset_index(inplace=True, drop=False, names="index")

segment_id_to_transcripts_a = (
sjoined_gdf[["index", "index_right"]]
.groupby("index")
sjoined_gdf[["segment_id_a", "index_right"]]
.groupby("segment_id_a")
.agg({"index_right": set})["index_right"]
.to_dict()
)

sjoined_gdf = spatial_join_polygons_and_transcripts(
boundaries=segmentation_b, transcripts=transcripts
)
sjoined_gdf.reset_index(inplace=True, drop=False, names="index")

segment_id_to_transcripts_b = (
sjoined_gdf[["index", "index_right"]]
.groupby("index")
sjoined_gdf[["segment_id_b", "index_right"]]
.groupby("segment_id_b")
.agg({"index_right": set})["index_right"]
.to_dict()
)
Expand Down

0 comments on commit a13a7d2

Please sign in to comment.