Skip to content

Commit

Permalink
Add Jaccard Index Function (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffquinn-msk authored Nov 14, 2024
1 parent f798ab4 commit 2b13d16
Show file tree
Hide file tree
Showing 33 changed files with 437 additions and 308 deletions.
3 changes: 2 additions & 1 deletion src/nuc2seg/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import logging

import numpy as np
import tqdm

logger = logging.getLogger(__name__)
Expand Down
13 changes: 6 additions & 7 deletions src/nuc2seg/celltyping.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import tqdm
import numpy as np
import geopandas
import anndata

import geopandas
import numpy as np
import tqdm
from kneed import KneeLocator

from scipy.special import logsumexp
from scipy.special import softmax
from nuc2seg.xenium import logger

from nuc2seg.data import CelltypingResults
from scipy.special import logsumexp
from nuc2seg.xenium import logger


def aic_bic(gene_counts, expression_profiles, prior_probs):
Expand Down
8 changes: 4 additions & 4 deletions src/nuc2seg/celltyping_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import geopandas
import numpy as np
from shapely import Polygon, Point

from nuc2seg.celltyping import (
fit_celltype_em_model,
fit_celltyping_on_segments_and_transcripts,
Expand All @@ -6,10 +10,6 @@
predict_celltypes_for_segments_and_transcripts,
predict_celltype_probabilities_for_all_segments,
)
import numpy as np
import geopandas
from shapely import Polygon, Point
from nuc2seg.data import CelltypingResults


def test_fit_celltype_em_model():
Expand Down
4 changes: 2 additions & 2 deletions src/nuc2seg/cli/autofluorescence_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os.path

import nuc2seg.post_xenium_imaging
from nuc2seg import benchmark
from nuc2seg import log_config
from nuc2seg import plotting
from nuc2seg.data import SegmentationResults
from nuc2seg.xenium import read_xenium_cell_segmentation_masks
from nuc2seg import benchmark
from nuc2seg import plotting

logger = logging.getLogger(__name__)

Expand Down
2 changes: 0 additions & 2 deletions src/nuc2seg/cli/baysor_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
stitch_shapes,
filter_baysor_shapes_to_most_significant_nucleus_overlap,
read_baysor_shapefile,
)
from nuc2seg.segment import (
convert_transcripts_to_anndata,
)
from nuc2seg.utils import get_tile_idx
Expand Down
14 changes: 7 additions & 7 deletions src/nuc2seg/cli/baysor_postprocess_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import json
import math
import os
import shutil
import tempfile
import json
import geopandas as gpd
from unittest import mock

import anndata
import pandas
import geopandas as gpd
import numpy as np
from blended_tiling import TilingModule

from nuc2seg.cli import baysor_postprocess
from nuc2seg.data import CelltypingResults
from nuc2seg.utils import generate_tiles
from blended_tiling import TilingModule
import numpy as np
import math
from nuc2seg.cli import baysor_postprocess


