[BioRuby-cvs] bioruby/lib/bio/shell/plugin flatfile.rb,1.5,1.6
Katayama Toshiaki
k at pub.open-bio.org
Tue Nov 15 23:01:12 EST 2005
Update of /home/repository/bioruby/bioruby/lib/bio/shell/plugin
In directory pub.open-bio.org:/tmp/cvs-serv1421/plugin
Modified Files:
flatfile.rb
Log Message:
* flatfile method is added (similar to flatauto but returns raw entry)
* save_fasta method is renamed to flatfasta
* parse method is added which parse the entry string to obj by autodetection
* flatindex/flatsearch is changed to ask and uses USERDIR when SAVEDIR
is not available
Index: flatfile.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/plugin/flatfile.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** flatfile.rb 14 Nov 2005 02:01:54 -0000 1.5
--- flatfile.rb 16 Nov 2005 04:01:10 -0000 1.6
***************
*** 33,36 ****
--- 33,53 ----
private
+ 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
+
def flatauto(filename)
if block_given?
***************
*** 41,52 ****
end
else
! flat = Bio::FlatFile.auto(filename)
! entry = flat.next_entry
! flat.close
return entry
end
end
! def save_fasta(fastafile, *flatfiles)
puts "Saving fasta file (#{fastafile}) ... "
File.open(fastafile, "w") do |fasta|
--- 58,76 ----
end
else
! entry = ''
! Bio::FlatFile.auto(filename) do |flat|
! entry = flat.next_entry
! end
return entry
end
end
! def parse(entry)
! if cls = Bio::FlatFile.autodetect(entry)
! return cls.new(entry)
! end
! end
!
! def flatfasta(fastafile, *flatfiles)
puts "Saving fasta file (#{fastafile}) ... "
File.open(fastafile, "w") do |fasta|
***************
*** 65,80 ****
def flatindex(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
--- 89,101 ----
def flatindex(dbname, *flatfiles)
! prefix = Bio::Shell.create_save_dir + Core::BIOFLAT
! idxdir = prefix + dbname.to_s
begin
! print "Creating BioFlat index (#{idxdir}) ... "
! bdb = format = options = nil
! Bio::FlatFileIndex.makeindex(bdb, idxdir, format, options, *flatfiles)
puts "done"
rescue
! raise "Failed to create index (#{idxdir}) : #{$!}"
end
end
***************
*** 82,85 ****
--- 103,107 ----
def flatsearch(dbname, keyword)
dir = Core::SAVEDIR + Core::BIOFLAT + dbname.to_s
+ dir = Core::USERDIR + Core::BIOFLAT + dbname.to_s unless File.exists?(dir)
Bio::FlatFileIndex.open(dir) do |db|
if results = db.include?(keyword)
More information about the bioruby-cvs
mailing list