Skip to content

Commit 64be5bf

Browse files
committed
Replace preprocessing test data
1 parent 468fbec commit 64be5bf

8 files changed

Lines changed: 131505 additions & 41 deletions

File tree

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
tests/TCGA-MR-A520-01Z-00-DX1.2F323BAC-56C9-4A0C-9C1B-2B4F776056B4.svs
44

5-
tests/inputs/21_5_mask.pkl
6-
tests/inputs/21_5.zarr
7-
tests/patch_information.db
5+
tests/inputs/TCGA-18-5592-01Z-00-DX1.zarr
6+
tests/inputs/TCGA-18-5592-01Z-00-DX1_mask.pkl
87

98
tests/output.pkl
109
tests/output_zarr.zarr

pathflowai/cli_preprocessing.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import dask
1212
import time
1313

14-
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"], "max_content_width": 90}
14+
CONTEXT_SETTINGS = {"help_option_names": [
15+
"-h", "--help"], "max_content_width": 90}
1516

1617

1718
@click.group(context_settings=CONTEXT_SETTINGS)
@@ -34,7 +35,6 @@ def output_if_exists(filename):
3435
Filename.
3536
3637
"""
37-
3838
if os.path.exists(filename):
3939
return filename
4040
return None
@@ -200,15 +200,17 @@ def preprocess_pipeline(
200200
".png",
201201
".h5",
202202
]:
203-
svs_file = output_if_exists(join(input_dir, "{}{}".format(basename, ext)))
203+
svs_file = output_if_exists(
204+
join(input_dir, "{}{}".format(basename, ext)))
204205
if svs_file is not None:
205206
break
206207

207208
if img2npy and not svs_file.endswith(".npy"):
208209
svs_file = img2npy_(input_dir, basename, svs_file)
209210

210211
xml_file = output_if_exists(join(input_dir, "{}.xml".format(basename)))
211-
npy_mask = output_if_exists(join(input_dir, "{}_mask.npy".format(basename)))
212+
npy_mask = output_if_exists(
213+
join(input_dir, "{}_mask.npy".format(basename)))
212214
out_zarr = join(input_dir, "{}.zarr".format(basename))
213215
out_pkl = join(input_dir, "{}_mask.pkl".format(basename))
214216
adj_npy = ""
@@ -230,7 +232,8 @@ def preprocess_pipeline(
230232
npy_mask = join(input_dir, "{}_mask.npz".format(basename))
231233
target_segmentation_class = 1
232234
generate_finetune_segmentation = True
233-
create_zero_mask(npy_mask, out_zarr if not no_zarr else svs_file, out_pkl)
235+
create_zero_mask(
236+
npy_mask, out_zarr if not no_zarr else svs_file, out_pkl)
234237

235238
preprocess_point = time.time()
236239
print("Data dump took {}".format(preprocess_point - start))
@@ -363,7 +366,8 @@ def remove_basename_from_db(input_patch_db, output_patch_db, basename, patch_siz
363366
conn.close()
364367
df = df.loc[df["ID"] != basename]
365368
conn = sqlite3.connect(output_patch_db)
366-
df.set_index("index").to_sql(str(patch_size), con=conn, if_exists="replace")
369+
df.set_index("index").to_sql(
370+
str(patch_size), con=conn, if_exists="replace")
367371
conn.close()
368372

369373

@@ -439,20 +443,23 @@ def collapse_annotations(
439443
conn.close()
440444
from_to = zip(from_annotations, to_annotations)
441445
if remove_background_annotation:
442-
df = df.loc[df[remove_background_annotation] <= (1.0 - max_background_area)]
446+
df = df.loc[df[remove_background_annotation]
447+
<= (1.0 - max_background_area)]
443448
for fr, to in from_to:
444449
df.loc[:, to] += df[fr]
445450
df = df[[col for col in list(df) if col not in from_annotations]]
446451
annotations = list(df.iloc[:, 6:])
447-
df = df.rename(columns={annot: str(i) for i, annot in enumerate(annotations)})
452+
df = df.rename(columns={annot: str(i)
453+
for i, annot in enumerate(annotations)})
448454
annotations = list(df.iloc[:, 6:])
449455
df.loc[:, "annotation"] = np.vectorize(
450456
lambda i: annotations[df.iloc[i, 6:].values.argmax()]
451457
)(np.arange(df.shape[0]))
452458
df.loc[:, "index"] = np.arange(df.shape[0])
453459
conn = sqlite3.connect(output_patch_db)
454460
# print(df)
455-
df.set_index("index").to_sql(str(patch_size), con=conn, if_exists="replace")
461+
df.set_index("index").to_sql(
462+
str(patch_size), con=conn, if_exists="replace")
456463
conn.close()
457464

458465

tests/inputs/21_5.npy

-733 KB
Binary file not shown.

tests/inputs/21_5_mask.npy

-977 KB
Binary file not shown.
1.41 MB
Loading

0 commit comments

Comments
 (0)