def test_baysor_postprocess(
Expand Down
3 changes: 2 additions & 1 deletion src/nuc2seg/cli/celltyping.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import argparse
import logging

import numpy as np

from nuc2seg import log_config
from nuc2seg.celltyping import fit_celltyping_on_segments_and_transcripts
from nuc2seg.xenium import (
load_nuclei,
load_and_filter_transcripts_as_points,
create_shapely_rectangle,
)
from nuc2seg.celltyping import fit_celltyping_on_segments_and_transcripts

logger = logging.getLogger(__name__)

Expand Down
9 changes: 4 additions & 5 deletions src/nuc2seg/cli/combine_segmentations.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import argparse
import logging
import os.path
from typing import Optional

import anndata
import geopandas as gpd
import numpy as np
import pandas
import shapely
from typing import Optional
from shapely.geometry import Polygon
from blended_tiling import TilingModule
from shapely.geometry import Polygon

from nuc2seg import log_config
from nuc2seg.data import Nuc2SegDataset, SegmentationResults
from nuc2seg.data import Nuc2SegDataset
from nuc2seg.plotting import (
plot_segmentation_class_assignment,
celltype_histogram,
celltype_area_violin,
)
from nuc2seg.segment import segmentation_array_to_shapefile
from nuc2seg.utils import get_tile_idx, generate_tiles
from nuc2seg.preprocessing import create_shapely_rectangle
from nuc2seg.utils import get_tile_idx, generate_tiles

logger = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions src/nuc2seg/cli/plot_predictions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse
import logging
import os.path
import tqdm

import numpy as np
import tqdm

from nuc2seg import log_config
from nuc2seg.data import (
Expand All @@ -11,8 +12,8 @@
ModelPredictions,
SegmentationResults,
)
from nuc2seg.utils import generate_tiles
from nuc2seg.plotting import plot_model_predictions
from nuc2seg.utils import generate_tiles

logger = logging.getLogger(__name__)

Expand Down
17 changes: 9 additions & 8 deletions src/nuc2seg/cli/preprocess.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import argparse
import logging
import pandas
import os.path

from nuc2seg import log_config
import pandas
from matplotlib import pyplot as plt
from nuc2seg.xenium import (
load_nuclei,
load_and_filter_transcripts_as_points,
create_shapely_rectangle,
)

from nuc2seg import log_config
from nuc2seg.celltyping import (
select_best_celltyping_chain,
predict_celltypes_for_segments_and_transcripts,
)
from nuc2seg.preprocessing import create_rasterized_dataset, create_nuc2seg_dataset
from nuc2seg.data import CelltypingResults
from nuc2seg.plotting import plot_celltype_estimation_results, rank_genes_groups_plot
from nuc2seg.preprocessing import create_rasterized_dataset, create_nuc2seg_dataset
from nuc2seg.xenium import (
load_nuclei,
load_and_filter_transcripts_as_points,
create_shapely_rectangle,
)

logger = logging.getLogger(__name__)

Expand Down
10 changes: 2 additions & 8 deletions src/nuc2seg/cli/preprocess_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import os
import shutil
import tempfile
import json
import geopandas as gpd
from unittest import mock
import anndata
import pandas

from nuc2seg.data import CelltypingResults, Nuc2SegDataset
from nuc2seg.utils import generate_tiles
from blended_tiling import TilingModule
import numpy as np
import math

from nuc2seg.cli import preprocess
from nuc2seg.data import CelltypingResults, Nuc2SegDataset


def test_baysor_postprocess(
Expand Down
2 changes: 1 addition & 1 deletion src/nuc2seg/cli/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from nuc2seg.segment import (
greedy_cell_segmentation,
convert_segmentation_to_shapefile,
convert_transcripts_to_anndata,
)
from nuc2seg.postprocess import convert_transcripts_to_anndata
from nuc2seg.xenium import (
load_and_filter_transcripts_as_points,
)
Expand Down
2 changes: 1 addition & 1 deletion src/nuc2seg/cli/tile_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import logging

from nuc2seg import log_config
from nuc2seg.data import Nuc2SegDataset
from nuc2seg.preprocessing import (
tile_dataset_to_disk,
)
from nuc2seg.data import Nuc2SegDataset

logger = logging.getLogger(__name__)

Expand Down
11 changes: 6 additions & 5 deletions src/nuc2seg/cli/tile_xenium.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import argparse
import logging
import pandas as pd
import math

import pandas as pd
from shapely import box

from nuc2seg import log_config
from nuc2seg.xenium import (
load_and_filter_transcripts_as_table,
)
from nuc2seg.preprocessing import (
tile_transcripts_to_disk,
tile_nuclei_to_disk,
)
from shapely import box
from nuc2seg.xenium import (
load_and_filter_transcripts_as_table,
)

logger = logging.getLogger(__name__)

Expand Down
9 changes: 5 additions & 4 deletions src/nuc2seg/cli/train.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import argparse
import logging
import numpy as np
import os.path

import numpy as np
from pytorch_lightning import Trainer
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning.loggers import WandbLogger

from nuc2seg import log_config
from nuc2seg.data import Nuc2SegDataset, TiledDataset, TrainTestSplit
from nuc2seg.unet_model import SparseUNet, Nuc2SegDataModule
from pytorch_lightning import Trainer, Callback
from pytorch_lightning.loggers import WandbLogger
from pytorch_lightning.callbacks import ModelCheckpoint

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions src/nuc2seg/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import pandas
import geopandas
import pandas
import pytest
import shapely


Expand Down
10 changes: 5 additions & 5 deletions src/nuc2seg/data.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import h5py
import logging
import torch
import pandas
import numpy as np

import h5py
import numpy as np
import pandas
import torch
from blended_tiling import TilingModule
from torch.nn.utils.rnn import pad_sequence
from torch.utils.data import Dataset
from blended_tiling import TilingModule

from nuc2seg.utils import generate_tiles

Expand Down
10 changes: 6 additions & 4 deletions src/nuc2seg/data_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os.path
import shutil
import tempfile

import numpy as np
import pytest
from blended_tiling import TilingModule

from nuc2seg.data import (
Nuc2SegDataset,
TiledDataset,
CelltypingResults,
RasterizedDataset,
)
from nuc2seg.utils import generate_tiles
import numpy as np
import tempfile
import os.path
from blended_tiling import TilingModule


@pytest.fixture(scope="package")
Expand Down
10 changes: 5 additions & 5 deletions src/nuc2seg/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import torch
import numpy as np
import torch
import torch.nn.functional as F
import tqdm
from matplotlib import pyplot as plt
from scipy.special import softmax, expit
from torch import Tensor
from matplotlib import pyplot as plt
import tqdm

from nuc2seg.preprocessing import pol2cart
from nuc2seg.data import collate_tiles
import torch.nn.functional as F
from nuc2seg.preprocessing import pol2cart


def dice_coeff(
Expand Down
3 changes: 2 additions & 1 deletion src/nuc2seg/evaluate_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import torch

from nuc2seg.evaluate import (
dice_coeff,
multiclass_dice_coeff,
Expand All @@ -6,7 +8,6 @@
angle_accuracy,
celltype_accuracy,
)
import torch


def test_dice_coeff():
Expand Down
5 changes: 3 additions & 2 deletions src/nuc2seg/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import geopandas
import numpy as np
import pandas
import seaborn as sns
import tqdm
from matplotlib import cm, gridspec, animation
from matplotlib import pyplot as plt
from shapely import box
import seaborn as sns
from nuc2seg.segment import greedy_cell_segmentation

from nuc2seg.data import (
Nuc2SegDataset,
ModelPredictions,
SegmentationResults,
CelltypingResults,
)
from nuc2seg.preprocessing import pol2cart
from nuc2seg.segment import greedy_cell_segmentation


def plot_tiling(bboxes, output_path):
Expand Down
Loading

0 comments on commit 2b13d16

Please sign in to comment.