Skip to content

Commit 5bbe0bb

Browse files
committed
implement custom atlas reader function and remove unused dependencies
1 parent 74f018f commit 5bbe0bb

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

PyNutil/io/read_and_write.py

+36
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,42 @@
1111
import cv2
1212
from .reconstruct_dzi import reconstruct_dzi
1313

14+
def open_custom_region_file(path):
15+
"""
16+
Opens a custom region file created by QCAlign or manually by the user.
17+
18+
Parameters
19+
----------
20+
path : str
21+
the path to the TSV or XLSX file containing the custom region mappings.
22+
If the file extension is not XLSX we will assume it is TSV. By default
23+
QCAlign exports TSV files with a TXT extension.
24+
25+
Returns
26+
----------
27+
custom_region_to_rgb : dict
28+
mapping of custom region name to the RGB colour you would like to assign it.
29+
custom_region_to_atlas_ids : dict
30+
mapping of custom region name to the regions it is composed of from the atlas
31+
you have chosen.
32+
"""
33+
if path.lower().endswith(".xlsx"):
34+
df = pd.read_excel(path)
35+
else:
36+
df = pd.read_csv(path, sep="\t")
37+
if len(df.columns) < 2:
38+
raise ValueError("Expected at least two columns in the file.")
39+
custom_region_names = df.columns[1:]
40+
rgb_values = df.iloc[0,:].values[1:]
41+
try:
42+
rgb_values = [list(int(i) for i in rgb.split(';')) for rgb in rgb_values]
43+
except ValueError:
44+
print("Error: Non integer value found in rgb list")
45+
atlas_ids = df.iloc[1:,1:].T.values
46+
atlas_ids = [[int(j) for j in i if not j is np.nan] for i in atlas_ids]
47+
custom_region_to_rgb = dict(zip(custom_region_names,rgb_values))
48+
custom_region_to_atlas_ids = dict(zip(custom_region_names,atlas_ids))
49+
return custom_region_to_rgb, custom_region_to_atlas_ids
1450

1551
def read_flat_file(file):
1652
"""

PyNutil/main.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import json
2-
import os
3-
42
from .io.atlas_loader import load_atlas_data, load_custom_atlas
53
from .processing.data_analysis import quantify_labeled_points
64
from .io.file_operations import save_analysis_output
5+
from .io.read_and_write import open_custom_region_file
76
from .processing.coordinate_extraction import folder_to_atlas_space
8-
from .processing.counting_and_load import label_points
9-
107

118
class PyNutil:
129
"""

0 commit comments

Comments
 (0)