module Bio::Shell
bio/shell/demo.rb - demo mode for the BioRuby shell¶ ↑
- Copyright
-
Copyright (C) 2006 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: demo.rb,v 1.4 2007/04/05 23:35:41 trevor Exp $
bio/shell/interface.rb - core user interface of the BioRuby shell¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: interface.rb,v 1.19 2007/11/15 07:08:49 k Exp $
bio/shell/irb.rb - CUI for the BioRuby shell¶ ↑
- Copyright
-
Copyright (C) 2006 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: irb.rb,v 1.3 2007/04/05 23:35:41 trevor Exp $
bio/shell/plugin/blast.rb - plugin for BLAST services¶ ↑
- Copyright
-
Copyright (C) 2006 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: blast.rb,v 1.3 2007/04/05 23:35:41 trevor Exp $
bio/shell/plugin/codon.rb - plugin for the codon table¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: codon.rb,v 1.16 2007/04/05 23:35:41 trevor Exp $
bio/shell/plugin/emboss.rb - methods to use EMBOSS¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: emboss.rb,v 1.3 2007/04/05 23:35:41 trevor Exp $
bio/shell/plugin/entry.rb - extract entry and sequence¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id:$
bio/shell/plugin/flatfile.rb - plugin for flatfile database¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: flatfile.rb,v 1.13 2007/04/05 23:45:11 trevor Exp $
bio/shell/plugin/keggapi.rb - plugin for KEGG API¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: keggapi.rb,v 1.12 2007/04/05 23:35:41 trevor Exp $
bio/shell/plugin/ncbirest.rb - plugin for NCBI eUtils¶ ↑
- Copyright
-
Copyright (C) 2009 Naohisa Goto <ng@bioruby.org>
- License
-
The Ruby License
$Id:$
bio/shell/plugin/obda.rb - plugin for OBDA¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: obda.rb,v 1.10 2007/04/05 23:45:11 trevor Exp $
bio/shell/plugin/psort.rb - plugin for PSORT¶ ↑
- Copyright
-
Copyright (C) 2006 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: psort.rb,v 1.3 2007/04/05 23:35:41 trevor Exp $
bio/shell/plugin/seq.rb - plugin for biological sequence manipulations¶ ↑
- Copyright
-
Copyright (C) 2005 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: seq.rb,v 1.21 2007/04/05 23:35:41 trevor Exp $
bio/shell/plugin/soap.rb - web services¶ ↑
- Copyright
-
Copyright (C) 2006 Toshiaki Katayama <k@bioruby.org>
- License
-
Ruby's
$Id: soap.rb,v 1.1 2007/07/09 11:17:09 k Exp $
bio/shell/plugin/togows.rb - plugin for TogoWS REST service¶ ↑
- Copyright
-
Copyright (C) 2009 Naohisa Goto <ng@bioruby.org>
- License
-
The Ruby License
$Id:$
bio/shell/script.rb - script mode for the BioRuby shell¶ ↑
- Copyright
-
Copyright (C) 2006 Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: script.rb,v 1.3 2007/04/05 23:35:41 trevor Exp $
bio/shell/web.rb - GUI for the BioRuby shell¶ ↑
- Copyright
-
Copyright (C) 2006 Nobuya Tanaka <t@chemruby.org>, Toshiaki Katayama <k@bioruby.org>
- License
-
The Ruby License
$Id: web.rb,v 1.5 2007/06/26 08:38:38 k Exp $
Private Instance Methods
# File lib/bio/shell/plugin/codon.rb, line 199 def aminoacids names = Bio::AminoAcid.names names.sort.each do |aa, code| if aa.length == 1 puts "#{aa}\t#{code}\t#{names[code]}" end end return names end
# File lib/bio/shell/plugin/keggapi.rb, line 66 def bconv(str) result = keggapi.bconv(str) puts result return result end
# File lib/bio/shell/plugin/keggapi.rb, line 45 def bfind(str) result = keggapi.bfind(str) return result end
# File lib/bio/shell/plugin/keggapi.rb, line 50 def bget(str) result = keggapi.bget(str) if block_given? yield result else puts result return result end end
# File lib/bio/shell/plugin/keggapi.rb, line 39 def binfo(db = "all") result = keggapi.binfo(db) puts result return result end
# File lib/bio/shell/plugin/obda.rb, line 38 def biofetch(db, id, style = 'raw', format = 'default') serv = Bio::Fetch.new("http://www.ebi.ac.uk/cgi-bin/dbfetch") result = serv.fetch(db, id, style, format) return result end
# File lib/bio/shell/plugin/keggapi.rb, line 60 def btit(str) result = keggapi.btit(str) puts result return result end
file system
# File lib/bio/shell/interface.rb, line 179 def cd(dir = ENV['HOME']) if dir Dir.chdir(dir) end puts Dir.pwd.inspect end
# File lib/bio/shell/plugin/codon.rb, line 181 def codontable(num = 1, codon_usage = nil) cct = ColoredCodonTable.new(num, codon_usage) if codon_usage return cct else puts cct.output return cct.table end end
# File lib/bio/shell/plugin/codon.rb, line 191 def codontables tables = Bio::CodonTable::DEFINITIONS tables.sort.each do |i, definition| puts "#{i}\t#{definition}" end return tables end
config
# File lib/bio/shell/interface.rb, line 62 def config(mode = :show, *opts) case mode when :show, "show" Bio::Shell.config_show when :echo, "echo" Bio::Shell.config_echo when :color, "color" Bio::Shell.config_color when :splash, "splash" Bio::Shell.config_splash when :pager, "pager" Bio::Shell.config_pager(*opts) when :message, "message" Bio::Shell.config_message(*opts) else puts "Invalid mode (#{mode}) - :show, :echo, :color, :splash, :massage" end end
www.biodas.org/ www.dasregistry.org/
# File lib/bio/shell/plugin/das.rb, line 37 def das(url = nil) if url @das = Bio::DAS.new(url) else @das ||= keggdas end end
# File lib/bio/shell/plugin/soap.rb, line 58 def ddbjsoap(wsdl = nil) case wsdl when :blast @ddbjsoap = Bio::DDBJ::XML::Blast.new when :fasta @ddbjsoap = Bio::DDBJ::XML::Fasta.new when :clustalw @ddbjsoap = Bio::DDBJ::XML::ClustalW.new when :ddbj @ddbjsoap = Bio::DDBJ::XML::DDBJ.new when :gib @ddbjsoap = Bio::DDBJ::XML::Gib.new when :gtop @ddbjsoap = Bio::DDBJ::XML::Gtop.new when :pml @ddbjsoap = Bio::DDBJ::XML::PML.new when :srs @ddbjsoap = Bio::DDBJ::XML::SRS.new when :txsearch @ddbjsoap = Bio::DDBJ::XML::TxSearch.new when /^http/ @ddbjsoap = Bio::DDBJ::XML.new(wsdl) else @ddbjsoap ||= Bio::DDBJ::XML.new end return @ddbjsoap end
# File lib/bio/shell/demo.rb, line 15 def demo(part = nil) demo = Demo.new if part demo.send(part) else demo.all end end
# File lib/bio/shell/interface.rb, line 190 def dir(file = nil) if file if File.directory?(file) files = Dir.glob("#{file}/*") else files = Dir.glob(file) end else files = Dir.glob("*") end if files str = " UGO Date Byte File\n" str << "------ ------------------------------ ----------- ------------\n" files.sort.each { |f| stat = File.lstat(f) mode = format("%6o", stat.mode) date = stat.mtime byte = stat.size name = f.inspect str << format("%s %30s%13d %s\n", mode, date, byte, name) } puts str return files.sort end end
# File lib/bio/shell/interface.rb, line 95 def disp(*objs) # The original idea is from http://sheepman.parfait.ne.jp/20050215.html if cmd = Bio::Shell.config[:pager] pg = IO.popen(cmd, "w") begin stdout_save = STDOUT.clone STDOUT.reopen(pg) objs.each do |obj| if obj.is_a?(String) if File.exists?(obj) system("#{cmd} #{obj}") else obj.display end else pp obj end end ensure STDOUT.reopen(stdout_save) stdout_save.close pg.close end else objs.each do |obj| if obj.is_a?(String) obj.display else pp obj end end end end
Displays a DNA sequence by ascii art in B-type double helix. Argument need to be at least 16 bases in length.
# File lib/bio/shell/plugin/seq.rb, line 134 def doublehelix(str) seq = getseq(str) if seq.length < 16 warn "Error: Sequence must be longer than 16 bases." return end if seq.moltype != Bio::Sequence::NA warn "Error: Sequence must be a DNA sequence." return end pairs = [ [5, 0], [4, 2], [3, 3], [2, 4], [1, 4], [0, 3], [0, 2], [1, 0] ] seq.window_search(16, 16) do |subseq| pairs.each_with_index do |ij, x| base = subseq[x, 1] puts ' ' * ij[0] + base + '-' * ij[1] + base.complement + "\n" end pairs.reverse.each_with_index do |ij, x| base = subseq[x + 8, 1] puts ' ' * ij[0] + base.complement + '-' * ij[1] + base + "\n" end end end
# File lib/bio/shell/plugin/soap.rb, line 24 def ebisoap(wsdl = nil) case wsdl when :ipscan @ebisoap = Bio::EBI::SOAP::InterProScan.new(wsdl) when :emboss @ebisoap = Bio::EBI::SOAP::Emboss.new(wsdl) when :clustalw @ebisoap = Bio::EBI::SOAP::ClustalW.new(wsdl) when :tcoffee @ebisoap = Bio::EBI::SOAP::TCoffee.new(wsdl) when :muscle @ebisoap = Bio::EBI::SOAP::Muscle.new(wsdl) when :fasta @ebisoap = Bio::EBI::SOAP::Fasta.new(wsdl) when :wublast @ebisoap = Bio::EBI::SOAP::WUBlast.new(wsdl) when :mpsrch @ebisoap = Bio::EBI::SOAP::MPsrch.new(wsdl) when :scanps @ebisoap = Bio::EBI::SOAP::ScanPS.new(wsdl) when :msd @ebisoap = Bio::EBI::SOAP::MSD.new(wsdl) when :ontology @ebisoap = Bio::EBI::SOAP::Ontology.new(wsdl) when :citation @ebisoap = Bio::EBI::SOAP::Citation.new(wsdl) when /^http/ @ebisoap = Bio::EBI::SOAP.new(wsdl) else @ebisoap ||= Bio::EBI::SOAP.new end return @ebisoap end
NCBI eUtils EFetch service.
With 1 argument, it gets sequence(s) by using Bio::NCBI::REST::EFetch::Methods#sequence. Nucleotide or protein database is automatically selected for each id.
Example:
efetch('AF237819')
With two or more arguments, and when the 2nd argument is Symbol, it calls the corresponding Bio::NCBI::REST::EFetch class method.
Example:
efetch('13054692', :pubmed) # the same as Bio::NCBI::REST::EFetch.pubmed('13054692')
Otherwise, it acts the same as Bio::NCBI::REST#efetch.
# File lib/bio/shell/plugin/ncbirest.rb, line 32 def efetch(ids, *arg) if arg.empty? then ret = Bio::NCBI::REST::EFetch.nucleotide(ids) unless /^LOCUS / =~ ret.to_s then ret = Bio::NCBI::REST::EFetch.protein(ids) end ret elsif arg[0].kind_of?(Symbol) meth = arg[0] case meth.to_s when /\A(journal|omim|pmc|pubmed|sequence|taxonomy)\z/ Bio::NCBI::REST::EFetch.__send__(meth, ids, *(arg[1..-1])) else nil end else Bio::NCBI::REST.efetch(ids, *arg) end end
NCBI eUtils EInfo
# File lib/bio/shell/plugin/ncbirest.rb, line 53 def einfo Bio::NCBI::REST.einfo end
# File lib/bio/shell/plugin/das.rb, line 49 def ensembl(url = "http://das.ensembl.org/") das(url) end
# File lib/bio/shell/plugin/emboss.rb, line 19 def entret(usa) Bio::EMBOSS.entret(usa) end
NCBI eUtils ESearch
# File lib/bio/shell/plugin/ncbirest.rb, line 58 def esearch(str, *arg) Bio::NCBI::REST.esearch(str, *arg) end
Same as Bio::NCBI::REST#esearch_count
# File lib/bio/shell/plugin/ncbirest.rb, line 63 def esearch_count(str, *arg) Bio::NCBI::REST.esearch_count(str, *arg) end
# File lib/bio/shell/plugin/flatfile.rb, line 32 def flatauto(filename) if block_given? Bio::FlatFile.auto(filename) do |flat| flat.each do |entry| yield entry end end else entry = '' Bio::FlatFile.auto(filename) do |flat| entry = flat.next_entry end return entry end end
# File lib/bio/shell/plugin/flatfile.rb, line 54 def flatfasta(fastafile, *flatfiles) puts "Saving fasta file (#{fastafile}) ... " File.open(fastafile, "w") do |fasta| flatfiles.each do |flatfile| puts " converting -- #{flatfile}" Bio::FlatFile.auto(flatfile) do |flat| flat.each do |entry| header = "#{entry.entry_id} #{entry.definition}" fasta.puts entry.seq.to_fasta(header, 50) end end end end puts "done" end
# File lib/bio/shell/plugin/flatfile.rb, line 15 def flatfile(filename) if block_given? Bio::FlatFile.auto(filename) do |flat| flat.each do |entry| yield flat.entry_raw end end else entry = '' Bio::FlatFile.auto(filename) do |flat| flat.next_entry entry = flat.entry_raw end return entry end end
# File lib/bio/shell/plugin/flatfile.rb, line 70 def flatindex(dbname, *flatfiles) begin dir = Bio::Shell.create_flat_dir(dbname) print "Creating BioFlat index (#{dir}) ... " bdb = format = options = nil Bio::FlatFileIndex.makeindex(bdb, dir, format, options, *flatfiles) puts "done" rescue warn "Error: Failed to create index (#{dir}) : #{$!}" end end
# File lib/bio/shell/plugin/flatfile.rb, line 48 def flatparse(entry) if cls = Bio::FlatFile.autodetect(entry) return cls.new(entry) end end
# File lib/bio/shell/plugin/flatfile.rb, line 82 def flatsearch(dbname, keyword) dir = Bio::Shell.find_flat_dir(dbname) unless dir warn "Error: Failed to open database (#{dbname})" return end entry = '' Bio::FlatFileIndex.open(dir) do |db| if results = db.include?(keyword) results.each do |entry_id| entry << db.search_primary(entry_id).to_s end else warn "Error: No hits found in #{dbname} (#{keyword})" end end return entry end
Obtain a database entry from
* IO -- IO object (first entry only) * "filename" -- local file (first entry only) * "db:entry" -- local BioFlat, OBDA, EMBOSS, KEGG API
# File lib/bio/shell/plugin/entry.rb, line 63 def getent(arg) entry = "" db, entry_id = arg.to_s.strip.split(/\:/, 2) # local file if arg.respond_to?(:gets) or File.exists?(arg) puts "Retrieving entry from file (#{arg})" entry = flatfile(arg) # BioFlat in ./.bioruby/bioflat/ or ~/.bioinformatics/.bioruby/bioflat/ elsif Bio::Shell.find_flat_dir(db) puts "Retrieving entry from local BioFlat database (#{arg})" entry = flatsearch(db, entry_id) # OBDA in ~/.bioinformatics/seqdatabase.ini elsif obdadbs.include?(db) puts "Retrieving entry from OBDA (#{arg})" entry = obdaentry(db, entry_id) else # EMBOSS USA in ~/.embossrc begin str = entret(arg) rescue SystemCallError str = '' end if $? and $?.exitstatus == 0 and str.length != 0 puts "Retrieving entry from EMBOSS (#{arg})" entry = str # via Internet else case db.to_s.downcase when 'genbank', 'gb', 'nuccore', 'indsc' # NCBI puts "Retrieving entry from NCBI eUtils" entry = efetch(entry_id) when 'embl', 'emb', /\Aembl/, /\Auni/, 'sp', /\Aensembl/ # EBI puts "Retrieving entry from EBI Dbfetch" db = 'embl' if db == 'emb' db = 'uniprotkb' if db == 'uniprot' or db == 'sp' entry = biofetch(db, entry_id) when 'ddbj', 'dbj', 'dad' # TogoWS REST puts "Retrieving entry from TogoWS" db = 'ddbj' if db == 'dbj' entry = togowsentry(db, entry_id) else togodblist = Bio::TogoWS::REST.entry_database_list rescue [] if togodblist.include?(db) then # TogoWS REST puts "Retrieving entry from TogoWS" entry = togowsentry(db, entry_id) else # KEGG API at http://www.genome.jp/kegg/soap/ puts "Retrieving entry from KEGG API (#{arg})" entry = bget(arg) end end end end return entry end
Obtain a parsed object from sources that ent() supports.
# File lib/bio/shell/plugin/entry.rb, line 133 def getobj(arg) str = getent(arg) flatparse(str) end
Obtain a Bio::Sequence::NA (DNA) or a Bio::Sequence::AA (Amino Acid) sequence from
* String -- "atgcatgc" or "MQKKP" * IO -- io = IO.popen("gzip -dc db.gz") (first entry only) * "filename" -- "gbvrl.gbk" (first entry only) * "db:entry" -- "embl:BUM" (entry is retrieved by the ent method)
# File lib/bio/shell/plugin/entry.rb, line 30 def getseq(arg) seq = "" if arg.kind_of?(Bio::Sequence) seq = arg elsif arg.respond_to?(:gets) or File.exists?(arg) ent = flatauto(arg) elsif arg[/:/] ent = getobj(arg) else tmp = arg end if ent.respond_to?(:seq) tmp = ent.seq elsif ent.respond_to?(:naseq) #seq = ent.naseq tmp = ent.naseq elsif ent.respond_to?(:aaseq) #seq = ent.aaseq tmp = ent.aaseq end if tmp and tmp.is_a?(String) and not tmp.empty? #seq = Bio::Sequence.auto(tmp).seq seq = Bio::Sequence.auto(tmp) end return seq end
# File lib/bio/shell/interface.rb, line 129 def head(arg, num = 10) str = "" if File.exists?(arg) File.open(arg) do |file| num.times do if line = file.gets str << line end end end else arg.to_s.each_with_index do |line, i| break if i >= num str << line end end puts str return str end
Convert sequence to colored HTML string
# File lib/bio/shell/plugin/seq.rb, line 16 def htmlseq(str) if str.kind_of?(Bio::Sequence) seq = str else seq = getseq(str) end if seq.is_a?(Bio::Sequence::AA) scheme = Bio::ColorScheme::Taylor else scheme = Bio::ColorScheme::Nucleotide end html = %Q[<div style="font-family:monospace;">\n] seq.fold(50).each_byte do |c| case c.chr when "\n" html += "<br>\n" else color = scheme[c.chr] html += %Q[<span style="background:\##{color};">#{c.chr}</span>\n] end end html += "</div>\n" return html end
# File lib/bio/shell/plugin/keggapi.rb, line 28 def keggapi(wsdl = nil) if wsdl @keggapi = Bio::KEGG::API.new(wsdl) else @keggapi ||= Bio::KEGG::API.new end return @keggapi end
GenomeNet
# File lib/bio/shell/plugin/blast.rb, line 17 def keggblast(query) server = Bio::Blast.remote("blastp", "genes", "", "genomenet_tab") if query[/^>/] data = Bio::FastaFormat.new(query) desc = data.definition tmp = getseq(data.seq) else desc = "query" tmp = getseq(query) end if tmp.respond_to?(:translate) aaseq = tmp.translate else aaseq = tmp end fasta = aaseq.to_fasta(desc, 60) result = server.query(fasta) puts server.output return result end
# File lib/bio/shell/plugin/das.rb, line 45 def keggdas(url = "http://das.hgc.jp/cgi-bin/") das(url) end
DATABASES
# File lib/bio/shell/plugin/keggapi.rb, line 74 def keggdbs list = keggapi.list_databases result = Bio::Shell::Private.keggapi_definition2tab(list).join("\n") puts result return list.map {|x| x.entry_id} end
# File lib/bio/shell/plugin/keggapi.rb, line 96 def kegggenomeseq(org) result = "" require 'net/ftp' Net::FTP.open("ftp.genome.jp", "anonymous") do |ftp| path = "/pub/kegg/genomes/#{org}" list = ftp.nlst(path) file = list.grep(/.*genome$/).shift if file open("ftp://ftp.genome.jp/#{file}") do |file| result = file.read end end end return result end
# File lib/bio/shell/plugin/keggapi.rb, line 81 def keggorgs list = keggapi.list_organisms result = Bio::Shell::Private.keggapi_definition2tab(list).sort.join("\n") puts result return list.map {|x| x.entry_id} end
# File lib/bio/shell/plugin/keggapi.rb, line 88 def keggpathways(org = "map") list = keggapi.list_pathways(org) result = Bio::Shell::Private.keggapi_definition2tab(list).join("\n") puts result return list.map {|x| x.entry_id} end
work space
# File lib/bio/shell/interface.rb, line 17 def ls bind = Bio::Shell.cache[:binding] list = eval("local_variables", bind).reject { |x| eval(x, bind).nil? } puts list.inspect return list end
# File lib/bio/shell/plugin/midi.rb, line 397 def midifile(filename, seq, *args) begin print "Saving MIDI file (#{filename}) ... " File.open(filename, "w") do |file| file.puts seq.to_midi(*args) end puts "done" rescue warn "Error: Failed to save (#{filename}) : #{$!}" end end
# File lib/bio/shell/plugin/soap.rb, line 15 def ncbisoap(wsdl = nil) if wsdl @ncbisoap = Bio::NCBI::SOAP.new(wsdl) else @ncbisoap ||= Bio::NCBI::SOAP.new end return @ncbisoap end
# File lib/bio/shell/plugin/codon.rb, line 209 def nucleicacids names = Bio::NucleicAcid.names %w(a t g c u r y w s k m b v h d n).each do |base| puts "#{base}\t#{names[base]}\t#{names[base.upcase]}" end return names end
# File lib/bio/shell/plugin/obda.rb, line 15 def obda @obda ||= Bio::Registry.new end
# File lib/bio/shell/plugin/obda.rb, line 33 def obdadbs result = obda.databases.map {|db| db.database} return result end
# File lib/bio/shell/plugin/obda.rb, line 19 def obdaentry(dbname, entry_id) db = obda.get_database(dbname) unless db warn "Error: No such database (#{dbname})" return end entry = db.get_by_id(entry_id) if block_given? yield entry else return entry end end
pager
# File lib/bio/shell/interface.rb, line 87 def pager(cmd = nil) unless Bio::Shell.config[:pager] cmd ||= ENV['PAGER'] end Bio::Shell.config_pager(cmd) puts "Pager is set to '#{cmd ? cmd : 'off'}'" end
# File lib/bio/shell/plugin/psort.rb, line 15 def psort1(str) seq = getseq(str) if seq.is_a?(Bio::Sequence::NA) seq = seq.translate end psort = Bio::PSORT::PSORT1.imsut fasta = seq.to_fasta results = psort.exec(fasta).final_result results.each do |result| puts "#{result["certainty"].to_f*100.0}\t#{result["prediction"]}" end return results.first["prediction"] end
# File lib/bio/shell/plugin/psort.rb, line 31 def psort2(str) seq = getseq(str) if seq.is_a?(Bio::Sequence::NA) seq = seq.translate end psort = Bio::PSORT::PSORT2.imsut fasta = seq.to_fasta results = psort.exec(fasta).prob.sort_by{|x, y| y}.reverse results.each do |loc, prob| next if prob <= 0.0 puts "#{prob}\t#{Bio::PSORT::PSORT2::SclNames[loc]}" end return results.first.first end
# File lib/bio/shell/plugin/psort.rb, line 48 def psort2locations names = Bio::PSORT::PSORT2::SclNames names.sort.each do |loc, desc| puts "#{loc}\t#{desc}" end return names end
# File lib/bio/shell/interface.rb, line 186 def pwd puts Dir.pwd.inspect end
Read a text file and collect the first word of each line in array
# File lib/bio/shell/plugin/entry.rb, line 16 def readlist(filename) list = [] File.open(filename).each do |line| list << line[/^\S+/] end return list end
# File lib/bio/shell/interface.rb, line 81 def reload_config Bio::Shell.load_config end
object
# File lib/bio/shell/interface.rb, line 50 def reload_object Bio::Shell.load_object end
plugin
# File lib/bio/shell/interface.rb, line 56 def reload_plugin Bio::Shell.load_plugin end
# File lib/bio/shell/interface.rb, line 26 def rm(name) bind = Bio::Shell.cache[:binding] list = eval("local_variables", bind).reject { |x| eval(x, bind).nil? } begin if list.include?(name.to_s) eval("#{name} = nil", bind) else raise end rescue warn "Usage: rm :var or rm 'var' (rm var is not valid)" end end
file save
# File lib/bio/shell/interface.rb, line 151 def savefile(file, *objs) datadir = Bio::Shell.data_dir message = "Save file '#{file}' in '#{datadir}' directory? [y/n] " if ! file[/^#{datadir}/] and Bio::Shell.ask_yes_or_no(message) file = File.join(datadir, file) end if File.exists?(file) message = "Overwrite existing '#{file}' file? [y/n] " if ! Bio::Shell.ask_yes_or_no(message) puts " ... save aborted." return end end begin print "Saving file (#{file}) ... " File.open(file, "w") do |f| objs.each do |obj| f.puts obj.to_s end end puts "done" rescue warn "Error: Failed to save (#{file}) : #{$!}" end end
script
# File lib/bio/shell/interface.rb, line 44 def script(mode = nil) Bio::Shell.script(mode) end
# File lib/bio/shell/plugin/emboss.rb, line 15 def seqret(usa) Bio::EMBOSS.seqret(usa) end
Displays some basic properties of the sequence.
# File lib/bio/shell/plugin/seq.rb, line 54 def seqstat(str) max = 150 seq = getseq(str) rep = "\n* * * Sequence statistics * * *\n\n" if seq.moltype == Bio::Sequence::NA fwd = seq rev = seq.complement if seq.length > max dot = " ..." fwd = fwd.subseq(1, max) rev = rev.subseq(1, max) end rep << "5'->3' sequence : #{fwd.fold(70,20).strip}#{dot}\n" rep << "3'->5' sequence : #{rev.fold(70,20).strip}#{dot}\n" [ 1, 2, 3, -1, -2, -3 ].each do |frame| pep = seq.subseq(1, max+2).translate(frame).fold(70,20).strip rep << "Translation #{frame.to_s.rjust(2)} : #{pep}#{dot}\n" end rep << "Length : #{seq.length} bp\n" rep << "GC percent : #{seq.gc_percent} %\n" ary = [] seq.composition.sort.each do |base, num| percent = format("%.2f", 100.0 * num / seq.length).rjust(6) count = num.to_s.rjust(seq.length.to_s.length) ary << " #{base} - #{count} (#{percent} %)\n" end rep << "Composition : #{ary.join.strip}\n" rep << "Codon usage :\n" hash = Hash.new("0.0%") seq.codon_usage.sort.each do |codon, num| percent = format("%.1f%", 100.0 * num / (seq.length / 3)) hash[codon] = percent end rep << codontable(1, hash).output begin rep << "Molecular weight : #{seq.molecular_weight}\n" rescue rep << "Molecular weight : #{$!}\n" end begin rep << "Protein weight : #{seq.translate.chomp('*').molecular_weight}\n" rescue rep << "Protein weight : #{$!}\n" end else pep = seq if seq.length > max dot = " ..." pep = seq.subseq(1, max) end rep << "N->C sequence : #{pep.fold(70,20).strip}#{dot}\n" rep << "Length : #{seq.length} aa\n" names = Bio::AminoAcid.names ary = [] seq.composition.sort.each do |aa, num| percent = format("%.2f", 100.0 * num / seq.length).rjust(6) count = num.to_s.rjust(seq.length.to_s.length) code = names[aa] name = names[names[aa]] ary << " #{aa} #{code} - #{count} (#{percent} %) #{name}\n" end rep << "Composition : #{ary.join.strip}\n" begin rep << "Protein weight : #{seq.molecular_weight}\n" rescue rep << "Protein weight : #{$!}\n" end end rep << "//\n" puts rep return rep end
# File lib/bio/shell/plugin/seq.rb, line 44 def sixtrans(str) seq = getseq(str) [ 1, 2, 3, -1, -2, -3 ].each do |frame| title = "Translation #{frame.to_s.rjust(2)}" puts seq.translate(frame).to_fasta(title, 60) end end
Shortcut method to fetch entry(entries) by using TogoWS REST “entry” service. Multiple databases may be used.
# File lib/bio/shell/plugin/togows.rb, line 18 def togows(ids, *arg) Bio::TogoWS::REST.retrieve(ids, *arg) end
Data format conversion by using TogoWS REST “convert” service. Same as Bio::TogoWS::REST#convert(data, format_from, format_to).
# File lib/bio/shell/plugin/togows.rb, line 36 def togowsconvert(data, format_from, format_to) Bio::TogoWS::REST.convert(data, format_from, format_to) end
Fetches entry(entries) by using TogoWS REST “entry” service. Same as Bio::TogoWS::REST#entry(database, ids, *arg).
# File lib/bio/shell/plugin/togows.rb, line 24 def togowsentry(database, ids, *arg) Bio::TogoWS::REST.entry(database, ids, *arg) end
Database search by using TogoWS REST “search” service. Same as Bio::TogoWS::REST#search(database, term, *arg).
# File lib/bio/shell/plugin/togows.rb, line 30 def togowssearch(database, term, *arg) Bio::TogoWS::REST.search(database, term, *arg) end
# File lib/bio/shell/plugin/das.rb, line 53 def wormbase(url = "http://www.wormbase.org/db/") das(url) end