1111import dask
1212import 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
0 commit comments