11#!/usr/bin/env python
2-
2+ import argparse
33import synapseclient
44import synapseutils
55from getpass import getpass
66from os import devnull
77from contextlib import redirect_stdout
8- import argparse
8+ from glob import glob
9+ from json import load
10+ from os .path import exists
911
1012ECA_SYNAPSE_ID = "syn32148000"
1113
@@ -24,10 +26,40 @@ def download(dataset_path, username, password):
2426 synapseutils .syncFromSynapse (syn , ECA_SYNAPSE_ID , path = dataset_path , manifest = "suppress" )
2527 print ("Download finished.\n " )
2628
29+ def check (dataset_path ):
30+ print ("Checking for missing files in \" " + dataset_path + "\" ." )
31+
32+ manifest_files = glob (dataset_path + "/*/manifest.json" )
33+ if len (manifest_files ) < 2 :
34+ print ("Missing manifest files detected!" )
35+ return
36+ samples = []
37+ for manifest_file in manifest_files :
38+ with open (manifest_file ) as file :
39+ samples += load (file )
40+
41+ for sample in samples :
42+ image_exists = exists (dataset_path + "/" + sample ["image_file" ])
43+ mask_exists = exists (dataset_path + "/" + sample ["mask_file" ])
44+ if not image_exists or not mask_exists :
45+ print ("Missing samples detected!" )
46+ return
47+
48+ print ("Dataset is complete." )
49+
2750if __name__ == "__main__" :
2851 parser = argparse .ArgumentParser ()
52+ parser .add_argument (nargs = 1 , dest = 'command' , default = None , choices = ["download" , "check" ])
2953 parser .add_argument ('-d' , '--dir' , dest = 'directory' , default = "eca-data" , help = "The directory to download the dataset to" , metavar = "\b " )
3054 parser .add_argument ('-u' , '--user' , dest = 'username' , default = None , help = "Synapse username" , metavar = "\b " )
3155 parser .add_argument ('-p' , '--pass' , dest = 'password' , default = None , help = "Synapse password" , metavar = "\b " )
3256 args = parser .parse_args ()
33- download (args .directory , args .username , args .password )
57+
58+ args .command = args .command [0 ]
59+
60+ if args .command == "download" :
61+ download (args .directory , args .username , args .password )
62+ elif args .command == "check" :
63+ check (args .directory )
64+ else :
65+ raise Exception ("Invalid command! Options are \" download\" , and \" check\" ." )
0 commit comments