Skip to content

Commit

Permalink
Update otoferlin correction script
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Dec 9, 2024
1 parent 3bcca74 commit 70a5856
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion scripts/otoferlin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# These are the otoferlin tomograms.
INPUT_ROOT = "/home/ag-wichmann/data/otoferlin/tomograms"
OUTPUT_ROOT = "/home/ag-wichmann/data/otoferlin/segmentation"
OUTPUT_ROOT = "./segmentation"

STRUCTURE_NAMES = ("ribbon", "PD", "membrane")

Expand Down
30 changes: 8 additions & 22 deletions scripts/otoferlin/correct_structure_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
import os
from glob import glob
from pathlib import Path

import imageio.v3 as imageio
import h5py
import mrcfile
import napari
import numpy as np

# TODO refactor everything once things are merged
ROOT = "/home/ag-wichmann/data/otoferlin/tomograms"
if not os.path.exists(ROOT):
ROOT = "./data/tomograms"

SEG_ROOT = "./segmentation/v2"
from synapse_net.file_utils import read_mrc
from common import get_all_tomograms, get_seg_path


def correct_structure_segmentation(mrc_path):
rel_path = os.path.relpath(mrc_path, ROOT)
rel_folder, fname = os.path.split(rel_path)
fname = os.path.splitext(fname)[0]
seg_path = os.path.join(SEG_ROOT, rel_folder, f"{fname}.h5")

with mrcfile.open(mrc_path, permissive=True) as mrc:
data = np.asarray(mrc.data[:])
data = np.flip(data, axis=1)
seg_path = get_seg_path(mrc_path)

correction_folder = os.path.join(SEG_ROOT, rel_folder, "correction")
data, _ = read_mrc(mrc_path)
correction_folder = os.path.join(os.path.split(seg_path)[0], "correction")
fname = Path(mrc_path).stem

names = ("ribbon", "PD", "membrane", "veiscles_postprocessed")
segmentations = {}
Expand All @@ -52,10 +41,7 @@ def correct_structure_segmentation(mrc_path):


def main():
tomograms = glob(os.path.join(ROOT, "**", "*.mrc"), recursive=True)
tomograms += glob(os.path.join(ROOT, "**", "*.rec"), recursive=True)
tomograms = sorted(tomograms)

tomograms = get_all_tomograms()
for tomo in tomograms:
correct_structure_segmentation(tomo)

Expand Down

0 comments on commit 70a5856

Please sign in to comment.