[BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.6, 1.7 cut_symbol.rb, 1.2, 1.3
Trevor Wennblom
trevor at dev.open-bio.org
Mon Jan 1 02:16:07 UTC 2007
Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme
In directory dev.open-bio.org:/tmp/cvs-serv512/lib/bio/util/restriction_enzyme
Modified Files:
analysis.rb cut_symbol.rb
Log Message:
Index: cut_symbol.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/cut_symbol.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** cut_symbol.rb 31 Dec 2006 21:50:31 -0000 1.2
--- cut_symbol.rb 1 Jan 2007 02:16:05 -0000 1.3
***************
*** 1,4 ****
#
! # bio/util/restrction_enzyme/cut_symbol.rb -
#
# Author:: Trevor Wennblom <mailto:trevor at corevx.com>
--- 1,4 ----
#
! # bio/util/restrction_enzyme/cut_symbol.rb - Defines the symbol used to mark a cut in an enzyme sequence
#
# Author:: Trevor Wennblom <mailto:trevor at corevx.com>
***************
*** 9,13 ****
#
! nil # separate file-level rdoc from following statement
module Bio; end
--- 9,13 ----
#
! nil # to separate file-level rdoc from following statement # !> useless use of nil in void context
module Bio; end
***************
*** 15,19 ****
#
! # bio/util/restrction_enzyme/cut_symbol.rb -
#
# Author:: Trevor Wennblom <mailto:trevor at corevx.com>
--- 15,19 ----
#
! # bio/util/restrction_enzyme/cut_symbol.rb - Defines the symbol used to mark a cut in an enzyme sequence
#
# Author:: Trevor Wennblom <mailto:trevor at corevx.com>
***************
*** 21,57 ****
# License:: Distributes under the same terms as Ruby
#
module CutSymbol
! require 'singleton'
!
! class CutSymbol__
! include Singleton
! attr_accessor :cut_symbol
! attr_accessor :escaped_cut_symbol
! end
!
! # NOTE verify this sometime
! def cut_symbol=(c)
! CutSymbol__.instance.cut_symbol = c
end
! def cut_symbol
! CutSymbol__.instance.cut_symbol ||= '^'
! end
! def escaped_cut_symbol
! CutSymbol__.instance.escaped_cut_symbol ||= "\\#{cut_symbol}" # \^
! end
! # Used to check if multiple cut symbols are next to each other
def re_cut_symbol_adjacent
%r"#{escaped_cut_symbol}{2}"
end
! # A Regexp of the cut_symbol. Convenience method.
def re_cut_symbol
%r"#{escaped_cut_symbol}"
end
end # CutSymbol
! end # Bio::RestrictionEnzyme
\ No newline at end of file
--- 21,115 ----
# License:: Distributes under the same terms as Ruby
#
+ # = Usage
+ #
+ # #require 'bio/util/restriction_enzyme/cut_symbol'
+ # require 'cut_symbol'
+ # include Bio::RestrictionEnzyme::CutSymbol
+ #
+ # cut_symbol # => "^"
+ # set_cut_symbol('|') # => "|"
+ # cut_symbol # => "|"
+ # escaped_cut_symbol # => "\\|"
+ # re_cut_symbol # => /\|/
+ # set_cut_symbol('^') # => "^"
+ # "abc^de" =~ re_cut_symbol # => 3
+ # "abc^de" =~ re_cut_symbol_adjacent # => nil
+ # "abc^^de" =~ re_cut_symbol_adjacent # => 3
+ # "a^bc^^de" =~ re_cut_symbol_adjacent # => 4
+ # "a^bc^de" =~ re_cut_symbol_adjacent # => nil
+ #
module CutSymbol
! # Set the token to be used as the cut symbol in a restriction enzyme sequece
! #
! # Starts as +^+ character
! #
! # ---
! # *Arguments*
! # * +glyph+: The single character to be used as the cut symbol in an enzyme sequence
! # *Returns*:: +glyph+
! def set_cut_symbol(glyph)
! CutSymbol__.cut_symbol = glyph
end
! # Get the token that's used as the cut symbol in a restriction enzyme sequece
! #
! # ---
! # *Arguments*
! # * _none_
! # *Returns*:: +glyph+
! def cut_symbol; CutSymbol__.cut_symbol; end
! # Get the token that's used as the cut symbol in a restriction enzyme sequece with
! # a back-slash preceding it.
! #
! # ---
! # *Arguments*
! # * _none_
! # *Returns*:: +\glyph+
! def escaped_cut_symbol; CutSymbol__.escaped_cut_symbol; end
! # Used to check if multiple cut symbols are next to each other.
! #
! # ---
! # *Arguments*
! # * _none_
! # *Returns*:: +RegExp+
def re_cut_symbol_adjacent
%r"#{escaped_cut_symbol}{2}"
end
! # A Regexp of the cut_symbol.
! #
! # ---
! # *Arguments*
! # * _none_
! # *Returns*:: +RegExp+
def re_cut_symbol
%r"#{escaped_cut_symbol}"
end
+ #########
+ protected
+ #########
+
+ require 'singleton'
+
+ # Class to keep state
+ class CutSymbol__
+ include Singleton
+
+ @cut_symbol = '^'
+
+ def self.cut_symbol; @cut_symbol; end
+
+ def self.cut_symbol=(glyph);
+ raise ArgumentError if glyph.size != 1
+ @cut_symbol = glyph
+ end
+
+ def self.escaped_cut_symbol; "\\" + self.cut_symbol; end
+ end
+
end # CutSymbol
! end # Bio::RestrictionEnzyme
Index: analysis.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** analysis.rb 31 Dec 2006 21:50:31 -0000 1.6
--- analysis.rb 1 Jan 2007 02:16:05 -0000 1.7
***************
*** 33,37 ****
require 'bio/util/restriction_enzyme'
! require 'bio/util/restriction_enzyme/analysis/sequence_range.rb'
class Bio::RestrictionEnzyme
--- 33,37 ----
require 'bio/util/restriction_enzyme'
! require 'bio/util/restriction_enzyme/analysis/sequence_range'
class Bio::RestrictionEnzyme
More information about the bioruby-cvs
mailing list