[BioRuby-cvs] bioruby/lib/bio/appl/iprscan report.rb,1.8,1.9

Mitsuteru C. Nakao nakao at dev.open-bio.org
Wed Jul 18 11:11:59 UTC 2007


Update of /home/repository/bioruby/bioruby/lib/bio/appl/iprscan
In directory dev.open-bio.org:/tmp/cvs-serv28494/lib/bio/appl/iprscan

Modified Files:
	report.rb 
Log Message:
* Changed method names:
  1. reports_in_* -> parse_*
  2. parse_in_* -> parse_*_entry
  3. to_* -> format_*
* Added Report#output(:format_type) method to be the facade pattern of 
  format_* methods.


Index: report.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/iprscan/report.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** report.rb	17 Jul 2007 14:16:50 -0000	1.8
--- report.rb	18 Jul 2007 11:11:57 -0000	1.9
***************
*** 24,28 ****
      # == USAGE
      #  # Read a marged.txt and split each entry.
!     #  Bio::Iprscan::Report.reports_in_txt(File.read("marged.txt")) do |report| 
      #    report.query_id
      #    report.matches.size
--- 24,28 ----
      # == USAGE
      #  # Read a marged.txt and split each entry.
!     #  Bio::Iprscan::Report.parse_txt(File.read("marged.txt")) do |report| 
      #    report.query_id
      #    report.matches.size
***************
*** 41,45 ****
      #  end
      #
!     #  Bio::Iprscan::Report.reports_in_raw(File.read("marged.raw")) do |report| 
      #    report.class #=> Bio::Iprscan::Report
      #  end
--- 41,45 ----
      #  end
      #
!     #  Bio::Iprscan::Report.parse_raw(File.read("marged.raw")) do |report| 
      #    report.class #=> Bio::Iprscan::Report
      #  end
***************
*** 66,74 ****
        
        # == USAGE
!       #  Bio::Iprscan::Report.reports_in_raw(File.open("merged.raw")) do |report|
        #    report
        #  end
        #
!       def self.reports_in_raw(io)
          entry = ''
          while line = io.gets
--- 66,74 ----
        
        # == USAGE
!       #  Bio::Iprscan::Report.parse_raw(File.open("merged.raw")) do |report|
        #    report
        #  end
        #
!       def self.parse_raw(io)
          entry = ''
          while line = io.gets
***************
*** 76,80 ****
              entry << line
            elsif entry != ''
!             yield Bio::Iprscan::Report.parse_in_raw(entry)
              entry = line
            else
--- 76,80 ----
              entry << line
            elsif entry != ''
!             yield Bio::Iprscan::Report.parse_raw_entry(entry)
              entry = line
            else
***************
*** 82,91 ****
            end
          end
!         yield Bio::Iprscan::Report.parse_in_raw(entry) if entry != ''
        end
      
        # Parser method for a raw formated entry. Retruns a Bio::Iprscan::Report 
        # object.
!       def self.parse_in_raw(str)
          report = self.new
          str.split(/\n/).each do |line|
--- 82,91 ----
            end
          end
!         yield Bio::Iprscan::Report.parse_raw_entry(entry) if entry != ''
        end
      
        # Parser method for a raw formated entry. Retruns a Bio::Iprscan::Report 
        # object.
!       def self.parse_raw_entry(str)
          report = self.new
          str.split(/\n/).each do |line|
***************
*** 117,123 ****
        # Parser method for a xml formated entry. Retruns a Bio::Iprscan::Report 
        # object.
!       def self.parse_in_xml(str)
!         NotImplementedError
!       end
  
        # Splits the entry stream.
--- 117,122 ----
        # Parser method for a xml formated entry. Retruns a Bio::Iprscan::Report 
        # object.
! #      def self.parse_xml(str)
! #      end
  
        # Splits the entry stream.
***************
*** 125,133 ****
        # == Usage
        #
!       #  Bio::Iprscan::Report.reports_in_txt(File.open("merged.txt")) do |report|
        #    report.class #=> Bio::Iprscan::Report
        #  end
        #
!       def self.reports_in_txt(io)
          io.each("\n\nSequence") do |entry|
            if entry =~ /Sequence$/
--- 124,132 ----
        # == Usage
        #
!       #  Bio::Iprscan::Report.reports_txt(File.open("merged.txt")) do |report|
        #    report.class #=> Bio::Iprscan::Report
        #  end
        #
!       def self.parse_txt(io)
          io.each("\n\nSequence") do |entry|
            if entry =~ /Sequence$/
***************
*** 137,141 ****
              entry = 'Sequence' + entry
            end
!           yield self.parse_in_txt(entry)
          end
        end
--- 136,140 ----
              entry = 'Sequence' + entry
            end
!           yield self.parse_txt_entry(entry)
          end
        end
***************
*** 146,150 ****
        # object.
        #
