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