inprogress
[jalview.git] / forester / ruby / scripts / ensembl_ftp.rb
1 require 'net/ftp'
2
3 EMAIL           = '?'
4 PUB_RELEASE_DIR = '/pub/release-65/fasta'
5 PEP_DIR         = '/pep'
6
7 ftp = Net::FTP.new('ftp.ensembl.org', 'anonymous', EMAIL)
8 ftp.passive = true # To avoid "No route to host" error.
9 ftp.chdir( PUB_RELEASE_DIR )
10 files = ftp.list('*_*') # To only look at files with an underscore.
11 count = 0
12 files.each do | file |
13   species = file.split().last
14   begin
15     ftp.chdir(species + PEP_DIR)
16     pepfiles = ftp.list()
17     pepfiles.each do | pepfile |
18       pepfile = pepfile.split().last
19       if pepfile =~ /all.fa.gz/ # Only want the "all.fa.gz" files (and not the
20                                 # "abinitio" files).
21         ftp.getbinaryfile(pepfile)
22         puts 'downloaded "' + pepfile + '"'
23         count += 1
24       end
25     end
26   rescue Exception
27     puts 'ignoring "' + species + '"'
28   end
29   ftp.chdir(PUB_RELEASE_DIR) # To go back to the starting directory.
30 end
31 ftp.close
32 puts 'done (downloaded ' + count.to_s + ' files)'