!       def self.parse_in_txt(str)
          unless str =~ /^Sequence /
            raise ArgumentError, "Invalid format:  \n\n#{str}"
--- 145,149 ----
        # object.
        #
!       def self.parse_txt_entry(str)
          unless str =~ /^Sequence /
            raise ArgumentError, "Invalid format:  \n\n#{str}"
***************
*** 190,199 ****
        # 
        # == Usage
!       #  Bio::Iprscan::Report.reports_in_ptxt(File.open("merged.txt")) do |report|
        #    report
        #  end
!       def self.reports_in_ptxt(io)
          io.each("\n\/\/\n") do |entry|
!           yield self.parse_in_ptxt(entry)
          end
        end
--- 189,198 ----
        # 
        # == Usage
!       #  Bio::Iprscan::Report.parse_ptxt(File.open("merged.txt")) do |report|
        #    report
        #  end
!       def self.parse_ptxt(io)
          io.each("\n\/\/\n") do |entry|
!           yield self.parse_ptxt_entry(entry)
          end
        end
***************
*** 205,212 ****
        #
        #  File.read("marged.txt").each(Bio::Iprscan::Report::RS) do |e| 
!       #    report = Bio::Iprscan::Report.parse_in_ptxt(e)
        #  end
        #
!       def self.parse_in_ptxt(str)
          report = self.new
          ipr_line = ''
--- 204,211 ----
        #
        #  File.read("marged.txt").each(Bio::Iprscan::Report::RS) do |e| 
!       #    report = Bio::Iprscan::Report.parse_ptxt_entry(e)
        #  end
        #
!       def self.parse_ptxt_entry(str)
          report = self.new
          ipr_line = ''
***************
*** 242,267 ****
        end
  
!       def to_html
!         NotImplementedError
        end
        
!       def to_xml
!         NotImplementedError
!       end
        
!       def to_ebixml
!         NotImplementedError        
!       end
        
!       def to_txt
!         NotImplementedError        
!       end
        
!       def to_raw
          @matches.map { |match|
            [self.query_id,
             self.crc64,
             self.query_length,
!            match.method,
             match.accession,
             match.description,
--- 241,273 ----
        end
  
! 
!       # Output interpro matches in the format_type.
!       def output(format_type)
!         case format_type
!         when 'raw', :raw
!           format_raw
!         else
!           raise NameError, "Invalid format_type."
!         end
        end
+ 
+ #      def format_html
+ #      end
        
! #      def format_xml
! #      end
        
! #      def format_ebixml
! #      end
        
! #      def format_txt
! #      end
        
!       def format_raw
          @matches.map { |match|
            [self.query_id,
             self.crc64,
             self.query_length,
!            match.method_name,
             match.accession,
             match.description,
***************
*** 278,302 ****
        end
        
!       def to_gff3
!         NotImplementedError        
!       end
  
  
!       # Returns a Hash (key as an interpro id and value as index key for 
!       # matches (Array).
        #
!       #   report.list_of_interpro.each do |ipr_id, indexes|
!       #     indexes.each do |index|
!       #       report.matches[index].ipr_id == ipr_id #=> true
        #     end
        #   end
        #
!       def list_of_interpro
!         @ipr_ids = {} unless @ipr_ids
!         @matches.each_with_index do |match, i|
!           @ipr_ids[match.ipr_id] = [] unless @ipr_ids[match.ipr_id]
!           @ipr_ids[match.ipr_id] << i
          end
-         @ipr_ids
        end
  
--- 284,310 ----
        end
        
! #      def format_gff3
! #      end
  
  
!       # Returns a Hash (key as an Interpro ID and value as a Match).
        #
!       #   report.to_hash.each do |ipr_id, matches|
!       #     matches.each do |match|
!       #       report.matches.ipr_id == ipr_id #=> true
        #     end
        #   end
        #
!       def to_hash
!         unless @ipr_ids
!           @ipr_ids = {} 
!           @matches.each_with_index do |match, i|
!             @ipr_ids[match.ipr_id] ||= []
!             @ipr_ids[match.ipr_id] << match
!           end
!           return @ipr_ids
!         else
!           return @ipr_ids
          end
        end
  
***************
*** 333,338 ****
          def length;          @data[:length];          end
          # the analysis method launched.
!         def method;          @data[:method];          end  # Object#metod overrided by Match#method
!         # the Gene Ontology description for the InterPro entry, in "Aspect:term (ID)" format.
          def go_terms;        @data[:go_terms];        end
          # Id of the input sequence.
--- 341,346 ----
          def length;          @data[:length];          end
          # the analysis method launched.
!         def method_name;          @data[:method];          end
!         # the Gene Ontology description for the InterPro entry, in "Aspect :term (ID)" format.
          def go_terms;        @data[:go_terms];        end
          # Id of the input sequence.




More information about the bioruby-cvs mailing list