Skip to content

Commit a48b6c2

Browse files
committed
Added function to download and use GTDB representative genomes
1 parent 463f9bd commit a48b6c2

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

flextaxd/create_databases.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def __init__(self, message,expression=""):
165165
skip=False
166166
if os.path.exists("{db_path}/library/library.fna".format(db_path=args.db_name)):
167167
ans = input("Database library file already exist, (u)se library, (o)verwrite (c)ancel? (u o,c): ")
168-
print(ans)
169168
if ans in ["o", "O"]:
170169
logger.info("Overwrite current build progress")
171170
shutil.rmtree("{db_path}".format(db_path=args.db_name))
@@ -189,9 +188,8 @@ def __init__(self, message,expression=""):
189188
still_missing = missing
190189
if len(still_missing) > 0: print("Not able to download: {nr}".format(nr=len(still_missing)))
191190
else:
192-
print(new_genome_path)
193191
new_genomes, missing = process_directory_obj.process_folder(new_genome_path)
194-
genomes =+ new_genomes
192+
genomes += new_genomes
195193
else:
196194
if len(missing) > 0:
197195
logger.info("Genome annotations with no matching source: {nr}".format(nr=len(missing)))

flextaxd/modules/DownloadGenomes.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)