[BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.11, 1.12 analysis_basic.rb, 1.4, 1.5

Trevor Wennblom trevor at dev.open-bio.org
Fri Jan 5 05:33:31 UTC 2007


Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme
In directory dev.open-bio.org:/tmp/cvs-serv15820/restriction_enzyme

Modified Files:
	analysis.rb analysis_basic.rb 
Log Message:


Index: analysis_basic.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis_basic.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** analysis_basic.rb	2 Jan 2007 07:33:46 -0000	1.4
--- analysis_basic.rb	5 Jan 2007 05:33:29 -0000	1.5
***************
*** 9,20 ****
  #
  
- #--
- #if RUBY_VERSION[0..2] == '1.9' or RUBY_VERSION == '2.0'
- #  err = "This class makes use of 'include' on ranges quite a bit.  Possibly unstable in development Ruby.  2005/12/20."
- #  err += "http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/167182?167051-169742"
- #  raise err
- #end
- #++
- 
  require 'pathname'
  libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
--- 9,12 ----
***************
*** 34,37 ****
--- 26,31 ----
    # ---
    # See Bio::RestrictionEnzyme::Analysis.cut
+   # 
+   # NOTE: move this into Bio::Sequence::NA
    def cut_with_enzyme(*args)
      Bio::RestrictionEnzyme::Analysis.cut(self, *args)
***************
*** 42,45 ****
--- 36,40 ----
  require 'pp'
  
+ require 'set'  # for method create_enzyme_actions
  require 'bio/util/restriction_enzyme'
  require 'bio/util/restriction_enzyme/range/sequence_range'
***************
*** 57,88 ****
  
    def self.cut( sequence, *args )
! #    self.new.cut( sequence, *args )
    end
  
    def self.cut_without_permutations( sequence, *args )
      self.new.cut_without_permutations( sequence, *args )
    end
  
    # Example:
    #
!   #   Analysis.cut_without_permutations('gaattc', 'EcoRI')
    #
    # _same as:_
    #
!   #   Analysis.cut_without_permutations('gaattc', 'g^aattc')
    # ---
    # *Arguments*
!   # * +sequence+: +String+ kind of object that will be used as a nucleic acid sequence
!   # * +args+: Series of 
!   # *Returns*:: +Hash+ ?(array?) of Bio::RestrictionEnzyme::Analysis::UniqueFragment objects
    def cut_without_permutations( sequence, *args )
!     return {} if !sequence.kind_of?(String) or sequence.empty?
      sequence = Bio::Sequence::NA.new( sequence )
  
!     tmp = create_enzyme_actions( sequence, *args )
!     #enzyme_actions = tmp[0].merge(tmp[1])
!     enzyme_actions = tmp[0] + tmp[1]
! 
      sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 )
      enzyme_actions.each do |enzyme_action|
        enzyme_action.cut_ranges.each do |cut_range|
--- 52,107 ----
  
    def self.cut( sequence, *args )
!     # Just a placeholder, actually defined in bio/util/restriction_enzyme/analysis.rb
!     #self.new.cut( sequence, *args )
    end
  
+   # See cut_without_permutations instance method
    def self.cut_without_permutations( sequence, *args )
      self.new.cut_without_permutations( sequence, *args )
    end
  
+   # See main documentation for Bio::RestrictionEnzyme
+   #
+   # Bio::RestrictionEnzyme.cut is preferred over this!
+   #
+   # USE AT YOUR OWN RISK
+   #
+   # This is a simpler version of method +cut+.  +cut+ takes into account
+   # permutations of cut variations based on competitiveness of enzymes for an
+   # enzyme cutsite or enzyme bindsite on a sequence.  This does not take into
+   # account those possibilities and is therefore faster, but less likely to be
+   # accurate.
+   #
+   # This code is mainly included as an example for those interested to study
+   # without having to wade through the extra layer of complexity added by the
+   # permutations.
+   # 
    # Example:
    #
!   # FIXME add output
!   #
!   #   Bio::RestrictionEnzyme::Analysis.cut_without_permutations('gaattc', 'EcoRI')
    #
    # _same as:_
    #
