[BioRuby-cvs] bioruby/lib/bio/io fastacmd.rb,1.8,1.9

Mitsuteru C. Nakao nakao at pub.open-bio.org
Sat Jan 28 07:42:01 UTC 2006


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

Modified Files:
	fastacmd.rb 
Log Message:
* Added RDoc.


Index: fastacmd.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/fastacmd.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** fastacmd.rb	26 Sep 2005 13:00:08 -0000	1.8
--- fastacmd.rb	28 Jan 2006 07:41:59 -0000	1.9
***************
*** 1,7 ****
  #
! # bio/io/fastacmd.rb - NCBI fastacmd wrapper class
  #
! #   Copyright (C) 2005 Shuji SHIGENOBU <shige at nibb.ac.jp>
! #   Copyright (C) 2005 Toshiaki Katayama <k at bioruby.org>
  #
  #  This library is free software; you can redistribute it and/or
--- 1,42 ----
  #
! # = bio/io/fastacmd.rb - NCBI fastacmd wrapper class
  #
! # Copyright::  Copyright (C) 2005 
! #              Shuji SHIGENOBU <shige at nibb.ac.jp>,
! #              Toshiaki Katayama <k at bioruby.org>
! # Lisence::    LGPL
! #
! # $Id$
! #
! # == Description
! #
! # Retrives FASTA formatted sequences from a blast database using 
! # NCBI fastacmd command.
! # 
! # == Examples
! #
! #    database = ARGV.shift || "/db/myblastdb"
! #    entry_id = ARGV.shift || "sp:128U_DROME"
! #    ent_list = ["sp:1433_SPIOL", "sp:1432_MAIZE"]
! #
! #    fastacmd = Bio::Blast::Fastacmd.new(database)
! #
! #    entry = fastacmd.get_by_id(entry_id)
! #    fastacmd.fetch(entry_id)
! #    fastacmd.fetch(ent_list)
! #
! #    fastacmd.fetch(ent_list).each do |fasta|
! #      puts fasta
! #    end
! #
! # == References
! #
! # * NCBI tool
! #   ftp://ftp.ncbi.nih.gov/blast/executables/LATEST/ncbi.tar.gz
! #
! # * fastacmd.html
! #   http://biowulf.nih.gov/apps/blast/doc/fastacmd.html
! #
! #--
  #
  #  This library is free software; you can redistribute it and/or
***************
*** 19,23 ****
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #  $Id$
  #
  
--- 54,58 ----
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #++
  #
  
***************
*** 29,32 ****
--- 64,69 ----
  class Blast
  
+ # NCBI fastacmd wrapper class
+ #
  class Fastacmd
  
***************
*** 34,49 ****
    include Bio::Command::Tools
  
!   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)
--- 71,113 ----
    include Bio::Command::Tools
  
!   # Database file path.
!   attr_accessor :database
! 
!   # fastcmd command file path.
!   attr_accessor :fastacmd
! 
!   # 
!   attr_accessor :errorlog
! 
!   # Initalize a fastacmd object.
!   #    
!   #    fastacmd = Bio::Blast::Fastacmd.new("/db/myblastdb")
!   def initialize(blast_database_file_path)
!     @database = blast_database_file_path
      @fastacmd = 'fastacmd'
    end
  
! 
!   # get an entry_id and returns a Bio::FastaFormat object.
!   #
!   #   entry_id = "sp:128U_DROME"
!   #   entry = fastacmd.get_by_id(entry_id)
    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.
!   #
!   # 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)
!   #
!   # Fastacmd#fetch method also accepts a list of entry_id and returns
!   # an Array of Bio::FastaFormat objects.
!   #    
!   #    ent_list = ["sp:1433_SPIOL", "sp:1432_MAIZE"]
!   #    p fastacmd.fetch(ent_list)
!   #
    def fetch(list)
      if list.respond_to?(:join)
***************
*** 60,63 ****
--- 124,134 ----
    end
  
+   # Iterates each entry.
+   #
+   # You can also iterate on all sequences in the database!
+   #    fastacmd.each do |fasta|
+   #      p [ fasta.definition[0..30], fasta.seq.size ]
+   #    end
+   #
    def each_entry
      cmd = [ @fastacmd, '-d', @database, '-D', 'T' ]
***************
*** 65,70 ****
        inn.close_write
        Bio::FlatFile.open(Bio::FastaFormat, out) do |f|
!         f.each_entry do |e|
!           yield e
          end
        end
--- 136,141 ----
        inn.close_write
        Bio::FlatFile.open(Bio::FastaFormat, out) do |f|
!         f.each_entry do |entry|
!           yield entry
          end
        end
***************
*** 74,123 ****
    alias each each_entry
  
! end
! 
! end
! end
! 
! 
! if __FILE__ == $0
! 
!   database = ARGV.shift || "/db/myblastdb"
!   entry_id = ARGV.shift || "sp:128U_DROME"
!   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
! 
!   # Bio::FastaFormat becomes a fasta format string when printed by puts.
!   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)
! 
!   ### 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)
! 
!   # So, you can iterate on the results.
!   fastacmd.fetch(ent_list).each do |fasta|
!     puts fasta
!   end
! 
! 
!   ### Iterates on all entries
  
!   # You can also iterate on all sequences in the database!
!   fastacmd.each do |fasta|
!     p [ fasta.definition[0..30], fasta.seq.size ]
!   end
  
- end
  
--- 145,152 ----
    alias each each_entry
  
! end # class Fastacmd
  
! end # class Blast
! end # module Bio
  
  




More information about the bioruby-cvs mailing list