|
11 | 11 | import cv2
|
12 | 12 | from .reconstruct_dzi import reconstruct_dzi
|
13 | 13 |
|
| 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 |
14 | 50 |
|
15 | 51 | def read_flat_file(file):
|
16 | 52 | """
|
|
0 commit comments