[BioRuby-cvs] bioruby/lib/bio/io fastacmd.rb,1.5,1.6

Katayama Toshiaki k at pub.open-bio.org
Wed Aug 10 08:55:08 EDT 2005


Update of /home/repository/bioruby/bioruby/lib/bio/io
In directory pub.open-bio.org:/tmp/cvs-serv6448/lib/bio/io

Modified Files:
	fastacmd.rb 
Log Message:
* renamed to Bio::Blast::Fastacmd (from Bio::Fastacmd)
* popen is left for win32 environmnets (open3 is recommended, although)


Index: fastacmd.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/fastacmd.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** fastacmd.rb	10 Aug 2005 05:41:31 -0000	1.5
--- fastacmd.rb	10 Aug 2005 12:55:06 -0000	1.6
***************
*** 27,58 ****
  
  module Bio
  
!   class Fastacmd
  
!     include Enumerable
  
!     def initialize(db)
!       @database = db
!       @fastacmd = 'fastacmd'
!     end
!     attr_accessor :database, :fastacmd
  
!     # get an entry_id and returns a Bio::FastaFormat object
!     def get_by_id(entry_id)
!       fetch(entry_id).shift
      end
  
!     # get one or more entry_id and returns an Array of Bio::FastaFormat objects
!     def fetch(list)
!       if list.respond_to?(:join)
!         entry_id = list.join(",")
!       else
!         entry_id = list
        end
! 
        cmd = [ @fastacmd, '-d', @database, '-s', entry_id ]
        Open3.popen3(*cmd) do |inn, out, err|
          inn.close
!         t = Thread.start { err.read }
          results = Bio::FlatFile.new(Bio::FastaFormat, out).to_a
          t.join
--- 27,66 ----
  
  module Bio
+ class Blast
  
! class Fastacmd
  
!   include Enumerable
  
!   def initialize(db)
!     @database = db
!     @fastacmd = 'fastacmd'
!   end
!   attr_accessor :database, :fastacmd, :errorlog
  
!   # get an entry_id and returns a Bio::FastaFormat object
!   def get_by_id(entry_id)
!     fetch(entry_id).shift
!   end
! 
!   # get one or more entry_id and returns an Array of Bio::FastaFormat objects
!   def fetch(list)
!     if list.respond_to?(:join)
!       entry_id = list.join(",")
!     else
!       entry_id = list
      end
  
!     if RUBY_PLATFORM[/mswin32|bccwin32/]	 # replace with appl/factory.rb
!       cmd = "#{@fastacmd} -d #{@database} -s #{entry_id}"
!       IO.popen(cmd, "r") do |io|
!         io.sync = true
!         results = Bio::FlatFile.new(Bio::FastaFormat, io).to_a
        end
!     else
        cmd = [ @fastacmd, '-d', @database, '-s', entry_id ]
        Open3.popen3(*cmd) do |inn, out, err|
          inn.close
!         t = Thread.start { @errorlog = err.read }
          results = Bio::FlatFile.new(Bio::FastaFormat, out).to_a
          t.join
***************
*** 60,82 ****
        end
      end
  
!     def each_entry
        cmd = [ @fastacmd, '-d', @database, '-D', 'T' ]
        Open3.popen3(*cmd) do |inn, out, err|
          inn.close
!         t = Thread.start { err.read }
!         f = Bio::FlatFile.new(Bio::FastaFormat, out)
!         f.each_entry do |e|
!           yield e
          end
          t.join
        end
-       self
      end
!     alias :each :each_entry
! 
    end
  
  end
  
  
--- 68,105 ----
        end
      end
+   end
  
!   def each_entry
!     if RUBY_PLATFORM[/mswin32|bccwin32/]	 # replace with appl/factory.rb
!       cmd = "#{@fastacmd} -d #{@database} -D T"
!       IO.popen(cmd, "r") do |io|
!         io.sync = true
!         Bio::FlatFile.open(Bio::FastaFormat, io) do |f|
!           f.each_entry do |e|
!             yield e
!           end
!         end
!       end
!     else
        cmd = [ @fastacmd, '-d', @database, '-D', 'T' ]
        Open3.popen3(*cmd) do |inn, out, err|
          inn.close
!         t = Thread.start { @errorlog = err.read }
!         Bio::FlatFile.open(Bio::FastaFormat, out) do |f|
!           f.each_entry do |e|
!             yield e
!           end
          end
          t.join
        end
      end
!     self
    end
+   alias :each :each_entry
+ 
+ end
  
  end
+ end
  
  
***************
*** 87,96 ****
    ent_list = ["sp:1433_SPIOL", "sp:1432_MAIZE"]
  
!   fastacmd = Bio::Fastacmd.new(database)
  
    ### Retrieve one sequence
    entry = fastacmd.get_by_id(entry_id)
  
!   # Bio::Fastacmd#get_by_id(entry_id) returns a Bio::FastaFormat object.
    p entry
  
--- 110,119 ----
    ent_list = ["sp:1433_SPIOL", "sp:1432_MAIZE"]
  
!   fastacmd = Bio::Blast::Fastacmd.new(database)
  
    ### Retrieve one sequence
    entry = fastacmd.get_by_id(entry_id)
  
!   # Fastacmd#get_by_id(entry_id) returns a Bio::FastaFormat object.
    p entry
  
***************
*** 98,102 ****
    puts entry
  
!   # Bio::Fastacmd#fetch(entry_id) returns an Array of a Bio::FastaFormat
    # object even when the result is a single entry.
    p fastacmd.fetch(entry_id)
--- 121,125 ----
    puts entry
  
!   # Fastacmd#fetch(entry_id) returns an Array of a Bio::FastaFormat
    # object even when the result is a single entry.
    p fastacmd.fetch(entry_id)
***************
*** 104,108 ****
    ### Retrieve more sequences
  
!   # Bio::Fastacmd#fetch method also accepts a list of entry_id and returns
    # an Array of Bio::FastaFormat objects.
    p fastacmd.fetch(ent_list)
--- 127,131 ----
    ### Retrieve more sequences
  
!   # Fastacmd#fetch method also accepts a list of entry_id and returns
    # an Array of Bio::FastaFormat objects.
    p fastacmd.fetch(ent_list)



More information about the bioruby-cvs mailing list