!   #   Bio::RestrictionEnzyme::Analysis.cut_without_permutations('gaattc', 'g^aattc')
    # ---
    # *Arguments*
!   # * +sequence+: +String+ kind of object that will be used as a nucleic acid sequence.
!   # * +args+: Series of enzyme names, enzymes sequences with cut marks, or RestrictionEnzyme objects.
!   # *Returns*:: Fragments object populated with Fragment objects.
    def cut_without_permutations( sequence, *args )
!     return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty?
      sequence = Bio::Sequence::NA.new( sequence )
  
!     # create_enzyme_actions returns two seperate array elements, they're not
!     # needed separated here so we put them into one array
!     enzyme_actions = create_enzyme_actions( sequence, *args ).flatten
!     return fragments_for_display( {} ) if enzyme_actions.empty?
!     
!     # Primary and complement strands are both measured from '0' to 'sequence.size-1' here
      sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 )
+     
+     # Add the cuts to the sequence_range from each enzyme_action
      enzyme_actions.each do |enzyme_action|
        enzyme_action.cut_ranges.each do |cut_range|
***************
*** 91,102 ****
      end
  
      sequence_range.fragments.primary = sequence
      sequence_range.fragments.complement = sequence.forward_complement
!     unique_fragments_for_display( {0 => sequence_range} )
    end
  
!   UniqueFragment = Struct.new(:primary, :complement)
    
!   class UniqueFragments < Array
      def primary; strip_and_sort(:primary); end
      def complement; strip_and_sort(:complement); end
--- 110,148 ----
      end
  
+     # Fill in the source sequence for sequence_range so it knows what bases
+     # to use
      sequence_range.fragments.primary = sequence
      sequence_range.fragments.complement = sequence.forward_complement
!     
!     # Format the fragments for the user
!     fragments_for_display( {0 => sequence_range} )
    end
  
!   # A Fragment is a sequence fragment composed of a primary and 
!   # complementary that would be found floating in solution after a full
!   # sequence is digested by a RestrictionEnzyme.
!   #
!   # You will notice that either the primary or complement strand will be
!   # padded with spaces to make them line up according to the original DNA
!   # configuration before being cut.
!   #
!   # Example:
!   #
!   #   primary =    "gattaca"
!   #   complement = "   atga"
!   # 
!   # View these with the 'primary' and 'complement' methods.
!   # 
!   # Fragment is a simple +Struct+ object.
!   Fragment = Struct.new(:primary, :complement)
    
!   # Fragments inherits from +Array+.
!   #
!   # Fragments is a container for Fragment objects.  It adds the
!   # methods +primary+ and +complement+ which returns an +Array+ of all
!   # respective strands from it's Fragment members.  Note that it will
!   # not return duplicate items and does not return the spacing that you would
!   # find by accessing the members directly.
!   class Fragments < Array
      def primary; strip_and_sort(:primary); end
      def complement; strip_and_sort(:complement); end
***************
*** 114,130 ****
  
  
!   # * +hsh+: +Hash+  Key is a permutation ID, if any.  Value is SequenceRange object that has cuts.
    # 
!   def unique_fragments_for_display( hsh )
!     uf_ary = UniqueFragments.new
!     return uf_ary if hsh == nil
  
      hsh.each do |permutation_id, sequence_range|
        sequence_range.fragments.for_display.each do |fragment|
!         uf_ary << UniqueFragment.new(fragment.primary, fragment.complement)
        end
      end
!     uf_ary.uniq!
!     uf_ary
    end
  
--- 160,181 ----
  
  
!   # Take the fragments from SequenceRange objects generated from add_cut_range
!   # and return unique results as a Fragment object.
    # 
!   # ---
!   # *Arguments*
!   # * +hsh+: +Hash+  Keys are a permutation ID, if any.  Values are SequenceRange objects that have cuts applied.
!   # *Returns*:: Fragments object populated with Fragment objects.
!   def fragments_for_display( hsh )
!     ary = Fragments.new
!     return ary unless hsh
  
      hsh.each do |permutation_id, sequence_range|
        sequence_range.fragments.for_display.each do |fragment|
