Skip to content

Commit

Permalink
solving KoslickiLab#20, possible solve for KoslickiLab#21
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmudhera committed Aug 31, 2022
1 parent 384198d commit ac0f6e2
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions scripts/get_reference_genomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,11 @@ def check_count(self, path, INTIAL_COUNT, number_of_genomes):
return False
return True

def download_FNA_file(self, path, current_directory_name): # download all FASTA files in a directory
def download_FNA_and_GBFF_file(self, path, current_directory_name): # download all FASTA files in a directory
ftp = self.ftp
path = self.make_file(os.path.join(path, f"{current_directory_name}"))
for filename in ftp.nlst():
if filename.endswith(".fna.gz"):
completeName = os.path.join(path, filename)
file = open(completeName, "wb")
ftp.retrbinary(f"RETR {filename}", file.write)
file.close()

def download_GBFF_file(self,path, current_directory_name):
ftp = self.ftp
#path = self.make_file(os.path.join(path, f"{current_directory_name}"))
for filename in ftp.nlst():
if filename.endswith(".gbff.gz"):
if filename.endswith(".fna.gz") or filename.endswith(".gbff.gz"):
completeName = os.path.join(path, filename)
file = open(completeName, "wb")
ftp.retrbinary(f"RETR {filename}", file.write)
Expand Down Expand Up @@ -156,8 +146,7 @@ def main():
raise Exception(f"The file path must be a directory. I was given {save_path}")
# check if directory is empty
if os.listdir(save_path):
print(f" WARNING: the directory {save_path} is not empty, press any key to continue or ctrl+c to exit")
input()
print(f" WARNING: the directory {save_path} is not empty.")

# Instantiate the helper class
helper = Helper(credentials)
Expand Down Expand Up @@ -205,8 +194,7 @@ def main():
print('Downloading genome: ' + current_directory_name)

try:
helper.download_FNA_file(path, current_directory_name)
helper.download_GBFF_file(path, current_directory_name)
helper.download_FNA_and_GBFF_file(path, current_directory_name)
except EOFError:
print('Problem downloading genome ' + current_directory_name + ' due to a closed onnection, skipping this.')
cmd = 'rm -rf ' + path+'/'+current_directory_name
Expand All @@ -220,7 +208,7 @@ def main():

helper.return_to_original_direct()
continue

total_downloaded += 1
helper.return_to_original_direct()

Expand Down

0 comments on commit ac0f6e2

Please sign in to comment.