@@ -40,6 +40,7 @@ def main():
4040)
4141@click .option (
4242 "--mode" ,
43+ default = "show" ,
4344 help = "'show' to display meta information only or 'save' to save "
4445 "the meta information, default=show" ,
4546)
@@ -52,23 +53,43 @@ def main():
5253def slide_info (wsi_input , output_dir , file_types , mode , workers = None ):
5354 """Displays or saves WSI metadata"""
5455 file_types = tuple (file_types .split (", " ))
56+
5557 if os .path .isdir (wsi_input ):
5658 files_all = utils .misc .grab_files_from_dir (
5759 input_path = wsi_input , file_types = file_types
5860 )
61+ if output_dir is None and mode == "save" :
62+ input_dir , _ , _ = utils .misc .split_path_name_ext (wsi_input )
63+ output_dir = pathlib .Path (input_dir ).joinpath ("meta" )
64+
5965 elif os .path .isfile (wsi_input ):
6066 files_all = [
6167 wsi_input ,
6268 ]
69+ if output_dir is None and mode == "save" :
70+ input_dir , _ , _ = utils .misc .split_path_name_ext (wsi_input )
71+ output_dir = pathlib .Path (input_dir ).joinpath (".." ).joinpath ("meta" )
6372 else :
6473 raise ValueError ("wsi_input path is not valid" )
6574
6675 print (files_all )
6776
68- dataloader .slide_info .slide_info (
69- input_path = files_all , output_dir = output_dir , mode = mode , workers = workers ,
77+ slide_params = dataloader .slide_info .slide_info (
78+ input_path = files_all , workers = workers ,
7079 )
7180
81+ if mode == "show" :
82+ for slide_param in slide_params :
83+ print (slide_param )
84+
85+ if mode == "save" :
86+ output_dir .mkdir (parents = True , exist_ok = True )
87+ for slide_param in slide_params :
88+ utils .misc .save_yaml (slide_param ,
89+ pathlib .Path (output_dir )
90+ .joinpath (slide_param ["file_name" ] + ".yaml" ))
91+ print ("Meta files saved at " + str (output_dir ))
92+
7293
7394@main .command ()
7495@click .option ("--wsi_input" , help = "Path to WSI file" )
0 commit comments