!         ary << Fragment.new(fragment.primary, fragment.complement)
        end
      end
!     ary.uniq!
!     ary
    end
  
***************
*** 134,138 ****
    # +args+:: The enzymes to use.
    def create_enzyme_actions( sequence, *args )
-     require 'set'
      all_enzyme_actions = []
      
--- 185,188 ----
***************
*** 145,149 ****
      end
      
!     # VerticalCutRange should really be called VerticalAndHorizontalCutRange
      
      # * all_enzyme_actions is now full of EnzymeActions at specific locations across 
--- 195,199 ----
      end
      
!     # FIXME VerticalCutRange should really be called VerticalAndHorizontalCutRange
      
      # * all_enzyme_actions is now full of EnzymeActions at specific locations across 
***************
*** 156,164 ****
      #   competitive, however neither bind site may be part of the other
      #   enzyme's cut or else they do become competitive.
!     # * note that a small enzyme may possibly cut inbetween two cuts far apart
!     #   made by a larger enzyme, this would be a "sometimes" cut since it's
!     #   not guaranteed that the larger enzyme will cut first, therefore there
!     #   is competition.
!     
      # Take current EnzymeAction's entire bind site and compare it to all other
      # EzymeAction's cut ranges.  Only look for vertical cuts as boundaries
--- 206,210 ----
      #   competitive, however neither bind site may be part of the other
      #   enzyme's cut or else they do become competitive.
!     #
      # Take current EnzymeAction's entire bind site and compare it to all other
      # EzymeAction's cut ranges.  Only look for vertical cuts as boundaries
***************
*** 172,176 ****
      #
      # Then the bind site (and EnzymeAction range) for Enzyme B would need it's
!     # right side to be 2 or less, or it's left side to be 6 or greater.
      
      competition_indexes = Set.new
--- 218,222 ----
      #
      # Then the bind site (and EnzymeAction range) for Enzyme B would need it's
!     # right side to be at index 2 or less, or it's left side to be 6 or greater.
      
      competition_indexes = Set.new
***************
*** 199,203 ****
    end
  
!   # Returns an +Array+ of the match indicies of a RegExp to a string.
    #
    # ---
--- 245,253 ----
    end
  
!   # Returns an +Array+ of the match indicies of a +RegExp+ to a string.
!   #
!   # Example:
!   #
!   #   find_match_locations('abccdefeg', /[ce]/) # => [2,3,5,7]
    #
    # ---

Index: analysis.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** analysis.rb	2 Jan 2007 07:33:46 -0000	1.11
--- analysis.rb	5 Jan 2007 05:33:29 -0000	1.12
***************
*** 9,20 ****
  #
  
- #--
- #if RUBY_VERSION[0..2] == '1.9' or RUBY_VERSION == '2.0'
- #  err = "This class makes use of 'include' on ranges quite a bit.  Possibly unstable in development Ruby.  2005/12/20."
- #  err += "http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/167182?167051-169742"
- #  raise err
- #end
- #++
- 
  require 'pathname'
  libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s
--- 9,12 ----
***************
*** 34,44 ****
  class Analysis
  
    def self.cut( sequence, *args )
      self.new.cut( sequence, *args )
    end
  
    def cut( sequence, *args )
!     return nil if !sequence.kind_of?(String) or sequence.empty?
!     unique_fragments_for_display( cut_and_return_by_permutations( sequence, *args ) )
    end
  
--- 26,59 ----
  class Analysis
  
+   # See cut instance method
    def self.cut( sequence, *args )
      self.new.cut( sequence, *args )
    end
  
