X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=wiki%2FRubyExamples.wiki;h=7e49fce59afad4a065a222eda84505495aedac65;hb=149c4d125eaba81f80bf76548f47f3ba75b384c6;hp=b52eef0b88658b9c3b1715fba597936a5619ab16;hpb=9b56c6f0e306f87bb42fd31e77a2e970854607ea;p=jalview.git diff --git a/wiki/RubyExamples.wiki b/wiki/RubyExamples.wiki index b52eef0..7e49fce 100644 --- a/wiki/RubyExamples.wiki +++ b/wiki/RubyExamples.wiki @@ -1,13 +1,50 @@ -#summary One-sentence summary of this page. +#summary Ruby examples -= Introduction = += Ruby Examples = -Add your content here. +Various simple Ruby examples. +Author: [http://www.cmzmasek.net/ Christian M Zmasek], Sanford-Burnham Medical Research Institute -= Details = + +Copyright (C) 2011 Christian M Zmasek. All rights reserved. -Add your content here. Format your content with: - * Text in *bold* or _italic_ - * Headings, paragraphs, and lists - * Automatic links to other wiki pages \ No newline at end of file + += Using net/ftp to download all Proteomes from the Ensembl Database = + +This, or something like it, can be used to download from Ensembl all "pep.all.fa.gz" files. + +{{{ +require 'net/ftp' + +EMAIL = 'myemail' +PUB_RELEASE_DIR = '/pub/release-64/fasta' +PEP_DIR = '/pep' + +ftp = Net::FTP.new('ftp.ensembl.org', 'anonymous', EMAIL) +ftp.passive = true # To avoid "No route to host" error. +ftp.chdir( PUB_RELEASE_DIR ) +files = ftp.list('*_*') # To only look at files with an underscore. +count = 0 +files.each do | file | + species = file.split().last + begin + ftp.chdir(species + PEP_DIR) + pepfiles = ftp.list() + pepfiles.each do | pepfile | + pepfile = pepfile.split().last + if pepfile =~ /all.fa.gz/ # Only want the "all.fa.gz" files (and not the + # "abinitio" files). + ftp.getbinaryfile(pepfile) + puts 'downloaded "' + pepfile + '"' + count += 1 + end + end + rescue Exception + puts 'ignoring "' + species + '"' + end + ftp.chdir(PUB_RELEASE_DIR) # To go back to the starting directory. +end +ftp.close +puts 'done (downloaded ' + count.to_s + ' files)' +}}} \ No newline at end of file