Edited wiki page RubyExamples through web user interface.
[jalview.git] / wiki / RubyExamples.wiki
1 #summary Ruby examples
2
3 = Introduction =
4
5 Various Ruby examples.
6
7 Author: [http://www.cmzmasek.net/ Christian M Zmasek], Sanford-Burnham Medical Research Institute
8
9  
10 Copyright (C) 2011 Christian M Zmasek. All rights reserved.
11
12
13 = Using net/ftp to download all Proteomes from the Ensembl Database =
14
15 {{{
16 require 'net/ftp'
17
18 EMAIL           = 'myemail'
19 PUB_RELEASE_DIR = '/pub/release-64/fasta'
20 PEP_DIR          = '/pep'
21
22 ftp = Net::FTP.new('ftp.ensembl.org', 'anonymous', EMAIL)
23 ftp.passive = true # To avoid "No route to host" error.
24 ftp.chdir( PUB_RELEASE_DIR )
25 files = ftp.list('*_*') # To only look at files with an underscore.
26 count = 0
27 files.each do | file |
28   species = file.split().last
29   begin
30     ftp.chdir(species + PEP_DIR)
31     pepfiles = ftp.list()
32     pepfiles.each do | pepfile |
33       pepfile = pepfile.split().last
34       if pepfile =~ /all.fa./
35         ftp.getbinaryfile(pepfile)
36         puts 'downloaded "' + pepfile + '"'
37         count += 1
38       end
39     end
40   rescue Exception
41     puts 'ignoring "' + species + '"'
42   end
43   ftp.chdir(PUB_RELEASE_DIR) # To go back to the starting directory.
44 end
45 ftp.close
46 puts 'done (downloaded ' + count.to_s + ' files)'
47 }}}