@@ -0,0 +1,1681 @@
+#!/usr/bin/env python%0Afrom __future__ import print_function%0Aimport ftplib%0Aimport sys%0A%0Agenome_list_fh = open(%22downloaded_genomes.txt%22,%22w%22)%0A%0Aftp = ftplib.FTP(%22ftp.ncbi.nlm.nih.gov%22)%0Aftp.connect()%0Aftp.login()%0Abase_path=%22/genomes/refseq/fungi%22%0Aftp.cwd(base_path)%0A#Get species%0Aspecies_list = ftp.nlst()%0A#for each species%0Afor species in species_list:%0A%09print(%22Species: %7B%7D%22.format(species))%0A%09species_path = base_path + %22/%7B%7D/latest_assembly_versions%22.format(species)%0A%09#Go into species assembly directory%0A%09try:%0A%09%09ftp.cwd(species_path)%0A%09except Exception as e:%0A%09%09print(%22+ Cannot go into dir %7B%7D%22.format(species_path),file=sys.stderr)%0A%09%09print(e,file=sys.stderr)%0A%09%09continue%0A%09%09%0A%09#Get assemblies%0A%09assemblies = ftp.nlst()%0A%09for asm in assemblies:%0A%09%09print(%22Entering assembly %7B%7D%22.format(asm))%0A%09%09try:%0A%09%09%09ftp.cwd(species_path + %22/%22 +  asm)%0A%09%09except Exception as e:%0A%09%09%09print(%22+ Cannot enter dir %7B%7D%22.format(species_path+%22/%22+asm),file=sys.stderr)%0A%09%09%09print(e,file=sys.stderr)%0A%09%09%09continue%0A%09%09%0A%09%09asm_file_list = ftp.nlst()%0A%09%09files_to_dl = %5Bf for f in asm_file_list if (f.endswith(%22genomic.fna.gz%22)) and (%22cds_from_genomic%22 not in f) and (%22rna_from_genomic%22 not in f)%5D%0A%09%09if not files_to_dl:%0A%09%09%09#Try downloading the cds%0A%09%09%09files_to_dl = %5Bf for f in asm_file_list if (f.endswith(%22cds_from_genomic.fna.gz%22)) %5D%0A%09%09for filename in files_to_dl:%0A%09%09%09print(%22Downloading file %7B%7D%22.format(filename))%0A%09%09%09print('%7B%7D%5Ct%7B%7D%5Ct%7B%7D'.format(species,asm,filename),file=genome_list_fh)%0A%09%09%09try:%0A%09%09%09%09with open(filename,%22wb%22) as fh:%0A%09%09%09%09%09ftp.retrbinary(%22RETR %7B%7D%22.format(filename), fh.write, 8*1024)%0A%09%09%09except Exception as e:%0A%09%09%09%09print(%22%3EError downloading %7B%7D%22.format(asm_filename),file=sys.stderr)%0A%09%09%09%09print(e,file=sys.stderr)%0A%09%09%09%0Aftp.close()%0A

Add script to download refseq fungal genomes via FTP