Skip to content

Commit fe722e0

Browse files
Add code for synapse model export and for initial synapse analysis
1 parent 1d1adee commit fe722e0

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
import json
3+
4+
import numpy as np
5+
import pandas as pd
6+
7+
from flamingo_tools.s3_utils import BUCKET_NAME, create_s3_target
8+
9+
10+
def check_project():
11+
s3 = create_s3_target()
12+
cochleae = ['M_LR_000226_L', 'M_LR_000226_R', 'M_LR_000227_L', 'M_LR_000227_R']
13+
14+
for cochlea in cochleae:
15+
content = s3.open(f"{BUCKET_NAME}/{cochlea}/dataset.json", mode="r", encoding="utf-8")
16+
info = json.loads(content.read())
17+
sources = info["sources"]
18+
19+
# Load the synapse table.
20+
syn = sources["synapse_v3"]["spots"]
21+
rel_path = syn["tableData"]["tsv"]["relativePath"]
22+
table_content = s3.open(os.path.join(BUCKET_NAME, cochlea, rel_path, "default.tsv"), mode="rb")
23+
syn_table = pd.read_csv(table_content, sep="\t")
24+
25+
# Load the corresponding ihc table.
26+
ihc = sources["IHC_v2"]["segmentation"]
27+
rel_path = ihc["tableData"]["tsv"]["relativePath"]
28+
table_content = s3.open(os.path.join(BUCKET_NAME, cochlea, rel_path, "default.tsv"), mode="rb")
29+
ihc_table = pd.read_csv(table_content, sep="\t")
30+
31+
# Keep only the synapses that were matched to a valid IHC.
32+
component_id = 2 if cochlea == "M_LR_000226_R" else 1
33+
valid_ihcs = ihc_table.label_id[ihc_table.component_labels == component_id].values
34+
35+
valid_syn_table = syn_table[syn_table.matched_ihc.isin(valid_ihcs)]
36+
n_synapses = len(valid_syn_table)
37+
38+
_, syn_per_ihc = np.unique(valid_syn_table.matched_ihc.values, return_counts=True)
39+
40+
print("Cochlea:", cochlea)
41+
print("N-Synapses:", n_synapses)
42+
print("Average Syn per IHC:", np.mean(syn_per_ihc))
43+
print("STDEV Syn per IHC:", np.std(syn_per_ihc))
44+
print()
45+
46+
47+
def main():
48+
check_project()
49+
50+
51+
if __name__ == "__main__":
52+
main()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import argparse
2+
import sys
3+
4+
import torch
5+
from torch_em.util import load_model
6+
7+
sys.path.append("/home/pape/Work/my_projects/czii-protein-challenge")
8+
sys.path.append("/user/pape41/u12086/Work/my_projects/czii-protein-challenge")
9+
10+
11+
def export_model(input_, output):
12+
model = load_model(input_, device="cpu")
13+
torch.save(model, output)
14+
15+
16+
def main():
17+
parser = argparse.ArgumentParser()
18+
parser.add_argument("-i", "--input", required=True)
19+
parser.add_argument("-o", "--output", required=True)
20+
args = parser.parse_args()
21+
export_model(args.input, args.output)
22+
23+
24+
if __name__ == "__main__":
25+
main()

0 commit comments

Comments
 (0)