[BioRuby-cvs] bioruby/lib/bio/shell/plugin seq.rb, NONE,
1.1 flatfile.rb, NONE, 1.1 obda.rb, NONE, 1.1
Katayama Toshiaki
k at pub.open-bio.org
Fri Sep 23 09:57:10 EDT 2005
Update of /home/repository/bioruby/bioruby/lib/bio/shell/plugin
In directory pub.open-bio.org:/tmp/cvs-serv22949/lib/bio/shell/plugin
Added Files:
seq.rb flatfile.rb obda.rb
Log Message:
* Newly added BioRuby shell - command line user interface for the BioRuby
--- NEW FILE: obda.rb ---
#
# bio/shell/plugin/obda.rb - plugin for OBDA
#
# Copyright (C) 2005 KATAYAMA Toshiaki <k at bioruby.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: obda.rb,v 1.1 2005/09/23 13:57:08 k Exp $
#
require 'bio/io/registry'
module Bio::Shell
def bioregistry
@obda = Bio::Registry.new
end
def getentry(dbname, entry_id)
bioregistry unless @obda
db = @obda.get_database(dbname)
entry = db.get_by_id(entry_id)
if block_given?
yield entry
else
display entry
end
return entry
end
end
--- NEW FILE: flatfile.rb ---
#
# bio/shell/plugin/flatfile.rb - plugin for flatfile database
#
# Copyright (C) 2005 KATAYAMA Toshiaki <k at bioruby.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: flatfile.rb,v 1.1 2005/09/23 13:57:08 k Exp $
#
require 'bio/io/flatfile'
module Bio::Shell
def convert_to_fasta(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
def bioflat_index(dbname, *flatfiles)
prefix = Core::SAVEDIR + Core::BIOFLAT
unless File.directory?(prefix)
Bio::Shell.create_save_dir
end
dir = prefix + dbname.to_s
bdb = format = options = nil
begin
print "Creating BioFlat index (#{dir}) ... "
Bio::FlatFileIndex.makeindex(bdb, dir, format, options, *flatfiles)
puts "done"
rescue
raise "Failed to create index (#{dir}) : #{$!}"
end
end
def bioflat_search(dbname, keyword)
dir = Core::SAVEDIR + Core::BIOFLAT + dbname.to_s
# Bio::FlatFileIndex.open(dir) do |db|
db = Bio::FlatFileIndex.open(dir)
if results = db.include?(keyword)
results.each do |entry_id|
display db.search_primary(entry_id)
end
else
display "No hits found"
end
# end
db.close
end
def bioflat_namespaces(dbname)
dir = Core::SAVEDIR + Core::BIOFLAT + dbname.to_s
db = Bio::FlatFileIndex.open(dir)
display db.namespaces.inspect
db.close
end
end
--- NEW FILE: seq.rb ---
#
# bio/shell/plugin/seq.rb - plugin for biological sequence manipulations
#
# Copyright (C) 2005 KATAYAMA Toshiaki <k at bioruby.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: seq.rb,v 1.1 2005/09/23 13:57:08 k Exp $
#
require 'bio/sequence'
module Bio::Shell
def naseq(str)
Bio::Sequence::NA.new(str)
end
def aaseq(str)
Bio::Sequence::AA.new(str)
end
def revseq(str)
seq = Bio::Sequence::NA.new(str)
res = seq.complement
display res
return res
end
def translate(str)
seq = Bio::Sequence::NA.new(str)
res = seq.translate
display res
return res
end
def seq_report(str)
if File.exist?(str)
Bio::FlatFile.open(nil, arg).each do |f|
seq = f.seq
if seq.class == Bio::Sequence::NA
na_report(seq)
else
aa_report(seq)
end
end
else
case Bio::Seq.guess(str)
when :NA
display na_report(str)
when :AA
display aa_report(str)
end
return Bio::Seq.guess(str)
end
end
def na_report(seq)
seq = naseq(seq) unless seq === Bio::Sequence::NA
str = ""
str << "input sequence : #{seq}\n"
str << "reverse complement : #{seq.complement}\n"
str << "translation 1 : #{seq.translate}\n"
str << "translation 2 : #{seq.translate(2)}\n"
str << "translation 3 : #{seq.translate(3)}\n"
str << "translation -1 : #{seq.translate(-1)}\n"
str << "translation -2 : #{seq.translate(-2)}\n"
str << "translation -3 : #{seq.translate(-3)}\n"
str << "gc percent : #{seq.gc} %\n"
str << "composition : #{seq.composition.inspect}\n"
str << "molecular weight : #{seq.molecular_weight}\n"
str << "complemnet weight : #{seq.complement.molecular_weight}\n"
str << "protein weight : #{seq.translate.molecular_weight}\n"
str << "//\n"
return str
end
def aa_report(seq)
seq = aaseq(seq) unless seq === Bio::Sequence::AA
str = ""
str << "input sequence : #{seq}\n"
str << "composition : #{seq.composition.inspect}\n"
str << "protein weight : #{seq.molecular_weight}\n"
str << "amino acid codes : #{seq.codes.inspect}\n"
str << "amino acid names : #{seq.names.inspect}\n"
str << "//\n"
return str
end
end
More information about the bioruby-cvs
mailing list