@@ -65,21 +65,29 @@ def download_represenatives(self,genome_path,url="https://data.ace.uq.edu.au/pub
6565 path
6666 '''
6767 logger .debug (genome_path )
68- logger .info ("Download represenative genomes from {url}" .format (url = url ))
68+ input_file_name = url .split ("/" )[- 1 ]
69+ self .location = genome_path .rstrip ("/" )+ "/representatives"
6970 self .representative_file = url .rsplit ("/" )[- 1 ]
70- location = genome_path .rstrip ("/" )+ "/representatives"
71- #as suggested by @SilentGhost the `location` and `url` should be separate argument
72- args = ['wget' , '-r' , '-l' , '1' , '-p' , '-P' , location , url ]
71+ '''Check if exists already if so ask to replace or continue without downloading'''
72+ if os .path .exists (self .location + "/" + input_file_name ):
73+ ans = input ("A represenative file already exist, (u)se file, (o)verwrite (c)ancel? (u o,c): " )
74+ if ans in ["o" , "O" ]:
75+ logger .info ("Overwrite current progress" )
76+ os .remove ("{file}" .format (file = input_file_name ))
77+ elif ans .strip () in ["u" , "U" ]:
78+ logger .info ("Resume database build" )
79+ return input_file_name
80+ else :
81+ exit ("Cancel execution!" )
82+ logger .info ("Download represenative genomes from {url}" .format (url = url ))
83+ #as suggested by @SilentGhost the `self.location` and `url` should be separate argument
84+ args = ['wget' , '-nd' , '-r' , '-l' , '1' , '-p' , '-P' , self .location , url ]
7385 logger .debug (" " .join (args ))
74- input_file_name = url .split ("/" )[- 1 ]
75- downloaded_file = location + "/" + input_file_name
7686 logger .info ("Waiting for download process to finish (this may take a while)!" )
7787 p = Popen (args , stdout = PIPE )
78- (output , err ) = p .communicate () #now wait plus that you can send commands to process
79- #This makes the wait possible
80-
88+ (output , err ) = p .communicate ()
8189 p_status = p .wait ()
82- return downloaded_file
90+ return input_file_name
8391
8492 def parse_representatives (self ,downloaded_file ):
8593 '''Parse representative genomes
@@ -90,9 +98,12 @@ def parse_representatives(self,downloaded_file):
9098 path - path to unzipped folder
9199 '''
92100 args = ["tar" , "-xf" , downloaded_file ]
93- output = Popen (args , stdout = PIPE )
94- folder_path = downloaded_file .rsplit ("." ,2 )[0 ] ## remove tar and gz
95- return folder_path
101+ logger .info ("Untar file {f}" .format (f = downloaded_file ))
102+ logger .debug (" " .join (args ))
103+ p = Popen (args , stdout = PIPE ,cwd = self .location )
104+ (output , err ) = p .communicate ()
105+ p_status = p .wait ()
106+ return self .location
96107
97108 def download_files (self ,files ):
98109 '''Download list of GCF and or GCA files from NCBI
0 commit comments