+   # See main documentation for Bio::RestrictionEnzyme
+   #
+   #
+   # +cut+ takes into account
+   # permutations of cut variations based on competitiveness of enzymes for an
+   # enzyme cutsite or enzyme bindsite on a sequence.
+   #
+   # Example:
+   #
+   # FIXME add output
+   #
+   #   Bio::RestrictionEnzyme::Analysis.cut('gaattc', 'EcoRI')
+   #
+   # _same as:_
+   #
+   #   Bio::RestrictionEnzyme::Analysis.cut('gaattc', 'g^aattc')
+   # ---
+   # *Arguments*
+   # * +sequence+: +String+ kind of object that will be used as a nucleic acid sequence.
+   # * +args+: Series of enzyme names, enzymes sequences with cut marks, or RestrictionEnzyme objects.
+   # *Returns*:: Fragments object populated with Fragment objects.
    def cut( sequence, *args )
!     return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty?
!     # Format the fragments for the user
!     fragments_for_display( cut_and_return_by_permutations( sequence, *args ) )
    end
  
***************
*** 47,61 ****
    #########
    
    def cut_and_return_by_permutations( sequence, *args )
-     return {} if !sequence.kind_of?(String) or sequence.empty?
-     sequence = Bio::Sequence::NA.new( sequence )
-     sequence.freeze
-     
-     # +Hash+ Key is permutation ID, value is SequenceRange
      my_hash = {}
      
      enzyme_actions, initial_cuts = create_enzyme_actions( sequence, *args )
      return my_hash if enzyme_actions.empty? and initial_cuts.empty?
! 
      if enzyme_actions.size > 1
        permutations = permute(enzyme_actions.size)
--- 62,81 ----
    #########
    
+   # See cut instance method
+   #
+   # ---
+   # *Arguments*
+   # * +sequence+: +String+ kind of object that will be used as a nucleic acid sequence.
+   # * +args+: Series of enzyme names, enzymes sequences with cut marks, or RestrictionEnzyme objects.
+   # *Returns*:: +Hash+ Keys are a permutation ID, values are SequenceRange objects that have cuts applied.
    def cut_and_return_by_permutations( sequence, *args )
      my_hash = {}
      
+     return my_hash if !sequence.kind_of?(String) or sequence.empty?
+     sequence = Bio::Sequence::NA.new( sequence )
+     
      enzyme_actions, initial_cuts = create_enzyme_actions( sequence, *args )
      return my_hash if enzyme_actions.empty? and initial_cuts.empty?
!     
      if enzyme_actions.size > 1
        permutations = permute(enzyme_actions.size)
***************
*** 63,76 ****
        permutations.each do |permutation|
          previous_cut_ranges = []
!         sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new(  0, 
!                                                                             0, 
!                                                                             sequence.size-1, 
!                                                                             sequence.size-1 )
!                                                                             
!         initial_cuts.each { |enzyme_action|
!           #raise initial_cuts.inspect
!            
!                             enzyme_action.cut_ranges.each { |cut_range| 
!                                                             sequence_range.add_cut_range(cut_range) } }
  
          permutation.each do |id|
--- 83,97 ----
        permutations.each do |permutation|
          previous_cut_ranges = []
!         # Primary and complement strands are both measured from '0' to 'sequence.size-1' here
!         sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 )
! 
!         # Add the cuts to the sequence_range from each enzyme_action contained
!         # in initial_cuts.  These are the cuts that have no competition so are
!         # not subject to permutations.
!         initial_cuts.each do |enzyme_action|
!           enzyme_action.cut_ranges.each do |cut_range|
!             sequence_range.add_cut_range(cut_range)
!           end
!         end
  
          permutation.each do |id|
***************
*** 109,112 ****
--- 130,135 ----
          end
  
+         # Fill in the source sequence for sequence_range so it knows what bases
+         # to use
          sequence_range.fragments.primary = sequence
          sequence_range.fragments.complement = sequence.forward_complement
***************
*** 116,123 ****
      else # !if enzyme_actions.size > 1
        sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 )
- 
-       #initial_cuts.each { |key, enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } }
        initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } }
- 
        sequence_range.fragments.primary = sequence
        sequence_range.fragments.complement = sequence.forward_complement
--- 139,143 ----




More information about the bioruby-cvs mailing list