From trevor at dev.open-bio.org Mon Jan 1 00:07:06 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 05:07:06 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme cut_symbol.rb, 1.3, 1.4 double_stranded.rb, 1.2, 1.3 Message-ID: <200701010507.l01576ei000879@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv855/lib/bio/util/restriction_enzyme Modified Files: cut_symbol.rb double_stranded.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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cut_symbol.rb 1 Jan 2007 02:16:05 -0000 1.3 --- cut_symbol.rb 1 Jan 2007 05:07:04 -0000 1.4 *************** *** 91,95 **** ######### ! protected ######### --- 91,95 ---- ######### ! #protected # NOTE this is a Module, can't hide CutSymbol__ ######### Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** double_stranded.rb 31 Dec 2006 21:50:31 -0000 1.2 --- double_stranded.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 31,41 **** # License:: Distributes under the same terms as Ruby # ! # A pair of +SingleStrand+ and +SingleStrandComplement+ objects with methods to # add utility to their relation. # # = Notes ! # * This is created by Bio::RestrictionEnzyme.new for convenience. ! # * The two strands accessible are +primary+ and +complement+. ! # * SingleStrand methods may be used on DoubleStranded and they will be passed to +primary+. # class DoubleStranded --- 31,41 ---- # License:: Distributes under the same terms as Ruby # ! # A pair of SingleStrand and SingleStrandComplement objects with methods to # add utility to their relation. # # = Notes ! # * This is created by Bio::RestrictionEnzyme.new for convenience. ! # * The two strands accessible are +primary+ and +complement+. ! # * SingleStrand methods may be used on DoubleStranded and they will be passed to +primary+. # class DoubleStranded From trevor at dev.open-bio.org Mon Jan 1 00:07:06 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 05:07:06 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis calculated_cuts.rb, 1.2, 1.3 Message-ID: <200701010507.l01576Wx000883@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv855/lib/bio/util/restriction_enzyme/analysis Modified Files: calculated_cuts.rb Log Message: Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/calculated_cuts.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** calculated_cuts.rb 31 Dec 2006 21:50:31 -0000 1.2 --- calculated_cuts.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 135,141 **** def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current ! vcs = '|' ! hcs = '-' ! vhcs = '+' num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } --- 135,141 ---- def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current ! vcs = '|' # Vertical cut symbol ! hcs = '-' # Horizontal cut symbol ! vhcs = '+' # Intersection of vertical and horizontal cut symbol num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } *************** *** 174,193 **** end - =begin - def vc_primary_add(c) - @vc_primary << c - @current = false - end - - def vc_complement_add(c) - @vc_complement << c - @current = false - end - - def hc_between_strands_add(c) - @hc_between_strands << c - @current = false - end - =end ######### protected --- 174,177 ---- From trevor at dev.open-bio.org Mon Jan 1 00:07:06 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 05:07:06 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/double_stranded aligned_strands.rb, 1.2, 1.3 cut_location_pair.rb, 1.2, 1.3 cut_location_pair_in_enzyme_notation.rb, 1.2, 1.3 cut_locations.rb, 1.2, 1.3 cut_locations_in_enzyme_notation.rb, 1.2, 1.3 Message-ID: <200701010507.l01576Zk000886@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded In directory dev.open-bio.org:/tmp/cvs-serv855/lib/bio/util/restriction_enzyme/double_stranded Modified Files: aligned_strands.rb cut_location_pair.rb cut_location_pair_in_enzyme_notation.rb cut_locations.rb cut_locations_in_enzyme_notation.rb Log Message: Index: aligned_strands.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** aligned_strands.rb 31 Dec 2006 21:50:31 -0000 1.2 --- aligned_strands.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - Align two SingleStrand objects # # Author:: Trevor Wennblom *************** *** 21,25 **** # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - # # Author:: Trevor Wennblom --- 21,25 ---- # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - Align two SingleStrand objects # # Author:: Trevor Wennblom *************** *** 27,31 **** # License:: Distributes under the same terms as Ruby # ! # Align two SingleStrand::Pattern objects and return a Result # object with +primary+ and +complement+ accessors. # --- 27,31 ---- # License:: Distributes under the same terms as Ruby # ! # Align two SingleStrand objects and return a Result # object with +primary+ and +complement+ accessors. # *************** *** 37,53 **** Result = Struct.new(:primary, :complement) ! # Pad and align two String objects. # ! # +a+:: First String ! # +b+:: Second String # ! # Example invocation: ! # AlignedStrands.align('nngattacannnnn', 'nnnnnctaatgtnn') # ! # Example return value: ! # # # def self.align(a, b) a = a.to_s --- 37,60 ---- Result = Struct.new(:primary, :complement) ! # Pad and align two String objects without cut symbols. # ! # This will look for the sub-sequence without left and right 'n' padding ! # and re-apply 'n' padding to both strings on both sides equal to the ! # maximum previous padding on that side. # ! # The sub-sequences stripped of left and right 'n' padding must be of equal ! # length. # ! # Example: ! # AlignedStrands.align('nngattacannnnn', 'nnnnnctaatgtnn') # => ! # # + # --- + # *Arguments* + # * +a+: Primary strand + # * +b+: Complementary strand + # *Returns*:: +Result+ object with equal padding on both strings def self.align(a, b) a = a.to_s *************** *** 64,79 **** # Pad and align two String objects with cut symbols. # ! # +a+:: First String ! # +b+:: Second String ! # +a_cuts+:: First strand cut locations in 0-based index notation ! # +b_cuts+:: Second strand cut locations in 0-based index notation ! # ! # Example invocation: ! # AlignedStrands.with_cuts('nngattacannnnn', 'nnnnnctaatgtnn', [0, 10, 12], [0, 2, 12]) ! # ! # Example return value: ! # # # # Notes: --- 71,79 ---- # Pad and align two String objects with cut symbols. # ! # Example: ! # AlignedStrands.with_cuts('nngattacannnnn', 'nnnnnctaatgtnn', [0, 10, 12], [0, 2, 12]) # => ! # # # Notes: *************** *** 81,86 **** # * This is meant to be able to handle multiple cuts and completely # unrelated cutsites on the two strands, therefore no biological ! # shortcuts are made. # def self.align_with_cuts(a,b,a_cuts,b_cuts) a = a.to_s --- 81,96 ---- # * This is meant to be able to handle multiple cuts and completely # unrelated cutsites on the two strands, therefore no biological ! # algorithm assumptions (shortcuts) are made. ! # ! # The sequences stripped of left and right 'n' padding must be of equal ! # length. # + # --- + # *Arguments* + # * +a+: Primary sequence + # * +b+: Complementary sequence + # * +a_cuts+: Primary strand cut locations in 0-based index notation + # * +b_cuts+: Complementary strand cut locations in 0-based index notation + # *Returns*:: +Result+ object with equal padding on both strings and spacing between bases def self.align_with_cuts(a,b,a_cuts,b_cuts) a = a.to_s Index: cut_locations.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_locations.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_locations.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_locations.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - Contains an Array of CutLocationPair objects # # Author:: Trevor Wennblom *************** *** 19,23 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - # # Author:: Trevor Wennblom --- 19,23 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - Contains an Array of CutLocationPair objects # # Author:: Trevor Wennblom *************** *** 25,30 **** --- 25,45 ---- # License:: Distributes under the same terms as Ruby # + # Contains an +Array+ of CutLocationPair objects. + # class CutLocations < Array + # CutLocations constructor. + # + # Contains an +Array+ of CutLocationPair objects. + # + # Example: + # clp1 = CutLocationPair.new(3,2) + # clp2 = CutLocationPair.new(7,9) + # pairs = CutLocations.new(clp1, clp2) + # + # --- + # *Arguments* + # * +args+: Any number of +CutLocationPair+ objects + # *Returns*:: nothing def initialize(*args) validate_args(args) *************** *** 32,39 **** --- 47,66 ---- end + # Returns an +Array+ of locations of cuts on the primary strand + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the primary strand def primary self.collect {|a| a[0]} end + # Returns an +Array+ of locations of cuts on the complementary strand + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the complementary strand def complement self.collect {|a| a[1]} Index: cut_locations_in_enzyme_notation.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_locations_in_enzyme_notation.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_locations_in_enzyme_notation.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - Inherits from DoubleStrand::CutLocations # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - Inherits from DoubleStrand::CutLocations # # Author:: Trevor Wennblom *************** *** 26,39 **** --- 26,64 ---- # License:: Distributes under the same terms as Ruby # + # Inherits from DoubleStranded::CutLocations. Contains CutLocationPairInEnzymeNotation objects. + # Adds helper methods to convert from enzyme index notation to 0-based array index notation. + # class CutLocationsInEnzymeNotation < CutLocations + # Returns +Array+ of locations of cuts on the primary + # strand in 0-based array index notation. + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the primary strand in 0-based array index notation. def primary_to_array_index helper_for_to_array_index(self.primary) end + # Returns +Array+ of locations of cuts on the complementary + # strand in 0-based array index notation. + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the complementary strand in 0-based array index notation. def complement_to_array_index helper_for_to_array_index(self.complement) end + # Returns the contents of the present CutLocationsInEnzymeNotation object as + # a CutLocations object with the contents converted from enzyme notation + # to 0-based array index notation. + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +CutLocations+ def to_array_index unless self.primary_to_array_index.size == self.complement_to_array_index.size Index: cut_location_pair_in_enzyme_notation.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_location_pair_in_enzyme_notation.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_location_pair_in_enzyme_notation.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - Inherits from DoubleStranded::CutLocationPair # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - Inherits from DoubleStranded::CutLocationPair # # Author:: Trevor Wennblom *************** *** 26,30 **** # License:: Distributes under the same terms as Ruby # ! # See CutLocationPair # class CutLocationPairInEnzymeNotation < CutLocationPair --- 26,31 ---- # License:: Distributes under the same terms as Ruby # ! # Inherits from DoubleStranded::CutLocationPair , stores the cut location pair in ! # enzyme notation instead of 0-based. # class CutLocationPairInEnzymeNotation < CutLocationPair *************** *** 35,43 **** def validate_2( a, b ) ! if a == 0 ! raise ArgumentError, "Enzyme index notation only. 0 values are illegal." ! end ! ! if b == 0 raise ArgumentError, "Enzyme index notation only. 0 values are illegal." end --- 36,40 ---- def validate_2( a, b ) ! if (a == 0) or (b == 0) raise ArgumentError, "Enzyme index notation only. 0 values are illegal." end Index: cut_location_pair.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_location_pair.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_location_pair.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - Stores a cut location pair in 0-based index notation # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - Stores a cut location pair in 0-based index notation # # Author:: Trevor Wennblom *************** *** 26,48 **** # License:: Distributes under the same terms as Ruby # ! # Stores a cut location pair in 0-based index notation ! # ! # Input: ! # +pair+:: May be two values represented as an Array, a Range, or a ! # combination of Integer and nil values. The first value ! # represents a cut on the primary strand, the second represents ! # a cut on the complement strand. ! # ! # Example: ! # clp = CutLocationPair.new(3,2) ! # clp.primary # 3 ! # clp.complement # 2 ! # ! # Notes: ! # * a value of +nil+ is an explicit representation of 'no cut' # class CutLocationPair < Array ! attr_reader :primary, :complement def initialize( *pair ) a = b = nil --- 26,60 ---- # License:: Distributes under the same terms as Ruby # ! # Stores a single cut location pair in 0-based index notation for use with ! # DoubleStranded enzyme sequences. # class CutLocationPair < Array ! # Location of the cut on the primary strand. ! # Corresponds - or 'pairs' - to the complement cut. ! # A value of +nil+ is an explicit representation of 'no cut'. ! attr_reader :primary ! ! # Location of the cut on the complementary strand. ! # Corresponds - or 'pairs' - to the primary cut. ! # A value of +nil+ is an explicit representation of 'no cut'. ! attr_reader :complement + # CutLocationPair constructor. + # + # Stores a single cut location pair in 0-based index notation for use with + # DoubleStranded enzyme sequences. + # + # Example: + # clp = CutLocationPair.new(3,2) + # clp.primary # 3 + # clp.complement # 2 + # + # --- + # *Arguments* + # * +pair+: May be two values represented as an Array, a Range, or a + # combination of Integer and nil values. The first value + # represents a cut on the primary strand, the second represents + # a cut on the complement strand. + # *Returns*:: nothing def initialize( *pair ) a = b = nil *************** *** 64,67 **** --- 76,80 ---- @primary = a @complement = b + return end *************** *** 85,93 **** def validate_2( a, b ) ! if a != nil and a.negative? ! raise ArgumentError, "0-based index notation only. Negative values are illegal." ! end ! ! if b != nil and b.negative? raise ArgumentError, "0-based index notation only. Negative values are illegal." end --- 98,102 ---- def validate_2( a, b ) ! if (a != nil and a.negative?) or (b != nil and b.negative?) raise ArgumentError, "0-based index notation only. Negative values are illegal." end From trevor at dev.open-bio.org Mon Jan 1 18:47:30 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 23:47:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis_basic.rb, NONE, 1.1 analysis.rb, 1.7, 1.8 double_stranded.rb, 1.3, 1.4 Message-ID: <200701012347.l01NlUaJ002435@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv2413/restriction_enzyme Modified Files: analysis.rb double_stranded.rb Added Files: analysis_basic.rb Log Message: --- NEW FILE: analysis_basic.rb --- # # bio/util/restrction_enzyme/analysis_basic.rb - Does the work of fragmenting the DNA from the enzymes # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: analysis_basic.rb,v 1.1 2007/01/01 23:47:27 trevor Exp $ # #-- #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 $:.unshift(libpath) unless $:.include?(libpath) require 'bio' class Bio::Sequence::NA # Example: # # seq = Bio::Sequence::NA.new('gaattc') # cuts = seq.cut_with_enzyme('EcoRI') # # _or_ # # seq = Bio::Sequence::NA.new('gaattc') # cuts = seq.cut_with_enzyme('g^aattc') # --- # See Bio::RestrictionEnzyme::Analysis.cut def cut_with_enzyme(*args) Bio::RestrictionEnzyme::Analysis.cut(self, *args) end alias cut_with_enzymes cut_with_enzyme end require 'pp' require 'bio/util/restriction_enzyme' require 'bio/util/restriction_enzyme/analysis/sequence_range' class Bio::RestrictionEnzyme # # bio/util/restrction_enzyme/analysis_basic.rb - Does the work of fragmenting the DNA from the enzymes # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class Analysis 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]) sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| sr_with_cuts.add_cut_range(cut_range) end end sr_with_cuts.fragments.primary = sequence sr_with_cuts.fragments.complement = sequence.forward_complement unique_fragments_for_display( {0 => sr_with_cuts} ) end ######### protected ######### UniqueFragment = Struct.new(:primary, :complement) class UniqueFragments < Array def primary tmp = [] self.each { |uf| tmp << uf.primary } tmp.sort.map { |e| e.tr(' ', '') } end def complement tmp = [] self.each { |uf| tmp << uf.complement } tmp.sort.map { |e| e.tr(' ', '') } end end def unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) uf_ary = UniqueFragments.new return uf_ary if hash_of_sequence_ranges_with_cuts == nil or hash_of_sequence_ranges_with_cuts.empty? hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| sr_with_cuts.fragments.for_display.each do |fragment| uf = UniqueFragment.new uf.primary = fragment.primary uf.complement = fragment.complement duplicate = false uf_ary.each do |element| if (uf.primary == element.primary) and (uf.complement == element.complement) duplicate = true break end end uf_ary << uf unless duplicate end end uf_ary end # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. # # +sequence+:: The string of DNA to match the enzyme recognition sites against # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) id = 0 enzyme_actions_that_sometimes_cut = {} enzyme_actions_that_always_cut = {} indicies_of_sometimes_cut = [] args.each do |enzyme| enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| #enzyme_actions_that_always_cut[id] = enzyme_to_enzyme_action( enzyme, offset ) enzyme_actions_that_always_cut[id] = enzyme.create_action_at( offset ) id += 1 end end # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut max = enzyme_actions_that_always_cut.size - 1 0.upto(max) do |i| enzyme_action = enzyme_actions_that_always_cut[i] conflict = false other_cut_ranges = {} enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; other_cut_ranges[key] = i_ea.cut_ranges } other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last if (enzyme_action.right <= previous_cut_left) or (enzyme_action.left > previous_cut_right) or (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts # no conflict else conflict = true end indicies_of_sometimes_cut += [i, key] if conflict == true end end end indicies_of_sometimes_cut.uniq.each do |i| enzyme_actions_that_sometimes_cut[i] = enzyme_actions_that_always_cut[i] enzyme_actions_that_always_cut.delete(i) end [enzyme_actions_that_sometimes_cut, enzyme_actions_that_always_cut] end # Returns an +Array+ of the match indicies of a RegExp to a string. # # --- # *Arguments* # * +string+: The string to scan # * +re+: A RegExp to use # *Returns*:: +Array+ with indicies of match locations def find_match_locations( string, re ) md = string.match( re ) locations = [] counter = 0 while md # save the match index relative to the original string locations << (counter += md.begin(0)) # find the next match md = string[ (counter += 1)..-1 ].match( re ) end locations end end # Analysis end # Bio::RestrictionEnzyme Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** analysis.rb 1 Jan 2007 02:16:05 -0000 1.7 --- analysis.rb 1 Jan 2007 23:47:27 -0000 1.8 *************** *** 21,37 **** $:.unshift(libpath) unless $:.include?(libpath) ! require 'bio' ! class Bio::Sequence::NA ! # See Bio::RestrictionEnzyme::Analysis.cut ! def cut_with_enzyme(*args) ! Bio::RestrictionEnzyme::Analysis.cut(self, *args) ! end ! alias cut_with_enzymes cut_with_enzyme ! end ! ! require 'pp' ! ! require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' class Bio::RestrictionEnzyme --- 21,25 ---- $:.unshift(libpath) unless $:.include?(libpath) ! require 'bio/util/restriction_enzyme/analysis_basic' class Bio::RestrictionEnzyme *************** *** 50,84 **** end ! def self.cut_without_permutations( sequence, *args ) ! self.new.cut_without_permutations( sequence, *args ) ! end ! ! def self.cut_and_return_by_permutations( sequence, *args ) ! self.new.cut_and_return_by_permutations( sequence, *args ) ! end ! ! def cut_without_permutations( sequence, *args ) ! return {} if !sequence.kind_of?(String) or sequence.empty? ! sequence = Bio::Sequence::NA.new( sequence ) ! ! #enzyme_actions = create_enzyme_actions( sequence, *args ) ! tmp = create_enzyme_actions( sequence, *args ) ! enzyme_actions = tmp[0].merge(tmp[1]) ! ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) ! enzyme_actions.each do |id, enzyme_action| ! enzyme_action.cut_ranges.each do |cut_range| ! sr_with_cuts.add_cut_range(cut_range) ! end ! end ! ! sr_with_cuts.fragments.primary = sequence ! sr_with_cuts.fragments.complement = sequence.forward_complement ! ! tmp = {} ! tmp[0] = sr_with_cuts ! unique_fragments_for_display( tmp ) end def cut_and_return_by_permutations( sequence, *args ) return {} if !sequence.kind_of?(String) or sequence.empty? --- 38,51 ---- end ! def cut( sequence, *args ) ! return nil if !sequence.kind_of?(String) or sequence.empty? ! hash_of_sequence_ranges_with_cuts = cut_and_return_by_permutations( sequence, *args ) ! unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) end + ######### + protected + ######### + def cut_and_return_by_permutations( sequence, *args ) return {} if !sequence.kind_of?(String) or sequence.empty? *************** *** 123,134 **** previous_cut_right = cut_range.range.last - =begin - puts "--- #{permutation.inspect} ---" - puts "Previous cut left: #{previous_cut_left}" - puts "EA.left #{enzyme_action.left}" - puts "Previous cut right: #{previous_cut_right}" - puts "EA.right: #{enzyme_action.right}" - =end - # Keep in mind: # * The cut location is to the immediate right of the base located at the index. --- 90,93 ---- *************** *** 140,148 **** (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts # no conflict - #puts "no conflict" - else conflict = true - #puts "conflict" end end --- 99,104 ---- *************** *** 161,178 **** end - #pp hash_of_sequence_ranges_with_cuts hash_of_sequence_ranges_with_cuts end - def cut( sequence, *args ) - return nil if !sequence.kind_of?(String) or sequence.empty? - hash_of_sequence_ranges_with_cuts = cut_and_return_by_permutations( sequence, *args ) - unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) - end - - ######### - protected - ######### - def permute(count, permutations = [[0]]) return permutations if count <= 1 --- 117,123 ---- *************** *** 190,366 **** end - UniqueFragment = Struct.new(:primary, :complement) - class UniqueFragments < Array - def primary - tmp = [] - self.each { |uf| tmp << uf.primary } - tmp.sort.map { |e| e.tr(' ', '') } - end - def complement - tmp = [] - self.each { |uf| tmp << uf.complement } - tmp.sort.map { |e| e.tr(' ', '') } - end - end - - def unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) - uf_ary = UniqueFragments.new - return uf_ary if hash_of_sequence_ranges_with_cuts == nil or hash_of_sequence_ranges_with_cuts.empty? - - hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| - sr_with_cuts.fragments.for_display.each do |fragment| - uf = UniqueFragment.new - uf.primary = fragment.primary - uf.complement = fragment.complement - - duplicate = false - uf_ary.each do |element| - if (uf.primary == element.primary) and (uf.complement == element.complement) - duplicate = true - break - end - end - - uf_ary << uf unless duplicate - end - end - uf_ary - end - - - =begin - Strand = Struct.new(:primary, :complement, :p_left, :p_right, :c_left, :c_right) - - def ts_fragments_to_strands( sequence, fragments ) - sequence = Bio::Sequence::NA.new( sequence ) - strands = [] - fragments.each do |f| - p = sequence[f.p_left..f.p_right] - c = sequence[f.c_left..f.c_right] - strands << Strand.new(p, c, f.p_left, f.p_right, f.c_left, f.c_right) - end - strands - end - =end - - # Defines a single enzyme action, in this case being a range that correlates - # to the DNA sequence that may contain it's own internal cuts. - class EnzymeAction < SequenceRange - end - - # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. - # - # +sequence+:: The string of DNA to match the enzyme recognition sites against - # +args+:: The enzymes to use. - def create_enzyme_actions( sequence, *args ) - id = 0 - enzyme_actions_that_sometimes_cut = {} - enzyme_actions_that_always_cut = {} - indicies_of_sometimes_cut = [] - - args.each do |enzyme| - enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded - find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| - enzyme_actions_that_always_cut[id] = enzyme_to_enzyme_action( enzyme, offset ) - id += 1 - end - end - - # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut - - max = enzyme_actions_that_always_cut.size - 1 - 0.upto(max) do |i| - enzyme_action = enzyme_actions_that_always_cut[i] - conflict = false - other_cut_ranges = {} - #enzyme_actions.each { |key,enzyme_action| next if i == key; puts "i: #{i}, key: #{key}"; previous_cut_ranges += enzyme_action.cut_ranges } - # enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; puts "i: #{i}, key: #{key}"; other_cut_ranges[key] = i_ea.cut_ranges } - enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; other_cut_ranges[key] = i_ea.cut_ranges } - # puts "Enzyme action #{i}:" - # pp enzyme_actions[i] - # pp enzyme_action - # puts "Previous cut ranges:" - # pp previous_cut_ranges - - other_cut_ranges.each do |key, cut_ranges| - cut_ranges.each do |cut_range| - next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts - previous_cut_left = cut_range.range.first - previous_cut_right = cut_range.range.last - - if (enzyme_action.right <= previous_cut_left) or - (enzyme_action.left > previous_cut_right) or - (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts - # no conflict - # puts "no conflict" - - else - conflict = true - # puts "conflict" - #puts "cut range:" - #pp cut_range - #puts "enzyme action:" - #pp enzyme_action - end - - indicies_of_sometimes_cut += [i, key] if conflict == true - end - end - - # We don't need to make permutations with this enzyme action if it always cuts - # indicies << i if conflict == false - end - # pp indicies_of_sometimes_cut - - indicies_of_sometimes_cut.uniq.each do |i| - enzyme_actions_that_sometimes_cut[i] = enzyme_actions_that_always_cut[i] - enzyme_actions_that_always_cut.delete(i) - end - #puts 'Always cut:' - #pp enzyme_actions_that_always_cut - #puts 'Permute:' - #pp enzyme_actions_that_sometimes_cut - - [enzyme_actions_that_sometimes_cut, enzyme_actions_that_always_cut] - end - - # Returns the offsets of the match of a RegExp to a string. - # - # +string+:: The string to scan. - # +re+:: A regexp to use. - def find_match_locations( string, re ) - md = string.match( re ) - locations = [] - location = -1 - while md - location += md.pre_match.size + 1 - locations << location - # md[0] is the same as $&, or "the match" itself - md = (md[0][1..-1] + md.post_match).match( re ) - end - locations - end - - # Takes a RestrictionEnzyme and a numerical offset to the sequence and - # returns an EnzymeAction - # - # +enzyme+:: RestrictionEnzyme - # +offset+:: Numerical offset of where the enzyme action occurs on the seqeunce - def enzyme_to_enzyme_action( enzyme, offset ) - enzyme_action = EnzymeAction.new(offset, offset + enzyme.primary.size-1, offset, offset + enzyme.complement.size-1) - - enzyme.cut_locations.each do |cut_pair| - p = cut_pair[0] - c = cut_pair[1] - if c >= p - enzyme_action.add_cut_range(offset+p, nil, nil, offset+c) - else - enzyme_action.add_cut_range(nil, offset+p, offset+c, nil) - end - end - - enzyme_action - end - end # Analysis end # Bio::RestrictionEnzyme --- 135,138 ---- Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** double_stranded.rb 1 Jan 2007 05:07:04 -0000 1.3 --- double_stranded.rb 1 Jan 2007 23:47:27 -0000 1.4 *************** *** 14,17 **** --- 14,19 ---- require 'bio/db/rebase' require 'bio/util/restriction_enzyme' + require 'bio/util/restriction_enzyme/analysis/sequence_range' + require 'bio/util/restriction_enzyme/cut_symbol' require 'bio/util/restriction_enzyme/single_strand' *************** *** 96,99 **** --- 98,102 ---- # Decide if this String is an enzyme name or a pattern if Bio::RestrictionEnzyme.enzyme_name?( erp ) + # FIXME we added this to rebase... # Check if it's a known name known_enzyme = false *************** *** 157,160 **** --- 160,252 ---- !blunt? end + + # Takes a RestrictionEnzyme object and a numerical offset to the sequence and + # returns an EnzymeAction + # + # +restriction_enzyme+:: RestrictionEnzyme + # +offset+:: Numerical offset of where the enzyme action occurs on the seqeunce + def create_action_at( offset ) + #def enzyme_to_enzyme_action( restriction_enzyme, offset ) + enzyme_action = EnzymeAction.new( offset, + offset + @primary.size-1, + offset, + offset + @complement.size-1) + + @cut_locations.each do |cut_location_pair| + # cut_pair is a DoubleStranded::CutLocationPair + p, c = cut_location_pair.primary, cut_location_pair.complement + if c >= p + enzyme_action.add_cut_range(offset+p, nil, nil, offset+c) + else + enzyme_action.add_cut_range(nil, offset+p, offset+c, nil) + end + end + + enzyme_action + end + + # An EnzymeAction is a way of representing a potential effect that a + # RestrictionEnzyme may have on a nucleotide sequence, an 'action'. + # + # Multiple cuts in multiple locations on a sequence may occur in one + # 'action' if it is done by a single enzyme. + # + # An EnzymeAction is a series of locations that represents where the restriction + # enzyme will bind on the sequence, as well as what ranges are cut on the + # sequence itself. The complexity is due to the fact that our virtual + # restriction enzyme may create multiple segments from its cutting action, + # on which another restriction enzyme may operate upon. + # + # For example, the DNA sequence: + # + # 5' - G A A T A A A C G A - 3' + # 3' - C T T A T T T G C T - 5' + # + # When mixed with the restriction enzyme with the following cut pattern: + # + # 5' - A|A T A A A C|G - 3' + # +-+ + + # 3' - T T|A T T T G|C - 5' + # + # And also mixed with the restriction enzyme of the following cut pattern: + # + # 5' - A A|A C - 3' + # +-+ + # 3' - T|T T G - 5' + # + # Would result in a DNA sequence with these cuts: + # + # 5' - G A|A T A A|A C|G A - 3' + # +-+ +-+ + + # 3' - C T T|A T|T T G|C T - 5' + # + # Or these separate "free-floating" sequences: + # + # 5' - G A - 3' + # 3' - C T T - 5' + # + # 5' - A T A A - 3' + # 3' - A T - 5' + # + # 5' - A C - 3' + # 3' - T T G - 5' + # + # 5' - G A - 3' + # 3' - C T - 5' + # + # This would be represented by two EnzymeActions - one for each + # RestrictionEnzyme. + # + # To initialize an EnzymeAction you must first instantiate it with the + # beginning and ending locations of where it will operate on a nucleotide + # sequence. + # + # Next the ranges of cu + # + # An EnzymeAction is + # Defines a single enzyme action, in this case being a range that correlates + # to the DNA sequence that may contain it's own internal cuts. + class EnzymeAction < Bio::RestrictionEnzyme::Analysis::SequenceRange + end ######### From trevor at dev.open-bio.org Mon Jan 1 18:47:30 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 23:47:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis calculated_cuts.rb, 1.3, 1.4 cut_range.rb, 1.2, 1.3 cut_ranges.rb, 1.3, 1.4 horizontal_cut_range.rb, 1.2, 1.3 sequence_range.rb, 1.4, 1.5 vertical_cut_range.rb, 1.2, 1.3 Message-ID: <200701012347.l01NlU6G002440@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv2413/restriction_enzyme/analysis Modified Files: calculated_cuts.rb cut_range.rb cut_ranges.rb horizontal_cut_range.rb sequence_range.rb vertical_cut_range.rb Log Message: Index: vertical_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/vertical_cut_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** vertical_cut_range.rb 31 Dec 2006 21:50:31 -0000 1.2 --- vertical_cut_range.rb 1 Jan 2007 23:47:28 -0000 1.3 *************** *** 31,34 **** --- 31,56 ---- attr_reader :range + # VerticalCutRange provides an extremely raw, yet precise, method of + # defining the location of cuts on primary and complementary sequences. + # + # Many VerticalCutRange objects are used with HorizontalCutRange objects + # to be contained in CutRanges to define the cut pattern that a + # specific enzyme may make. + # + # VerticalCutRange takes up to four possible cuts, two on the primary + # strand and two on the complementary strand. In typical usage + # you will want to make a single cut on the primary strand and a single + # cut on the complementary strand. + # + # However, you can construct it with whatever cuts you desire to accomadate + # the most eccentric of imaginary restriction enzymes. + # + # --- + # *Arguments* + # * +p_cut_left+: (_optional_) Left-most cut on the primary strand. +nil+ to skip + # * +p_cut_right+: (_optional_) Right-most cut on the primary strand. +nil+ to skip + # * +c_cut_left+: (_optional_) Left-most cut on the complementary strand. +nil+ to skip + # * +c_cut_right+: (_optional_) Right-most cut on the complementary strand. +nil+ to skip + # *Returns*:: nothing def initialize( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @p_cut_left = p_cut_left *************** *** 45,50 **** --- 67,80 ---- @range = nil @range = (@min.. at max) unless @min == nil or @max == nil + return end + # Check if a location falls within the minimum or maximum values of this + # range. + # + # --- + # *Arguments* + # * +i+: Location to check if it is included in the range + # *Returns*:: +true+ _or_ +false+ def include?(i) return false if @range == nil Index: horizontal_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/horizontal_cut_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** horizontal_cut_range.rb 31 Dec 2006 21:50:31 -0000 1.2 --- horizontal_cut_range.rb 1 Jan 2007 23:47:28 -0000 1.3 *************** *** 36,41 **** # The 'range' here is actually off by one on the left # side in relation to a normal CutRange, so using the normal ! # variables from CutRange would result in unpredictable ! # behavior. @p_cut_left = nil --- 36,52 ---- # The 'range' here is actually off by one on the left # side in relation to a normal CutRange, so using the normal ! # variables from CutRange would result in bad behavior. ! # ! # See below - the first horizontal cut is the primary cut plus one. ! # ! # 1 2 3 4 5 6 7 ! # G A|T T A C A ! # +-----+ ! # C T A A T|G T ! # 1 2 3 4 5 6 7 ! # ! # Primary cut = 2 ! # Complement cut = 5 ! # Horizontal cuts = 3, 4, 5 @p_cut_left = nil *************** *** 50,53 **** --- 61,71 ---- end + # Check if a location falls within the minimum or maximum values of this + # range. + # + # --- + # *Arguments* + # * +i+: Location to check if it is included in the range + # *Returns*:: +true+ _or_ +false+ def include?(i) @range.include?(i) Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/calculated_cuts.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** calculated_cuts.rb 1 Jan 2007 05:07:04 -0000 1.3 --- calculated_cuts.rb 1 Jan 2007 23:47:28 -0000 1.4 *************** *** 27,30 **** --- 27,34 ---- # License:: Distributes under the same terms as Ruby # + # cc = CalculatedCuts.new(@size) + # cc.add_cuts_from_cut_ranges(@cut_ranges) + # cc.remove_incomplete_cuts + # # 1 2 3 4 5 6 7 # G A|T T A C A *************** *** 41,55 **** include StringFormatting ! # Vertical cuts on the primary strand attr_reader :vc_primary ! # Vertical cuts on the complement strand attr_reader :vc_complement ! # Horizontal cuts attr_reader :hc_between_strands # Set to +true+ if the fragment CalculatedCuts is working on is circular attr_accessor :circular def initialize(size=nil, circular=false) --- 45,69 ---- include StringFormatting ! # +Array+ of vertical cuts on the primary strand in 0-based index notation attr_reader :vc_primary ! # +Array+ of vertical cuts on the complementary strand in 0-based index notation attr_reader :vc_complement ! # +Array+ of horizontal cuts between strands in 0-based index notation attr_reader :hc_between_strands # Set to +true+ if the fragment CalculatedCuts is working on is circular attr_accessor :circular + + # An +Array+ with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. + attr_reader :strands_for_display + + # If +false+ the strands_for_display method needs to be called to update the contents + # of @strands_for_display. Becomes out of date whenever add_cuts_from_cut_ranges is called. + attr_reader :strands_for_display_current + + # Size of the sequence being digested. + attr_reader :size def initialize(size=nil, circular=false) *************** *** 61,64 **** --- 75,82 ---- end + # --- + # *Arguments* + # * +cut_ranges+: An +Array+ of HorizontalCutRange or VerticalCutRange objects + # *Returns*:: nothing def add_cuts_from_cut_ranges(cut_ranges) @strands_for_display_current = false *************** *** 68,71 **** --- 86,91 ---- @vc_complement += [cut_range.c_cut_left, cut_range.c_cut_right] + # Add horizontal cut ranges. This may happen from cuts made inbetween a + # VerticalCutRange or may be specifically defined by a HorizontalCutRange. if cut_range.class == VerticalCutRange ( cut_range.min + 1 ).upto( cut_range.max ){|i| @hc_between_strands << i} if cut_range.min < cut_range.max *************** *** 75,80 **** --- 95,129 ---- end clean_all + #return end + # There may be incomplete cuts made, this method removes the cuts that don't + # create sub-sequences for easier processing. + # + # For example, stray horizontal cuts that do not end with a left + # and right separation: + # + # G A T T A C A + # +-- --- + # C T|A A T G T + # + # Or stray vertical cuts: + # + # G A T T A C A + # +-- + + # C T|A A T|G T + # + # However note that for non-circular sequences this would be a successful + # cut which would result in a floating 'GT' sub-sequence: + # + # G A T T A C A + # +--- + # C T A A T|G T + # + # Blunt cuts are also complete cuts. + # --- + # *Arguments* + # * +size+: (_optional_) Size of the sequence being digested. Defined here or during initalization of CalculatedCuts. + # *Returns*:: nothing def remove_incomplete_cuts(size=nil) @strands_for_display_current = false *************** *** 90,94 **** if @circular # NOTE ! # if it's circular we should start at the beginning of a cut for orientation # scan for it, hack off the first set of hcuts and move them to the back else --- 139,143 ---- if @circular # NOTE ! # if it's circular we should start at the beginning of a cut for orientation, # scan for it, hack off the first set of hcuts and move them to the back else *************** *** 133,136 **** --- 182,196 ---- end + # Sets @strands_for_display_current to +true+ and populates @strands_for_display. + # + # --- + # *Arguments* + # * +str1+: (_optional_) For displaying a primary strand. If +nil+ a numbered sequence will be used in place. + # * +str2+: (_optional_) For displaying a complementary strand. If +nil+ a numbered sequence will be used in place. + # * +vcp+: (_optional_) An array of vertical cut locations on the primary strand. If +nil+ the contents of @vc_primary is used. + # * +vcc+: (_optional_) An array of vertical cut locations on the complementary strand. If +nil+ the contents of @vc_complementary is used. + # * +hc+: (_optional_) An array of horizontal cut locations between strands. If +nil+ the contents of @hc_between_strands is used. + # *Returns*:: +Array+ An array with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. + # def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current *************** *** 178,181 **** --- 238,243 ---- ######### + # remove nil values, remove duplicate values, and + # sort @vc_primary, @vc_complement, and @hc_between_strands def clean_all [@vc_primary, @vc_complement, @hc_between_strands].collect { |a| a.delete(nil); a.uniq!; a.sort! } Index: cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/cut_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_range.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_range.rb 1 Jan 2007 23:47:28 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom *************** *** 26,29 **** --- 26,31 ---- # License:: Distributes under the same terms as Ruby # + # Abstract base class for HorizontalCutRange and VerticalCutRange + # class CutRange end # CutRange Index: cut_ranges.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/cut_ranges.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cut_ranges.rb 1 Jan 2007 02:16:05 -0000 1.3 --- cut_ranges.rb 1 Jan 2007 23:47:28 -0000 1.4 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom *************** *** 12,24 **** $:.unshift(libpath) unless $:.include?(libpath) - #require 'bio' - module Bio; end class Bio::RestrictionEnzyme class Analysis ! #class Analysis ! # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - # # Author:: Trevor Wennblom --- 12,21 ---- $:.unshift(libpath) unless $:.include?(libpath) module Bio; end class Bio::RestrictionEnzyme class Analysis ! # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom *************** *** 26,29 **** --- 23,28 ---- # License:: Distributes under the same terms as Ruby # + # Container for many CutRange objects or CutRange child objects. Inherits from array. + # class CutRanges < Array def min; self.collect{|a| a.min}.flatten.sort.first; end Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/sequence_range.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sequence_range.rb 1 Jan 2007 02:31:22 -0000 1.4 --- sequence_range.rb 1 Jan 2007 23:47:28 -0000 1.5 *************** *** 87,98 **** # scan for it, hack off the first set of hcuts and move them to the back else - # last_index = @size - 1 p_cut.unshift(-1) unless p_cut.include?(-1) - # p_cut.push(last_index) unless p_cut.include?(last_index) c_cut.unshift(-1) unless c_cut.include?(-1) - # c_cut.push(last_index) unless c_cut.include?(last_index) end - if @circular largest_bin = 0 --- 87,94 ---- *************** *** 114,118 **** -1.upto(@size-1) do |idx| - # if bins are out of sync but the strands are attached if p_bin != c_bin and h.include?(idx) == false --- 110,113 ---- *************** *** 134,138 **** x.call(c_bin) end - end --- 129,132 ---- *************** *** 141,148 **** bins.delete(-1) unless @circular - # require 'pp' - # pp bins - - #NOTE str1 = nil str2 = nil --- 135,138 ---- *************** *** 159,166 **** end - #pp fragments.for_display - # pp fragments - # exit - @__fragments = fragments return fragments --- 149,152 ---- From trevor at dev.open-bio.org Mon Jan 1 18:54:35 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 23:54:35 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range - New directory Message-ID: <200701012354.l01NsZPO002475@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv2455/range Log Message: Directory /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range added to the repository From trevor at dev.open-bio.org Mon Jan 1 19:12:30 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:12:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range - New directory Message-ID: <200701020012.l020CUSi002607@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv2587/sequence_range Log Message: Directory /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range added to the repository From trevor at dev.open-bio.org Mon Jan 1 19:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.8, 1.9 analysis_basic.rb, 1.1, 1.2 double_stranded.rb, 1.4, 1.5 Message-ID: <200701020013.l020D9ZK002682@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme Modified Files: analysis.rb analysis_basic.rb double_stranded.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.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** analysis_basic.rb 1 Jan 2007 23:47:27 -0000 1.1 --- analysis_basic.rb 2 Jan 2007 00:13:07 -0000 1.2 *************** *** 43,47 **** require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' class Bio::RestrictionEnzyme --- 43,47 ---- require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/range/sequence_range' class Bio::RestrictionEnzyme *************** *** 83,87 **** enzyme_actions = tmp[0].merge(tmp[1]) ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| --- 83,87 ---- enzyme_actions = tmp[0].merge(tmp[1]) ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| *************** *** 167,171 **** other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| ! next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last --- 167,171 ---- other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** analysis.rb 1 Jan 2007 23:47:27 -0000 1.8 --- analysis.rb 2 Jan 2007 00:13:07 -0000 1.9 *************** *** 64,68 **** if permutations.empty? ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |key, enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } hash_of_sequence_ranges_with_cuts[0] = sr_with_cuts --- 64,68 ---- if permutations.empty? ! sr_with_cuts = 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| sr_with_cuts.add_cut_range(cut_range) } } hash_of_sequence_ranges_with_cuts[0] = sr_with_cuts *************** *** 71,75 **** permutations.each do |permutation| previous_cut_ranges = [] ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } --- 71,75 ---- permutations.each do |permutation| previous_cut_ranges = [] ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } *************** *** 86,90 **** # so all cut locations must be checked that would fall underneath. previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last --- 86,90 ---- # so all cut locations must be checked that would fall underneath. previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** double_stranded.rb 1 Jan 2007 23:47:27 -0000 1.4 --- double_stranded.rb 2 Jan 2007 00:13:07 -0000 1.5 *************** *** 14,18 **** require 'bio/db/rebase' require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' require 'bio/util/restriction_enzyme/cut_symbol' --- 14,18 ---- require 'bio/db/rebase' require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/range/sequence_range' require 'bio/util/restriction_enzyme/cut_symbol' *************** *** 247,251 **** # Defines a single enzyme action, in this case being a range that correlates # to the DNA sequence that may contain it's own internal cuts. ! class EnzymeAction < Bio::RestrictionEnzyme::Analysis::SequenceRange end --- 247,251 ---- # Defines a single enzyme action, in this case being a range that correlates # to the DNA sequence that may contain it's own internal cuts. ! class EnzymeAction < Bio::RestrictionEnzyme::Range::SequenceRange end From trevor at dev.open-bio.org Mon Jan 1 19:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range cut_range.rb, NONE, 1.1 cut_ranges.rb, NONE, 1.1 horizontal_cut_range.rb, NONE, 1.1 sequence_range.rb, NONE, 1.1 vertical_cut_range.rb, NONE, 1.1 Message-ID: <200701020013.l020D99D002693@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme/range Added Files: cut_range.rb cut_ranges.rb horizontal_cut_range.rb sequence_range.rb vertical_cut_range.rb Log Message: --- NEW FILE: vertical_cut_range.rb --- # # bio/util/restrction_enzyme/range/vertical_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: vertical_cut_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_range' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/vertical_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class VerticalCutRange < CutRange attr_reader :p_cut_left, :p_cut_right attr_reader :c_cut_left, :c_cut_right attr_reader :min, :max attr_reader :range # VerticalCutRange provides an extremely raw, yet precise, method of # defining the location of cuts on primary and complementary sequences. # # Many VerticalCutRange objects are used with HorizontalCutRange objects # to be contained in CutRanges to define the cut pattern that a # specific enzyme may make. # # VerticalCutRange takes up to four possible cuts, two on the primary # strand and two on the complementary strand. In typical usage # you will want to make a single cut on the primary strand and a single # cut on the complementary strand. # # However, you can construct it with whatever cuts you desire to accomadate # the most eccentric of imaginary restriction enzymes. # # --- # *Arguments* # * +p_cut_left+: (_optional_) Left-most cut on the primary strand. +nil+ to skip # * +p_cut_right+: (_optional_) Right-most cut on the primary strand. +nil+ to skip # * +c_cut_left+: (_optional_) Left-most cut on the complementary strand. +nil+ to skip # * +c_cut_right+: (_optional_) Right-most cut on the complementary strand. +nil+ to skip # *Returns*:: nothing def initialize( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @p_cut_left = p_cut_left @p_cut_right = p_cut_right @c_cut_left = c_cut_left @c_cut_right = c_cut_right a = [@p_cut_left, @c_cut_left, @p_cut_right, @c_cut_right] a.delete(nil) a.sort! @min = a.first @max = a.last @range = nil @range = (@min.. at max) unless @min == nil or @max == nil return end # Check if a location falls within the minimum or maximum values of this # range. # # --- # *Arguments* # * +i+: Location to check if it is included in the range # *Returns*:: +true+ _or_ +false+ def include?(i) return false if @range == nil @range.include?(i) end end # VerticalCutRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: horizontal_cut_range.rb --- # # bio/util/restrction_enzyme/range/horizontal_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: horizontal_cut_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_range' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/horizontal_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class HorizontalCutRange < CutRange attr_reader :p_cut_left, :p_cut_right attr_reader :c_cut_left, :c_cut_right attr_reader :min, :max attr_reader :hcuts def initialize( left, right=left ) raise "left > right" if left > right # The 'range' here is actually off by one on the left # side in relation to a normal CutRange, so using the normal # variables from CutRange would result in bad behavior. # # See below - the first horizontal cut is the primary cut plus one. # # 1 2 3 4 5 6 7 # G A|T T A C A # +-----+ # C T A A T|G T # 1 2 3 4 5 6 7 # # Primary cut = 2 # Complement cut = 5 # Horizontal cuts = 3, 4, 5 @p_cut_left = nil @p_cut_right = nil @c_cut_left = nil @c_cut_right = nil @min = nil @max = nil @range = nil @hcuts = (left..right) end # Check if a location falls within the minimum or maximum values of this # range. # # --- # *Arguments* # * +i+: Location to check if it is included in the range # *Returns*:: +true+ _or_ +false+ def include?(i) @range.include?(i) end end # HorizontalCutRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: sequence_range.rb --- # # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: sequence_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_ranges' require 'bio/util/restriction_enzyme/range/horizontal_cut_range' require 'bio/util/restriction_enzyme/range/vertical_cut_range' require 'bio/util/restriction_enzyme/range/sequence_range/calculated_cuts' require 'bio/util/restriction_enzyme/range/sequence_range/fragments' require 'bio/util/restriction_enzyme/range/sequence_range/fragment' require 'bio' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class SequenceRange attr_reader :p_left, :p_right attr_reader :c_left, :c_right attr_reader :left, :right attr_reader :size attr_reader :cut_ranges def initialize( p_left = nil, p_right = nil, c_left = nil, c_right = nil ) @__fragments_current = false raise ArgumentError if p_left == nil and c_left == nil raise ArgumentError if p_right == nil and c_right == nil (raise ArgumentError unless p_left <= p_right) unless p_left == nil or p_right == nil (raise ArgumentError unless c_left <= c_right) unless c_left == nil or c_right == nil @p_left = p_left @p_right = p_right @c_left = c_left @c_right = c_right tmp = [p_left, c_left] tmp.delete(nil) @left = tmp.sort.first tmp = [p_right, c_right] tmp.delete(nil) @right = tmp.sort.last @size = (@right - @left) + 1 unless @left == nil or @right == nil @cut_ranges = CutRanges.new end =begin Special Case: Horizontal cuts at beginning or end of strand =end Bin = Struct.new(:c, :p) def fragments return @__fragments if @__fragments_current == true @__fragments_current = true cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) cc.add_cuts_from_cut_ranges(@cut_ranges) cc.remove_incomplete_cuts p_cut = cc.vc_primary c_cut = cc.vc_complement h = cc.hc_between_strands if @circular # NOTE # if it's circular we should start at the beginning of a cut for orientation # scan for it, hack off the first set of hcuts and move them to the back else p_cut.unshift(-1) unless p_cut.include?(-1) c_cut.unshift(-1) unless c_cut.include?(-1) end if @circular largest_bin = 0 else largest_bin = -1 end p_bin = largest_bin c_bin = largest_bin bins = { largest_bin => Bin.new } # bin_id, bin bins[ largest_bin ].p = [] bins[ largest_bin ].c = [] x = lambda do |bin_id| largest_bin += 1 bins[ bin_id ] = Bin.new bins[ bin_id ].p = [] bins[ bin_id ].c = [] end -1.upto(@size-1) do |idx| # if bins are out of sync but the strands are attached if p_bin != c_bin and h.include?(idx) == false bins.delete( [p_bin, c_bin].sort.last ) p_bin = c_bin = [p_bin, c_bin].sort.first largest_bin -= 1 end bins[ p_bin ].p << idx bins[ c_bin ].c << idx if p_cut.include? idx p_bin = largest_bin + 1 x.call(p_bin) end if c_cut.include? idx c_bin = largest_bin + 1 x.call(c_bin) end end # Easy way to indicate the start of a strand just in case # there is a horizontal cut at position 0 bins.delete(-1) unless @circular str1 = nil str2 = nil num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } (str1 == nil) ? a = num_txt_repeat.call : a = str1.dup (str2 == nil) ? b = num_txt_repeat.call : b = str2.dup fragments = Fragments.new(a,b) bins.sort.each do |k, bin| fragment = Fragment.new( bin.p, bin.c ) fragments << fragment end @__fragments = fragments return fragments end # Cut occurs immediately after the index supplied. # For example, a cut at '0' would mean a cut occurs between 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false if p_cut_left.kind_of? CutRange @cut_ranges << p_cut_left else (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) end end def add_cut_ranges(*cut_ranges) cut_ranges.flatten! cut_ranges.each do |cut_range| raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange self.add_cut_range( cut_range ) end end def add_horizontal_cut_range( left, right=left ) @__fragments_current = false @cut_ranges << HorizontalCutRange.new( left, right ) end end # SequenceRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: cut_ranges.rb --- # # bio/util/restrction_enzyme/range/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: cut_ranges.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # Container for many CutRange objects or CutRange child objects. Inherits from array. # class CutRanges < Array def min; self.collect{|a| a.min}.flatten.sort.first; end def max; self.collect{|a| a.max}.flatten.sort.last; end def include?(i); self.collect{|a| a.include?(i)}.include?(true); end end # CutRanges end # Range end # Bio::RestrictionEnzyme --- NEW FILE: cut_range.rb --- # # bio/util/restrction_enzyme/range/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: cut_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # Abstract base class for HorizontalCutRange and VerticalCutRange # class CutRange end # CutRange end # Range end # Bio::RestrictionEnzyme From trevor at dev.open-bio.org Mon Jan 1 19:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis calculated_cuts.rb, 1.4, NONE cut_range.rb, 1.3, NONE cut_ranges.rb, 1.4, NONE fragment.rb, 1.3, NONE fragments.rb, 1.2, NONE horizontal_cut_range.rb, 1.3, NONE sequence_range.rb, 1.5, NONE vertical_cut_range.rb, 1.3, NONE Message-ID: <200701020013.l020D9Xl002689@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme/analysis Removed Files: calculated_cuts.rb cut_range.rb cut_ranges.rb fragment.rb fragments.rb horizontal_cut_range.rb sequence_range.rb vertical_cut_range.rb Log Message: --- vertical_cut_range.rb DELETED --- --- fragment.rb DELETED --- --- horizontal_cut_range.rb DELETED --- --- fragments.rb DELETED --- --- calculated_cuts.rb DELETED --- --- cut_range.rb DELETED --- --- cut_ranges.rb DELETED --- --- sequence_range.rb DELETED --- From trevor at dev.open-bio.org Mon Jan 1 19:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range calculated_cuts.rb, NONE, 1.1 fragment.rb, NONE, 1.1 fragments.rb, NONE, 1.1 Message-ID: <200701020013.l020D9Ea002702@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme/range/sequence_range Added Files: calculated_cuts.rb fragment.rb fragments.rb Log Message: --- NEW FILE: calculated_cuts.rb --- # # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: calculated_cuts.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/cut_symbol' require 'bio/util/restriction_enzyme/string_formatting' module Bio; end class Bio::RestrictionEnzyme class Range class SequenceRange # # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # cc = CalculatedCuts.new(@size) # cc.add_cuts_from_cut_ranges(@cut_ranges) # cc.remove_incomplete_cuts # # 1 2 3 4 5 6 7 # G A|T T A C A # +-----+ # C T A A T|G T # 1 2 3 4 5 6 7 # # Primary cut = 2 # Complement cut = 5 # Horizontal cuts = 3, 4, 5 # class CalculatedCuts include CutSymbol include StringFormatting # +Array+ of vertical cuts on the primary strand in 0-based index notation attr_reader :vc_primary # +Array+ of vertical cuts on the complementary strand in 0-based index notation attr_reader :vc_complement # +Array+ of horizontal cuts between strands in 0-based index notation attr_reader :hc_between_strands # Set to +true+ if the fragment CalculatedCuts is working on is circular attr_accessor :circular # An +Array+ with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. attr_reader :strands_for_display # If +false+ the strands_for_display method needs to be called to update the contents # of @strands_for_display. Becomes out of date whenever add_cuts_from_cut_ranges is called. attr_reader :strands_for_display_current # Size of the sequence being digested. attr_reader :size def initialize(size=nil, circular=false) @size = size @circular = circular @vc_primary = [] @vc_complement = [] @hc_between_strands = [] end # --- # *Arguments* # * +cut_ranges+: An +Array+ of HorizontalCutRange or VerticalCutRange objects # *Returns*:: nothing def add_cuts_from_cut_ranges(cut_ranges) @strands_for_display_current = false cut_ranges.each do |cut_range| @vc_primary += [cut_range.p_cut_left, cut_range.p_cut_right] @vc_complement += [cut_range.c_cut_left, cut_range.c_cut_right] # Add horizontal cut ranges. This may happen from cuts made inbetween a # VerticalCutRange or may be specifically defined by a HorizontalCutRange. if cut_range.class == VerticalCutRange ( cut_range.min + 1 ).upto( cut_range.max ){|i| @hc_between_strands << i} if cut_range.min < cut_range.max elsif cut_range.class == HorizontalCutRange ( cut_range.hcuts.first ).upto( cut_range.hcuts.last ){|i| @hc_between_strands << i} end end clean_all #return end # There may be incomplete cuts made, this method removes the cuts that don't # create sub-sequences for easier processing. # # For example, stray horizontal cuts that do not end with a left # and right separation: # # G A T T A C A # +-- --- # C T|A A T G T # # Or stray vertical cuts: # # G A T T A C A # +-- + # C T|A A T|G T # # However note that for non-circular sequences this would be a successful # cut which would result in a floating 'GT' sub-sequence: # # G A T T A C A # +--- # C T A A T|G T # # Blunt cuts are also complete cuts. # --- # *Arguments* # * +size+: (_optional_) Size of the sequence being digested. Defined here or during initalization of CalculatedCuts. # *Returns*:: nothing def remove_incomplete_cuts(size=nil) @strands_for_display_current = false @size = size if size raise IndexError, "Size of the strand must be provided here or during initalization." if !@size.kind_of?(Fixnum) and not @circular vcuts = (@vc_primary + @vc_complement).uniq.sort hcuts = @hc_between_strands last_index = @size - 1 good_hcuts = [] potential_hcuts = [] if @circular # NOTE # if it's circular we should start at the beginning of a cut for orientation, # scan for it, hack off the first set of hcuts and move them to the back else vcuts.unshift(-1) unless vcuts.include?(-1) vcuts.push(last_index) unless vcuts.include?(last_index) end hcuts.each do |hcut| raise IndexError if hcut < -1 or hcut > last_index # skipped a nucleotide potential_hcuts.clear if !potential_hcuts.empty? and (hcut - potential_hcuts.last).abs > 1 if potential_hcuts.empty? if vcuts.include?( hcut ) and vcuts.include?( hcut - 1 ) good_hcuts += [hcut] elsif vcuts.include?( hcut - 1 ) potential_hcuts << hcut end else if vcuts.include?( hcut ) good_hcuts += potential_hcuts + [hcut] potential_hcuts.clear else potential_hcuts << hcut end end end check_vc = lambda do |vertical_cuts, opposing_vcuts| # opposing_vcuts is here only to check for blunt cuts, so there shouldn't # be any out-of-order problems with this good_vc = [] vertical_cuts.each { |vc| good_vc << vc if good_hcuts.include?( vc ) or good_hcuts.include?( vc + 1 ) or opposing_vcuts.include?( vc ) } good_vc end @vc_primary = check_vc.call(@vc_primary, @vc_complement) @vc_complement = check_vc.call(@vc_complement, @vc_primary) @hc_between_strands = good_hcuts clean_all end # Sets @strands_for_display_current to +true+ and populates @strands_for_display. # # --- # *Arguments* # * +str1+: (_optional_) For displaying a primary strand. If +nil+ a numbered sequence will be used in place. # * +str2+: (_optional_) For displaying a complementary strand. If +nil+ a numbered sequence will be used in place. # * +vcp+: (_optional_) An array of vertical cut locations on the primary strand. If +nil+ the contents of @vc_primary is used. # * +vcc+: (_optional_) An array of vertical cut locations on the complementary strand. If +nil+ the contents of @vc_complementary is used. # * +hc+: (_optional_) An array of horizontal cut locations between strands. If +nil+ the contents of @hc_between_strands is used. # *Returns*:: +Array+ An array with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. # def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current vcs = '|' # Vertical cut symbol hcs = '-' # Horizontal cut symbol vhcs = '+' # Intersection of vertical and horizontal cut symbol num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } (str1 == nil) ? a = num_txt_repeat.call : a = str1.dup (str2 == nil) ? b = num_txt_repeat.call : b = str2.dup vcp = @vc_primary if vcp==nil vcc = @vc_complement if vcc==nil hc = @hc_between_strands if hc==nil vcuts = (vcp + vcc).uniq.sort vcp.reverse.each { |c| a.insert(c+1, vcs) } vcc.reverse.each { |c| b.insert(c+1, vcs) } between = ' ' * @size hc.each {|hcut| between[hcut,1] = hcs } s_a = add_spacing(a, vcs) s_b = add_spacing(b, vcs) s_bet = add_spacing(between) # NOTE watch this for circular i = 0 0.upto( s_a.size-1 ) do if (s_a[i,1] == vcs) or (s_b[i,1] == vcs) s_bet[i] = vhcs elsif i != 0 and s_bet[i-1,1] == hcs and s_bet[i+1,1] == hcs s_bet[i] = hcs end i+=1 end @strands_for_display_current = true @strands_for_display = [s_a, s_bet, s_b] end ######### protected ######### # remove nil values, remove duplicate values, and # sort @vc_primary, @vc_complement, and @hc_between_strands def clean_all [@vc_primary, @vc_complement, @hc_between_strands].collect { |a| a.delete(nil); a.uniq!; a.sort! } end end # CalculatedCuts end # SequenceRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: fragment.rb --- # # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: fragment.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_ranges' require 'bio/util/restriction_enzyme/range/horizontal_cut_range' require 'bio' module Bio; end class Bio::RestrictionEnzyme class Range class SequenceRange # # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class Fragment attr_reader :size def initialize( primary_bin, complement_bin ) @primary_bin = primary_bin @complement_bin = complement_bin end DisplayFragment = Struct.new(:primary, :complement) def for_display(p_str=nil, c_str=nil) df = DisplayFragment.new df.primary = '' df.complement = '' both_bins = (@primary_bin + @complement_bin).sort.uniq both_bins.each do |item| @primary_bin.include?(item) ? df.primary << p_str[item] : df.primary << ' ' @complement_bin.include?(item) ? df.complement << c_str[item] : df.complement << ' ' end df end end # Fragment end # SequenceRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: fragments.rb --- # # bio/util/restrction_enzyme/analysis/fragments.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: fragments.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) module Bio; end class Bio::RestrictionEnzyme class Range class SequenceRange # # bio/util/restrction_enzyme/analysis/fragments.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class Fragments < Array attr_accessor :primary attr_accessor :complement def initialize(primary, complement) @primary = primary @complement = complement end DisplayFragment = Struct.new(:primary, :complement) def for_display(p_str=nil, c_str=nil) p_str ||= @primary c_str ||= @complement pretty_fragments = [] self.each { |fragment| pretty_fragments << fragment.for_display(p_str, c_str) } pretty_fragments end end # Fragments end # SequenceRange end # Range end # Bio::RestrictionEnzyme From trevor at dev.open-bio.org Mon Jan 1 19:19:08 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:19:08 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range calculated_cuts.rb, 1.1, 1.2 fragment.rb, 1.1, 1.2 fragments.rb, 1.1, 1.2 Message-ID: <200701020019.l020J8r2002755@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv2735/range/sequence_range Modified Files: calculated_cuts.rb fragment.rb fragments.rb Log Message: Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** calculated_cuts.rb 2 Jan 2007 00:13:07 -0000 1.1 --- calculated_cuts.rb 2 Jan 2007 00:19:06 -0000 1.2 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/calculated_cuts.rb - # # Author:: Trevor Wennblom *************** *** 22,26 **** # ! # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom --- 22,26 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/calculated_cuts.rb - # # Author:: Trevor Wennblom Index: fragment.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/fragment.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fragment.rb 2 Jan 2007 00:13:07 -0000 1.1 --- fragment.rb 2 Jan 2007 00:19:06 -0000 1.2 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/fragment.rb - # # Author:: Trevor Wennblom *************** *** 22,26 **** # ! # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom --- 22,26 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/fragment.rb - # # Author:: Trevor Wennblom Index: fragments.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/fragments.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fragments.rb 2 Jan 2007 00:13:07 -0000 1.1 --- fragments.rb 2 Jan 2007 00:19:06 -0000 1.2 *************** *** 18,22 **** # ! # bio/util/restrction_enzyme/analysis/fragments.rb - # # Author:: Trevor Wennblom --- 18,22 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/fragments.rb - # # Author:: Trevor Wennblom From trevor at dev.open-bio.org Mon Jan 1 19:22:29 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:22:29 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme/analysis test_calculated_cuts.rb, 1.2, 1.3 test_sequence_range.rb, 1.2, 1.3 Message-ID: <200701020022.l020MT3s002785@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv2765 Modified Files: test_calculated_cuts.rb test_sequence_range.rb Log Message: Index: test_sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis/test_sequence_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_sequence_range.rb 31 Dec 2006 18:46:15 -0000 1.2 --- test_sequence_range.rb 2 Jan 2007 00:22:27 -0000 1.3 *************** *** 14,24 **** require 'test/unit' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' ! require 'bio/util/restriction_enzyme/analysis/fragments' ! require 'bio/util/restriction_enzyme/analysis/cut_range' ! require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/analysis/vertical_cut_range' ! require 'bio/util/restriction_enzyme/analysis/cut_ranges' module Bio #:nodoc: --- 14,24 ---- require 'test/unit' ! require 'bio/util/restriction_enzyme/range/sequence_range' ! require 'bio/util/restriction_enzyme/range/sequence_range/fragments' ! require 'bio/util/restriction_enzyme/range/cut_range' ! require 'bio/util/restriction_enzyme/range/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/range/vertical_cut_range' ! require 'bio/util/restriction_enzyme/range/cut_ranges' module Bio #:nodoc: *************** *** 27,37 **** def setup ! @t = Bio::RestrictionEnzyme::Analysis::SequenceRange ! @fs = Bio::RestrictionEnzyme::Analysis::Fragments #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! @vcr = Bio::RestrictionEnzyme::Analysis::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Analysis::CutRanges ! @hcr = Bio::RestrictionEnzyme::Analysis::HorizontalCutRange @obj_1 = @t.new(0,5) --- 27,37 ---- def setup ! @t = Bio::RestrictionEnzyme::Range::SequenceRange ! @fs = Bio::RestrictionEnzyme::Range::SequenceRange::Fragments #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! @vcr = Bio::RestrictionEnzyme::Range::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Range::CutRanges ! @hcr = Bio::RestrictionEnzyme::Range::HorizontalCutRange @obj_1 = @t.new(0,5) Index: test_calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis/test_calculated_cuts.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_calculated_cuts.rb 31 Dec 2006 18:46:15 -0000 1.2 --- test_calculated_cuts.rb 2 Jan 2007 00:22:27 -0000 1.3 *************** *** 14,22 **** require 'test/unit' ! require 'bio/util/restriction_enzyme/analysis/calculated_cuts' ! require 'bio/util/restriction_enzyme/analysis/cut_range' ! require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/analysis/vertical_cut_range' ! require 'bio/util/restriction_enzyme/analysis/cut_ranges' module Bio #:nodoc: --- 14,22 ---- require 'test/unit' ! require 'bio/util/restriction_enzyme/range/sequence_range/calculated_cuts' ! require 'bio/util/restriction_enzyme/range/cut_range' ! require 'bio/util/restriction_enzyme/range/cut_ranges' ! require 'bio/util/restriction_enzyme/range/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/range/vertical_cut_range' module Bio #:nodoc: *************** *** 25,32 **** def setup ! @t = Bio::RestrictionEnzyme::Analysis::CalculatedCuts ! @vcr = Bio::RestrictionEnzyme::Analysis::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Analysis::CutRanges ! @hcr = Bio::RestrictionEnzyme::Analysis::HorizontalCutRange #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) --- 25,32 ---- def setup ! @t = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts ! @vcr = Bio::RestrictionEnzyme::Range::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Range::CutRanges ! @hcr = Bio::RestrictionEnzyme::Range::HorizontalCutRange #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) From trevor at dev.open-bio.org Tue Jan 2 01:18:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:09 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme/analysis test_cut_ranges.rb, NONE, 1.1 Message-ID: <200701020618.l026I9Lc003133@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv3107/restriction_enzyme/analysis Added Files: test_cut_ranges.rb Log Message: --- NEW FILE: test_cut_ranges.rb --- # # test/unit/bio/util/restriction_enzyme/analysis/test_cut_ranges.rb - Unit test for Bio::RestrictionEnzyme::Analysis::SequenceRange # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: test_cut_ranges.rb,v 1.1 2007/01/02 06:18:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'test/unit' require 'bio/util/restriction_enzyme/range/sequence_range' require 'bio/util/restriction_enzyme/range/sequence_range/fragments' require 'bio/util/restriction_enzyme/range/cut_range' require 'bio/util/restriction_enzyme/range/horizontal_cut_range' require 'bio/util/restriction_enzyme/range/vertical_cut_range' require 'bio/util/restriction_enzyme/range/cut_ranges' module Bio #:nodoc: class TestCutRanges < Test::Unit::TestCase #:nodoc: def setup @t = Bio::RestrictionEnzyme::Range::SequenceRange @fs = Bio::RestrictionEnzyme::Range::SequenceRange::Fragments #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) @vcr = Bio::RestrictionEnzyme::Range::VerticalCutRange @crs = Bio::RestrictionEnzyme::Range::CutRanges @hcr = Bio::RestrictionEnzyme::Range::HorizontalCutRange @obj_2 = @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil)] ) @obj_3 = @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil), @hcr.new(0), @hcr.new(5)] ) @obj_7 = @crs.new( [@vcr.new(nil,2,nil,nil), @hcr.new(0,2)] ) @obj_z = @crs.new( [@vcr.new(nil,2,nil,5), @hcr.new(1,6)] ) end def test_obj_z assert_equal(6, @obj_z.max) assert_equal(1, @obj_z.min) assert_equal(2, @obj_z.min_vertical) assert_equal(5, @obj_z.max_vertical) assert_equal(true, @obj_z.include?(6)) assert_equal(true, @obj_z.include?(4)) assert_equal(true, @obj_z.include?(2)) assert_equal(false, @obj_z.include?(-1)) assert_equal(false, @obj_z.include?(0)) assert_equal(false, @obj_z.include?(7)) end def test_obj_7 assert_equal(2, @obj_7.max) assert_equal(0, @obj_7.min) assert_equal(2, @obj_7.min_vertical) assert_equal(2, @obj_7.max_vertical) assert_equal(true, @obj_7.include?(0)) assert_equal(true, @obj_7.include?(1)) assert_equal(true, @obj_7.include?(2)) assert_equal(false, @obj_7.include?(-1)) assert_equal(false, @obj_7.include?(3)) end def test_obj_2 assert_equal(4, @obj_2.max) assert_equal(0, @obj_2.min) assert_equal(0, @obj_2.min_vertical) assert_equal(4, @obj_2.max_vertical) assert_equal(true, @obj_2.include?(0)) assert_equal(true, @obj_2.include?(1)) assert_equal(true, @obj_2.include?(3)) assert_equal(true, @obj_2.include?(4)) assert_equal(false, @obj_2.include?(-1)) assert_equal(false, @obj_2.include?(5)) end def test_obj_3 assert_equal(5, @obj_3.max) assert_equal(0, @obj_3.min) assert_equal(0, @obj_3.min_vertical) assert_equal(4, @obj_3.max_vertical) assert_equal(true, @obj_3.include?(0)) assert_equal(true, @obj_3.include?(1)) assert_equal(true, @obj_3.include?(3)) assert_equal(true, @obj_3.include?(4)) assert_equal(true, @obj_3.include?(5)) assert_equal(false, @obj_3.include?(-1)) assert_equal(false, @obj_3.include?(6)) end end end From trevor at dev.open-bio.org Tue Jan 2 01:18:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:09 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.4, 1.5 test_double_stranded.rb, 1.3, 1.4 Message-ID: <200701020618.l026I96E003129@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3107/restriction_enzyme Modified Files: test_analysis.rb test_double_stranded.rb Log Message: Index: test_double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_double_stranded.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_double_stranded.rb 1 Jan 2007 02:16:05 -0000 1.3 --- test_double_stranded.rb 2 Jan 2007 06:18:07 -0000 1.4 *************** *** 35,39 **** @obj_7 = @t.new('garraxt', @cl.new(3,2), @cl.new(9,11)) ! @obj_8 = @t.new('garraxt', 3..2, 9..11) @obj_9 = @t.new('garraxt', [3,2], [9,11]) --- 35,39 ---- @obj_7 = @t.new('garraxt', @cl.new(3,2), @cl.new(9,11)) ! # @obj_8 = @t.new('garraxt', 3..2, 9..11) @obj_9 = @t.new('garraxt', [3,2], [9,11]) *************** *** 57,61 **** assert_equal('gar^raxtnn^n', @obj_7.primary.with_cut_symbols) ! assert_equal('gar^raxtnn^n', @obj_8.primary.with_cut_symbols) assert_equal('gar^raxtnn^n', @obj_9.primary.with_cut_symbols) --- 57,61 ---- assert_equal('gar^raxtnn^n', @obj_7.primary.with_cut_symbols) ! # assert_equal('gar^raxtnn^n', @obj_8.primary.with_cut_symbols) assert_equal('gar^raxtnn^n', @obj_9.primary.with_cut_symbols) *************** *** 75,79 **** assert_equal('ct^yytxannnn^n', @obj_7.complement.with_cut_symbols) ! assert_equal('ct^yytxannnn^n', @obj_8.complement.with_cut_symbols) assert_equal('ct^yytxannnn^n', @obj_9.complement.with_cut_symbols) --- 75,79 ---- assert_equal('ct^yytxannnn^n', @obj_7.complement.with_cut_symbols) ! # assert_equal('ct^yytxannnn^n', @obj_8.complement.with_cut_symbols) assert_equal('ct^yytxannnn^n', @obj_9.complement.with_cut_symbols) Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_analysis.rb 31 Dec 2006 18:46:14 -0000 1.4 --- test_analysis.rb 2 Jan 2007 06:18:07 -0000 1.5 *************** *** 31,34 **** --- 31,36 ---- @obj_4 = @t.cut('atgcatgcatgc', e1) + @obj_4bd = @t.cut('atgcatgcatgccccc', e1, 'cc^c') + e2 = @enz.new('atgcatgc', [3,5]) @obj_5 = @t.cut('atgcatgcatgc', e2) *************** *** 39,42 **** --- 41,47 ---- @obj_7 = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII') + @obj_7b = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaaccc', 'EcoRII', 'HincII', 'cc^c') + @obj_7bd = @t.cut_without_permutations('gaccaggaaaaagaccaggaaagcctggaaaagttaaccc', 'EcoRII', 'HincII', 'cc^c') + @obj_8 = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII', 'HincII') *************** *** 76,83 **** --- 81,105 ---- assert_equal(["ag", "agt", "cag"], @obj_3.primary) assert_equal(["atg", "atgcatg", "catg", "catgc"], @obj_4.primary) + =begin + A T G^C A T G C + + A T G C A T G C A T G C + + A T G^C A T G^C A T G C + + A T G C A T G^C A T G C + =end + + + e1 = @enz.new('atgcatgc', [3,3]) + @obj_4 = @t.cut('atgcatgcatgc', e1) + assert_equal(["atg", "atgcatg", "catgc", "catgcatgc"], @obj_5.primary) assert_equal(["a", "ag", "g", "ga"], @obj_6.primary) assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7.primary) assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8.primary) + + assert_equal(["atg", "atgcatg", "c", "catg", "catgcc", "catgccc", "cc", "cc"], @obj_4bd.primary) + assert_equal(["gg", "gg", "ggg", "gtac", "gtacg", "gtacgg", "tac", "tacgtac"], @obj_4bd.complement) end From trevor at dev.open-bio.org Tue Jan 2 01:18:40 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range cut_ranges.rb, 1.1, 1.2 horizontal_cut_range.rb, 1.1, 1.2 Message-ID: <200701020618.l026IeZg003178@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv3143/restriction_enzyme/range Modified Files: cut_ranges.rb horizontal_cut_range.rb Log Message: Index: horizontal_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/horizontal_cut_range.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** horizontal_cut_range.rb 2 Jan 2007 00:13:07 -0000 1.1 --- horizontal_cut_range.rb 2 Jan 2007 06:18:38 -0000 1.2 *************** *** 54,60 **** @c_cut_left = nil @c_cut_right = nil ! @min = nil ! @max = nil ! @range = nil @hcuts = (left..right) --- 54,61 ---- @c_cut_left = nil @c_cut_right = nil ! @min = left # NOTE this used to be 'nil', make sure all tests work ! @max = right # NOTE this used to be 'nil', make sure all tests work ! @range = (@min.. at max) unless @min == nil or @max == nil # NOTE this used to be 'nil', make sure all tests work ! @hcuts = (left..right) Index: cut_ranges.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/cut_ranges.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** cut_ranges.rb 2 Jan 2007 00:13:07 -0000 1.1 --- cut_ranges.rb 2 Jan 2007 06:18:38 -0000 1.2 *************** *** 29,32 **** --- 29,53 ---- def max; self.collect{|a| a.max}.flatten.sort.last; end def include?(i); self.collect{|a| a.include?(i)}.include?(true); end + + def min_vertical + vertical_min_max_helper( :min ) + end + + def max_vertical + vertical_min_max_helper( :max ) + end + + protected + + def vertical_min_max_helper( sym_which ) + tmp = [] + self.each do |a| + next unless a.class == Bio::RestrictionEnzyme::Range::VerticalCutRange + tmp << a.send( sym_which ) + end + z = (sym_which == :max) ? :last : :first + tmp.flatten.sort.send(z) + end + end # CutRanges end # Range From trevor at dev.open-bio.org Tue Jan 2 01:18:40 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.9, 1.10 analysis_basic.rb, 1.2, 1.3 Message-ID: <200701020618.l026IeDC003167@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3143/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.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** analysis_basic.rb 2 Jan 2007 00:13:07 -0000 1.2 --- analysis_basic.rb 2 Jan 2007 06:18:38 -0000 1.3 *************** *** 81,137 **** tmp = create_enzyme_actions( sequence, *args ) ! enzyme_actions = tmp[0].merge(tmp[1]) ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) ! enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| ! sr_with_cuts.add_cut_range(cut_range) end end ! sr_with_cuts.fragments.primary = sequence ! sr_with_cuts.fragments.complement = sequence.forward_complement ! unique_fragments_for_display( {0 => sr_with_cuts} ) end - ######### - protected - ######### - UniqueFragment = Struct.new(:primary, :complement) class UniqueFragments < Array ! def primary ! tmp = [] ! self.each { |uf| tmp << uf.primary } ! tmp.sort.map { |e| e.tr(' ', '') } ! end ! def complement ! tmp = [] ! self.each { |uf| tmp << uf.complement } ! tmp.sort.map { |e| e.tr(' ', '') } end end - def unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) - uf_ary = UniqueFragments.new - return uf_ary if hash_of_sequence_ranges_with_cuts == nil or hash_of_sequence_ranges_with_cuts.empty? - - hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| - sr_with_cuts.fragments.for_display.each do |fragment| - uf = UniqueFragment.new - uf.primary = fragment.primary - uf.complement = fragment.complement ! duplicate = false ! uf_ary.each do |element| ! if (uf.primary == element.primary) and (uf.complement == element.complement) ! duplicate = true ! break ! end ! end ! uf_ary << uf unless duplicate end end uf_ary end --- 81,130 ---- 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| ! sequence_range.add_cut_range(cut_range) end 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 ! ! protected ! ! def strip_and_sort( sym_strand ) ! self.map {|uf| uf.send( sym_strand ).tr(' ', '') }.sort end end + + ######### + protected + ######### ! # * +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| ! # NOTE might not need tr here ! uf_ary << UniqueFragment.new(fragment.primary.tr(' ', ''), fragment.complement.tr(' ', '')) end end + uf_ary.uniq! uf_ary end *************** *** 142,193 **** # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) ! id = 0 ! enzyme_actions_that_sometimes_cut = {} ! enzyme_actions_that_always_cut = {} ! indicies_of_sometimes_cut = [] ! args.each do |enzyme| enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! #enzyme_actions_that_always_cut[id] = enzyme_to_enzyme_action( enzyme, offset ) ! enzyme_actions_that_always_cut[id] = enzyme.create_action_at( offset ) ! id += 1 end end # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut ! max = enzyme_actions_that_always_cut.size - 1 ! 0.upto(max) do |i| ! enzyme_action = enzyme_actions_that_always_cut[i] conflict = false other_cut_ranges = {} - enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; other_cut_ranges[key] = i_ea.cut_ranges } other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left = cut_range.range.first ! previous_cut_right = cut_range.range.last ! if (enzyme_action.right <= previous_cut_left) or ! (enzyme_action.left > previous_cut_right) or ! (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts # no conflict else conflict = true end ! ! indicies_of_sometimes_cut += [i, key] if conflict == true end end end ! indicies_of_sometimes_cut.uniq.each do |i| ! enzyme_actions_that_sometimes_cut[i] = enzyme_actions_that_always_cut[i] ! enzyme_actions_that_always_cut.delete(i) ! end ! ! [enzyme_actions_that_sometimes_cut, enzyme_actions_that_always_cut] end --- 135,209 ---- # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) ! require 'set' ! always_cut = [] ! indicies_of_sometimes_cut = Set.new ! args.each do |enzyme| enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded + find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! always_cut << enzyme.create_action_at( offset ) end end + + # VerticalCutRange should really be called VerticalAndHorizontalCutRange + + # * always_cut is now full of EnzymeActions at specific locations across + # the sequence. + # * always_cut will now be examined to see if any EnzymeActions may + # conflict with one another, and if they do they'll be made note of in + # indicies_of_sometimes_cut. They will then be remove FIXME + # * a conflict occurs if another enzyme's bind site is compromised do due + # to another enzyme's cut. Enzyme's bind sites may overlap and not be + # 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. + + dirty = Set.new + =begin + always_cut.each_with_index do |ea, index| + + end + =end # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut ! always_cut.each_with_index do |ea, index1| conflict = false other_cut_ranges = {} + always_cut.each_with_index do |i_ea, index2| + next if index1 == index2 + other_cut_ranges[index2] = i_ea.cut_ranges + end + other_cut_ranges.each do |key, cut_ranges| + cut_ranges.each do |cut_range| next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left, previous_cut_right = cut_range.min, cut_range.max ! if (ea.right <= previous_cut_left) or ! (ea.left > previous_cut_right) or ! (ea.left > previous_cut_left and ea.right <= previous_cut_right) # in-between cuts # no conflict else conflict = true end ! indicies_of_sometimes_cut += [index1, key] if conflict == true end end end + + sometimes_cut = always_cut.values_at( *indicies_of_sometimes_cut ) + always_cut.delete_if {|x| sometimes_cut.include? x } ! #puts "Sometimes cut: #{sometimes_cut.size}" ! #puts "Always cut: #{always_cut.size}" ! #puts ! [sometimes_cut, always_cut] end Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** analysis.rb 2 Jan 2007 00:13:07 -0000 1.9 --- analysis.rb 2 Jan 2007 06:18:38 -0000 1.10 *************** *** 40,45 **** def cut( sequence, *args ) return nil if !sequence.kind_of?(String) or sequence.empty? ! hash_of_sequence_ranges_with_cuts = cut_and_return_by_permutations( sequence, *args ) ! unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) end --- 40,44 ---- 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 *************** *** 51,121 **** return {} if !sequence.kind_of?(String) or sequence.empty? sequence = Bio::Sequence::NA.new( sequence ) enzyme_actions, initial_cuts = create_enzyme_actions( sequence, *args ) ! return {} if enzyme_actions.empty? and initial_cuts.empty? if enzyme_actions.size > 1 permutations = permute(enzyme_actions.size) ! else ! permutations = [] ! end ! ! # Indexed by permutation. ! hash_of_sequence_ranges_with_cuts = {} ! ! if permutations.empty? ! sr_with_cuts = 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| sr_with_cuts.add_cut_range(cut_range) } } ! hash_of_sequence_ranges_with_cuts[0] = sr_with_cuts ! end ! ! permutations.each do |permutation| ! previous_cut_ranges = [] ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) ! initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } ! permutation.each do |id| ! enzyme_action = enzyme_actions[id] ! # conflict is false if the current enzyme action may cut in it's range. ! # conflict is true if it cannot do to a previous enzyme action making ! # a cut where this enzyme action needs a whole recognition site. ! conflict = false ! # If current size of enzyme_action overlaps with previous cut_range, don't cut ! # note that the enzyme action may fall in the middle of a previous enzyme action ! # so all cut locations must be checked that would fall underneath. ! previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left = cut_range.range.first ! previous_cut_right = cut_range.range.last ! # Keep in mind: ! # * The cut location is to the immediate right of the base located at the index. ! # ex: at^gc -- the cut location is at index 1 ! # * The enzyme action location is located at the base of the index. ! # ex: atgc -- 0 => 'a', 1 => 't', 2 => 'g', 3 => 'c' ! if (enzyme_action.right <= previous_cut_left) or ! (enzyme_action.left > previous_cut_right) or ! (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts ! # no conflict ! else ! conflict = true end end ! next if conflict == true ! enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } ! previous_cut_ranges += enzyme_action.cut_ranges end ! hash_of_sequence_ranges_with_cuts[permutation] = sr_with_cuts ! end ! hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| ! sr_with_cuts.fragments.primary = sequence ! sr_with_cuts.fragments.complement = sequence.forward_complement end ! hash_of_sequence_ranges_with_cuts end --- 50,129 ---- 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) ! ! 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| ! enzyme_action = enzyme_actions[id] ! # conflict is false if the current enzyme action may cut in it's range. ! # conflict is true if it cannot due to a previous enzyme action making ! # a cut where this enzyme action needs a whole recognition site. ! conflict = false ! # If current size of enzyme_action overlaps with previous cut_range, don't cut ! # note that the enzyme action may fall in the middle of a previous enzyme action ! # so all cut locations must be checked that would fall underneath. ! previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left = cut_range.range.first ! previous_cut_right = cut_range.range.last ! # Keep in mind: ! # * The cut location is to the immediate right of the base located at the index. ! # ex: at^gc -- the cut location is at index 1 ! # * The enzyme action location is located at the base of the index. ! # ex: atgc -- 0 => 'a', 1 => 't', 2 => 'g', 3 => 'c' ! if (enzyme_action.right <= previous_cut_left) or ! (enzyme_action.left > previous_cut_right) or ! (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts ! # no conflict ! else ! conflict = true ! end end + + next if conflict == true + enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } + previous_cut_ranges += enzyme_action.cut_ranges end ! sequence_range.fragments.primary = sequence ! sequence_range.fragments.complement = sequence.forward_complement ! my_hash[permutation] = sequence_range end + + 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 ! my_hash[0] = sequence_range end ! my_hash end From trevor at dev.open-bio.org Tue Jan 2 01:18:40 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/double_stranded cut_location_pair.rb, 1.3, 1.4 Message-ID: <200701020618.l026IeVN003173@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded In directory dev.open-bio.org:/tmp/cvs-serv3143/restriction_enzyme/double_stranded Modified Files: cut_location_pair.rb Log Message: Index: cut_location_pair.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cut_location_pair.rb 1 Jan 2007 05:07:04 -0000 1.3 --- cut_location_pair.rb 2 Jan 2007 06:18:38 -0000 1.4 *************** *** 63,67 **** a,b = init_with_array( pair[0] ) ! elsif pair[0].kind_of? Range a,b = init_with_array( [pair[0].first, pair[0].last] ) --- 63,67 ---- a,b = init_with_array( pair[0] ) ! elsif pair[0].kind_of? Range # FIXME This seems to be broken? Check tests a,b = init_with_array( [pair[0].first, pair[0].last] ) *************** *** 70,74 **** else ! raise ArgumentError, "#{pair[0].class} is an invalid class type." end --- 70,74 ---- else ! raise ArgumentError, "#{pair[0].class} is an invalid class type to initalize CutLocationPair." end From trevor at dev.open-bio.org Tue Jan 2 02:33:48 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 07:33:48 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.10, 1.11 analysis_basic.rb, 1.3, 1.4 Message-ID: <200701020733.l027Xm2G003294@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3272/lib/bio/util/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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** analysis_basic.rb 2 Jan 2007 06:18:38 -0000 1.3 --- analysis_basic.rb 2 Jan 2007 07:33:46 -0000 1.4 *************** *** 122,127 **** hsh.each do |permutation_id, sequence_range| sequence_range.fragments.for_display.each do |fragment| ! # NOTE might not need tr here ! uf_ary << UniqueFragment.new(fragment.primary.tr(' ', ''), fragment.complement.tr(' ', '')) end end --- 122,126 ---- 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 *************** *** 136,141 **** def create_enzyme_actions( sequence, *args ) require 'set' ! always_cut = [] ! indicies_of_sometimes_cut = Set.new args.each do |enzyme| --- 135,139 ---- def create_enzyme_actions( sequence, *args ) require 'set' ! all_enzyme_actions = [] args.each do |enzyme| *************** *** 143,147 **** find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! always_cut << enzyme.create_action_at( offset ) end end --- 141,145 ---- find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! all_enzyme_actions << enzyme.create_action_at( offset ) end end *************** *** 149,155 **** # VerticalCutRange should really be called VerticalAndHorizontalCutRange ! # * always_cut is now full of EnzymeActions at specific locations across # the sequence. ! # * always_cut will now be examined to see if any EnzymeActions may # conflict with one another, and if they do they'll be made note of in # indicies_of_sometimes_cut. They will then be remove FIXME --- 147,153 ---- # VerticalCutRange should really be called VerticalAndHorizontalCutRange ! # * all_enzyme_actions is now full of EnzymeActions at specific locations across # the sequence. ! # * all_enzyme_actions will now be examined to see if any EnzymeActions may # conflict with one another, and if they do they'll be made note of in # indicies_of_sometimes_cut. They will then be remove FIXME *************** *** 163,208 **** # is competition. ! dirty = Set.new ! ! =begin ! always_cut.each_with_index do |ea, index| ! ! end ! =end ! # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut ! ! always_cut.each_with_index do |ea, index1| ! conflict = false ! other_cut_ranges = {} ! always_cut.each_with_index do |i_ea, index2| ! next if index1 == index2 ! other_cut_ranges[index2] = i_ea.cut_ranges ! end ! other_cut_ranges.each do |key, cut_ranges| ! ! cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left, previous_cut_right = cut_range.min, cut_range.max ! if (ea.right <= previous_cut_left) or ! (ea.left > previous_cut_right) or ! (ea.left > previous_cut_left and ea.right <= previous_cut_right) # in-between cuts ! # no conflict ! else ! conflict = true ! end ! indicies_of_sometimes_cut += [index1, key] if conflict == true end end end ! ! sometimes_cut = always_cut.values_at( *indicies_of_sometimes_cut ) always_cut.delete_if {|x| sometimes_cut.include? x } - #puts "Sometimes cut: #{sometimes_cut.size}" - #puts "Always cut: #{always_cut.size}" - #puts [sometimes_cut, always_cut] end --- 161,199 ---- # 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 ! # since trailing horizontal cuts would have no influence on the bind site. ! # ! # If example Enzyme A makes this cut pattern (cut range 2..5): ! # ! # 0 1 2|3 4 5 6 7 ! # +-----+ ! # 0 1 2 3 4 5|6 7 ! # ! # 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 ! all_enzyme_actions[0..-2].each_with_index do |current_enzyme_action, i| ! next if competition_indexes.include? i ! all_enzyme_actions[i+1..-1].each_with_index do |comparison_enzyme_action, j| ! j += (i + 1) ! next if competition_indexes.include? j ! if (current_enzyme_action.right <= comparison_enzyme_action.cut_ranges.min_vertical) or ! (current_enzyme_action.left > comparison_enzyme_action.cut_ranges.max_vertical) ! # no conflict ! else ! competition_indexes += [i, j] # merge both indexes into the flat set end end end ! ! sometimes_cut = all_enzyme_actions.values_at( *competition_indexes ) ! always_cut = all_enzyme_actions always_cut.delete_if {|x| sometimes_cut.include? x } [sometimes_cut, always_cut] end Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** analysis.rb 2 Jan 2007 06:18:38 -0000 1.10 --- analysis.rb 2 Jan 2007 07:33:46 -0000 1.11 *************** *** 69,73 **** initial_cuts.each { |enzyme_action| ! raise initial_cuts.inspect enzyme_action.cut_ranges.each { |cut_range| --- 69,73 ---- initial_cuts.each { |enzyme_action| ! #raise initial_cuts.inspect enzyme_action.cut_ranges.each { |cut_range| From trevor at dev.open-bio.org Tue Jan 2 02:33:48 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 07:33:48 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.5, 1.6 Message-ID: <200701020733.l027Xm8l003300@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3272/test/unit/bio/util/restriction_enzyme Modified Files: test_analysis.rb Log Message: Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_analysis.rb 2 Jan 2007 06:18:07 -0000 1.5 --- test_analysis.rb 2 Jan 2007 07:33:46 -0000 1.6 *************** *** 31,35 **** @obj_4 = @t.cut('atgcatgcatgc', e1) ! @obj_4bd = @t.cut('atgcatgcatgccccc', e1, 'cc^c') e2 = @enz.new('atgcatgc', [3,5]) --- 31,35 ---- @obj_4 = @t.cut('atgcatgcatgc', e1) ! @obj_4bd = @t.cut('atgcatgcatgccc', e1, 'cc^c') # mix of always cut and sometimes cut e2 = @enz.new('atgcatgc', [3,5]) *************** *** 91,105 **** =end - - e1 = @enz.new('atgcatgc', [3,3]) - @obj_4 = @t.cut('atgcatgcatgc', e1) - assert_equal(["atg", "atgcatg", "catgc", "catgcatgc"], @obj_5.primary) assert_equal(["a", "ag", "g", "ga"], @obj_6.primary) assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7.primary) assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8.primary) ! ! assert_equal(["atg", "atgcatg", "c", "catg", "catgcc", "catgccc", "cc", "cc"], @obj_4bd.primary) ! assert_equal(["gg", "gg", "ggg", "gtac", "gtacg", "gtacgg", "tac", "tacgtac"], @obj_4bd.complement) end --- 91,121 ---- =end assert_equal(["atg", "atgcatg", "catgc", "catgcatgc"], @obj_5.primary) assert_equal(["a", "ag", "g", "ga"], @obj_6.primary) assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7.primary) assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8.primary) ! ! =begin ! e1 = @enz.new('atgcatgc', [3,3]) ! @obj_4bd = @t.cut('atgcatgcatgccc', e1, 'cc^c') # mix of sometimes cut and always cut ! ! [#, ! #, ! #, ! #, ! #] ! =end ! assert_equal(["atg", "atgcatg", "c", "catg", "catgcc"], @obj_4bd.primary) ! assert_equal(["gg", "gtac", "gtacg", "tac", "tacgtac"], @obj_4bd.complement) end From trevor at dev.open-bio.org Fri Jan 5 00:33:17 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 05:33:17 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.6, 1.7 Message-ID: <200701050533.l055XHeA015812@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15792/restriction_enzyme Modified Files: test_analysis.rb Log Message: Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_analysis.rb 2 Jan 2007 07:33:46 -0000 1.6 --- test_analysis.rb 5 Jan 2007 05:33:15 -0000 1.7 *************** *** 75,84 **** assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Analysis::UniqueFragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Analysis::UniqueFragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) assert_equal(["ag", "agt", "cag"], @obj_3.primary) assert_equal(["atg", "atgcatg", "catg", "catgc"], @obj_4.primary) =begin A T G^C A T G C --- 75,85 ---- assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) assert_equal(["ag", "agt", "cag"], @obj_3.primary) assert_equal(["atg", "atgcatg", "catg", "catgc"], @obj_4.primary) + =begin A T G^C A T G C From trevor at dev.open-bio.org Fri Jan 5 00:33:31 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 05:33:31 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.11, 1.12 analysis_basic.rb, 1.4, 1.5 Message-ID: <200701050533.l055XVsl015840@dev.open-bio.org> 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 ---- From trevor at dev.open-bio.org Fri Jan 5 01:03:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:03:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb,1.8,1.9 Message-ID: <200701050603.l0563OaL015895@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv15871 Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** restriction_enzyme.rb 1 Jan 2007 02:31:22 -0000 1.8 --- restriction_enzyme.rb 5 Jan 2007 06:03:22 -0000 1.9 *************** *** 28,31 **** --- 28,32 ---- # comments would be appreciated. # + # FIXME needs better docs # # = Description From trevor at dev.open-bio.org Fri Jan 5 01:03:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:03:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.1, 1.2 vertical_cut_range.rb, 1.1, 1.2 Message-ID: <200701050603.l0563Owf015907@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv15871/restriction_enzyme/range Modified Files: sequence_range.rb vertical_cut_range.rb Log Message: Index: vertical_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/vertical_cut_range.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** vertical_cut_range.rb 2 Jan 2007 00:13:07 -0000 1.1 --- vertical_cut_range.rb 5 Jan 2007 06:03:22 -0000 1.2 *************** *** 25,28 **** --- 25,29 ---- # License:: Distributes under the same terms as Ruby # + # FIXME docs are kind of out of date. Change this to VerticalAndHorizontalCutRange class VerticalCutRange < CutRange attr_reader :p_cut_left, :p_cut_right Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sequence_range.rb 2 Jan 2007 00:13:07 -0000 1.1 --- sequence_range.rb 5 Jan 2007 06:03:22 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- # License:: Distributes under the same terms as Ruby # + # FIXME algorithm heavy, needs better docs class SequenceRange *************** *** 64,70 **** end ! =begin ! Special Case: Horizontal cuts at beginning or end of strand ! =end Bin = Struct.new(:c, :p) --- 65,69 ---- end ! # NOTE Special Case: Horizontal cuts at beginning or end of strand Bin = Struct.new(:c, :p) From trevor at dev.open-bio.org Fri Jan 5 01:03:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:03:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.12, 1.13 analysis_basic.rb, 1.5, 1.6 double_stranded.rb, 1.5, 1.6 Message-ID: <200701050603.l0563OJ4015900@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15871/restriction_enzyme Modified Files: analysis.rb analysis_basic.rb double_stranded.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.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** analysis_basic.rb 5 Jan 2007 05:33:29 -0000 1.5 --- analysis_basic.rb 5 Jan 2007 06:03:22 -0000 1.6 *************** *** 90,94 **** # * +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? --- 90,94 ---- # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 134,138 **** # View these with the 'primary' and 'complement' methods. # ! # Fragment is a simple +Struct+ object. Fragment = Struct.new(:primary, :complement) --- 134,140 ---- # View these with the 'primary' and 'complement' methods. # ! # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. ! # ! # *Note: unrelated to SequenceRange::Fragment* Fragment = Struct.new(:primary, :complement) *************** *** 144,147 **** --- 146,151 ---- # not return duplicate items and does not return the spacing that you would # find by accessing the members directly. + # + # *Note: unrelated to SequenceRange::Fragments* class Fragments < Array def primary; strip_and_sort(:primary); end *************** *** 161,170 **** # 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 --- 165,174 ---- # Take the fragments from SequenceRange objects generated from add_cut_range ! # and return unique results as a Bio::RestrictionEnzyme::Analysis::Fragment object. # # --- # *Arguments* # * +hsh+: +Hash+ Keys are a permutation ID, if any. Values are SequenceRange objects that have cuts applied. ! # *Returns*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. def fragments_for_display( hsh ) ary = Fragments.new *************** *** 182,187 **** # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. # ! # +sequence+:: The string of DNA to match the enzyme recognition sites against ! # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) all_enzyme_actions = [] --- 186,194 ---- # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. # ! # --- ! # *Arguments* ! # * +sequence+: The string of DNA to match the enzyme recognition sites against ! # * +args+:: The enzymes to use. ! # *Returns*:: +Array+ with the first element being an array of EnzymeAction objects that +sometimes_cut+, and are subject to competition. The second is an array of EnzymeAction objects that +always_cut+ and are not subject to competition. def create_enzyme_actions( sequence, *args ) all_enzyme_actions = [] Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** analysis.rb 5 Jan 2007 05:33:29 -0000 1.12 --- analysis.rb 5 Jan 2007 06:03:22 -0000 1.13 *************** *** 51,55 **** # * +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? --- 51,55 ---- # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 116,119 **** --- 116,120 ---- # * The enzyme action location is located at the base of the index. # ex: atgc -- 0 => 'a', 1 => 't', 2 => 'g', 3 => 'c' + # method create_enzyme_actions has similar commentary if interested if (enzyme_action.right <= previous_cut_left) or (enzyme_action.left > previous_cut_right) or *************** *** 128,132 **** enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } previous_cut_ranges += enzyme_action.cut_ranges ! end # Fill in the source sequence for sequence_range so it knows what bases --- 129,133 ---- enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } previous_cut_ranges += enzyme_action.cut_ranges ! end # permutation.each # Fill in the source sequence for sequence_range so it knows what bases *************** *** 135,141 **** sequence_range.fragments.complement = sequence.forward_complement my_hash[permutation] = sequence_range ! end ! else # !if enzyme_actions.size > 1 sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } } --- 136,143 ---- sequence_range.fragments.complement = sequence.forward_complement my_hash[permutation] = sequence_range ! end # permutations.each ! else # if enzyme_actions.size == 1 ! # no permutations, just do it sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } } *************** *** 148,151 **** --- 150,191 ---- end + + # Returns permutation orders for a given number of elements. + # + # Examples: + # permute(0) # => [[0]] + # permute(1) # => [[0]] + # permute(2) # => [[1, 0], [0, 1]] + # permute(3) # => [[2, 1, 0], [2, 0, 1], [1, 2, 0], [0, 2, 1], [1, 0, 2], [0, 1, 2]] + # permute(4) # => [[3, 2, 1, 0], + # [3, 2, 0, 1], + # [3, 1, 2, 0], + # [3, 0, 2, 1], + # [3, 1, 0, 2], + # [3, 0, 1, 2], + # [2, 3, 1, 0], + # [2, 3, 0, 1], + # [1, 3, 2, 0], + # [0, 3, 2, 1], + # [1, 3, 0, 2], + # [0, 3, 1, 2], + # [2, 1, 3, 0], + # [2, 0, 3, 1], + # [1, 2, 3, 0], + # [0, 2, 3, 1], + # [1, 0, 3, 2], + # [0, 1, 3, 2], + # [2, 1, 0, 3], + # [2, 0, 1, 3], + # [1, 2, 0, 3], + # [0, 2, 1, 3], + # [1, 0, 2, 3], + # [0, 1, 2, 3]] + # + # --- + # *Arguments* + # * +count+: +Number+ of different elements to be permuted + # * +permutations+: ignore - for the recursive algorithm + # *Returns*:: +Array+ of +Array+ objects with different possible permutation orders. See examples. def permute(count, permutations = [[0]]) return permutations if count <= 1 Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** double_stranded.rb 2 Jan 2007 00:13:07 -0000 1.5 --- double_stranded.rb 5 Jan 2007 06:03:22 -0000 1.6 *************** *** 41,44 **** --- 41,46 ---- # * SingleStrand methods may be used on DoubleStranded and they will be passed to +primary+. # + # + # FIXME needs better docs class DoubleStranded include CutSymbol From trevor at dev.open-bio.org Fri Jan 5 01:11:17 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:11:17 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb,1.9,1.10 Message-ID: <200701050611.l056BHgZ015938@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv15916 Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** restriction_enzyme.rb 5 Jan 2007 06:03:22 -0000 1.9 --- restriction_enzyme.rb 5 Jan 2007 06:11:15 -0000 1.10 *************** *** 233,236 **** --- 233,275 ---- 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. + # + # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. + # + # *Note: unrelated to SequenceRange::Fragment* + 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. + # + # *Note: unrelated to SequenceRange::Fragments* + class Fragments < Array + def primary; strip_and_sort(:primary); end + def complement; strip_and_sort(:complement); end + + protected + + def strip_and_sort( sym_strand ) + self.map {|uf| uf.send( sym_strand ).tr(' ', '') }.sort + end + end end # RestrictionEnzyme end # Bio From trevor at dev.open-bio.org Fri Jan 5 01:11:17 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:11:17 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.13, 1.14 analysis_basic.rb, 1.6, 1.7 Message-ID: <200701050611.l056BHeg015943@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15916/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.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** analysis_basic.rb 5 Jan 2007 06:03:22 -0000 1.6 --- analysis_basic.rb 5 Jan 2007 06:11:15 -0000 1.7 *************** *** 90,94 **** # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 90,94 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 119,161 **** 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. ! # ! # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. ! # ! # *Note: unrelated to SequenceRange::Fragment* ! 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. ! # ! # *Note: unrelated to SequenceRange::Fragments* ! class Fragments < Array ! def primary; strip_and_sort(:primary); end ! def complement; strip_and_sort(:complement); end ! ! protected ! ! def strip_and_sort( sym_strand ) ! self.map {|uf| uf.send( sym_strand ).tr(' ', '') }.sort ! end ! end ######### --- 119,123 ---- end ! ######### *************** *** 177,181 **** hsh.each do |permutation_id, sequence_range| sequence_range.fragments.for_display.each do |fragment| ! ary << Fragment.new(fragment.primary, fragment.complement) end end --- 139,143 ---- hsh.each do |permutation_id, sequence_range| sequence_range.fragments.for_display.each do |fragment| ! ary << Bio::RestrictionEnzyme::Fragment.new(fragment.primary, fragment.complement) end end Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** analysis.rb 5 Jan 2007 06:03:22 -0000 1.13 --- analysis.rb 5 Jan 2007 06:11:15 -0000 1.14 *************** *** 51,55 **** # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 51,55 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? From trevor at dev.open-bio.org Fri Jan 5 01:11:41 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:11:41 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.7, 1.8 Message-ID: <200701050611.l056BfBr015972@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15952/restriction_enzyme Modified Files: test_analysis.rb Log Message: Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_analysis.rb 5 Jan 2007 05:33:15 -0000 1.7 --- test_analysis.rb 5 Jan 2007 06:11:39 -0000 1.8 *************** *** 75,80 **** assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) --- 75,80 ---- assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Fragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Fragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) From trevor at dev.open-bio.org Fri Jan 5 01:33:03 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:33:03 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb, 1.10, 1.11 Message-ID: <200701050633.l056X3Dx016024@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv16002 Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** restriction_enzyme.rb 5 Jan 2007 06:11:15 -0000 1.10 --- restriction_enzyme.rb 5 Jan 2007 06:33:01 -0000 1.11 *************** *** 233,265 **** 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. # ! # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. # ! # *Note: unrelated to SequenceRange::Fragment* 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. # ! # *Note: unrelated to SequenceRange::Fragments* class Fragments < Array def primary; strip_and_sort(:primary); end --- 233,277 ---- end ! # A Bio::RestrictionEnzyme::Fragment is a DNA fragment composed of fused primary and ! # complementary strands that would be found floating in solution after a full ! # sequence is digested by one or more RestrictionEnzymes. # # 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 they were cut. # # Example: # ! # Fragment 1: ! # primary = "attaca" ! # complement = " atga" # ! # Fragment 2: ! # primary = "g " ! # complement = "cta" # ! # View these with the +primary+ and +complement+ methods. # ! # Bio::RestrictionEnzyme::Fragment is a simple +Struct+ object. ! # ! # Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragment Fragment = Struct.new(:primary, :complement) ! # Bio::RestrictionEnzyme::Fragments inherits from +Array+. # ! # Bio::RestrictionEnzyme::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 in alphabetically sorted ! # order. Note that it will ! # not return duplicate items and does not return the spacing/padding ! # that you would # find by accessing the members directly. + # + # Example: # ! # primary = ['attaca', 'g'] ! # complement = ['atga', 'cta'] ! # ! # Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragments class Fragments < Array def primary; strip_and_sort(:primary); end From trevor at dev.open-bio.org Fri Jan 5 01:33:03 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:33:03 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.14, 1.15 analysis_basic.rb, 1.7, 1.8 double_stranded.rb, 1.6, 1.7 Message-ID: <200701050633.l056X3GO016029@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv16002/restriction_enzyme Modified Files: analysis.rb analysis_basic.rb double_stranded.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.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** analysis_basic.rb 5 Jan 2007 06:11:15 -0000 1.7 --- analysis_basic.rb 5 Jan 2007 06:33:01 -0000 1.8 *************** *** 51,59 **** class Analysis - 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 ) --- 51,54 ---- *************** *** 73,77 **** # 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. --- 68,72 ---- # accurate. # ! # This code is mainly included as an academic example # without having to wade through the extra layer of complexity added by the # permutations. *************** *** 90,94 **** # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 85,89 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 118,123 **** fragments_for_display( {0 => sequence_range} ) end - - ######### --- 113,116 ---- *************** *** 125,129 **** ######### - # Take the fragments from SequenceRange objects generated from add_cut_range # and return unique results as a Bio::RestrictionEnzyme::Analysis::Fragment object. --- 118,121 ---- Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** analysis.rb 5 Jan 2007 06:11:15 -0000 1.14 --- analysis.rb 5 Jan 2007 06:33:01 -0000 1.15 *************** *** 51,55 **** # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 51,55 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** double_stranded.rb 5 Jan 2007 06:03:22 -0000 1.6 --- double_stranded.rb 5 Jan 2007 06:33:01 -0000 1.7 *************** *** 148,152 **** end ! # Returns +true+ if the cut pattern creates blunt fragments def blunt? as = aligned_strands_with_cuts --- 148,153 ---- end ! # Returns +true+ if the cut pattern creates blunt fragments. ! # (opposite of sticky) def blunt? as = aligned_strands_with_cuts *************** *** 158,162 **** end ! # Returns +true+ if the cut pattern creates sticky fragments def sticky? !blunt? --- 159,164 ---- end ! # Returns +true+ if the cut pattern creates sticky fragments. ! # (opposite of blunt) def sticky? !blunt? *************** *** 239,242 **** --- 241,250 ---- # This would be represented by two EnzymeActions - one for each # RestrictionEnzyme. + # + # This is, however, subject to competition. If the second enzyme reaches + # the target first, the the first enzyme will not be able to find the + # appropriate bind site. + # + # FIXME complete these docs # # To initialize an EnzymeAction you must first instantiate it with the *************** *** 262,266 **** # * Reflect cuts that are in enzyme notation # * 0 is not a valid enzyme index, decrement 0 and all negative - # c_cl = p_cl.collect { |n| s.length - n }.collect { |n| n <= 0 ? n - 1 : n } #wrong. c_cl = p_cl.collect {|n| (n >= s.length or n < 1) ? ((s.length - n) - 1) : (s.length - n)} --- 270,273 ---- From trevor at dev.open-bio.org Sat Jan 6 00:35:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 05:35:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range calculated_cuts.rb, 1.2, 1.3 Message-ID: <200701060535.l065Z7T9018352@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv18327/restriction_enzyme/range/sequence_range Modified Files: calculated_cuts.rb Log Message: Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** calculated_cuts.rb 2 Jan 2007 00:19:06 -0000 1.2 --- calculated_cuts.rb 6 Jan 2007 05:35:05 -0000 1.3 *************** *** 76,79 **** --- 76,82 ---- end + # Accepts an +Array+ of CutRange type objects and applies them to + # @vc_complement, @vc_primary, and @hc_between_strands. + # # --- # *Arguments* From trevor at dev.open-bio.org Sat Jan 6 00:35:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 05:35:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.2, 1.3 Message-ID: <200701060535.l065Z7RI018349@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv18327/restriction_enzyme/range Modified Files: sequence_range.rb Log Message: Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sequence_range.rb 5 Jan 2007 06:03:22 -0000 1.2 --- sequence_range.rb 6 Jan 2007 05:35:04 -0000 1.3 *************** *** 29,34 **** # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby - # - # FIXME algorithm heavy, needs better docs class SequenceRange --- 29,32 ---- *************** *** 65,70 **** end ! # NOTE Special Case: Horizontal cuts at beginning or end of strand Bin = Struct.new(:c, :p) --- 63,96 ---- end ! # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between 0 and 1. ! def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) ! @__fragments_current = false ! ! if p_cut_left.kind_of? CutRange ! @cut_ranges << p_cut_left ! else ! (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil ! (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil ! (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil ! (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil ! ! @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! end ! end + def add_cut_ranges(*cut_ranges) + cut_ranges.flatten! + cut_ranges.each do |cut_range| + raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange + self.add_cut_range( cut_range ) + end + end + + def add_horizontal_cut_range( left, right=left ) + @__fragments_current = false + @cut_ranges << HorizontalCutRange.new( left, right ) + end + Bin = Struct.new(:c, :p) *************** *** 72,184 **** return @__fragments if @__fragments_current == true @__fragments_current = true cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) cc.add_cuts_from_cut_ranges(@cut_ranges) cc.remove_incomplete_cuts ! p_cut = cc.vc_primary c_cut = cc.vc_complement ! h = cc.hc_between_strands ! if @circular ! # NOTE ! # if it's circular we should start at the beginning of a cut for orientation ! # scan for it, hack off the first set of hcuts and move them to the back else p_cut.unshift(-1) unless p_cut.include?(-1) c_cut.unshift(-1) unless c_cut.include?(-1) end ! if @circular ! largest_bin = 0 ! else ! largest_bin = -1 ! end ! p_bin = largest_bin ! c_bin = largest_bin ! bins = { largest_bin => Bin.new } # bin_id, bin ! bins[ largest_bin ].p = [] ! bins[ largest_bin ].c = [] ! ! x = lambda do |bin_id| ! largest_bin += 1 ! bins[ bin_id ] = Bin.new ! bins[ bin_id ].p = [] ! bins[ bin_id ].c = [] ! end ! -1.upto(@size-1) do |idx| ! # if bins are out of sync but the strands are attached ! if p_bin != c_bin and h.include?(idx) == false ! bins.delete( [p_bin, c_bin].sort.last ) ! p_bin = c_bin = [p_bin, c_bin].sort.first ! largest_bin -= 1 end ! bins[ p_bin ].p << idx ! bins[ c_bin ].c << idx ! if p_cut.include? idx ! p_bin = largest_bin + 1 ! x.call(p_bin) end ! if c_cut.include? idx ! c_bin = largest_bin + 1 ! x.call(c_bin) ! end end ! ! # Easy way to indicate the start of a strand just in case # there is a horizontal cut at position 0 bins.delete(-1) unless @circular ! ! str1 = nil ! str2 = nil ! ! num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } ! (str1 == nil) ? a = num_txt_repeat.call : a = str1.dup ! (str2 == nil) ? b = num_txt_repeat.call : b = str2.dup ! ! fragments = Fragments.new(a,b) ! ! bins.sort.each do |k, bin| ! fragment = Fragment.new( bin.p, bin.c ) ! fragments << fragment ! end ! ! @__fragments = fragments ! return fragments ! end ! ! # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between 0 and 1. ! def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) ! @__fragments_current = false ! ! if p_cut_left.kind_of? CutRange ! @cut_ranges << p_cut_left ! else ! (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil ! (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil ! (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil ! (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil ! ! @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! end ! end ! ! def add_cut_ranges(*cut_ranges) ! cut_ranges.flatten! ! cut_ranges.each do |cut_range| ! raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange ! self.add_cut_range( cut_range ) ! end end ! ! def add_horizontal_cut_range( left, right=left ) ! @__fragments_current = false ! @cut_ranges << HorizontalCutRange.new( left, right ) end end # SequenceRange end # Range --- 98,194 ---- return @__fragments if @__fragments_current == true @__fragments_current = true + + num_txt = '0123456789' + num_txt_repeat = (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] + fragments = Fragments.new(num_txt_repeat, num_txt_repeat) cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) cc.add_cuts_from_cut_ranges(@cut_ranges) cc.remove_incomplete_cuts ! ! create_bins(cc).sort.each { |k, bin| fragments << Fragment.new( bin.p, bin.c ) } ! @__fragments = fragments ! return fragments ! end ! ! ######### ! protected ! ######### ! ! # Example: ! # cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) ! # cc.add_cuts_from_cut_ranges(@cut_ranges) ! # cc.remove_incomplete_cuts ! # bins = create_bins(cc) ! # ! # Example return value: ! # {0=>#, ! # 2=>#, ! # 3=>#, ! # 4=>#} ! # ! # --- ! # *Arguments* ! # * +cc+: Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts ! # *Returns*:: +Hash+ Keys are unique, values are Bio::RestrictionEnzyme::Range::SequenceRange::Bin objects filled with indexes of the sequence locations they represent. ! def create_bins(cc) p_cut = cc.vc_primary c_cut = cc.vc_complement ! h_cut = cc.hc_between_strands ! if @circular ! # NOTE ! # if it's circular we should start at the beginning of a cut for orientation ! # scan for it, hack off the first set of hcuts and move them to the back ! ! unique_id = 0 else p_cut.unshift(-1) unless p_cut.include?(-1) c_cut.unshift(-1) unless c_cut.include?(-1) + unique_id = -1 end ! p_bin_id = c_bin_id = unique_id ! bins = {} ! setup_new_bin(bins, unique_id) ! -1.upto(@size-1) do |idx| # NOTE - circular, for the future - should '-1' be replace with 'unique_id'? ! ! # if bin_ids are out of sync but the strands are attached ! if (p_bin_id != c_bin_id) and !h_cut.include?(idx) ! min_id, max_id = [p_bin_id, c_bin_id].sort ! bins.delete(max_id) ! p_bin_id = c_bin_id = min_id end ! bins[ p_bin_id ].p << idx ! bins[ c_bin_id ].c << idx ! if p_cut.include? idx ! p_bin_id = (unique_id += 1) ! setup_new_bin(bins, p_bin_id) end ! if c_cut.include? idx # repetition ! c_bin_id = (unique_id += 1) # repetition ! setup_new_bin(bins, c_bin_id) # repetition ! end # repetition ! end ! ! # Bin "-1" is an easy way to indicate the start of a strand just in case # there is a horizontal cut at position 0 bins.delete(-1) unless @circular ! bins end ! ! # Modifies bins in place by creating a new element with key bin_id and ! # initializing the bin. ! def setup_new_bin(bins, bin_id) ! bins[ bin_id ] = Bin.new ! bins[ bin_id ].p = [] ! bins[ bin_id ].c = [] end + end # SequenceRange end # Range From trevor at dev.open-bio.org Sat Jan 6 00:52:54 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 05:52:54 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.3, 1.4 Message-ID: <200701060552.l065qsPn018382@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv18362/restriction_enzyme/range Modified Files: sequence_range.rb Log Message: Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sequence_range.rb 6 Jan 2007 05:35:04 -0000 1.3 --- sequence_range.rb 6 Jan 2007 05:52:52 -0000 1.4 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/range/sequence_range.rb - A defined range over a nucleotide sequence # # Author:: Trevor Wennblom *************** *** 24,43 **** class Range # ! # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby class SequenceRange ! attr_reader :p_left, :p_right ! attr_reader :c_left, :c_right ! attr_reader :left, :right attr_reader :size attr_reader :cut_ranges def initialize( p_left = nil, p_right = nil, c_left = nil, c_right = nil ) - @__fragments_current = false raise ArgumentError if p_left == nil and c_left == nil raise ArgumentError if p_right == nil and c_right == nil --- 24,64 ---- class Range # ! # bio/util/restrction_enzyme/range/sequence_range.rb - A defined range over a nucleotide sequence # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby + # + # A defined range over a nucleotide sequence. + # + # This class accomadates having cuts defined on a sequence and returning the + # fragments made by those cuts. class SequenceRange ! # Left-most index of primary strand ! attr_reader :p_left ! ! # Right-most index of primary strand ! attr_reader :p_right ! ! # Left-most index of complementary strand ! attr_reader :c_left ! ! # Right-most index of complementary strand ! attr_reader :c_right ! # Left-most index of DNA sequence ! attr_reader :left ! ! # Right-most index of DNA sequence ! attr_reader :right ! ! # Size of DNA sequence attr_reader :size + + # CutRanges in this SequenceRange attr_reader :cut_ranges def initialize( p_left = nil, p_right = nil, c_left = nil, c_right = nil ) raise ArgumentError if p_left == nil and c_left == nil raise ArgumentError if p_right == nil and c_right == nil *************** *** 45,68 **** (raise ArgumentError unless c_left <= c_right) unless c_left == nil or c_right == nil ! @p_left = p_left ! @p_right = p_right ! @c_left = c_left ! @c_right = c_right ! ! tmp = [p_left, c_left] ! tmp.delete(nil) ! @left = tmp.sort.first ! ! tmp = [p_right, c_right] ! tmp.delete(nil) ! @right = tmp.sort.last ! @size = (@right - @left) + 1 unless @left == nil or @right == nil - @cut_ranges = CutRanges.new end # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false --- 66,79 ---- (raise ArgumentError unless c_left <= c_right) unless c_left == nil or c_right == nil ! @p_left, @p_right, @c_left, @c_right = p_left, p_right, c_left, c_right ! @left = [p_left, c_left].compact.sort.first ! @right = [p_right, c_right].compact.sort.last @size = (@right - @left) + 1 unless @left == nil or @right == nil @cut_ranges = CutRanges.new + @__fragments_current = false end # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between bases 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false *************** *** 81,86 **** def add_cut_ranges(*cut_ranges) ! cut_ranges.flatten! ! cut_ranges.each do |cut_range| raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange self.add_cut_range( cut_range ) --- 92,96 ---- def add_cut_ranges(*cut_ranges) ! cut_ranges.flatten.each do |cut_range| raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange self.add_cut_range( cut_range ) *************** *** 93,98 **** --- 103,137 ---- end + # A Bio::RestrictionEnzyme::Range::SequenceRange::Bin holds an +Array+ of + # indexes for the primary and complement strands (+p+ and +c+ accessors). + # + # Example hash with Bin values: + # {0=>#, + # 2=>#, + # 3=>#, + # 4=>#} Bin = Struct.new(:c, :p) + # Calculates the fragments over this sequence range as defined after using + # the methods add_cut_range, add_cut_ranges, and/or add_horizontal_cut_range + # + # Example return value: + # [#, + # #, + # #, + # #] + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: Bio::RestrictionEnzyme::Range::SequenceRange::Fragments def fragments return @__fragments if @__fragments_current == true From trevor at dev.open-bio.org Sat Jan 6 01:13:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 06:13:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.4, 1.5 Message-ID: <200701060613.l066DO2f018434@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv18414/restriction_enzyme/range Modified Files: sequence_range.rb Log Message: Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sequence_range.rb 6 Jan 2007 05:52:52 -0000 1.4 --- sequence_range.rb 6 Jan 2007 06:13:22 -0000 1.5 *************** *** 74,94 **** end # Cut occurs immediately after the index supplied. # For example, a cut at '0' would mean a cut occurs between bases 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false ! ! if p_cut_left.kind_of? CutRange @cut_ranges << p_cut_left else ! (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil ! (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil ! (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil ! (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil ! @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) end end def add_cut_ranges(*cut_ranges) cut_ranges.flatten.each do |cut_range| --- 74,109 ---- end + + # If the first object is HorizontalCutRange or VerticalCutRange, that is + # added to the SequenceRange. Otherwise this method + # builds a VerticalCutRange object and adds it to the SequenceRange. + # + # Note: # Cut occurs immediately after the index supplied. # For example, a cut at '0' would mean a cut occurs between bases 0 and 1. + # + # --- + # *Arguments* + # * +p_cut_left+: (_optional_) Left-most cut on the primary strand *or* a CutRange object. +nil+ to skip + # * +p_cut_right+: (_optional_) Right-most cut on the primary strand. +nil+ to skip + # * +c_cut_left+: (_optional_) Left-most cut on the complementary strand. +nil+ to skip + # * +c_cut_right+: (_optional_) Right-most cut on the complementary strand. +nil+ to skip + # *Returns*:: nothing def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false ! if p_cut_left.kind_of? CutRange # shortcut @cut_ranges << p_cut_left else ! [p_cut_left, p_cut_right, c_cut_left, c_cut_right].each { |n| (raise IndexError unless n >= @left and n <= @right) unless n == nil } @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) end end + # Add a series of CutRange objects (HorizontalCutRange or VerticalCutRange). + # + # --- + # *Arguments* + # * +cut_ranges+: A series of CutRange objects + # *Returns*:: nothing def add_cut_ranges(*cut_ranges) cut_ranges.flatten.each do |cut_range| *************** *** 98,101 **** --- 113,123 ---- end + # Builds a HorizontalCutRange object and adds it to the SequenceRange. + # + # --- + # *Arguments* + # * +left+: Left-most cut + # * +right+: (_optional_) Right side - by default this equals the left side, default is recommended. + # *Returns*:: nothing def add_horizontal_cut_range( left, right=left ) @__fragments_current = false From trevor at dev.open-bio.org Mon Jan 8 01:38:41 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 08 Jan 2007 06:38:41 +0000 Subject: [BioRuby-cvs] bioruby/lib bio.rb,1.79,1.80 Message-ID: <200701080638.l086cfa2012151@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib In directory dev.open-bio.org:/tmp/cvs-serv12129/lib Modified Files: bio.rb Log Message: Adding Bio::Lasergene file format Index: bio.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio.rb,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** bio.rb 31 Dec 2006 20:54:25 -0000 1.79 --- bio.rb 8 Jan 2007 06:38:38 -0000 1.80 *************** *** 117,120 **** --- 117,121 ---- autoload :NBRF, 'bio/db/nbrf' autoload :REBASE, 'bio/db/rebase' + autoload :Lasergene, 'bio/db/lasergene' autoload :Newick, 'bio/db/newick' From trevor at dev.open-bio.org Mon Jan 8 01:38:41 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 08 Jan 2007 06:38:41 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db test_lasergene.rb,NONE,1.1 Message-ID: <200701080638.l086cfMl012154@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db In directory dev.open-bio.org:/tmp/cvs-serv12129/test/unit/bio/db Added Files: test_lasergene.rb Log Message: Adding Bio::Lasergene file format --- NEW FILE: test_lasergene.rb --- # # test/unit/bio/db/test_rebase.rb - Unit test for Bio::Lasergene # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2007 Center for Biomedical Research Informatics, University of Minnesota (http://cbri.umn.edu) # License:: Distributes under the same terms as Ruby # # $Id: test_lasergene.rb,v 1.1 2007/01/08 06:38:39 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'test/unit' require 'bio' require 'bio/db/lasergene' module Bio #:nodoc: class TestLasergene < Test::Unit::TestCase #:nodoc: def setup file_format_1 = < Update of /home/repository/bioruby/bioruby/lib/bio/db In directory dev.open-bio.org:/tmp/cvs-serv12185/lib/bio/db Added Files: lasergene.rb Log Message: Adding Bio::Lasergene file format --- NEW FILE: lasergene.rb --- # # bio/db/lasergene.rb - Interface for DNAStar Lasergene sequence file format # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2007 Center for Biomedical Research Informatics, University of Minnesota (http://cbri.umn.edu) # License:: Distributes under the same terms as Ruby # # $Id: lasergene.rb,v 1.1 2007/01/08 06:39:14 trevor Exp $ # module Bio #:nodoc: # # bio/db/lasergene.rb - Interface for DNAStar Lasergene sequence file format # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2007 Center for Biomedical Research Informatics, University of Minnesota (http://cbri.umn.edu) # License:: Distributes under the same terms as Ruby # # = Description # # Bio::Lasergene reads DNAStar Lasergene formatted sequence files, or +.seq+ # files. It only expects to find one sequence per file. # # = Usage # # require 'bio' # filename = 'MyFile.seq' # lseq = Bio::Lasergene.new( IO.readlines(filename) ) # lseq.entry_id # => "Contig 1" # lseq.seq # => ATGACGTATCCAAAGAGGCGTTACC # # = Comments # # I'm only aware of the following three kinds of Lasergene file formats. Feel # free to send me other examples that may not currently be accounted for. # # File format 1: # # ## begin ## # "Contig 1" (1,934) # Contig Length: 934 bases # Average Length/Sequence: 467 bases # Total Sequence Length: 1869 bases # Top Strand: 2 sequences # Bottom Strand: 2 sequences # Total: 4 sequences # ^^ # ATGACGTATCCAAAGAGGCGTTACCGGAGAAGAAGACACCGCCCCCGCAGTCCTCTTGGCCAGATCCTCCGCCGCCGCCCCTGGCTCGTCCACCCCCGCCACAGTTACCGCTGGAGAAGGAAAAATGGCATCTTCAWCACCCGCCTATCCCGCAYCTTCGGAWRTACTATCAAGCGAACCACAGTCAGAACGCCCTCCTGGGCGGTGGACATGATGAGATTCAATATTAATGACTTTCTTCCCCCAGGAGGGGGCTCAAACCCCCGCTCTGTGCCCTTTGAATACTACAGAATAAGAAAGGTTAAGGTTGAATTCTGGCCCTGCTCCCCGATCACCCAGGGTGACAGGGGAATGGGCTCCAGTGCTGWTATTCTAGMTGATRRCTTKGTAACAAAGRCCACAGCCCTCACCTATGACCCCTATGTAAACTTCTCCTCCCGCCATACCATAACCCAGCCCTTCTCCTACCRCTCCCGYTACTTTACCCCCAAACCTGTCCTWGATKCCACTATKGATKACTKCCAACCAAACAACAAAAGAAACCAGCTGTGGSTGAGACTACAWACTGCTGGAAATGTAGACCWCGTAGGCCTSGGCACTGCGTKCGAAAACAGTATATACGACCAGGAATACAATATCCGTGTMACCATGTATGTACAATTCAGAGAATTTAATCTTAAAGACCCCCCRCTTMACCCKTAATGAATAATAAMAACCATTACGAAGTGATAAAAWAGWCTCAGTAATTTATTYCATATGGAAATTCWSGGCATGGGGGGGAAAGGGTGACGAACKKGCCCCCTTCCTCCSTSGMYTKTTCYGTAGCATTCYTCCAMAAYACCWAGGCAGYAMTCCTCCSATCAAGAGcYTSYACAGCTGGGACAGCAGTTGAGGAGGACCATTCAAAGGGGGTCGGATTGCTGGTAATCAGA # ## end ## # # # File format 2: # # ## begin ## # ^^: 350,935 # Contig 1 (1,935) # Contig Length: 935 bases # Average Length/Sequence: 580 bases # Total Sequence Length: 2323 bases # Top Strand: 2 sequences # Bottom Strand: 2 sequences # Total: 4 sequences # ^^ # ATGTCGGGGAAATGCTTGACCGCGGGCTACTGCTCATCATTGCTTTCTTTGTGGTATATCGTGCCGTTCTGTTTTGCTGTGCTCGTCAACGCCAGCGGCGACAGCAGCTCTCATTTTCAGTCGATTTATAACTTGACGTTATGTGAGCTGAATGGCACGAACTGGCTGGCAGACAACTTTAACTGGGCTGTGGAGACTTTTGTCATCTTCCCCGTGTTGACTCACATTGTTTCCTATGGTGCACTCACTACCAGTCATTTTCTTGACACAGTTGGTCTAGTTACTGTGTCTACCGCCGGGTTTTATCACGGGCGGTACGTCTTGAGTAGCATCTACGCGGTCTGTGCTCTGGCTGCGTTGATTTGCTTCGCCATCAGGTTTGCGAAGAACTGCATGTCCTGGCGCTACTCTTGCACTAGATACACCAACTTCCTCCTGGACACCAAGGGCAGACTCTATCGTTGGCGGTCGCCTGTCATCATAGAGAAAGGGGGTAAGGTTGAGGTCGAAGGTCATCTGATCGATCTCAAAAGAGTTGTGCTTGATGGCTCTGTGGCGACACCTTTAACCAGAGTTTCAGCGGAACAATGGGGTCGTCCCTAGACGACTTTTGCCATGATAGTACAGCCCCACAGAAGGTGCTCTTGGCGTTTTCCATCACCTACACGCCAGTGATGATATATGCCCTAAAGGTAAGCCGCGGCCGACTTTTGGGGCTTCTGCACCTTTTGATTTTTTTGAACTGTGCCTTTACTTTCGGGTACATGACATTCGTGCACTTTCGGAGCACGAACAAGGTCGCGCTCACTATGGGAGCAGTAGTCGCACTCCTTTGGGGGGTGTACTCAGCCATAGAAACCTGGAAATTCATCACCTCCAGATGCCGTTGTGCTTGCTAGGCCGCAAGTACATTCTGGCCCCTGCCCACCACGTTG # ## end ## # # File format 3 (non-standard Lasergene header): # # ## begin ## # LOCUS PRU87392 15411 bp RNA linear VRL 17-NOV-2000 # DEFINITION Porcine reproductive and respiratory syndrome virus strain VR-2332, # complete genome. # ACCESSION U87392 AF030244 U00153 # VERSION U87392.3 GI:11192298 # [...cut...] # 3'UTR 15261..15411 # polyA_site 15409 # ORIGIN # ^^ # atgacgtataggtgttggctctatgccttggcatttgtattgtcaggagctgtgaccattggcacagcccaaaacttgctgcacagaaacacccttctgtgatagcctccttcaggggagcttagggtttgtccctagcaccttgcttccggagttgcactgctttacggtctctccacccctttaaccatgtctgggatacttgatcggtgcacgtgtacccccaatgccagggtgtttatggcggagggccaagtctactgcacacgatgcctcagtgcacggtctctccttcccctgaacctccaagtttctgagctcggggtgctaggcctattctacaggcccgaagagccactccggtggacgttgccacgtgcattccccactgttgagtgctcccccgccggggcctgctggctttctgcaatctttccaatcgcacgaatgaccagtggaaacctgaacttccaacaaagaatggtacgggtcgcagctgagctttacagagccggccagctcacccctgcagtcttgaaggctctacaagtttatgaacggggttgccgctggtaccccattgttggacctgtccctggagtggccgttttcgccaattccctacatgtgagtgataaacctttcccgggagcaactcacgtgttgaccaacctgccgctcccgcagagacccaagcctgaagacttttgcccctttgagtgtgctatggctactgtctatgacattggtcatgacgccgtcatgtatgtggccgaaaggaaagtctcctgggcccctcgtggcggggatgaagtgaaatttgaagctgtccccggggagttgaagttgattgcgaaccggctccgcacctccttcccgccccaccacacagtggacatgtctaagttcgccttcacagcccctgggtgtggtgtttctatgcgggtcgaacgccaacacggctgccttcccgctgacactgtcc! ctgaaggcaactgctggtggagcttgtttgacttgcttccactggaagttcagaacaaagaaattcgccatgctaaccaatttggctaccagaccaagcatggtgtctctggcaagtacctacagcggaggctgca[...cut...] # ## end ## # class Lasergene # Entire header before the sequence attr_reader :comments # Sequence # # Bio::Sequence::NA or Bio::Sequence::AA object attr_reader :sequence # Name of sequence # * Parsed from standard Lasergene header attr_reader :name # Contig length, length of present sequence # * Parsed from standard Lasergene header attr_reader :contig_length # Average length per sequence # * Parsed from standard Lasergene header attr_reader :average_length # Length of parent sequence # * Parsed from standard Lasergene header attr_reader :total_length # Number of top strand sequences # * Parsed from standard Lasergene header attr_reader :top_strand_sequences # Number of bottom strand sequences # * Parsed from standard Lasergene header attr_reader :bottom_strand_sequences # Number of sequences # * Parsed from standard Lasergene header attr_reader :total_sequences DELIMITER_1 = '^\^\^:' # Match '^^:' at the beginning of a line DELIMITER_2 = '^\^\^' # Match '^^' at the beginning of a line def initialize(lines) process(lines) end # * +cut_locations+: The cut locations in enzyme index notation. # Is the comment header recognized as standard Lasergene format? # # --- # *Arguments* # * _none_ # *Returns*:: +true+ _or_ +false+ def standard_comment? @standard_comment end # Sequence # # Bio::Sequence::NA or Bio::Sequence::AA object def seq @sequence end # Name of sequence # * Parsed from standard Lasergene header def entry_id @name end ######### protected ######### def process(lines) delimiter_1_indices = [] delimiter_2_indices = [] # If the data from the file is passed as one big String instead of # broken into an Array, convert lines to an Array if lines.kind_of? String lines = lines.tr("\r", '').split("\n") end lines.each_with_index do |line, index| if line.match DELIMITER_1 delimiter_1_indices << index elsif line.match DELIMITER_2 delimiter_2_indices << index end end raise InputError, "More than one delimiter of type '#{DELIMITER_1}'" if delimiter_1_indices.size > 1 raise InputError, "More than one delimiter of type '#{DELIMITER_2}'" if delimiter_2_indices.size > 1 raise InputError, "No comment to data separator of type '#{DELIMITER_2}'" if delimiter_2_indices.size < 1 if !delimiter_1_indices.empty? # toss out DELIMETER_1 and anything preceding it @comments = lines[ (delimiter_1_indices[0] + 1) .. (delimiter_2_indices[0] - 1) ] else @comments = lines[ 0 .. (delimiter_2_indices[0] - 1) ] end @standard_comment = false if @comments[0] =~ %r{(.+)\s+\(\d+,\d+\)} # if we have a standard Lasergene comment @standard_comment = true @name = $1 comments.each do |comment| if comment.match('Contig Length:\s+(\d+)') @contig_length = $1.to_i elsif comment.match('Average Length/Sequence:\s+(\d+)') @average_length = $1.to_i elsif comment.match('Total Sequence Length:\s+(\d+)') @total_length = $1.to_i elsif comment.match('Top Strand:\s+(\d+)') @top_strand_sequences = $1.to_i elsif comment.match('Bottom Strand:\s+(\d+)') @bottom_strand_sequences = $1.to_i elsif comment.match('Total:\s+(\d+)') @total_sequences = $1.to_i end end end @comments = @comments.join('') @sequence = Bio::Sequence.auto( lines[ (delimiter_2_indices[0] + 1) .. -1 ].join('') ) end end # Lasergene end # Bio From ngoto at dev.open-bio.org Thu Jan 11 09:35:34 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 11 Jan 2007 14:35:34 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db test_newick.rb,1.2,1.3 Message-ID: <200701111435.l0BEZYee028351@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db In directory dev.open-bio.org:/tmp/cvs-serv28331/test/unit/bio/db Modified Files: test_newick.rb Log Message: fixed incorrect libpath Index: test_newick.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/test_newick.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_newick.rb 13 Dec 2006 16:29:37 -0000 1.2 --- test_newick.rb 11 Jan 2007 14:35:32 -0000 1.3 *************** *** 13,17 **** require 'pathname' ! libpath = Pathname.new(File.join(File.dirname(__FILE__), [".."] * 3, "lib")).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) --- 13,17 ---- require 'pathname' ! libpath = Pathname.new(File.join(File.dirname(__FILE__), [".."] * 4, "lib")).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) From ngoto at dev.open-bio.org Fri Jan 12 11:10:30 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Fri, 12 Jan 2007 16:10:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio tree.rb,1.6,1.7 Message-ID: <200701121610.l0CGAU39030867@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv30847/lib/bio Modified Files: tree.rb Log Message: * fixed a bug: clear_node did not work correctly. * NotAdjacentNodesError is removed. * insert_node is changed to raise IndexError when the edge does not found. * remove_edge is changed to raise IndexError when the edge does not found. Index: tree.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/tree.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tree.rb 15 Dec 2006 18:45:17 -0000 1.6 --- tree.rb 12 Jan 2007 16:10:28 -0000 1.7 *************** *** 26,32 **** class NoPathError < RuntimeError; end - # Error when the two nodes are not adjacent. - class NotAdjacentNodesError < RuntimeError; end - # Edge object of each node. # By default, the object doesn't contain any node information. --- 26,29 ---- *************** *** 412,415 **** --- 409,413 ---- @pathway.graph[k].delete(node) end + @pathway.graph[node].clear self end *************** *** 440,443 **** --- 438,443 ---- # Removes an edge between source and target. + # Returns self. + # If the edge does not exist, raises IndexError. #--- # If two or more edges exists between source and target, *************** *** 445,448 **** --- 445,451 ---- #+++ def remove_edge(source, target) + unless self.get_edge(source, target) then + raise IndexError, 'edge not found' + end fwd = [ source, target ] rev = [ target, source ] *************** *** 815,819 **** # # Returns self. ! # If node1 and node2 are not adjacent, raises NotAdjacentNodesError. # # If new_node already exists in the tree, the tree would become --- 818,822 ---- # # Returns self. ! # If node1 and node2 are not adjacent, raises IndexError. # # If new_node already exists in the tree, the tree would become *************** *** 822,826 **** def insert_node(node1, node2, new_node, new_distance = nil) unless edge = self.get_edge(node1, node2) then ! raise NotAdjacentNodesError, 'node1 and node2 are not adjacent.' end new_edge = Edge.new(new_distance) --- 825,829 ---- def insert_node(node1, node2, new_node, new_distance = nil) unless edge = self.get_edge(node1, node2) then ! raise IndexError, 'nodes not found or two nodes are not adjacent' end new_edge = Edge.new(new_distance) From ngoto at dev.open-bio.org Fri Jan 12 11:12:07 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Fri, 12 Jan 2007 16:12:07 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio test_tree.rb,1.3,1.4 Message-ID: <200701121612.l0CGC7Qs030895@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio In directory dev.open-bio.org:/tmp/cvs-serv30875/test/unit/bio Modified Files: test_tree.rb Log Message: Large test methods are splitted into small methods. More tests are added. Index: test_tree.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_tree.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_tree.rb 13 Dec 2006 16:29:37 -0000 1.3 --- test_tree.rb 12 Jan 2007 16:12:05 -0000 1.4 *************** *** 262,265 **** --- 262,268 ---- assert_equal([ @rodents, @primates ].sort(&@by_id), @tree.adjacent_nodes(@mammals).sort(&@by_id)) + end + + def test_adjacent_nodes_nonexistent # test for not existed nodes assert_equal([], @tree.adjacent_nodes(Bio::Tree::Node.new)) *************** *** 275,279 **** --- 278,284 ---- assert_equal([[ @chimpanzee, @primates, @edge_primates_chimpanzee ]], @tree.out_edges(@chimpanzee)) + end + def test_out_edges_rodents adjacents = [ @mouse, @rat, @mammals ] edges = [ @edge_rodents_mouse, @edge_rodents_rat, @edge_mammals_rodents ] *************** *** 287,291 **** --- 292,298 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_out_edges_primates adjacents = [ @human, @chimpanzee, @mammals ] edges = [ @edge_primates_human, @edge_primates_chimpanzee, *************** *** 300,304 **** --- 307,313 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_out_edges_mammals adjacents = [ @rodents, @primates ] edges = [ @edge_mammals_rodents, @edge_mammals_primates ] *************** *** 312,316 **** --- 321,327 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_out_edges_nonexistent # test for not existed nodes assert_equal([], @tree.out_edges(Bio::Tree::Node.new)) *************** *** 327,331 **** --- 338,344 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_rat flag = nil r = @tree.each_out_edge(@rat) do |src, tgt, edge| *************** *** 337,341 **** --- 350,356 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_human flag = nil r = @tree.each_out_edge(@human) do |src, tgt, edge| *************** *** 347,351 **** --- 362,368 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_chimpanzee flag = nil r = @tree.each_out_edge(@chimpanzee) do |src, tgt, edge| *************** *** 357,361 **** --- 374,380 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_rodents adjacents = [ @mouse, @rat, @mammals ] edges = [ @edge_rodents_mouse, @edge_rodents_rat, @edge_mammals_rodents ] *************** *** 369,373 **** --- 388,394 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_each_out_edge_primates adjacents = [ @human, @chimpanzee, @mammals ] edges = [ @edge_primates_human, @edge_primates_chimpanzee, *************** *** 382,386 **** --- 403,409 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_each_out_edge_mammals adjacents = [ @rodents, @primates ] edges = [ @edge_mammals_rodents, @edge_mammals_primates ] *************** *** 394,398 **** --- 417,423 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_each_out_edge_nonexistent # test for not existed nodes flag = nil *************** *** 405,408 **** --- 430,591 ---- end + def test_out_degree + assert_equal(1, @tree.out_degree(@mouse)) + assert_equal(1, @tree.out_degree(@rat)) + assert_equal(3, @tree.out_degree(@rodents)) + assert_equal(1, @tree.out_degree(@human)) + assert_equal(1, @tree.out_degree(@chimpanzee)) + assert_equal(3, @tree.out_degree(@primates)) + assert_equal(2, @tree.out_degree(@mammals)) + end + + def test_out_degree_nonexistent + assert_equal(0, @tree.out_degree(Bio::Tree::Node.new)) + end + + def test_get_edge + assert_not_nil(@tree.get_edge(@rodents, @mouse)) + assert_not_nil(@tree.get_edge(@mouse, @rodents)) + assert_equal(@edge_rodents_mouse, @tree.get_edge(@rodents, @mouse)) + assert_equal(@edge_rodents_mouse, @tree.get_edge(@mouse, @rodents)) + + assert_not_nil(@tree.get_edge(@rodents, @rat)) + assert_not_nil(@tree.get_edge(@rat, @rodents)) + assert_equal(@edge_rodents_rat, @tree.get_edge(@rodents, @rat)) + assert_equal(@edge_rodents_rat, @tree.get_edge(@rat, @rodents)) + + assert_not_nil(@tree.get_edge(@mammals, @rodents)) + assert_not_nil(@tree.get_edge(@rodents, @mammals)) + assert_equal(@edge_mammals_rodents, @tree.get_edge(@mammals, @rodents)) + assert_equal(@edge_mammals_rodents, @tree.get_edge(@rodents, @mammals)) + + assert_not_nil(@tree.get_edge(@primates, @human)) + assert_not_nil(@tree.get_edge(@human, @primates)) + assert_equal(@edge_primates_human, @tree.get_edge(@primates, @human)) + assert_equal(@edge_primates_human, @tree.get_edge(@human, @primates)) + + assert_not_nil(@tree.get_edge(@primates, @chimpanzee)) + assert_not_nil(@tree.get_edge(@chimpanzee, @primates)) + assert_equal(@edge_primates_chimpanzee, @tree.get_edge(@primates, @chimpanzee)) + assert_equal(@edge_primates_chimpanzee, @tree.get_edge(@chimpanzee, @primates)) + + assert_not_nil(@tree.get_edge(@mammals, @primates)) + assert_not_nil(@tree.get_edge(@primates, @mammals)) + assert_equal(@edge_mammals_primates, @tree.get_edge(@mammals, @primates)) + assert_equal(@edge_mammals_primates, @tree.get_edge(@primates, @mammals)) + end + + def test_get_edge_indirect + assert_nil(@tree.get_edge(@mouse, @rat)) + assert_nil(@tree.get_edge(@human, @chimpanzee)) + end + + def test_get_edge_nonexistent + assert_nil(@tree.get_edge(@mouse, Bio::Tree::Node.new)) + end + + def test_get_node_by_name + assert_not_nil(@tree.get_node_by_name('mouse')) + assert_not_nil(@tree.get_node_by_name('rat')) + assert_not_nil(@tree.get_node_by_name('human')) + assert_not_nil(@tree.get_node_by_name('chimpanzee')) + assert_equal(@mouse, @tree.get_node_by_name('mouse')) + assert_equal(@rat, @tree.get_node_by_name('rat')) + assert_equal(@human, @tree.get_node_by_name('human')) + assert_equal(@chimpanzee, @tree.get_node_by_name('chimpanzee')) + end + + def test_get_node_by_name_noexistent + assert_nil(@tree.get_node_by_name('frog')) + end + + def test_add_edge + amphibian = Bio::Tree::Node.new('amphibian') + edge = Bio::Tree::Edge.new(0.3123) + assert_equal(edge, @tree.add_edge(@mammals, amphibian, edge)) + + frog = Bio::Tree::Node.new('frog') + newt = Bio::Tree::Node.new('newt') + assert_instance_of(Bio::Tree::Edge, @tree.add_edge(frog, newt)) + end + + def test_add_node + frog = Bio::Tree::Node.new('frog') + # the node does not exist + assert_nil(@tree.get_node_by_name('frog')) + assert_equal(false, @tree.include?(frog)) + # add node + assert_equal(@tree, @tree.add_node(frog)) + # the node exists + assert_equal(frog, @tree.get_node_by_name('frog')) + assert_equal(true, @tree.include?(frog)) + end + + def test_include? + assert_equal(true, @tree.include?(@mouse)) + assert_equal(true, @tree.include?(@rat)) + assert_equal(true, @tree.include?(@rodents)) + assert_equal(true, @tree.include?(@human)) + assert_equal(true, @tree.include?(@chimpanzee)) + assert_equal(true, @tree.include?(@primates)) + assert_equal(true, @tree.include?(@mammals)) + end + + def test_include_nonexistent + assert_equal(false, @tree.include?(Bio::Tree::Node.new)) + end + + def test_clear_node + assert_equal(2, @tree.out_degree(@mammals)) + # clear node + assert_equal(@tree, @tree.clear_node(@mammals)) + # checks + assert_equal(true, @tree.include?(@mammals)) + assert_equal(0, @tree.out_degree(@mammals)) + assert_equal(2, @tree.out_degree(@rodents)) + assert_equal(2, @tree.out_degree(@primates)) + end + + def test_clear_node_nonexistent + assert_raise(IndexError) { @tree.clear_node(Bio::Tree::Node.new) } + end + + def test_remove_node + assert_equal(2, @tree.out_degree(@mammals)) + # remove node + assert_equal(@tree, @tree.remove_node(@mammals)) + # checks + assert_equal(false, @tree.include?(@mammals)) + assert_equal(0, @tree.out_degree(@mammals)) + assert_equal(2, @tree.out_degree(@rodents)) + assert_equal(2, @tree.out_degree(@primates)) + end + + def test_remove_node_nonexistent + assert_raise(IndexError) { @tree.remove_node(Bio::Tree::Node.new) } + end + + def test_remove_node_if + assert_equal(@tree, @tree.remove_node_if { |node| node == @mouse }) + assert_equal(false, @tree.include?(@mouse)) + end + + def test_remove_node_if_false + ary = [] + assert_equal(@tree, @tree.remove_node_if { |node| ary << node; false }) + nodes = @nodes.sort(&@by_id) + assert_equal(nodes, ary.sort(&@by_id)) + assert_equal(nodes, @tree.nodes.sort(&@by_id)) + end + + def test_remove_edge + assert_not_nil(@tree.get_edge(@mouse, @rodents)) + assert_equal(@tree, @tree.remove_edge(@mouse, @rodents)) + assert_nil(@tree.get_edge(@mouse, @rodents)) + end + + def test_remove_edge_nonexistent + assert_raise(IndexError) { @tree.remove_edge(@mouse, @rat) } + end end #class TestTree2 From ngoto at dev.open-bio.org Fri Jan 12 11:19:26 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Fri, 12 Jan 2007 16:19:26 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db test_newick.rb,1.3,1.4 Message-ID: <200701121619.l0CGJQJo030925@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db In directory dev.open-bio.org:/tmp/cvs-serv30905/test/unit/bio/db Modified Files: test_newick.rb Log Message: changed to use Bio::Tree#get_node_by_name. Index: test_newick.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/test_newick.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_newick.rb 11 Jan 2007 14:35:32 -0000 1.3 --- test_newick.rb 12 Jan 2007 16:19:24 -0000 1.4 *************** *** 46,50 **** assert_equal(9, tree.descendents(tree.root).size) assert_equal(6, tree.leaves.size) ! leaf = tree.nodes.find { |x| x.name == 'HexFLZ83' } assert_equal(3, tree.ancestors(leaf).size) assert_equal(tree.path(tree.root, leaf)[1], tree.ancestors(leaf)[1]) --- 46,50 ---- assert_equal(9, tree.descendents(tree.root).size) assert_equal(6, tree.leaves.size) ! leaf = tree.get_node_by_name('HexFLZ83') assert_equal(3, tree.ancestors(leaf).size) assert_equal(tree.path(tree.root, leaf)[1], tree.ancestors(leaf)[1]) From k at dev.open-bio.org Sun Jan 14 23:33:54 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:33:54 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio db.rb,0.35,0.36 Message-ID: <200701150433.l0F4Xsa1028546@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv28542/lib/bio Modified Files: db.rb Log Message: * lines_fetch method is refined to concatenate indented sub field Index: db.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db.rb,v retrieving revision 0.35 retrieving revision 0.36 diff -C2 -d -r0.35 -r0.36 *** db.rb 19 Sep 2006 06:14:18 -0000 0.35 --- db.rb 15 Jan 2007 04:33:52 -0000 0.36 *************** *** 221,230 **** # Returns an Array containing each line of the field without a tag. # lines_fetch also stores the result in the @data hash. ! def lines_fetch(tag) ! unless @data[tag] ! @data[tag] = get(tag).split(/\n/).map{ |l| tag_cut(l) } ! end ! @data[tag] ! end end # class DB --- 221,245 ---- # Returns an Array containing each line of the field without a tag. # lines_fetch also stores the result in the @data hash. ! def lines_fetch(tag) ! unless @data[tag] ! list = [] ! lines = get(tag).split(/\n/) ! lines.each do |line| ! data = tag_cut(line) ! if data[/^\S/] # next sub field ! list << data ! else # continued sub field ! data.strip! ! if list.last[/\-$/] # folded ! list[-1] += data ! else ! list[-1] += " #{data}" # rest of list ! end ! end ! end ! @data[tag] = list ! end ! @data[tag] ! end end # class DB From k at dev.open-bio.org Sun Jan 14 23:34:34 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:34:34 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/kegg compound.rb,0.12,0.13 Message-ID: <200701150434.l0F4YYd8028589@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/kegg In directory dev.open-bio.org:/tmp/cvs-serv28585/lib/bio/db/kegg Modified Files: compound.rb Log Message: * comment method is added Index: compound.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/kegg/compound.rb,v retrieving revision 0.12 retrieving revision 0.13 diff -C2 -d -r0.12 -r0.13 *** compound.rb 19 Sep 2006 05:51:29 -0000 0.12 --- compound.rb 15 Jan 2007 04:34:32 -0000 0.13 *************** *** 2,6 **** # = bio/db/kegg/compound.rb - KEGG COMPOUND database class # ! # Copyright:: Copyright (C) 2001, 2002, 2004 Toshiaki Katayama # License:: Ruby's # --- 2,6 ---- # = bio/db/kegg/compound.rb - KEGG COMPOUND database class # ! # Copyright:: Copyright (C) 2001, 2002, 2004, 2007 Toshiaki Katayama # License:: Ruby's # *************** *** 92,95 **** --- 92,100 ---- end + # COMMENT + def comment + field_fetch('COMMENT') + end + end # COMPOUND From k at dev.open-bio.org Sun Jan 14 23:37:31 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:37:31 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/kegg genome.rb,0.15,0.16 Message-ID: <200701150437.l0F4bVg7028670@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/kegg In directory dev.open-bio.org:/tmp/cvs-serv28666/lib/bio/db/kegg Modified Files: genome.rb Log Message: * disease, data_source, original_db methods are added * scaffolds, gc, genomemap methods are obsoleted Index: genome.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/kegg/genome.rb,v retrieving revision 0.15 retrieving revision 0.16 diff -C2 -d -r0.15 -r0.16 *** genome.rb 19 Sep 2006 05:52:45 -0000 0.15 --- genome.rb 15 Jan 2007 04:37:29 -0000 0.16 *************** *** 2,6 **** # = bio/db/kegg/genome.rb - KEGG/GENOME database class # ! # Copyright:: Copyright (C) 2001, 2002 Toshiaki Katayama # License:: Ruby's # --- 2,6 ---- # = bio/db/kegg/genome.rb - KEGG/GENOME database class # ! # Copyright:: Copyright (C) 2001, 2002, 2007 Toshiaki Katayama # License:: Ruby's # *************** *** 72,75 **** --- 72,90 ---- end + # DATA_SOURCE -- Returns contents of the DATA_SOURCE record as a String. + def data_source + field_fetch('DATA_SOURCE') + end + + # ORIGINAL_DB -- Returns contents of the ORIGINAL_DB record as a String. + def original_db + field_fetch('ORIGINAL_DB') + end + + # DISEASE -- Returns contents of the COMMENT record as a String. + def disease + field_fetch('DISEASE') + end + # COMMENT -- Returns contents of the COMMENT record as a String. def comment *************** *** 99,104 **** hash['journal'] = $1 hash['volume'] = $2 ! hash['pages'] = $3 ! hash['year'] = $5 hash['medline'] = $6 else --- 114,119 ---- hash['journal'] = $1 hash['volume'] = $2 ! hash['pages'] = $3 ! hash['year'] = $5 hash['medline'] = $6 else *************** *** 145,163 **** end - # SCAFFOLD -- Returns contents of the SCAFFOLD records as an Array of Hash. - def scaffolds - unless @data['SCAFFOLD'] - @data['SCAFFOLD'] = [] - toptag2array(get('SCAFFOLD')).each do |chr| - hash = Hash.new('') - subtag2array(chr).each do |field| - hash[tag_get(field)] = truncate(tag_cut(field)) - end - @data['SCAFFOLD'].push(hash) - end - end - @data['SCAFFOLD'] - end - # STATISTICS -- Returns contents of the STATISTICS record as a Hash. def statistics --- 160,163 ---- *************** *** 167,177 **** case line when /nucleotides:\s+(\d+)/ ! hash['nalen'] = $1.to_i when /protein genes:\s+(\d+)/ hash['num_gene'] = $1.to_i when /RNA genes:\s+(\d+)/ hash['num_rna'] = $1.to_i - when /G\+C content:\s+(\d+.\d+)/ - hash['gc'] = $1.to_f end end --- 167,175 ---- case line when /nucleotides:\s+(\d+)/ ! hash['num_nuc'] = $1.to_i when /protein genes:\s+(\d+)/ hash['num_gene'] = $1.to_i when /RNA genes:\s+(\d+)/ hash['num_rna'] = $1.to_i end end *************** *** 183,187 **** # Returns number of nucleotides from the STATISTICS record as a Fixnum. def nalen ! statistics['nalen'] end alias length nalen --- 181,185 ---- # Returns number of nucleotides from the STATISTICS record as a Fixnum. def nalen ! statistics['num_nuc'] end alias length nalen *************** *** 197,210 **** end - # Returns G+C content from the STATISTICS record as a Float. - def gc - statistics['gc'] - end - - # GENOMEMAP -- Returns contents of the GENOMEMAP record as a String. - def genomemap - field_fetch('GENOMEMAP') - end - end # GENOME --- 195,198 ---- *************** *** 239,245 **** %w( CHROMOSOME chromosomes ), %w( PLASMID plasmids ), ! %w( SCAFFOLD plasmids ), ! %w( STATISTICS statistics nalen num_gene num_rna gc ), ! %w( GENOMEMAP genomemap ), ].each do |x| puts "### " + x.shift --- 227,231 ---- %w( CHROMOSOME chromosomes ), %w( PLASMID plasmids ), ! %w( STATISTICS statistics nalen num_gene num_rna ), ].each do |x| puts "### " + x.shift From k at dev.open-bio.org Sun Jan 14 23:50:08 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:50:08 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/kegg enzyme.rb,0.9,0.10 Message-ID: <200701150450.l0F4o8WE028731@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/kegg In directory dev.open-bio.org:/tmp/cvs-serv28727/lib/bio/db/kegg Modified Files: enzyme.rb Log Message: * entry_id is changed to entry method as it returns a "EC x.x.x.x Enzyme" style string. Instead, entry_id method is changed to return EC number only. * obsolete? method is added, which returns boolean value (true/false) according to the ENTRY line contains Obsolete or not. * all_reac, iubmb_reactions, kegg_reactions methods are added to support new ALL_REAC field. * inhibitors and orthologs methods are added. * substrates, products, inhibitors, cofactors, pathways, orthologs, diseases, motifs methods now utilizes new lines_fetch method in db.rb to process continuous sub field. Index: enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/kegg/enzyme.rb,v retrieving revision 0.9 retrieving revision 0.10 diff -C2 -d -r0.9 -r0.10 *** enzyme.rb 19 Sep 2006 05:52:05 -0000 0.9 --- enzyme.rb 15 Jan 2007 04:50:05 -0000 0.10 *************** *** 2,6 **** # = bio/db/kegg/enzyme.rb - KEGG/ENZYME database class # ! # Copyright:: Copyright (C) 2001, 2002 Toshiaki Katayama # License:: Ruby's # --- 2,6 ---- # = bio/db/kegg/enzyme.rb - KEGG/ENZYME database class # ! # Copyright:: Copyright (C) 2001, 2002, 2007 Toshiaki Katayama # License:: Ruby's # *************** *** 23,36 **** # ENTRY ! def entry_id field_fetch('ENTRY') end # NAME def names ! lines_fetch('NAME') end def name ! names[0] end --- 23,45 ---- # ENTRY ! def entry field_fetch('ENTRY') end + def entry_id + entry[/EC (\S+)/, 1] + end + + def obsolete? + entry[/Obsolete/] ? true : false + end + # NAME def names ! field_fetch('NAME').split(/\s*;\s*/) end + def name ! names.first end *************** *** 45,66 **** end ! # REACTION ';' def reaction field_fetch('REACTION') end # SUBSTRATE def substrates ! lines_fetch('SUBSTRATE') end # PRODUCT def products ! lines_fetch('PRODUCT') end # COFACTOR def cofactors ! lines_fetch('COFACTOR') end --- 54,98 ---- end ! # REACTION def reaction field_fetch('REACTION') end + + # ALL_REAC ';' + def all_reac + field_fetch('ALL_REAC') + end + + def iubmb_reactions + all_reac.sub(/;\s*\(other\).*/, '').split(/\s*;\s*/) + end + + def kegg_reactions + reac = all_reac + if reac[/\(other\)/] + reac.sub(/.*\(other\)\s*/, '').split(/\s*;\s*/) + else + [] + end + end # SUBSTRATE def substrates ! field_fetch('SUBSTRATE').split(/\s*;\s*/) end # PRODUCT def products ! field_fetch('PRODUCT').split(/\s*;\s*/) ! end ! ! # INHIBITOR ! def inhibitors ! field_fetch('INHIBITOR').split(/\s*;\s*/) end # COFACTOR def cofactors ! field_fetch('COFACTOR').split(/\s*;\s*/) end *************** *** 75,78 **** --- 107,115 ---- end + # ORTHOLOG + def orthologs + lines_fetch('ORTHOLOG') + end + # GENES def genes *************** *** 93,102 **** def structures unless @data['STRUCTURES'] ! @data['STRUCTURES'] = ! fetch('STRUCTURES').sub(/(PDB: )*/,'').split(/\s+/) end @data['STRUCTURES'] end # DBLINKS def dblinks --- 130,140 ---- def structures unless @data['STRUCTURES'] ! @data['STRUCTURES'] = fetch('STRUCTURES').sub(/(PDB: )*/,'').split(/\s+/) end @data['STRUCTURES'] end + # REFERENCE + # DBLINKS def dblinks From k at dev.open-bio.org Tue Jan 16 00:35:39 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:35:39 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates _log.rhtml, NONE, 1.1 _result.rhtml, 1.1, NONE Message-ID: <200701160535.l0G5ZdfP031183@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates In directory dev.open-bio.org:/tmp/cvs-serv31174/templates Added Files: _log.rhtml Removed Files: _result.rhtml Log Message: * _result.rhtml is renamed to _log.rhtml --- NEW FILE: _log.rhtml ---

Input: [<%= link_to_remote @number, :url => {:action => "reload_script", :number => @number} %>]
<%=h @script %>
Result: [<%= link_to_remote "methods", :url => {:action => "list_methods", :number => @number} %>] [<%= link_to_remote "classes", :url => {:action => "list_classes", :number => @number} %>] [<%= link_to_remote "modules", :url => {:action => "list_modules", :number => @number} %>]
<%=h @result %>
<% if @output %> Output:
<%=h @output %>
<% end %>
--- _result.rhtml DELETED --- From k at dev.open-bio.org Tue Jan 16 00:35:39 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:35:39 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby bioruby_generator.rb, 1.1, 1.2 Message-ID: <200701160535.l0G5Zd1Z031180@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby In directory dev.open-bio.org:/tmp/cvs-serv31174 Modified Files: bioruby_generator.rb Log Message: * _result.rhtml is renamed to _log.rhtml Index: bioruby_generator.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/bioruby_generator.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby_generator.rb 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby_generator.rb 16 Jan 2007 05:35:37 -0000 1.2 *************** *** 13,17 **** m.file '_classes.rhtml', 'app/views/bioruby/_classes.rhtml' m.file '_modules.rhtml', 'app/views/bioruby/_modules.rhtml' ! m.file '_result.rhtml', 'app/views/bioruby/_result.rhtml' m.file '_variables.rhtml', 'app/views/bioruby/_variables.rhtml' m.file 'commands.rhtml', 'app/views/bioruby/commands.rhtml' --- 13,17 ---- m.file '_classes.rhtml', 'app/views/bioruby/_classes.rhtml' m.file '_modules.rhtml', 'app/views/bioruby/_modules.rhtml' ! m.file '_log.rhtml', 'app/views/bioruby/_log.rhtml' m.file '_variables.rhtml', 'app/views/bioruby/_variables.rhtml' m.file 'commands.rhtml', 'app/views/bioruby/commands.rhtml' From k at dev.open-bio.org Tue Jan 16 00:38:08 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:38:08 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates shell_helper.rb, 1.1, NONE Message-ID: <200701160538.l0G5c8iU031281@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates In directory dev.open-bio.org:/tmp/cvs-serv31277 Removed Files: shell_helper.rb Log Message: * This file is not used (renamed to bioruby_helper.rb) --- shell_helper.rb DELETED --- From k at dev.open-bio.org Tue Jan 16 00:47:07 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:47:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates _methods.rhtml, 1.1, 1.2 bioruby.css, 1.1, 1.2 bioruby_controller.rb, 1.1, 1.2 bioruby_helper.rb, 1.1, 1.2 index.rhtml, 1.1, 1.2 Message-ID: <200701160547.l0G5l71S031360@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates In directory dev.open-bio.org:/tmp/cvs-serv31319 Modified Files: _methods.rhtml bioruby.css bioruby_controller.rb bioruby_helper.rb index.rhtml Log Message: Feature enhancements: * Input [#] is linked to action for filling textarea from history * [methods] is separated into columns for readability Fixes and improvements: * HIDE_VARIABLES is moved from helper to controller to avoid warning "already initialized constant - HIDE_VARIABLES" repeated upon reload *
is renamed to "log_#" with number for future extention *
are inserted in the
* CSS is modified and updated to follow evaluate -> log change Index: index.rhtml =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/index.rhtml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** index.rhtml 24 Dec 2006 08:27:15 -0000 1.1 --- index.rhtml 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 15,16 **** --- 15,19 ---- <%= end_form_tag %>
+
+
+ Index: bioruby_helper.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/bioruby_helper.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby_helper.rb 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby_helper.rb 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 1,8 **** module BiorubyHelper - HIDE_VARIABLES = [ - "_", "irb", "_erbout", - ] - include Bio::Shell --- 1,4 ---- *************** *** 16,20 **** def local_variables ! eval("local_variables", Bio::Shell.cache[:binding]) - HIDE_VARIABLES end --- 12,25 ---- def local_variables ! eval("local_variables", Bio::Shell.cache[:binding]) - ! BiorubyController::HIDE_VARIABLES ! end ! ! def render_log(page) ! page.insert_html :top, :logs, :partial => "log" ! page.replace_html "variables", :partial => "variables" ! page.hide "methods_#{@number}" ! page.hide "classes_#{@number}" ! page.hide "modules_#{@number}" end *************** *** 36,37 **** --- 41,43 ---- end + Index: bioruby_controller.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/bioruby_controller.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby_controller.rb 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby_controller.rb 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 1,8 **** class BiorubyController < ApplicationController ! HIDE_METHODS = Object.methods HIDE_MODULES = [ WEBrick, Base64::Deprecated, Base64, PP::ObjectMixin, ] --- 1,20 ---- class BiorubyController < ApplicationController ! HIDE_METHODS = Object.methods + [ "singleton_method_added" ] HIDE_MODULES = [ + ActiveSupport::CoreExtensions::String::Iterators, + ActiveSupport::CoreExtensions::String::StartsEndsWith, + ActiveSupport::CoreExtensions::String::Inflections, + ActiveSupport::CoreExtensions::String::Conversions, + ActiveSupport::CoreExtensions::String::Access, + ActiveSupport::CoreExtensions::Numeric::Bytes, + ActiveSupport::CoreExtensions::Numeric::Time, WEBrick, Base64::Deprecated, Base64, PP::ObjectMixin, + Bio::Shell + ] + + HIDE_VARIABLES = [ + "_", "irb", "_erbout", ] *************** *** 27,35 **** render :update do |page| ! page.insert_html :after, "console", :partial => "result" ! page.replace_html "variables", :partial => "variables" ! page.hide "methods_#{@number}" ! page.hide "classes_#{@number}" ! page.hide "modules_#{@number}" end end --- 39,43 ---- render :update do |page| ! render_log(page) end end *************** *** 37,40 **** --- 45,49 ---- def list_methods number = params[:number].to_i + script, result, output = Bio::Shell.cache[:results].restore(number) @class = result.class *************** *** 49,52 **** --- 58,62 ---- def list_classes number = params[:number].to_i + script, result, output = Bio::Shell.cache[:results].restore(number) class_name = result.class *************** *** 70,73 **** --- 80,84 ---- def list_modules number = params[:number].to_i + script, result, output = Bio::Shell.cache[:results].restore(number) @class = result.class *************** *** 80,83 **** --- 91,104 ---- end + def reload_script + number = params[:number].to_i + + script, result, output = Bio::Shell.cache[:results].restore(number) + + render :update do |page| + page.replace_html :script, script + end + end + def results if Bio::Shell.cache[:results].number > 0 *************** *** 89,93 **** render :update do |page| # delete all existing results in the current DOM for clean up ! page.select(".evaluate").each do |element| page.remove element end --- 110,115 ---- render :update do |page| # delete all existing results in the current DOM for clean up ! page.select(".log").each do |element| ! #page.hide element page.remove element end *************** *** 95,105 **** # add selected results to the current DOM min_num.upto(max_num) do |@number| @script, @result, @output = Bio::Shell.cache[:results].restore(@number) if @script ! page.insert_html :after, "console", :partial => "result" ! page.replace_html "variables", :partial => "variables" ! page.hide "methods_#{@number}" ! page.hide "classes_#{@number}" ! page.hide "modules_#{@number}" end end --- 117,124 ---- # add selected results to the current DOM min_num.upto(max_num) do |@number| + #page.show "log_#{@number}" @script, @result, @output = Bio::Shell.cache[:results].restore(@number) if @script ! render_log(page) end end Index: _methods.rhtml =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/_methods.rhtml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** _methods.rhtml 24 Dec 2006 08:27:15 -0000 1.1 --- _methods.rhtml 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 1,4 **** [ <%= @class %> ] ! <% @methods.sort.each do |x| %> ! <%= x %> ! <% end %> \ No newline at end of file --- 1,9 ---- [ <%= @class %> ] ! ! ! <%- step = @methods.size / 4 + 1 -%> ! <%- 0.step(@methods.size, step) do |i| -%> ! ! <%- end -%> ! !
<%= @methods.sort[i, step].join("
") %>
\ No newline at end of file Index: bioruby.css =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/bioruby.css,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby.css 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby.css 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 26,35 **** } ! div.evaluate div.input pre.script { background-color: #ffffeb; border-style: solid; } ! div.evaluate div.output div.methods { padding: 5px; background-color: #ffffdd; --- 26,35 ---- } ! div.log div.input pre.script { background-color: #ffffeb; border-style: solid; } ! div.log div.output div.methods { padding: 5px; background-color: #ffffdd; *************** *** 37,41 **** } ! div.evaluate div.output div.classes { padding: 5px; background-color: #ccffcc; --- 37,41 ---- } ! div.log div.output div.classes { padding: 5px; background-color: #ccffcc; *************** *** 43,47 **** } ! div.evaluate div.output div.modules { padding: 5px; background-color: #ffcccc; --- 43,47 ---- } ! div.log div.output div.modules { padding: 5px; background-color: #ffcccc; *************** *** 49,61 **** } ! div.evaluate div.output pre.result { border-style: dashed; } ! div.evaluate div.output pre.output { border-style: dashed; } ! div.evaluate hr.evaluate { border-style: dotted none none none; border-top-width: 1px; --- 49,61 ---- } ! div.log div.output pre.result { border-style: dashed; } ! div.log div.output pre.output { border-style: dashed; } ! div.log hr.result { border-style: dotted none none none; border-top-width: 1px; *************** *** 194,203 **** --- 194,209 ---- /* table */ + table#list_methods { + width: 680px; + } + th { vertical-align: top; + padding: 5px; } td { vertical-align: top; + padding: 5px; } *************** *** 205,208 **** --- 211,215 ---- textarea { + font-family: monospace; overflow: auto; } From trevor at dev.open-bio.org Mon Jan 1 00:12:56 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 00:12:56 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db rebase.rb,1.6,1.7 Message-ID: <200701010012.l010CudH000377@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db In directory dev.open-bio.org:/tmp/cvs-serv351/lib/bio/db Modified Files: rebase.rb Log Message: Index: rebase.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/rebase.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** rebase.rb 31 Dec 2006 23:22:03 -0000 1.6 --- rebase.rb 1 Jan 2007 00:12:54 -0000 1.7 *************** *** 80,83 **** --- 80,84 ---- # # pp rebase.enzymes[0..4] # ["AarI", "AasI", "AatI", "AatII", "Acc16I"] + # pp rebase.enzyme_name?('aasi') # true # pp rebase['AarI'].pattern # "CACCTGC" # pp rebase['AarI'].blunt? # false *************** *** 198,201 **** --- 199,215 ---- @data.keys.sort end + + # Check if supplied name is the name of an available enzyme + # + # --- + # *Arguments* + # * +name+: Enzyme name + # *Returns*:: +true/false+ + def enzyme_name?(name) + enzymes.each do |e| + return true if e.downcase == name.downcase + end + return false + end # Save the current data From trevor at dev.open-bio.org Mon Jan 1 00:12:56 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 00:12:56 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb,1.5,1.6 Message-ID: <200701010012.l010CuE4000382@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv351/lib/bio/util Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** restriction_enzyme.rb 31 Dec 2006 21:50:31 -0000 1.5 --- restriction_enzyme.rb 1 Jan 2007 00:12:54 -0000 1.6 *************** *** 203,227 **** # Returns a Bio::REBASE object loaded with all of the enzyme data on file. # ! #-- ! # FIXME: Use File.join ! #++ ! def self.rebase(enzymes_yaml = File.dirname(__FILE__) + '/restriction_enzyme/enzymes.yaml') ! #def self.rebase(enzymes_yaml = '/home/trevor/tmp5/bioruby/lib/bio/util/restriction_enzyme/enzymes.yaml') ! ! @@rebase_enzymes ||= Bio::REBASE.load_yaml(enzymes_yaml) @@rebase_enzymes end ! # Primitive way of determining if a string is an enzyme name. ! # ! # A nucleotide or nucleotide ! # set can't ever contain an 'i'. Restriction enzymes always end in 'i'. # ! #-- ! # FIXME: Change this to actually look up the enzyme name to see if it's valid. ! #++ # ! def self.enzyme_name?( str ) ! str[-1].chr.downcase == 'i' end --- 203,226 ---- # Returns a Bio::REBASE object loaded with all of the enzyme data on file. # ! # --- ! # *Arguments* ! # * _none_ ! # *Returns*:: Bio::REBASE ! def self.rebase ! enzymes_yaml_file = File.join(File.dirname(File.expand_path(__FILE__)), 'restriction_enzyme', 'enzymes.yaml') ! @@rebase_enzymes ||= Bio::REBASE.load_yaml(enzymes_yaml_file) @@rebase_enzymes end ! # Check if supplied name is the name of an available enzyme # ! # See Bio::REBASE.enzyme_name? # ! # --- ! # *Arguments* ! # * +name+: Enzyme name ! # *Returns*:: +true/false+ ! def self.enzyme_name?( name ) ! self.rebase.enzyme_name?(name) end From trevor at dev.open-bio.org Mon Jan 1 00:12:56 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 00:12:56 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db test_rebase.rb,1.3,1.4 Message-ID: <200701010012.l010Cu3C000387@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db In directory dev.open-bio.org:/tmp/cvs-serv351/test/unit/bio/db Modified Files: test_rebase.rb Log Message: Index: test_rebase.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/test_rebase.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_rebase.rb 31 Dec 2006 18:46:14 -0000 1.3 --- test_rebase.rb 1 Jan 2007 00:12:54 -0000 1.4 *************** *** 90,93 **** --- 90,98 ---- assert_equal(a['AatI'].supplier_names, ['Toyobo Biochemicals']) assert_equal(a['AatI'].suppliers, ['O']) + + assert_equal(a.enzyme_name?('aasi'), true) + assert_equal(a.enzyme_name?('AarI'), true) + assert_equal(a.enzyme_name?('Aari'), true) + assert_equal(a.enzyme_name?('AbrI'), false) end From trevor at dev.open-bio.org Mon Jan 1 00:12:56 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 00:12:56 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util test_restriction_enzyme.rb, 1.1, 1.2 Message-ID: <200701010012.l010CubO000392@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util In directory dev.open-bio.org:/tmp/cvs-serv351/test/unit/bio/util Modified Files: test_restriction_enzyme.rb Log Message: Index: test_restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/test_restriction_enzyme.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_restriction_enzyme.rb 31 Dec 2006 23:50:34 -0000 1.1 --- test_restriction_enzyme.rb 1 Jan 2007 00:12:54 -0000 1.2 *************** *** 35,39 **** assert_equal(@t.enzyme_name?('aari'), true) assert_equal(@t.enzyme_name?('EcoRI'), true) ! assert_equal(@t.enzyme_name?('EcoooRI'), true) # FIXME should actually be false end --- 35,39 ---- assert_equal(@t.enzyme_name?('aari'), true) assert_equal(@t.enzyme_name?('EcoRI'), true) ! assert_equal(@t.enzyme_name?('EcoooRI'), false) end From trevor at dev.open-bio.org Mon Jan 1 02:16:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 02:16:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis cut_ranges.rb, 1.2, 1.3 sequence_range.rb, 1.2, 1.3 tags.rb, 1.2, 1.3 Message-ID: <200701010216.l012G7TL000545@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv512/lib/bio/util/restriction_enzyme/analysis Modified Files: cut_ranges.rb sequence_range.rb tags.rb Log Message: Index: tags.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/tags.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tags.rb 31 Dec 2006 21:50:31 -0000 1.2 --- tags.rb 1 Jan 2007 02:16:05 -0000 1.3 *************** *** 5,9 **** #require 'bio/util/restriction_enzyme/analysis/shared_information' ! require 'bio' module Bio; end --- 5,9 ---- #require 'bio/util/restriction_enzyme/analysis/shared_information' ! #require 'bio' module Bio; end Index: cut_ranges.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/cut_ranges.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_ranges.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_ranges.rb 1 Jan 2007 02:16:05 -0000 1.3 *************** *** 12,20 **** $:.unshift(libpath) unless $:.include?(libpath) ! require 'bio' module Bio; end class Bio::RestrictionEnzyme class Analysis # --- 12,21 ---- $:.unshift(libpath) unless $:.include?(libpath) ! #require 'bio' module Bio; end class Bio::RestrictionEnzyme class Analysis + #class Analysis # Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/sequence_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sequence_range.rb 31 Dec 2006 21:50:31 -0000 1.2 --- sequence_range.rb 1 Jan 2007 02:16:05 -0000 1.3 *************** *** 12,16 **** $:.unshift(libpath) unless $:.include?(libpath) - require 'bio/util/restriction_enzyme/analysis/tags' require 'bio/util/restriction_enzyme/analysis/cut_ranges' require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range' --- 12,15 ---- From trevor at dev.open-bio.org Mon Jan 1 02:16:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 02:16:07 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_cut_symbol.rb, NONE, 1.1 test_double_stranded.rb, 1.2, 1.3 Message-ID: <200701010216.l012G7AU000550@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv512/test/unit/bio/util/restriction_enzyme Modified Files: test_double_stranded.rb Added Files: test_cut_symbol.rb Log Message: Index: test_double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_double_stranded.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_double_stranded.rb 31 Dec 2006 18:46:14 -0000 1.2 --- test_double_stranded.rb 1 Jan 2007 02:16:05 -0000 1.3 *************** *** 106,113 **** end - def test_index_error - assert_raise(IndexError) { @t.new('EzzRII') } - end - # NOTE def test_to_re --- 106,109 ---- --- NEW FILE: test_cut_symbol.rb --- # # test/unit/bio/util/restriction_enzyme/test_cut_symbol.rb - Unit test for Bio::RestrictionEnzyme::CutSymbol # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: test_cut_symbol.rb,v 1.1 2007/01/01 02:16:05 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'test/unit' require 'bio/util/restriction_enzyme/cut_symbol' module Bio #:nodoc: class TestStringFormatting < Test::Unit::TestCase #:nodoc: include Bio::RestrictionEnzyme::CutSymbol def setup end def test_methods assert_equal('^', cut_symbol) assert_equal('|', set_cut_symbol('|')) assert_equal('|', cut_symbol) assert_equal('\\|', escaped_cut_symbol) assert_equal(/\|/, re_cut_symbol) assert_equal('^', set_cut_symbol('^')) assert_equal(3, "abc^de" =~ re_cut_symbol) assert_equal(nil, "abc^de" =~ re_cut_symbol_adjacent) assert_equal(3, "abc^^de" =~ re_cut_symbol_adjacent) assert_equal(4, "a^bc^^de" =~ re_cut_symbol_adjacent) assert_equal(nil, "a^bc^de" =~ re_cut_symbol_adjacent) end end end From trevor at dev.open-bio.org Mon Jan 1 02:16:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 02:16:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb,1.6,1.7 Message-ID: <200701010216.l012G7EC000538@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv512/lib/bio/util Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** restriction_enzyme.rb 1 Jan 2007 00:12:54 -0000 1.6 --- restriction_enzyme.rb 1 Jan 2007 02:16:05 -0000 1.7 *************** *** 187,195 **** extend CutSymbol - # [+users_enzyme_or_rebase_or_pattern+] One of three possible parameters: The name of an enzyme, a REBASE::EnzymeEntry object, or a nucleotide pattern with a cut mark. - # [+cut_locations+] The cut locations in enzyme index notation. - # # See Bio::RestrictionEnzyme::DoubleStranded.new for more information. # #-- # Factory for DoubleStranded --- 187,197 ---- extend CutSymbol # See Bio::RestrictionEnzyme::DoubleStranded.new for more information. # + # --- + # *Arguments* + # * +users_enzyme_or_rebase_or_pattern+: One of three possible parameters: The name of an enzyme, a REBASE::EnzymeEntry object, or a nucleotide pattern with a cut mark. + # * +cut_locations+: The cut locations in enzyme index notation. + # *Returns*:: Bio::RestrictionEnzyme::DoubleStranded #-- # Factory for DoubleStranded From trevor at dev.open-bio.org Mon Jan 1 02:16:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 02:16:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.6, 1.7 cut_symbol.rb, 1.2, 1.3 Message-ID: <200701010216.l012G79V000541@dev.open-bio.org> 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 --- 1,4 ---- # ! # bio/util/restrction_enzyme/cut_symbol.rb - Defines the symbol used to mark a cut in an enzyme sequence # # Author:: Trevor Wennblom *************** *** 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 --- 15,19 ---- # ! # bio/util/restrction_enzyme/cut_symbol.rb - Defines the symbol used to mark a cut in an enzyme sequence # # Author:: Trevor Wennblom *************** *** 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 From trevor at dev.open-bio.org Mon Jan 1 02:31:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 02:31:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb,1.7,1.8 Message-ID: <200701010231.l012VONX000650@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv628 Modified Files: restriction_enzyme.rb Log Message: Removed skeleton code of tags feature in RestrictionEnzyme. Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** restriction_enzyme.rb 1 Jan 2007 02:16:05 -0000 1.7 --- restriction_enzyme.rb 1 Jan 2007 02:31:22 -0000 1.8 *************** *** 222,226 **** # *Arguments* # * +name+: Enzyme name ! # *Returns*:: +true/false+ def self.enzyme_name?( name ) self.rebase.enzyme_name?(name) --- 222,226 ---- # *Arguments* # * +name+: Enzyme name ! # *Returns*:: +true+ _or_ +false+ def self.enzyme_name?( name ) self.rebase.enzyme_name?(name) From trevor at dev.open-bio.org Mon Jan 1 02:31:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 02:31:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis fragment.rb, 1.2, 1.3 sequence_range.rb, 1.3, 1.4 tags.rb, 1.3, NONE Message-ID: <200701010231.l012VOUb000655@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv628/restriction_enzyme/analysis Modified Files: fragment.rb sequence_range.rb Removed Files: tags.rb Log Message: Removed skeleton code of tags feature in RestrictionEnzyme. --- tags.rb DELETED --- Index: fragment.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/fragment.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** fragment.rb 31 Dec 2006 21:50:31 -0000 1.2 --- fragment.rb 1 Jan 2007 02:31:22 -0000 1.3 *************** *** 12,16 **** $:.unshift(libpath) unless $:.include?(libpath) - require 'bio/util/restriction_enzyme/analysis/tags' require 'bio/util/restriction_enzyme/analysis/cut_ranges' require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range' --- 12,15 ---- *************** *** 31,46 **** attr_reader :size - # attr_reader :tags def initialize( primary_bin, complement_bin ) - # @tags = [] @primary_bin = primary_bin @complement_bin = complement_bin end - # def add_tag( index, info=nil ) - # @tags[index] = info - # end - DisplayFragment = Struct.new(:primary, :complement) --- 30,39 ---- Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/sequence_range.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sequence_range.rb 1 Jan 2007 02:16:05 -0000 1.3 --- sequence_range.rb 1 Jan 2007 02:31:22 -0000 1.4 *************** *** 37,41 **** attr_reader :left, :right attr_reader :size - attr_reader :tags attr_reader :cut_ranges --- 37,40 ---- *************** *** 62,66 **** @size = (@right - @left) + 1 unless @left == nil or @right == nil - @tags = Tags.new @cut_ranges = CutRanges.new end --- 61,64 ---- *************** *** 158,162 **** bins.sort.each do |k, bin| fragment = Fragment.new( bin.p, bin.c ) - @tags.each { |k,v| fragment.add_tag(k,v) if (ts.left..ts.right).include?(k) } fragments << fragment end --- 156,159 ---- *************** *** 169,179 **** return fragments end - - def add_tag( index, info=nil ) - @__fragments_current = false - - raise IndexError unless index >= @left and index <= @right - @tags[index] = info - end # Cut occurs immediately after the index supplied. --- 166,169 ---- From trevor at dev.open-bio.org Mon Jan 1 03:36:39 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 03:36:39 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme single_strand.rb, 1.2, 1.3 string_formatting.rb, 1.2, 1.3 Message-ID: <200701010336.l013ad4R000750@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv728/lib/bio/util/restriction_enzyme Modified Files: single_strand.rb string_formatting.rb Log Message: Index: string_formatting.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/string_formatting.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** string_formatting.rb 31 Dec 2006 21:50:31 -0000 1.2 --- string_formatting.rb 1 Jan 2007 03:36:37 -0000 1.3 *************** *** 33,41 **** # Example: # pattern = 'n^ng^arraxt^n' ! # add_spacing( pattern ) # ! # Returns: ! # "n^n g^a r r a x t^n" # def add_spacing( seq, cs = cut_symbol ) str = '' --- 33,49 ---- # Example: # pattern = 'n^ng^arraxt^n' ! # add_spacing( pattern ) # => "n^n g^a r r a x t^n" # ! # --- ! # *Arguments* ! # * +seq+: sequence with cut symbols ! # * +cs+: (_optional_) Cut symbol along the string. The reason this is ! # definable outside of CutSymbol is that this is a utility function used ! # to form vertical and horizontal cuts such as: # + # a|t g c + # +---+ + # t a c|g + # *Returns*:: +String+ sequence with single character distance between bases def add_spacing( seq, cs = cut_symbol ) str = '' *************** *** 58,61 **** --- 66,74 ---- # Remove extraneous nucleic acid wildcards ('n' padding) from the # left and right sides + # + # --- + # *Arguments* + # * +s+: sequence with extraneous 'n' padding + # *Returns*:: +String+ sequence without 'n' padding on the sides def strip_padding( s ) if s[0].chr == 'n' *************** *** 72,75 **** --- 85,93 ---- # Remove extraneous nucleic acid wildcards ('n' padding) from the # left and right sides and remove cut symbols + # + # --- + # *Arguments* + # * +s+: sequence with extraneous 'n' padding and cut symbols + # *Returns*:: +String+ sequence without 'n' padding on the sides or cut symbols def strip_cuts_and_padding( s ) strip_padding( s.tr(cut_symbol, '') ) *************** *** 77,80 **** --- 95,103 ---- # Return the 'n' padding on the left side of the strand + # + # --- + # *Arguments* + # * +s+: sequence with extraneous 'n' padding on the left side of the strand + # *Returns*:: +String+ the 'n' padding from the left side def left_padding( s ) s =~ %r{^n+} *************** *** 84,87 **** --- 107,115 ---- # Return the 'n' padding on the right side of the strand + # + # --- + # *Arguments* + # * +s+: sequence with extraneous 'n' padding on the right side of the strand + # *Returns*:: +String+ the 'n' padding from the right side def right_padding( s ) s =~ %r{n+$} Index: single_strand.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/single_strand.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** single_strand.rb 31 Dec 2006 21:50:31 -0000 1.2 --- single_strand.rb 1 Jan 2007 03:36:37 -0000 1.3 *************** *** 17,20 **** --- 17,21 ---- require 'bio/sequence' + module Bio; end class Bio::RestrictionEnzyme *************** *** 37,45 **** # The cut locations in enzyme notation. Contains a ! # CutLocationsInEnzymeNotation object. attr_reader :cut_locations_in_enzyme_notation # The cut locations transformed from enzyme index notation to 0-based ! # array index notation. Contains an Array attr_reader :cut_locations --- 38,47 ---- # The cut locations in enzyme notation. Contains a ! # CutLocationsInEnzymeNotation object set when the SingleStrand ! # object is initialized. attr_reader :cut_locations_in_enzyme_notation # The cut locations transformed from enzyme index notation to 0-based ! # array index notation. Contains an Array. attr_reader :cut_locations *************** *** 47,58 **** def orientation; [5,3]; end ! # +sequence+:: The enzyme sequence. ! # +c+:: Cut locations in enzyme notation. See CutLocationsInEnzymeNotation. # ! # * +sequence+ is required, +c+ is optional ! # * You cannot provide a sequence with cut symbols and provide cut locations. ! # * If +c+ is omitted, +input_pattern+ must contain a cut symbol. ! # * +sequence+ cannot contain adjacent cut symbols. # * +c+ is in enzyme index notation and therefore cannot contain a 0. # # +sequence+ must be a kind of: --- 49,67 ---- def orientation; [5,3]; end ! # Constructor for a Bio::RestrictionEnzyme::StingleStrand object. # ! # A single strand of restriction enzyme sequence pattern with a 5' to 3' orientation. ! # ! # --- ! # *Arguments* ! # * +sequence+: (_required_) The enzyme sequence. ! # * +c+: (_optional_) Cut locations in enzyme notation. ! # See Bio::RestrictionEnzyme::SingleStrand::CutLocationsInEnzymeNotation ! # ! # *Constraints* ! # * +sequence+ cannot contain immediately adjacent cut symbols (ex. atg^^c). # * +c+ is in enzyme index notation and therefore cannot contain a 0. + # * If +c+ is omitted, +sequence+ must contain a cut symbol. + # * You cannot provide both a sequence with cut symbols and provide cut locations - ambiguous. # # +sequence+ must be a kind of: *************** *** 62,69 **** # # +c+ must be a kind of: # * Integer, one or more # * Array - # * CutLocationsInEnzymeNotation # def initialize( sequence, *c ) c.flatten! # if an array was supplied as an argument --- 71,79 ---- # # +c+ must be a kind of: + # * Bio::RestrictionEnzyme::SingleStrand::CutLocationsInEnzymeNotation # * Integer, one or more # * Array # + # *Returns*:: nothing def initialize( sequence, *c ) c.flatten! # if an array was supplied as an argument *************** *** 80,83 **** --- 90,94 ---- super( pattern ) @cut_locations = @cut_locations_in_enzyme_notation.to_array_index + return end *************** *** 94,107 **** # TACGCAT # def palindromic? @stripped.reverse_complement == @stripped end ! # Pattern with no cut symbols and no 'n' padding. ! # * SingleStrand.new('garraxt', [-2, 1, 7]).stripped # "garraxt" attr_reader :stripped # The sequence with 'n' padding and cut symbols. # * SingleStrand.new('garraxt', [-2, 1, 7]).with_cut_symbols # => "n^ng^arraxt^n" def with_cut_symbols s = pattern --- 105,127 ---- # TACGCAT # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +true+ _or_ +false+ def palindromic? @stripped.reverse_complement == @stripped end ! # Sequence pattern with no cut symbols and no 'n' padding. ! # * SingleStrand.new('garraxt', [-2, 1, 7]).stripped # => "garraxt" attr_reader :stripped # The sequence with 'n' padding and cut symbols. # * SingleStrand.new('garraxt', [-2, 1, 7]).with_cut_symbols # => "n^ng^arraxt^n" + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: The sequence with 'n' padding and cut symbols. def with_cut_symbols s = pattern *************** *** 112,115 **** --- 132,140 ---- # The sequence with 'n' padding on the left and right for cuts larger than the sequence. # * SingleStrand.new('garraxt', [-2, 1, 7]).pattern # => "nngarraxtn" + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: The sequence with 'n' padding on the left and right for cuts larger than the sequence. def pattern return stripped if @cut_locations_in_enzyme_notation.min == nil *************** *** 117,121 **** # Add one more 'n' if a cut is at the last position ! right = (@cut_locations_in_enzyme_notation.max >= @stripped.length ? 'n' * (@cut_locations_in_enzyme_notation.max - @stripped.length + 1) : '') [left, stripped, right].to_s end --- 142,146 ---- # Add one more 'n' if a cut is at the last position ! right = ( (@cut_locations_in_enzyme_notation.max >= @stripped.length) ? ('n' * (@cut_locations_in_enzyme_notation.max - @stripped.length + 1)) : '') [left, stripped, right].to_s end *************** *** 123,139 **** # The sequence with 'n' pads, cut symbols, and spacing for alignment. # * SingleStrand.new('garraxt', [-2, 1, 7]).with_spaces # => "n^n g^a r r a x t^n" def with_spaces add_spacing( with_cut_symbols ) end - # FIXME recheck this - # NOTE: BEING WORKED ON, BUG EXISTS IN Bio::NucleicAcid - =begin - to_re - important - example z = [agc] - z must match [agcz] - not just [agc] - =end - ######### protected --- 148,160 ---- # The sequence with 'n' pads, cut symbols, and spacing for alignment. # * SingleStrand.new('garraxt', [-2, 1, 7]).with_spaces # => "n^n g^a r r a x t^n" + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: The sequence with 'n' pads, cut symbols, and spacing for alignment. def with_spaces add_spacing( with_cut_symbols ) end ######### protected *************** *** 142,146 **** def validate_args( input_pattern, input_cut_locations ) unless input_pattern.kind_of?(String) ! err = "input_pattern is not a String, Bio::Sequence::NA, or Bio::RestrictionEnzyme::SingleStrand::Sequence object\n" err += "pattern: #{input_pattern}\n" err += "class: #{input_pattern.class}" --- 163,167 ---- def validate_args( input_pattern, input_cut_locations ) unless input_pattern.kind_of?(String) ! err = "input_pattern is not a String, Bio::Sequence::NA, or Bio::RestrictionEnzyme::SingleStrand object\n" err += "pattern: #{input_pattern}\n" err += "class: #{input_pattern.class}" From trevor at dev.open-bio.org Mon Jan 1 03:36:39 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 03:36:39 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/single_strand cut_locations_in_enzyme_notation.rb, 1.2, 1.3 Message-ID: <200701010336.l013adxq000756@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/single_strand In directory dev.open-bio.org:/tmp/cvs-serv728/lib/bio/util/restriction_enzyme/single_strand Modified Files: cut_locations_in_enzyme_notation.rb Log Message: Index: cut_locations_in_enzyme_notation.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_locations_in_enzyme_notation.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_locations_in_enzyme_notation.rb 1 Jan 2007 03:36:37 -0000 1.3 *************** *** 33,36 **** --- 33,42 ---- # # Enzyme index notation:: 1.._n_, value before 1 is -1 + # + # example:: [-3][-2][-1][1][2][3][4][5] + # + # Negative values are used to indicate when a cut may occur at a specified + # distance before the sequence begins. This would be padded with 'n' + # nucleotides to represent wildcards. # # Notes: *************** *** 38,43 **** # * +nil+ is not allowed here as it has no meaning # * +nil+ values are kept track of in DoubleStranded::CutLocations as they ! # need a reference point on the correlating strand. +nil+ represents no ! # cut or a partial digestion. # class CutLocationsInEnzymeNotation < Array --- 44,50 ---- # * +nil+ is not allowed here as it has no meaning # * +nil+ values are kept track of in DoubleStranded::CutLocations as they ! # need a reference point on the correlating strand. In ! # DoubleStranded::CutLocations +nil+ represents no cut or a partial ! # digestion. # class CutLocationsInEnzymeNotation < Array *************** *** 45,55 **** extend CutSymbol ! attr_reader :min, :max def initialize(*a) a.flatten! # in case an array was passed as an argument if a.size == 1 and a[0].kind_of? String and a[0] =~ re_cut_symbol ! # Initialize with a cut symbol pattern such as 'n^ng^arraxt^n' s = a[0] a = [] --- 52,77 ---- extend CutSymbol ! # First cut, in enzyme-index notation ! attr_reader :min ! ! # Last cut, in enzyme-index notation ! attr_reader :max + # Constructor for CutLocationsInEnzymeNotation + # + # --- + # *Arguments* + # * +a+: Locations of cuts represented as a string with cuts or an array of values + # Examples: + # * n^ng^arraxt^n + # * 2 + # * -1, 5 + # * [-1, 5] + # *Returns*:: nothing def initialize(*a) a.flatten! # in case an array was passed as an argument if a.size == 1 and a[0].kind_of? String and a[0] =~ re_cut_symbol ! # Initialize with a cut symbol pattern such as 'n^ng^arraxt^n' s = a[0] a = [] *************** *** 78,81 **** --- 100,107 ---- # [ -2, 1, 3 ] -> [ 0, 2, 4 ] # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of cuts in 0-based index notation def to_array_index return [] if @min == nil From trevor at dev.open-bio.org Mon Jan 1 05:07:06 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 05:07:06 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme cut_symbol.rb, 1.3, 1.4 double_stranded.rb, 1.2, 1.3 Message-ID: <200701010507.l01576ei000879@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv855/lib/bio/util/restriction_enzyme Modified Files: cut_symbol.rb double_stranded.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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cut_symbol.rb 1 Jan 2007 02:16:05 -0000 1.3 --- cut_symbol.rb 1 Jan 2007 05:07:04 -0000 1.4 *************** *** 91,95 **** ######### ! protected ######### --- 91,95 ---- ######### ! #protected # NOTE this is a Module, can't hide CutSymbol__ ######### Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** double_stranded.rb 31 Dec 2006 21:50:31 -0000 1.2 --- double_stranded.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 31,41 **** # License:: Distributes under the same terms as Ruby # ! # A pair of +SingleStrand+ and +SingleStrandComplement+ objects with methods to # add utility to their relation. # # = Notes ! # * This is created by Bio::RestrictionEnzyme.new for convenience. ! # * The two strands accessible are +primary+ and +complement+. ! # * SingleStrand methods may be used on DoubleStranded and they will be passed to +primary+. # class DoubleStranded --- 31,41 ---- # License:: Distributes under the same terms as Ruby # ! # A pair of SingleStrand and SingleStrandComplement objects with methods to # add utility to their relation. # # = Notes ! # * This is created by Bio::RestrictionEnzyme.new for convenience. ! # * The two strands accessible are +primary+ and +complement+. ! # * SingleStrand methods may be used on DoubleStranded and they will be passed to +primary+. # class DoubleStranded From trevor at dev.open-bio.org Mon Jan 1 05:07:06 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 05:07:06 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis calculated_cuts.rb, 1.2, 1.3 Message-ID: <200701010507.l01576Wx000883@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv855/lib/bio/util/restriction_enzyme/analysis Modified Files: calculated_cuts.rb Log Message: Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/calculated_cuts.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** calculated_cuts.rb 31 Dec 2006 21:50:31 -0000 1.2 --- calculated_cuts.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 135,141 **** def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current ! vcs = '|' ! hcs = '-' ! vhcs = '+' num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } --- 135,141 ---- def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current ! vcs = '|' # Vertical cut symbol ! hcs = '-' # Horizontal cut symbol ! vhcs = '+' # Intersection of vertical and horizontal cut symbol num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } *************** *** 174,193 **** end - =begin - def vc_primary_add(c) - @vc_primary << c - @current = false - end - - def vc_complement_add(c) - @vc_complement << c - @current = false - end - - def hc_between_strands_add(c) - @hc_between_strands << c - @current = false - end - =end ######### protected --- 174,177 ---- From trevor at dev.open-bio.org Mon Jan 1 05:07:06 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 05:07:06 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/double_stranded aligned_strands.rb, 1.2, 1.3 cut_location_pair.rb, 1.2, 1.3 cut_location_pair_in_enzyme_notation.rb, 1.2, 1.3 cut_locations.rb, 1.2, 1.3 cut_locations_in_enzyme_notation.rb, 1.2, 1.3 Message-ID: <200701010507.l01576Zk000886@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded In directory dev.open-bio.org:/tmp/cvs-serv855/lib/bio/util/restriction_enzyme/double_stranded Modified Files: aligned_strands.rb cut_location_pair.rb cut_location_pair_in_enzyme_notation.rb cut_locations.rb cut_locations_in_enzyme_notation.rb Log Message: Index: aligned_strands.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** aligned_strands.rb 31 Dec 2006 21:50:31 -0000 1.2 --- aligned_strands.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - Align two SingleStrand objects # # Author:: Trevor Wennblom *************** *** 21,25 **** # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - # # Author:: Trevor Wennblom --- 21,25 ---- # ! # bio/util/restrction_enzyme/double_stranded/aligned_strands.rb - Align two SingleStrand objects # # Author:: Trevor Wennblom *************** *** 27,31 **** # License:: Distributes under the same terms as Ruby # ! # Align two SingleStrand::Pattern objects and return a Result # object with +primary+ and +complement+ accessors. # --- 27,31 ---- # License:: Distributes under the same terms as Ruby # ! # Align two SingleStrand objects and return a Result # object with +primary+ and +complement+ accessors. # *************** *** 37,53 **** Result = Struct.new(:primary, :complement) ! # Pad and align two String objects. # ! # +a+:: First String ! # +b+:: Second String # ! # Example invocation: ! # AlignedStrands.align('nngattacannnnn', 'nnnnnctaatgtnn') # ! # Example return value: ! # # # def self.align(a, b) a = a.to_s --- 37,60 ---- Result = Struct.new(:primary, :complement) ! # Pad and align two String objects without cut symbols. # ! # This will look for the sub-sequence without left and right 'n' padding ! # and re-apply 'n' padding to both strings on both sides equal to the ! # maximum previous padding on that side. # ! # The sub-sequences stripped of left and right 'n' padding must be of equal ! # length. # ! # Example: ! # AlignedStrands.align('nngattacannnnn', 'nnnnnctaatgtnn') # => ! # # + # --- + # *Arguments* + # * +a+: Primary strand + # * +b+: Complementary strand + # *Returns*:: +Result+ object with equal padding on both strings def self.align(a, b) a = a.to_s *************** *** 64,79 **** # Pad and align two String objects with cut symbols. # ! # +a+:: First String ! # +b+:: Second String ! # +a_cuts+:: First strand cut locations in 0-based index notation ! # +b_cuts+:: Second strand cut locations in 0-based index notation ! # ! # Example invocation: ! # AlignedStrands.with_cuts('nngattacannnnn', 'nnnnnctaatgtnn', [0, 10, 12], [0, 2, 12]) ! # ! # Example return value: ! # # # # Notes: --- 71,79 ---- # Pad and align two String objects with cut symbols. # ! # Example: ! # AlignedStrands.with_cuts('nngattacannnnn', 'nnnnnctaatgtnn', [0, 10, 12], [0, 2, 12]) # => ! # # # Notes: *************** *** 81,86 **** # * This is meant to be able to handle multiple cuts and completely # unrelated cutsites on the two strands, therefore no biological ! # shortcuts are made. # def self.align_with_cuts(a,b,a_cuts,b_cuts) a = a.to_s --- 81,96 ---- # * This is meant to be able to handle multiple cuts and completely # unrelated cutsites on the two strands, therefore no biological ! # algorithm assumptions (shortcuts) are made. ! # ! # The sequences stripped of left and right 'n' padding must be of equal ! # length. # + # --- + # *Arguments* + # * +a+: Primary sequence + # * +b+: Complementary sequence + # * +a_cuts+: Primary strand cut locations in 0-based index notation + # * +b_cuts+: Complementary strand cut locations in 0-based index notation + # *Returns*:: +Result+ object with equal padding on both strings and spacing between bases def self.align_with_cuts(a,b,a_cuts,b_cuts) a = a.to_s Index: cut_locations.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_locations.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_locations.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_locations.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - Contains an Array of CutLocationPair objects # # Author:: Trevor Wennblom *************** *** 19,23 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - # # Author:: Trevor Wennblom --- 19,23 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations.rb - Contains an Array of CutLocationPair objects # # Author:: Trevor Wennblom *************** *** 25,30 **** --- 25,45 ---- # License:: Distributes under the same terms as Ruby # + # Contains an +Array+ of CutLocationPair objects. + # class CutLocations < Array + # CutLocations constructor. + # + # Contains an +Array+ of CutLocationPair objects. + # + # Example: + # clp1 = CutLocationPair.new(3,2) + # clp2 = CutLocationPair.new(7,9) + # pairs = CutLocations.new(clp1, clp2) + # + # --- + # *Arguments* + # * +args+: Any number of +CutLocationPair+ objects + # *Returns*:: nothing def initialize(*args) validate_args(args) *************** *** 32,39 **** --- 47,66 ---- end + # Returns an +Array+ of locations of cuts on the primary strand + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the primary strand def primary self.collect {|a| a[0]} end + # Returns an +Array+ of locations of cuts on the complementary strand + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the complementary strand def complement self.collect {|a| a[1]} Index: cut_locations_in_enzyme_notation.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_locations_in_enzyme_notation.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_locations_in_enzyme_notation.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - Inherits from DoubleStrand::CutLocations # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb - Inherits from DoubleStrand::CutLocations # # Author:: Trevor Wennblom *************** *** 26,39 **** --- 26,64 ---- # License:: Distributes under the same terms as Ruby # + # Inherits from DoubleStranded::CutLocations. Contains CutLocationPairInEnzymeNotation objects. + # Adds helper methods to convert from enzyme index notation to 0-based array index notation. + # class CutLocationsInEnzymeNotation < CutLocations + # Returns +Array+ of locations of cuts on the primary + # strand in 0-based array index notation. + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the primary strand in 0-based array index notation. def primary_to_array_index helper_for_to_array_index(self.primary) end + # Returns +Array+ of locations of cuts on the complementary + # strand in 0-based array index notation. + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +Array+ of locations of cuts on the complementary strand in 0-based array index notation. def complement_to_array_index helper_for_to_array_index(self.complement) end + # Returns the contents of the present CutLocationsInEnzymeNotation object as + # a CutLocations object with the contents converted from enzyme notation + # to 0-based array index notation. + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: +CutLocations+ def to_array_index unless self.primary_to_array_index.size == self.complement_to_array_index.size Index: cut_location_pair_in_enzyme_notation.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_location_pair_in_enzyme_notation.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_location_pair_in_enzyme_notation.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - Inherits from DoubleStranded::CutLocationPair # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb - Inherits from DoubleStranded::CutLocationPair # # Author:: Trevor Wennblom *************** *** 26,30 **** # License:: Distributes under the same terms as Ruby # ! # See CutLocationPair # class CutLocationPairInEnzymeNotation < CutLocationPair --- 26,31 ---- # License:: Distributes under the same terms as Ruby # ! # Inherits from DoubleStranded::CutLocationPair , stores the cut location pair in ! # enzyme notation instead of 0-based. # class CutLocationPairInEnzymeNotation < CutLocationPair *************** *** 35,43 **** def validate_2( a, b ) ! if a == 0 ! raise ArgumentError, "Enzyme index notation only. 0 values are illegal." ! end ! ! if b == 0 raise ArgumentError, "Enzyme index notation only. 0 values are illegal." end --- 36,40 ---- def validate_2( a, b ) ! if (a == 0) or (b == 0) raise ArgumentError, "Enzyme index notation only. 0 values are illegal." end Index: cut_location_pair.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_location_pair.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_location_pair.rb 1 Jan 2007 05:07:04 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - Stores a cut location pair in 0-based index notation # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/double_stranded/cut_location_pair.rb - Stores a cut location pair in 0-based index notation # # Author:: Trevor Wennblom *************** *** 26,48 **** # License:: Distributes under the same terms as Ruby # ! # Stores a cut location pair in 0-based index notation ! # ! # Input: ! # +pair+:: May be two values represented as an Array, a Range, or a ! # combination of Integer and nil values. The first value ! # represents a cut on the primary strand, the second represents ! # a cut on the complement strand. ! # ! # Example: ! # clp = CutLocationPair.new(3,2) ! # clp.primary # 3 ! # clp.complement # 2 ! # ! # Notes: ! # * a value of +nil+ is an explicit representation of 'no cut' # class CutLocationPair < Array ! attr_reader :primary, :complement def initialize( *pair ) a = b = nil --- 26,60 ---- # License:: Distributes under the same terms as Ruby # ! # Stores a single cut location pair in 0-based index notation for use with ! # DoubleStranded enzyme sequences. # class CutLocationPair < Array ! # Location of the cut on the primary strand. ! # Corresponds - or 'pairs' - to the complement cut. ! # A value of +nil+ is an explicit representation of 'no cut'. ! attr_reader :primary ! ! # Location of the cut on the complementary strand. ! # Corresponds - or 'pairs' - to the primary cut. ! # A value of +nil+ is an explicit representation of 'no cut'. ! attr_reader :complement + # CutLocationPair constructor. + # + # Stores a single cut location pair in 0-based index notation for use with + # DoubleStranded enzyme sequences. + # + # Example: + # clp = CutLocationPair.new(3,2) + # clp.primary # 3 + # clp.complement # 2 + # + # --- + # *Arguments* + # * +pair+: May be two values represented as an Array, a Range, or a + # combination of Integer and nil values. The first value + # represents a cut on the primary strand, the second represents + # a cut on the complement strand. + # *Returns*:: nothing def initialize( *pair ) a = b = nil *************** *** 64,67 **** --- 76,80 ---- @primary = a @complement = b + return end *************** *** 85,93 **** def validate_2( a, b ) ! if a != nil and a.negative? ! raise ArgumentError, "0-based index notation only. Negative values are illegal." ! end ! ! if b != nil and b.negative? raise ArgumentError, "0-based index notation only. Negative values are illegal." end --- 98,102 ---- def validate_2( a, b ) ! if (a != nil and a.negative?) or (b != nil and b.negative?) raise ArgumentError, "0-based index notation only. Negative values are illegal." end From trevor at dev.open-bio.org Mon Jan 1 23:47:30 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 23:47:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis_basic.rb, NONE, 1.1 analysis.rb, 1.7, 1.8 double_stranded.rb, 1.3, 1.4 Message-ID: <200701012347.l01NlUaJ002435@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv2413/restriction_enzyme Modified Files: analysis.rb double_stranded.rb Added Files: analysis_basic.rb Log Message: --- NEW FILE: analysis_basic.rb --- # # bio/util/restrction_enzyme/analysis_basic.rb - Does the work of fragmenting the DNA from the enzymes # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: analysis_basic.rb,v 1.1 2007/01/01 23:47:27 trevor Exp $ # #-- #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 $:.unshift(libpath) unless $:.include?(libpath) require 'bio' class Bio::Sequence::NA # Example: # # seq = Bio::Sequence::NA.new('gaattc') # cuts = seq.cut_with_enzyme('EcoRI') # # _or_ # # seq = Bio::Sequence::NA.new('gaattc') # cuts = seq.cut_with_enzyme('g^aattc') # --- # See Bio::RestrictionEnzyme::Analysis.cut def cut_with_enzyme(*args) Bio::RestrictionEnzyme::Analysis.cut(self, *args) end alias cut_with_enzymes cut_with_enzyme end require 'pp' require 'bio/util/restriction_enzyme' require 'bio/util/restriction_enzyme/analysis/sequence_range' class Bio::RestrictionEnzyme # # bio/util/restrction_enzyme/analysis_basic.rb - Does the work of fragmenting the DNA from the enzymes # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class Analysis 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]) sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| sr_with_cuts.add_cut_range(cut_range) end end sr_with_cuts.fragments.primary = sequence sr_with_cuts.fragments.complement = sequence.forward_complement unique_fragments_for_display( {0 => sr_with_cuts} ) end ######### protected ######### UniqueFragment = Struct.new(:primary, :complement) class UniqueFragments < Array def primary tmp = [] self.each { |uf| tmp << uf.primary } tmp.sort.map { |e| e.tr(' ', '') } end def complement tmp = [] self.each { |uf| tmp << uf.complement } tmp.sort.map { |e| e.tr(' ', '') } end end def unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) uf_ary = UniqueFragments.new return uf_ary if hash_of_sequence_ranges_with_cuts == nil or hash_of_sequence_ranges_with_cuts.empty? hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| sr_with_cuts.fragments.for_display.each do |fragment| uf = UniqueFragment.new uf.primary = fragment.primary uf.complement = fragment.complement duplicate = false uf_ary.each do |element| if (uf.primary == element.primary) and (uf.complement == element.complement) duplicate = true break end end uf_ary << uf unless duplicate end end uf_ary end # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. # # +sequence+:: The string of DNA to match the enzyme recognition sites against # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) id = 0 enzyme_actions_that_sometimes_cut = {} enzyme_actions_that_always_cut = {} indicies_of_sometimes_cut = [] args.each do |enzyme| enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| #enzyme_actions_that_always_cut[id] = enzyme_to_enzyme_action( enzyme, offset ) enzyme_actions_that_always_cut[id] = enzyme.create_action_at( offset ) id += 1 end end # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut max = enzyme_actions_that_always_cut.size - 1 0.upto(max) do |i| enzyme_action = enzyme_actions_that_always_cut[i] conflict = false other_cut_ranges = {} enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; other_cut_ranges[key] = i_ea.cut_ranges } other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last if (enzyme_action.right <= previous_cut_left) or (enzyme_action.left > previous_cut_right) or (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts # no conflict else conflict = true end indicies_of_sometimes_cut += [i, key] if conflict == true end end end indicies_of_sometimes_cut.uniq.each do |i| enzyme_actions_that_sometimes_cut[i] = enzyme_actions_that_always_cut[i] enzyme_actions_that_always_cut.delete(i) end [enzyme_actions_that_sometimes_cut, enzyme_actions_that_always_cut] end # Returns an +Array+ of the match indicies of a RegExp to a string. # # --- # *Arguments* # * +string+: The string to scan # * +re+: A RegExp to use # *Returns*:: +Array+ with indicies of match locations def find_match_locations( string, re ) md = string.match( re ) locations = [] counter = 0 while md # save the match index relative to the original string locations << (counter += md.begin(0)) # find the next match md = string[ (counter += 1)..-1 ].match( re ) end locations end end # Analysis end # Bio::RestrictionEnzyme Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** analysis.rb 1 Jan 2007 02:16:05 -0000 1.7 --- analysis.rb 1 Jan 2007 23:47:27 -0000 1.8 *************** *** 21,37 **** $:.unshift(libpath) unless $:.include?(libpath) ! require 'bio' ! class Bio::Sequence::NA ! # See Bio::RestrictionEnzyme::Analysis.cut ! def cut_with_enzyme(*args) ! Bio::RestrictionEnzyme::Analysis.cut(self, *args) ! end ! alias cut_with_enzymes cut_with_enzyme ! end ! ! require 'pp' ! ! require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' class Bio::RestrictionEnzyme --- 21,25 ---- $:.unshift(libpath) unless $:.include?(libpath) ! require 'bio/util/restriction_enzyme/analysis_basic' class Bio::RestrictionEnzyme *************** *** 50,84 **** end ! def self.cut_without_permutations( sequence, *args ) ! self.new.cut_without_permutations( sequence, *args ) ! end ! ! def self.cut_and_return_by_permutations( sequence, *args ) ! self.new.cut_and_return_by_permutations( sequence, *args ) ! end ! ! def cut_without_permutations( sequence, *args ) ! return {} if !sequence.kind_of?(String) or sequence.empty? ! sequence = Bio::Sequence::NA.new( sequence ) ! ! #enzyme_actions = create_enzyme_actions( sequence, *args ) ! tmp = create_enzyme_actions( sequence, *args ) ! enzyme_actions = tmp[0].merge(tmp[1]) ! ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) ! enzyme_actions.each do |id, enzyme_action| ! enzyme_action.cut_ranges.each do |cut_range| ! sr_with_cuts.add_cut_range(cut_range) ! end ! end ! ! sr_with_cuts.fragments.primary = sequence ! sr_with_cuts.fragments.complement = sequence.forward_complement ! ! tmp = {} ! tmp[0] = sr_with_cuts ! unique_fragments_for_display( tmp ) end def cut_and_return_by_permutations( sequence, *args ) return {} if !sequence.kind_of?(String) or sequence.empty? --- 38,51 ---- end ! def cut( sequence, *args ) ! return nil if !sequence.kind_of?(String) or sequence.empty? ! hash_of_sequence_ranges_with_cuts = cut_and_return_by_permutations( sequence, *args ) ! unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) end + ######### + protected + ######### + def cut_and_return_by_permutations( sequence, *args ) return {} if !sequence.kind_of?(String) or sequence.empty? *************** *** 123,134 **** previous_cut_right = cut_range.range.last - =begin - puts "--- #{permutation.inspect} ---" - puts "Previous cut left: #{previous_cut_left}" - puts "EA.left #{enzyme_action.left}" - puts "Previous cut right: #{previous_cut_right}" - puts "EA.right: #{enzyme_action.right}" - =end - # Keep in mind: # * The cut location is to the immediate right of the base located at the index. --- 90,93 ---- *************** *** 140,148 **** (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts # no conflict - #puts "no conflict" - else conflict = true - #puts "conflict" end end --- 99,104 ---- *************** *** 161,178 **** end - #pp hash_of_sequence_ranges_with_cuts hash_of_sequence_ranges_with_cuts end - def cut( sequence, *args ) - return nil if !sequence.kind_of?(String) or sequence.empty? - hash_of_sequence_ranges_with_cuts = cut_and_return_by_permutations( sequence, *args ) - unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) - end - - ######### - protected - ######### - def permute(count, permutations = [[0]]) return permutations if count <= 1 --- 117,123 ---- *************** *** 190,366 **** end - UniqueFragment = Struct.new(:primary, :complement) - class UniqueFragments < Array - def primary - tmp = [] - self.each { |uf| tmp << uf.primary } - tmp.sort.map { |e| e.tr(' ', '') } - end - def complement - tmp = [] - self.each { |uf| tmp << uf.complement } - tmp.sort.map { |e| e.tr(' ', '') } - end - end - - def unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) - uf_ary = UniqueFragments.new - return uf_ary if hash_of_sequence_ranges_with_cuts == nil or hash_of_sequence_ranges_with_cuts.empty? - - hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| - sr_with_cuts.fragments.for_display.each do |fragment| - uf = UniqueFragment.new - uf.primary = fragment.primary - uf.complement = fragment.complement - - duplicate = false - uf_ary.each do |element| - if (uf.primary == element.primary) and (uf.complement == element.complement) - duplicate = true - break - end - end - - uf_ary << uf unless duplicate - end - end - uf_ary - end - - - =begin - Strand = Struct.new(:primary, :complement, :p_left, :p_right, :c_left, :c_right) - - def ts_fragments_to_strands( sequence, fragments ) - sequence = Bio::Sequence::NA.new( sequence ) - strands = [] - fragments.each do |f| - p = sequence[f.p_left..f.p_right] - c = sequence[f.c_left..f.c_right] - strands << Strand.new(p, c, f.p_left, f.p_right, f.c_left, f.c_right) - end - strands - end - =end - - # Defines a single enzyme action, in this case being a range that correlates - # to the DNA sequence that may contain it's own internal cuts. - class EnzymeAction < SequenceRange - end - - # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. - # - # +sequence+:: The string of DNA to match the enzyme recognition sites against - # +args+:: The enzymes to use. - def create_enzyme_actions( sequence, *args ) - id = 0 - enzyme_actions_that_sometimes_cut = {} - enzyme_actions_that_always_cut = {} - indicies_of_sometimes_cut = [] - - args.each do |enzyme| - enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded - find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| - enzyme_actions_that_always_cut[id] = enzyme_to_enzyme_action( enzyme, offset ) - id += 1 - end - end - - # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut - - max = enzyme_actions_that_always_cut.size - 1 - 0.upto(max) do |i| - enzyme_action = enzyme_actions_that_always_cut[i] - conflict = false - other_cut_ranges = {} - #enzyme_actions.each { |key,enzyme_action| next if i == key; puts "i: #{i}, key: #{key}"; previous_cut_ranges += enzyme_action.cut_ranges } - # enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; puts "i: #{i}, key: #{key}"; other_cut_ranges[key] = i_ea.cut_ranges } - enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; other_cut_ranges[key] = i_ea.cut_ranges } - # puts "Enzyme action #{i}:" - # pp enzyme_actions[i] - # pp enzyme_action - # puts "Previous cut ranges:" - # pp previous_cut_ranges - - other_cut_ranges.each do |key, cut_ranges| - cut_ranges.each do |cut_range| - next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts - previous_cut_left = cut_range.range.first - previous_cut_right = cut_range.range.last - - if (enzyme_action.right <= previous_cut_left) or - (enzyme_action.left > previous_cut_right) or - (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts - # no conflict - # puts "no conflict" - - else - conflict = true - # puts "conflict" - #puts "cut range:" - #pp cut_range - #puts "enzyme action:" - #pp enzyme_action - end - - indicies_of_sometimes_cut += [i, key] if conflict == true - end - end - - # We don't need to make permutations with this enzyme action if it always cuts - # indicies << i if conflict == false - end - # pp indicies_of_sometimes_cut - - indicies_of_sometimes_cut.uniq.each do |i| - enzyme_actions_that_sometimes_cut[i] = enzyme_actions_that_always_cut[i] - enzyme_actions_that_always_cut.delete(i) - end - #puts 'Always cut:' - #pp enzyme_actions_that_always_cut - #puts 'Permute:' - #pp enzyme_actions_that_sometimes_cut - - [enzyme_actions_that_sometimes_cut, enzyme_actions_that_always_cut] - end - - # Returns the offsets of the match of a RegExp to a string. - # - # +string+:: The string to scan. - # +re+:: A regexp to use. - def find_match_locations( string, re ) - md = string.match( re ) - locations = [] - location = -1 - while md - location += md.pre_match.size + 1 - locations << location - # md[0] is the same as $&, or "the match" itself - md = (md[0][1..-1] + md.post_match).match( re ) - end - locations - end - - # Takes a RestrictionEnzyme and a numerical offset to the sequence and - # returns an EnzymeAction - # - # +enzyme+:: RestrictionEnzyme - # +offset+:: Numerical offset of where the enzyme action occurs on the seqeunce - def enzyme_to_enzyme_action( enzyme, offset ) - enzyme_action = EnzymeAction.new(offset, offset + enzyme.primary.size-1, offset, offset + enzyme.complement.size-1) - - enzyme.cut_locations.each do |cut_pair| - p = cut_pair[0] - c = cut_pair[1] - if c >= p - enzyme_action.add_cut_range(offset+p, nil, nil, offset+c) - else - enzyme_action.add_cut_range(nil, offset+p, offset+c, nil) - end - end - - enzyme_action - end - end # Analysis end # Bio::RestrictionEnzyme --- 135,138 ---- Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** double_stranded.rb 1 Jan 2007 05:07:04 -0000 1.3 --- double_stranded.rb 1 Jan 2007 23:47:27 -0000 1.4 *************** *** 14,17 **** --- 14,19 ---- require 'bio/db/rebase' require 'bio/util/restriction_enzyme' + require 'bio/util/restriction_enzyme/analysis/sequence_range' + require 'bio/util/restriction_enzyme/cut_symbol' require 'bio/util/restriction_enzyme/single_strand' *************** *** 96,99 **** --- 98,102 ---- # Decide if this String is an enzyme name or a pattern if Bio::RestrictionEnzyme.enzyme_name?( erp ) + # FIXME we added this to rebase... # Check if it's a known name known_enzyme = false *************** *** 157,160 **** --- 160,252 ---- !blunt? end + + # Takes a RestrictionEnzyme object and a numerical offset to the sequence and + # returns an EnzymeAction + # + # +restriction_enzyme+:: RestrictionEnzyme + # +offset+:: Numerical offset of where the enzyme action occurs on the seqeunce + def create_action_at( offset ) + #def enzyme_to_enzyme_action( restriction_enzyme, offset ) + enzyme_action = EnzymeAction.new( offset, + offset + @primary.size-1, + offset, + offset + @complement.size-1) + + @cut_locations.each do |cut_location_pair| + # cut_pair is a DoubleStranded::CutLocationPair + p, c = cut_location_pair.primary, cut_location_pair.complement + if c >= p + enzyme_action.add_cut_range(offset+p, nil, nil, offset+c) + else + enzyme_action.add_cut_range(nil, offset+p, offset+c, nil) + end + end + + enzyme_action + end + + # An EnzymeAction is a way of representing a potential effect that a + # RestrictionEnzyme may have on a nucleotide sequence, an 'action'. + # + # Multiple cuts in multiple locations on a sequence may occur in one + # 'action' if it is done by a single enzyme. + # + # An EnzymeAction is a series of locations that represents where the restriction + # enzyme will bind on the sequence, as well as what ranges are cut on the + # sequence itself. The complexity is due to the fact that our virtual + # restriction enzyme may create multiple segments from its cutting action, + # on which another restriction enzyme may operate upon. + # + # For example, the DNA sequence: + # + # 5' - G A A T A A A C G A - 3' + # 3' - C T T A T T T G C T - 5' + # + # When mixed with the restriction enzyme with the following cut pattern: + # + # 5' - A|A T A A A C|G - 3' + # +-+ + + # 3' - T T|A T T T G|C - 5' + # + # And also mixed with the restriction enzyme of the following cut pattern: + # + # 5' - A A|A C - 3' + # +-+ + # 3' - T|T T G - 5' + # + # Would result in a DNA sequence with these cuts: + # + # 5' - G A|A T A A|A C|G A - 3' + # +-+ +-+ + + # 3' - C T T|A T|T T G|C T - 5' + # + # Or these separate "free-floating" sequences: + # + # 5' - G A - 3' + # 3' - C T T - 5' + # + # 5' - A T A A - 3' + # 3' - A T - 5' + # + # 5' - A C - 3' + # 3' - T T G - 5' + # + # 5' - G A - 3' + # 3' - C T - 5' + # + # This would be represented by two EnzymeActions - one for each + # RestrictionEnzyme. + # + # To initialize an EnzymeAction you must first instantiate it with the + # beginning and ending locations of where it will operate on a nucleotide + # sequence. + # + # Next the ranges of cu + # + # An EnzymeAction is + # Defines a single enzyme action, in this case being a range that correlates + # to the DNA sequence that may contain it's own internal cuts. + class EnzymeAction < Bio::RestrictionEnzyme::Analysis::SequenceRange + end ######### From trevor at dev.open-bio.org Mon Jan 1 23:47:30 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 23:47:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis calculated_cuts.rb, 1.3, 1.4 cut_range.rb, 1.2, 1.3 cut_ranges.rb, 1.3, 1.4 horizontal_cut_range.rb, 1.2, 1.3 sequence_range.rb, 1.4, 1.5 vertical_cut_range.rb, 1.2, 1.3 Message-ID: <200701012347.l01NlU6G002440@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv2413/restriction_enzyme/analysis Modified Files: calculated_cuts.rb cut_range.rb cut_ranges.rb horizontal_cut_range.rb sequence_range.rb vertical_cut_range.rb Log Message: Index: vertical_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/vertical_cut_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** vertical_cut_range.rb 31 Dec 2006 21:50:31 -0000 1.2 --- vertical_cut_range.rb 1 Jan 2007 23:47:28 -0000 1.3 *************** *** 31,34 **** --- 31,56 ---- attr_reader :range + # VerticalCutRange provides an extremely raw, yet precise, method of + # defining the location of cuts on primary and complementary sequences. + # + # Many VerticalCutRange objects are used with HorizontalCutRange objects + # to be contained in CutRanges to define the cut pattern that a + # specific enzyme may make. + # + # VerticalCutRange takes up to four possible cuts, two on the primary + # strand and two on the complementary strand. In typical usage + # you will want to make a single cut on the primary strand and a single + # cut on the complementary strand. + # + # However, you can construct it with whatever cuts you desire to accomadate + # the most eccentric of imaginary restriction enzymes. + # + # --- + # *Arguments* + # * +p_cut_left+: (_optional_) Left-most cut on the primary strand. +nil+ to skip + # * +p_cut_right+: (_optional_) Right-most cut on the primary strand. +nil+ to skip + # * +c_cut_left+: (_optional_) Left-most cut on the complementary strand. +nil+ to skip + # * +c_cut_right+: (_optional_) Right-most cut on the complementary strand. +nil+ to skip + # *Returns*:: nothing def initialize( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @p_cut_left = p_cut_left *************** *** 45,50 **** --- 67,80 ---- @range = nil @range = (@min.. at max) unless @min == nil or @max == nil + return end + # Check if a location falls within the minimum or maximum values of this + # range. + # + # --- + # *Arguments* + # * +i+: Location to check if it is included in the range + # *Returns*:: +true+ _or_ +false+ def include?(i) return false if @range == nil Index: horizontal_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/horizontal_cut_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** horizontal_cut_range.rb 31 Dec 2006 21:50:31 -0000 1.2 --- horizontal_cut_range.rb 1 Jan 2007 23:47:28 -0000 1.3 *************** *** 36,41 **** # The 'range' here is actually off by one on the left # side in relation to a normal CutRange, so using the normal ! # variables from CutRange would result in unpredictable ! # behavior. @p_cut_left = nil --- 36,52 ---- # The 'range' here is actually off by one on the left # side in relation to a normal CutRange, so using the normal ! # variables from CutRange would result in bad behavior. ! # ! # See below - the first horizontal cut is the primary cut plus one. ! # ! # 1 2 3 4 5 6 7 ! # G A|T T A C A ! # +-----+ ! # C T A A T|G T ! # 1 2 3 4 5 6 7 ! # ! # Primary cut = 2 ! # Complement cut = 5 ! # Horizontal cuts = 3, 4, 5 @p_cut_left = nil *************** *** 50,53 **** --- 61,71 ---- end + # Check if a location falls within the minimum or maximum values of this + # range. + # + # --- + # *Arguments* + # * +i+: Location to check if it is included in the range + # *Returns*:: +true+ _or_ +false+ def include?(i) @range.include?(i) Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/calculated_cuts.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** calculated_cuts.rb 1 Jan 2007 05:07:04 -0000 1.3 --- calculated_cuts.rb 1 Jan 2007 23:47:28 -0000 1.4 *************** *** 27,30 **** --- 27,34 ---- # License:: Distributes under the same terms as Ruby # + # cc = CalculatedCuts.new(@size) + # cc.add_cuts_from_cut_ranges(@cut_ranges) + # cc.remove_incomplete_cuts + # # 1 2 3 4 5 6 7 # G A|T T A C A *************** *** 41,55 **** include StringFormatting ! # Vertical cuts on the primary strand attr_reader :vc_primary ! # Vertical cuts on the complement strand attr_reader :vc_complement ! # Horizontal cuts attr_reader :hc_between_strands # Set to +true+ if the fragment CalculatedCuts is working on is circular attr_accessor :circular def initialize(size=nil, circular=false) --- 45,69 ---- include StringFormatting ! # +Array+ of vertical cuts on the primary strand in 0-based index notation attr_reader :vc_primary ! # +Array+ of vertical cuts on the complementary strand in 0-based index notation attr_reader :vc_complement ! # +Array+ of horizontal cuts between strands in 0-based index notation attr_reader :hc_between_strands # Set to +true+ if the fragment CalculatedCuts is working on is circular attr_accessor :circular + + # An +Array+ with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. + attr_reader :strands_for_display + + # If +false+ the strands_for_display method needs to be called to update the contents + # of @strands_for_display. Becomes out of date whenever add_cuts_from_cut_ranges is called. + attr_reader :strands_for_display_current + + # Size of the sequence being digested. + attr_reader :size def initialize(size=nil, circular=false) *************** *** 61,64 **** --- 75,82 ---- end + # --- + # *Arguments* + # * +cut_ranges+: An +Array+ of HorizontalCutRange or VerticalCutRange objects + # *Returns*:: nothing def add_cuts_from_cut_ranges(cut_ranges) @strands_for_display_current = false *************** *** 68,71 **** --- 86,91 ---- @vc_complement += [cut_range.c_cut_left, cut_range.c_cut_right] + # Add horizontal cut ranges. This may happen from cuts made inbetween a + # VerticalCutRange or may be specifically defined by a HorizontalCutRange. if cut_range.class == VerticalCutRange ( cut_range.min + 1 ).upto( cut_range.max ){|i| @hc_between_strands << i} if cut_range.min < cut_range.max *************** *** 75,80 **** --- 95,129 ---- end clean_all + #return end + # There may be incomplete cuts made, this method removes the cuts that don't + # create sub-sequences for easier processing. + # + # For example, stray horizontal cuts that do not end with a left + # and right separation: + # + # G A T T A C A + # +-- --- + # C T|A A T G T + # + # Or stray vertical cuts: + # + # G A T T A C A + # +-- + + # C T|A A T|G T + # + # However note that for non-circular sequences this would be a successful + # cut which would result in a floating 'GT' sub-sequence: + # + # G A T T A C A + # +--- + # C T A A T|G T + # + # Blunt cuts are also complete cuts. + # --- + # *Arguments* + # * +size+: (_optional_) Size of the sequence being digested. Defined here or during initalization of CalculatedCuts. + # *Returns*:: nothing def remove_incomplete_cuts(size=nil) @strands_for_display_current = false *************** *** 90,94 **** if @circular # NOTE ! # if it's circular we should start at the beginning of a cut for orientation # scan for it, hack off the first set of hcuts and move them to the back else --- 139,143 ---- if @circular # NOTE ! # if it's circular we should start at the beginning of a cut for orientation, # scan for it, hack off the first set of hcuts and move them to the back else *************** *** 133,136 **** --- 182,196 ---- end + # Sets @strands_for_display_current to +true+ and populates @strands_for_display. + # + # --- + # *Arguments* + # * +str1+: (_optional_) For displaying a primary strand. If +nil+ a numbered sequence will be used in place. + # * +str2+: (_optional_) For displaying a complementary strand. If +nil+ a numbered sequence will be used in place. + # * +vcp+: (_optional_) An array of vertical cut locations on the primary strand. If +nil+ the contents of @vc_primary is used. + # * +vcc+: (_optional_) An array of vertical cut locations on the complementary strand. If +nil+ the contents of @vc_complementary is used. + # * +hc+: (_optional_) An array of horizontal cut locations between strands. If +nil+ the contents of @hc_between_strands is used. + # *Returns*:: +Array+ An array with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. + # def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current *************** *** 178,181 **** --- 238,243 ---- ######### + # remove nil values, remove duplicate values, and + # sort @vc_primary, @vc_complement, and @hc_between_strands def clean_all [@vc_primary, @vc_complement, @hc_between_strands].collect { |a| a.delete(nil); a.uniq!; a.sort! } Index: cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/cut_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cut_range.rb 31 Dec 2006 21:50:31 -0000 1.2 --- cut_range.rb 1 Jan 2007 23:47:28 -0000 1.3 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom *************** *** 20,24 **** # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - # # Author:: Trevor Wennblom --- 20,24 ---- # ! # bio/util/restrction_enzyme/analysis/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom *************** *** 26,29 **** --- 26,31 ---- # License:: Distributes under the same terms as Ruby # + # Abstract base class for HorizontalCutRange and VerticalCutRange + # class CutRange end # CutRange Index: cut_ranges.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/cut_ranges.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cut_ranges.rb 1 Jan 2007 02:16:05 -0000 1.3 --- cut_ranges.rb 1 Jan 2007 23:47:28 -0000 1.4 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom *************** *** 12,24 **** $:.unshift(libpath) unless $:.include?(libpath) - #require 'bio' - module Bio; end class Bio::RestrictionEnzyme class Analysis ! #class Analysis ! # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - # # Author:: Trevor Wennblom --- 12,21 ---- $:.unshift(libpath) unless $:.include?(libpath) module Bio; end class Bio::RestrictionEnzyme class Analysis ! # ! # bio/util/restrction_enzyme/analysis/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom *************** *** 26,29 **** --- 23,28 ---- # License:: Distributes under the same terms as Ruby # + # Container for many CutRange objects or CutRange child objects. Inherits from array. + # class CutRanges < Array def min; self.collect{|a| a.min}.flatten.sort.first; end Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis/sequence_range.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sequence_range.rb 1 Jan 2007 02:31:22 -0000 1.4 --- sequence_range.rb 1 Jan 2007 23:47:28 -0000 1.5 *************** *** 87,98 **** # scan for it, hack off the first set of hcuts and move them to the back else - # last_index = @size - 1 p_cut.unshift(-1) unless p_cut.include?(-1) - # p_cut.push(last_index) unless p_cut.include?(last_index) c_cut.unshift(-1) unless c_cut.include?(-1) - # c_cut.push(last_index) unless c_cut.include?(last_index) end - if @circular largest_bin = 0 --- 87,94 ---- *************** *** 114,118 **** -1.upto(@size-1) do |idx| - # if bins are out of sync but the strands are attached if p_bin != c_bin and h.include?(idx) == false --- 110,113 ---- *************** *** 134,138 **** x.call(c_bin) end - end --- 129,132 ---- *************** *** 141,148 **** bins.delete(-1) unless @circular - # require 'pp' - # pp bins - - #NOTE str1 = nil str2 = nil --- 135,138 ---- *************** *** 159,166 **** end - #pp fragments.for_display - # pp fragments - # exit - @__fragments = fragments return fragments --- 149,152 ---- From trevor at dev.open-bio.org Mon Jan 1 23:54:35 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 01 Jan 2007 23:54:35 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range - New directory Message-ID: <200701012354.l01NsZPO002475@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv2455/range Log Message: Directory /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range added to the repository From trevor at dev.open-bio.org Tue Jan 2 00:12:30 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:12:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range - New directory Message-ID: <200701020012.l020CUSi002607@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv2587/sequence_range Log Message: Directory /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range added to the repository From trevor at dev.open-bio.org Tue Jan 2 00:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.8, 1.9 analysis_basic.rb, 1.1, 1.2 double_stranded.rb, 1.4, 1.5 Message-ID: <200701020013.l020D9ZK002682@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme Modified Files: analysis.rb analysis_basic.rb double_stranded.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.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** analysis_basic.rb 1 Jan 2007 23:47:27 -0000 1.1 --- analysis_basic.rb 2 Jan 2007 00:13:07 -0000 1.2 *************** *** 43,47 **** require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' class Bio::RestrictionEnzyme --- 43,47 ---- require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/range/sequence_range' class Bio::RestrictionEnzyme *************** *** 83,87 **** enzyme_actions = tmp[0].merge(tmp[1]) ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| --- 83,87 ---- enzyme_actions = tmp[0].merge(tmp[1]) ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| *************** *** 167,171 **** other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| ! next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last --- 167,171 ---- other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** analysis.rb 1 Jan 2007 23:47:27 -0000 1.8 --- analysis.rb 2 Jan 2007 00:13:07 -0000 1.9 *************** *** 64,68 **** if permutations.empty? ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |key, enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } hash_of_sequence_ranges_with_cuts[0] = sr_with_cuts --- 64,68 ---- if permutations.empty? ! sr_with_cuts = 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| sr_with_cuts.add_cut_range(cut_range) } } hash_of_sequence_ranges_with_cuts[0] = sr_with_cuts *************** *** 71,75 **** permutations.each do |permutation| previous_cut_ranges = [] ! sr_with_cuts = SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } --- 71,75 ---- permutations.each do |permutation| previous_cut_ranges = [] ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } *************** *** 86,90 **** # so all cut locations must be checked that would fall underneath. previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last --- 86,90 ---- # so all cut locations must be checked that would fall underneath. previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts previous_cut_left = cut_range.range.first previous_cut_right = cut_range.range.last Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** double_stranded.rb 1 Jan 2007 23:47:27 -0000 1.4 --- double_stranded.rb 2 Jan 2007 00:13:07 -0000 1.5 *************** *** 14,18 **** require 'bio/db/rebase' require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' require 'bio/util/restriction_enzyme/cut_symbol' --- 14,18 ---- require 'bio/db/rebase' require 'bio/util/restriction_enzyme' ! require 'bio/util/restriction_enzyme/range/sequence_range' require 'bio/util/restriction_enzyme/cut_symbol' *************** *** 247,251 **** # Defines a single enzyme action, in this case being a range that correlates # to the DNA sequence that may contain it's own internal cuts. ! class EnzymeAction < Bio::RestrictionEnzyme::Analysis::SequenceRange end --- 247,251 ---- # Defines a single enzyme action, in this case being a range that correlates # to the DNA sequence that may contain it's own internal cuts. ! class EnzymeAction < Bio::RestrictionEnzyme::Range::SequenceRange end From trevor at dev.open-bio.org Tue Jan 2 00:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range cut_range.rb, NONE, 1.1 cut_ranges.rb, NONE, 1.1 horizontal_cut_range.rb, NONE, 1.1 sequence_range.rb, NONE, 1.1 vertical_cut_range.rb, NONE, 1.1 Message-ID: <200701020013.l020D99D002693@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme/range Added Files: cut_range.rb cut_ranges.rb horizontal_cut_range.rb sequence_range.rb vertical_cut_range.rb Log Message: --- NEW FILE: vertical_cut_range.rb --- # # bio/util/restrction_enzyme/range/vertical_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: vertical_cut_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_range' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/vertical_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class VerticalCutRange < CutRange attr_reader :p_cut_left, :p_cut_right attr_reader :c_cut_left, :c_cut_right attr_reader :min, :max attr_reader :range # VerticalCutRange provides an extremely raw, yet precise, method of # defining the location of cuts on primary and complementary sequences. # # Many VerticalCutRange objects are used with HorizontalCutRange objects # to be contained in CutRanges to define the cut pattern that a # specific enzyme may make. # # VerticalCutRange takes up to four possible cuts, two on the primary # strand and two on the complementary strand. In typical usage # you will want to make a single cut on the primary strand and a single # cut on the complementary strand. # # However, you can construct it with whatever cuts you desire to accomadate # the most eccentric of imaginary restriction enzymes. # # --- # *Arguments* # * +p_cut_left+: (_optional_) Left-most cut on the primary strand. +nil+ to skip # * +p_cut_right+: (_optional_) Right-most cut on the primary strand. +nil+ to skip # * +c_cut_left+: (_optional_) Left-most cut on the complementary strand. +nil+ to skip # * +c_cut_right+: (_optional_) Right-most cut on the complementary strand. +nil+ to skip # *Returns*:: nothing def initialize( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @p_cut_left = p_cut_left @p_cut_right = p_cut_right @c_cut_left = c_cut_left @c_cut_right = c_cut_right a = [@p_cut_left, @c_cut_left, @p_cut_right, @c_cut_right] a.delete(nil) a.sort! @min = a.first @max = a.last @range = nil @range = (@min.. at max) unless @min == nil or @max == nil return end # Check if a location falls within the minimum or maximum values of this # range. # # --- # *Arguments* # * +i+: Location to check if it is included in the range # *Returns*:: +true+ _or_ +false+ def include?(i) return false if @range == nil @range.include?(i) end end # VerticalCutRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: horizontal_cut_range.rb --- # # bio/util/restrction_enzyme/range/horizontal_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: horizontal_cut_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_range' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/horizontal_cut_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class HorizontalCutRange < CutRange attr_reader :p_cut_left, :p_cut_right attr_reader :c_cut_left, :c_cut_right attr_reader :min, :max attr_reader :hcuts def initialize( left, right=left ) raise "left > right" if left > right # The 'range' here is actually off by one on the left # side in relation to a normal CutRange, so using the normal # variables from CutRange would result in bad behavior. # # See below - the first horizontal cut is the primary cut plus one. # # 1 2 3 4 5 6 7 # G A|T T A C A # +-----+ # C T A A T|G T # 1 2 3 4 5 6 7 # # Primary cut = 2 # Complement cut = 5 # Horizontal cuts = 3, 4, 5 @p_cut_left = nil @p_cut_right = nil @c_cut_left = nil @c_cut_right = nil @min = nil @max = nil @range = nil @hcuts = (left..right) end # Check if a location falls within the minimum or maximum values of this # range. # # --- # *Arguments* # * +i+: Location to check if it is included in the range # *Returns*:: +true+ _or_ +false+ def include?(i) @range.include?(i) end end # HorizontalCutRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: sequence_range.rb --- # # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: sequence_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_ranges' require 'bio/util/restriction_enzyme/range/horizontal_cut_range' require 'bio/util/restriction_enzyme/range/vertical_cut_range' require 'bio/util/restriction_enzyme/range/sequence_range/calculated_cuts' require 'bio/util/restriction_enzyme/range/sequence_range/fragments' require 'bio/util/restriction_enzyme/range/sequence_range/fragment' require 'bio' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class SequenceRange attr_reader :p_left, :p_right attr_reader :c_left, :c_right attr_reader :left, :right attr_reader :size attr_reader :cut_ranges def initialize( p_left = nil, p_right = nil, c_left = nil, c_right = nil ) @__fragments_current = false raise ArgumentError if p_left == nil and c_left == nil raise ArgumentError if p_right == nil and c_right == nil (raise ArgumentError unless p_left <= p_right) unless p_left == nil or p_right == nil (raise ArgumentError unless c_left <= c_right) unless c_left == nil or c_right == nil @p_left = p_left @p_right = p_right @c_left = c_left @c_right = c_right tmp = [p_left, c_left] tmp.delete(nil) @left = tmp.sort.first tmp = [p_right, c_right] tmp.delete(nil) @right = tmp.sort.last @size = (@right - @left) + 1 unless @left == nil or @right == nil @cut_ranges = CutRanges.new end =begin Special Case: Horizontal cuts at beginning or end of strand =end Bin = Struct.new(:c, :p) def fragments return @__fragments if @__fragments_current == true @__fragments_current = true cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) cc.add_cuts_from_cut_ranges(@cut_ranges) cc.remove_incomplete_cuts p_cut = cc.vc_primary c_cut = cc.vc_complement h = cc.hc_between_strands if @circular # NOTE # if it's circular we should start at the beginning of a cut for orientation # scan for it, hack off the first set of hcuts and move them to the back else p_cut.unshift(-1) unless p_cut.include?(-1) c_cut.unshift(-1) unless c_cut.include?(-1) end if @circular largest_bin = 0 else largest_bin = -1 end p_bin = largest_bin c_bin = largest_bin bins = { largest_bin => Bin.new } # bin_id, bin bins[ largest_bin ].p = [] bins[ largest_bin ].c = [] x = lambda do |bin_id| largest_bin += 1 bins[ bin_id ] = Bin.new bins[ bin_id ].p = [] bins[ bin_id ].c = [] end -1.upto(@size-1) do |idx| # if bins are out of sync but the strands are attached if p_bin != c_bin and h.include?(idx) == false bins.delete( [p_bin, c_bin].sort.last ) p_bin = c_bin = [p_bin, c_bin].sort.first largest_bin -= 1 end bins[ p_bin ].p << idx bins[ c_bin ].c << idx if p_cut.include? idx p_bin = largest_bin + 1 x.call(p_bin) end if c_cut.include? idx c_bin = largest_bin + 1 x.call(c_bin) end end # Easy way to indicate the start of a strand just in case # there is a horizontal cut at position 0 bins.delete(-1) unless @circular str1 = nil str2 = nil num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } (str1 == nil) ? a = num_txt_repeat.call : a = str1.dup (str2 == nil) ? b = num_txt_repeat.call : b = str2.dup fragments = Fragments.new(a,b) bins.sort.each do |k, bin| fragment = Fragment.new( bin.p, bin.c ) fragments << fragment end @__fragments = fragments return fragments end # Cut occurs immediately after the index supplied. # For example, a cut at '0' would mean a cut occurs between 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false if p_cut_left.kind_of? CutRange @cut_ranges << p_cut_left else (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) end end def add_cut_ranges(*cut_ranges) cut_ranges.flatten! cut_ranges.each do |cut_range| raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange self.add_cut_range( cut_range ) end end def add_horizontal_cut_range( left, right=left ) @__fragments_current = false @cut_ranges << HorizontalCutRange.new( left, right ) end end # SequenceRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: cut_ranges.rb --- # # bio/util/restrction_enzyme/range/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: cut_ranges.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/cut_ranges.rb - Container for many CutRange objects or CutRange child objects. # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # Container for many CutRange objects or CutRange child objects. Inherits from array. # class CutRanges < Array def min; self.collect{|a| a.min}.flatten.sort.first; end def max; self.collect{|a| a.max}.flatten.sort.last; end def include?(i); self.collect{|a| a.include?(i)}.include?(true); end end # CutRanges end # Range end # Bio::RestrictionEnzyme --- NEW FILE: cut_range.rb --- # # bio/util/restrction_enzyme/range/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: cut_range.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 5, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio' module Bio; end class Bio::RestrictionEnzyme class Range # # bio/util/restrction_enzyme/range/cut_range.rb - Abstract base class for HorizontalCutRange and VerticalCutRange # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # Abstract base class for HorizontalCutRange and VerticalCutRange # class CutRange end # CutRange end # Range end # Bio::RestrictionEnzyme From trevor at dev.open-bio.org Tue Jan 2 00:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/analysis calculated_cuts.rb, 1.4, NONE cut_range.rb, 1.3, NONE cut_ranges.rb, 1.4, NONE fragment.rb, 1.3, NONE fragments.rb, 1.2, NONE horizontal_cut_range.rb, 1.3, NONE sequence_range.rb, 1.5, NONE vertical_cut_range.rb, 1.3, NONE Message-ID: <200701020013.l020D9Xl002689@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme/analysis Removed Files: calculated_cuts.rb cut_range.rb cut_ranges.rb fragment.rb fragments.rb horizontal_cut_range.rb sequence_range.rb vertical_cut_range.rb Log Message: --- vertical_cut_range.rb DELETED --- --- fragment.rb DELETED --- --- horizontal_cut_range.rb DELETED --- --- fragments.rb DELETED --- --- calculated_cuts.rb DELETED --- --- cut_range.rb DELETED --- --- cut_ranges.rb DELETED --- --- sequence_range.rb DELETED --- From trevor at dev.open-bio.org Tue Jan 2 00:13:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:13:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range calculated_cuts.rb, NONE, 1.1 fragment.rb, NONE, 1.1 fragments.rb, NONE, 1.1 Message-ID: <200701020013.l020D9Ea002702@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv2656/restriction_enzyme/range/sequence_range Added Files: calculated_cuts.rb fragment.rb fragments.rb Log Message: --- NEW FILE: calculated_cuts.rb --- # # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: calculated_cuts.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/cut_symbol' require 'bio/util/restriction_enzyme/string_formatting' module Bio; end class Bio::RestrictionEnzyme class Range class SequenceRange # # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # cc = CalculatedCuts.new(@size) # cc.add_cuts_from_cut_ranges(@cut_ranges) # cc.remove_incomplete_cuts # # 1 2 3 4 5 6 7 # G A|T T A C A # +-----+ # C T A A T|G T # 1 2 3 4 5 6 7 # # Primary cut = 2 # Complement cut = 5 # Horizontal cuts = 3, 4, 5 # class CalculatedCuts include CutSymbol include StringFormatting # +Array+ of vertical cuts on the primary strand in 0-based index notation attr_reader :vc_primary # +Array+ of vertical cuts on the complementary strand in 0-based index notation attr_reader :vc_complement # +Array+ of horizontal cuts between strands in 0-based index notation attr_reader :hc_between_strands # Set to +true+ if the fragment CalculatedCuts is working on is circular attr_accessor :circular # An +Array+ with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. attr_reader :strands_for_display # If +false+ the strands_for_display method needs to be called to update the contents # of @strands_for_display. Becomes out of date whenever add_cuts_from_cut_ranges is called. attr_reader :strands_for_display_current # Size of the sequence being digested. attr_reader :size def initialize(size=nil, circular=false) @size = size @circular = circular @vc_primary = [] @vc_complement = [] @hc_between_strands = [] end # --- # *Arguments* # * +cut_ranges+: An +Array+ of HorizontalCutRange or VerticalCutRange objects # *Returns*:: nothing def add_cuts_from_cut_ranges(cut_ranges) @strands_for_display_current = false cut_ranges.each do |cut_range| @vc_primary += [cut_range.p_cut_left, cut_range.p_cut_right] @vc_complement += [cut_range.c_cut_left, cut_range.c_cut_right] # Add horizontal cut ranges. This may happen from cuts made inbetween a # VerticalCutRange or may be specifically defined by a HorizontalCutRange. if cut_range.class == VerticalCutRange ( cut_range.min + 1 ).upto( cut_range.max ){|i| @hc_between_strands << i} if cut_range.min < cut_range.max elsif cut_range.class == HorizontalCutRange ( cut_range.hcuts.first ).upto( cut_range.hcuts.last ){|i| @hc_between_strands << i} end end clean_all #return end # There may be incomplete cuts made, this method removes the cuts that don't # create sub-sequences for easier processing. # # For example, stray horizontal cuts that do not end with a left # and right separation: # # G A T T A C A # +-- --- # C T|A A T G T # # Or stray vertical cuts: # # G A T T A C A # +-- + # C T|A A T|G T # # However note that for non-circular sequences this would be a successful # cut which would result in a floating 'GT' sub-sequence: # # G A T T A C A # +--- # C T A A T|G T # # Blunt cuts are also complete cuts. # --- # *Arguments* # * +size+: (_optional_) Size of the sequence being digested. Defined here or during initalization of CalculatedCuts. # *Returns*:: nothing def remove_incomplete_cuts(size=nil) @strands_for_display_current = false @size = size if size raise IndexError, "Size of the strand must be provided here or during initalization." if !@size.kind_of?(Fixnum) and not @circular vcuts = (@vc_primary + @vc_complement).uniq.sort hcuts = @hc_between_strands last_index = @size - 1 good_hcuts = [] potential_hcuts = [] if @circular # NOTE # if it's circular we should start at the beginning of a cut for orientation, # scan for it, hack off the first set of hcuts and move them to the back else vcuts.unshift(-1) unless vcuts.include?(-1) vcuts.push(last_index) unless vcuts.include?(last_index) end hcuts.each do |hcut| raise IndexError if hcut < -1 or hcut > last_index # skipped a nucleotide potential_hcuts.clear if !potential_hcuts.empty? and (hcut - potential_hcuts.last).abs > 1 if potential_hcuts.empty? if vcuts.include?( hcut ) and vcuts.include?( hcut - 1 ) good_hcuts += [hcut] elsif vcuts.include?( hcut - 1 ) potential_hcuts << hcut end else if vcuts.include?( hcut ) good_hcuts += potential_hcuts + [hcut] potential_hcuts.clear else potential_hcuts << hcut end end end check_vc = lambda do |vertical_cuts, opposing_vcuts| # opposing_vcuts is here only to check for blunt cuts, so there shouldn't # be any out-of-order problems with this good_vc = [] vertical_cuts.each { |vc| good_vc << vc if good_hcuts.include?( vc ) or good_hcuts.include?( vc + 1 ) or opposing_vcuts.include?( vc ) } good_vc end @vc_primary = check_vc.call(@vc_primary, @vc_complement) @vc_complement = check_vc.call(@vc_complement, @vc_primary) @hc_between_strands = good_hcuts clean_all end # Sets @strands_for_display_current to +true+ and populates @strands_for_display. # # --- # *Arguments* # * +str1+: (_optional_) For displaying a primary strand. If +nil+ a numbered sequence will be used in place. # * +str2+: (_optional_) For displaying a complementary strand. If +nil+ a numbered sequence will be used in place. # * +vcp+: (_optional_) An array of vertical cut locations on the primary strand. If +nil+ the contents of @vc_primary is used. # * +vcc+: (_optional_) An array of vertical cut locations on the complementary strand. If +nil+ the contents of @vc_complementary is used. # * +hc+: (_optional_) An array of horizontal cut locations between strands. If +nil+ the contents of @hc_between_strands is used. # *Returns*:: +Array+ An array with the primary strand with vertical cuts, the horizontal cuts, and the complementary strand with vertical cuts. # def strands_for_display(str1 = nil, str2 = nil, vcp=nil, vcc=nil, hc=nil) return @strands_for_display if @strands_for_display_current vcs = '|' # Vertical cut symbol hcs = '-' # Horizontal cut symbol vhcs = '+' # Intersection of vertical and horizontal cut symbol num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } (str1 == nil) ? a = num_txt_repeat.call : a = str1.dup (str2 == nil) ? b = num_txt_repeat.call : b = str2.dup vcp = @vc_primary if vcp==nil vcc = @vc_complement if vcc==nil hc = @hc_between_strands if hc==nil vcuts = (vcp + vcc).uniq.sort vcp.reverse.each { |c| a.insert(c+1, vcs) } vcc.reverse.each { |c| b.insert(c+1, vcs) } between = ' ' * @size hc.each {|hcut| between[hcut,1] = hcs } s_a = add_spacing(a, vcs) s_b = add_spacing(b, vcs) s_bet = add_spacing(between) # NOTE watch this for circular i = 0 0.upto( s_a.size-1 ) do if (s_a[i,1] == vcs) or (s_b[i,1] == vcs) s_bet[i] = vhcs elsif i != 0 and s_bet[i-1,1] == hcs and s_bet[i+1,1] == hcs s_bet[i] = hcs end i+=1 end @strands_for_display_current = true @strands_for_display = [s_a, s_bet, s_b] end ######### protected ######### # remove nil values, remove duplicate values, and # sort @vc_primary, @vc_complement, and @hc_between_strands def clean_all [@vc_primary, @vc_complement, @hc_between_strands].collect { |a| a.delete(nil); a.uniq!; a.sort! } end end # CalculatedCuts end # SequenceRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: fragment.rb --- # # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: fragment.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'bio/util/restriction_enzyme/range/cut_ranges' require 'bio/util/restriction_enzyme/range/horizontal_cut_range' require 'bio' module Bio; end class Bio::RestrictionEnzyme class Range class SequenceRange # # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class Fragment attr_reader :size def initialize( primary_bin, complement_bin ) @primary_bin = primary_bin @complement_bin = complement_bin end DisplayFragment = Struct.new(:primary, :complement) def for_display(p_str=nil, c_str=nil) df = DisplayFragment.new df.primary = '' df.complement = '' both_bins = (@primary_bin + @complement_bin).sort.uniq both_bins.each do |item| @primary_bin.include?(item) ? df.primary << p_str[item] : df.primary << ' ' @complement_bin.include?(item) ? df.complement << c_str[item] : df.complement << ' ' end df end end # Fragment end # SequenceRange end # Range end # Bio::RestrictionEnzyme --- NEW FILE: fragments.rb --- # # bio/util/restrction_enzyme/analysis/fragments.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: fragments.rb,v 1.1 2007/01/02 00:13:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) module Bio; end class Bio::RestrictionEnzyme class Range class SequenceRange # # bio/util/restrction_enzyme/analysis/fragments.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # class Fragments < Array attr_accessor :primary attr_accessor :complement def initialize(primary, complement) @primary = primary @complement = complement end DisplayFragment = Struct.new(:primary, :complement) def for_display(p_str=nil, c_str=nil) p_str ||= @primary c_str ||= @complement pretty_fragments = [] self.each { |fragment| pretty_fragments << fragment.for_display(p_str, c_str) } pretty_fragments end end # Fragments end # SequenceRange end # Range end # Bio::RestrictionEnzyme From trevor at dev.open-bio.org Tue Jan 2 00:19:08 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:19:08 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range calculated_cuts.rb, 1.1, 1.2 fragment.rb, 1.1, 1.2 fragments.rb, 1.1, 1.2 Message-ID: <200701020019.l020J8r2002755@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv2735/range/sequence_range Modified Files: calculated_cuts.rb fragment.rb fragments.rb Log Message: Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** calculated_cuts.rb 2 Jan 2007 00:13:07 -0000 1.1 --- calculated_cuts.rb 2 Jan 2007 00:19:06 -0000 1.2 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/calculated_cuts.rb - # # Author:: Trevor Wennblom *************** *** 22,26 **** # ! # bio/util/restrction_enzyme/analysis/calculated_cuts.rb - # # Author:: Trevor Wennblom --- 22,26 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/calculated_cuts.rb - # # Author:: Trevor Wennblom Index: fragment.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/fragment.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fragment.rb 2 Jan 2007 00:13:07 -0000 1.1 --- fragment.rb 2 Jan 2007 00:19:06 -0000 1.2 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/fragment.rb - # # Author:: Trevor Wennblom *************** *** 22,26 **** # ! # bio/util/restrction_enzyme/analysis/fragment.rb - # # Author:: Trevor Wennblom --- 22,26 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/fragment.rb - # # Author:: Trevor Wennblom Index: fragments.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/fragments.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fragments.rb 2 Jan 2007 00:13:07 -0000 1.1 --- fragments.rb 2 Jan 2007 00:19:06 -0000 1.2 *************** *** 18,22 **** # ! # bio/util/restrction_enzyme/analysis/fragments.rb - # # Author:: Trevor Wennblom --- 18,22 ---- # ! # bio/util/restrction_enzyme/range/sequence_range/fragments.rb - # # Author:: Trevor Wennblom From trevor at dev.open-bio.org Tue Jan 2 00:22:29 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 00:22:29 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme/analysis test_calculated_cuts.rb, 1.2, 1.3 test_sequence_range.rb, 1.2, 1.3 Message-ID: <200701020022.l020MT3s002785@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv2765 Modified Files: test_calculated_cuts.rb test_sequence_range.rb Log Message: Index: test_sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis/test_sequence_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_sequence_range.rb 31 Dec 2006 18:46:15 -0000 1.2 --- test_sequence_range.rb 2 Jan 2007 00:22:27 -0000 1.3 *************** *** 14,24 **** require 'test/unit' ! require 'bio/util/restriction_enzyme/analysis/sequence_range' ! require 'bio/util/restriction_enzyme/analysis/fragments' ! require 'bio/util/restriction_enzyme/analysis/cut_range' ! require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/analysis/vertical_cut_range' ! require 'bio/util/restriction_enzyme/analysis/cut_ranges' module Bio #:nodoc: --- 14,24 ---- require 'test/unit' ! require 'bio/util/restriction_enzyme/range/sequence_range' ! require 'bio/util/restriction_enzyme/range/sequence_range/fragments' ! require 'bio/util/restriction_enzyme/range/cut_range' ! require 'bio/util/restriction_enzyme/range/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/range/vertical_cut_range' ! require 'bio/util/restriction_enzyme/range/cut_ranges' module Bio #:nodoc: *************** *** 27,37 **** def setup ! @t = Bio::RestrictionEnzyme::Analysis::SequenceRange ! @fs = Bio::RestrictionEnzyme::Analysis::Fragments #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! @vcr = Bio::RestrictionEnzyme::Analysis::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Analysis::CutRanges ! @hcr = Bio::RestrictionEnzyme::Analysis::HorizontalCutRange @obj_1 = @t.new(0,5) --- 27,37 ---- def setup ! @t = Bio::RestrictionEnzyme::Range::SequenceRange ! @fs = Bio::RestrictionEnzyme::Range::SequenceRange::Fragments #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! @vcr = Bio::RestrictionEnzyme::Range::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Range::CutRanges ! @hcr = Bio::RestrictionEnzyme::Range::HorizontalCutRange @obj_1 = @t.new(0,5) Index: test_calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis/test_calculated_cuts.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_calculated_cuts.rb 31 Dec 2006 18:46:15 -0000 1.2 --- test_calculated_cuts.rb 2 Jan 2007 00:22:27 -0000 1.3 *************** *** 14,22 **** require 'test/unit' ! require 'bio/util/restriction_enzyme/analysis/calculated_cuts' ! require 'bio/util/restriction_enzyme/analysis/cut_range' ! require 'bio/util/restriction_enzyme/analysis/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/analysis/vertical_cut_range' ! require 'bio/util/restriction_enzyme/analysis/cut_ranges' module Bio #:nodoc: --- 14,22 ---- require 'test/unit' ! require 'bio/util/restriction_enzyme/range/sequence_range/calculated_cuts' ! require 'bio/util/restriction_enzyme/range/cut_range' ! require 'bio/util/restriction_enzyme/range/cut_ranges' ! require 'bio/util/restriction_enzyme/range/horizontal_cut_range' ! require 'bio/util/restriction_enzyme/range/vertical_cut_range' module Bio #:nodoc: *************** *** 25,32 **** def setup ! @t = Bio::RestrictionEnzyme::Analysis::CalculatedCuts ! @vcr = Bio::RestrictionEnzyme::Analysis::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Analysis::CutRanges ! @hcr = Bio::RestrictionEnzyme::Analysis::HorizontalCutRange #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) --- 25,32 ---- def setup ! @t = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts ! @vcr = Bio::RestrictionEnzyme::Range::VerticalCutRange ! @crs = Bio::RestrictionEnzyme::Range::CutRanges ! @hcr = Bio::RestrictionEnzyme::Range::HorizontalCutRange #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) From trevor at dev.open-bio.org Tue Jan 2 06:18:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:09 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme/analysis test_cut_ranges.rb, NONE, 1.1 Message-ID: <200701020618.l026I9Lc003133@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/analysis In directory dev.open-bio.org:/tmp/cvs-serv3107/restriction_enzyme/analysis Added Files: test_cut_ranges.rb Log Message: --- NEW FILE: test_cut_ranges.rb --- # # test/unit/bio/util/restriction_enzyme/analysis/test_cut_ranges.rb - Unit test for Bio::RestrictionEnzyme::Analysis::SequenceRange # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby # # $Id: test_cut_ranges.rb,v 1.1 2007/01/02 06:18:07 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 6, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'test/unit' require 'bio/util/restriction_enzyme/range/sequence_range' require 'bio/util/restriction_enzyme/range/sequence_range/fragments' require 'bio/util/restriction_enzyme/range/cut_range' require 'bio/util/restriction_enzyme/range/horizontal_cut_range' require 'bio/util/restriction_enzyme/range/vertical_cut_range' require 'bio/util/restriction_enzyme/range/cut_ranges' module Bio #:nodoc: class TestCutRanges < Test::Unit::TestCase #:nodoc: def setup @t = Bio::RestrictionEnzyme::Range::SequenceRange @fs = Bio::RestrictionEnzyme::Range::SequenceRange::Fragments #a.add_cut_range(p_cut_left, p_cut_right, c_cut_left, c_cut_right ) @vcr = Bio::RestrictionEnzyme::Range::VerticalCutRange @crs = Bio::RestrictionEnzyme::Range::CutRanges @hcr = Bio::RestrictionEnzyme::Range::HorizontalCutRange @obj_2 = @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil)] ) @obj_3 = @crs.new( [@vcr.new(0,2,nil,nil), @vcr.new(3,nil,4,nil), @hcr.new(0), @hcr.new(5)] ) @obj_7 = @crs.new( [@vcr.new(nil,2,nil,nil), @hcr.new(0,2)] ) @obj_z = @crs.new( [@vcr.new(nil,2,nil,5), @hcr.new(1,6)] ) end def test_obj_z assert_equal(6, @obj_z.max) assert_equal(1, @obj_z.min) assert_equal(2, @obj_z.min_vertical) assert_equal(5, @obj_z.max_vertical) assert_equal(true, @obj_z.include?(6)) assert_equal(true, @obj_z.include?(4)) assert_equal(true, @obj_z.include?(2)) assert_equal(false, @obj_z.include?(-1)) assert_equal(false, @obj_z.include?(0)) assert_equal(false, @obj_z.include?(7)) end def test_obj_7 assert_equal(2, @obj_7.max) assert_equal(0, @obj_7.min) assert_equal(2, @obj_7.min_vertical) assert_equal(2, @obj_7.max_vertical) assert_equal(true, @obj_7.include?(0)) assert_equal(true, @obj_7.include?(1)) assert_equal(true, @obj_7.include?(2)) assert_equal(false, @obj_7.include?(-1)) assert_equal(false, @obj_7.include?(3)) end def test_obj_2 assert_equal(4, @obj_2.max) assert_equal(0, @obj_2.min) assert_equal(0, @obj_2.min_vertical) assert_equal(4, @obj_2.max_vertical) assert_equal(true, @obj_2.include?(0)) assert_equal(true, @obj_2.include?(1)) assert_equal(true, @obj_2.include?(3)) assert_equal(true, @obj_2.include?(4)) assert_equal(false, @obj_2.include?(-1)) assert_equal(false, @obj_2.include?(5)) end def test_obj_3 assert_equal(5, @obj_3.max) assert_equal(0, @obj_3.min) assert_equal(0, @obj_3.min_vertical) assert_equal(4, @obj_3.max_vertical) assert_equal(true, @obj_3.include?(0)) assert_equal(true, @obj_3.include?(1)) assert_equal(true, @obj_3.include?(3)) assert_equal(true, @obj_3.include?(4)) assert_equal(true, @obj_3.include?(5)) assert_equal(false, @obj_3.include?(-1)) assert_equal(false, @obj_3.include?(6)) end end end From trevor at dev.open-bio.org Tue Jan 2 06:18:09 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:09 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.4, 1.5 test_double_stranded.rb, 1.3, 1.4 Message-ID: <200701020618.l026I96E003129@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3107/restriction_enzyme Modified Files: test_analysis.rb test_double_stranded.rb Log Message: Index: test_double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_double_stranded.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_double_stranded.rb 1 Jan 2007 02:16:05 -0000 1.3 --- test_double_stranded.rb 2 Jan 2007 06:18:07 -0000 1.4 *************** *** 35,39 **** @obj_7 = @t.new('garraxt', @cl.new(3,2), @cl.new(9,11)) ! @obj_8 = @t.new('garraxt', 3..2, 9..11) @obj_9 = @t.new('garraxt', [3,2], [9,11]) --- 35,39 ---- @obj_7 = @t.new('garraxt', @cl.new(3,2), @cl.new(9,11)) ! # @obj_8 = @t.new('garraxt', 3..2, 9..11) @obj_9 = @t.new('garraxt', [3,2], [9,11]) *************** *** 57,61 **** assert_equal('gar^raxtnn^n', @obj_7.primary.with_cut_symbols) ! assert_equal('gar^raxtnn^n', @obj_8.primary.with_cut_symbols) assert_equal('gar^raxtnn^n', @obj_9.primary.with_cut_symbols) --- 57,61 ---- assert_equal('gar^raxtnn^n', @obj_7.primary.with_cut_symbols) ! # assert_equal('gar^raxtnn^n', @obj_8.primary.with_cut_symbols) assert_equal('gar^raxtnn^n', @obj_9.primary.with_cut_symbols) *************** *** 75,79 **** assert_equal('ct^yytxannnn^n', @obj_7.complement.with_cut_symbols) ! assert_equal('ct^yytxannnn^n', @obj_8.complement.with_cut_symbols) assert_equal('ct^yytxannnn^n', @obj_9.complement.with_cut_symbols) --- 75,79 ---- assert_equal('ct^yytxannnn^n', @obj_7.complement.with_cut_symbols) ! # assert_equal('ct^yytxannnn^n', @obj_8.complement.with_cut_symbols) assert_equal('ct^yytxannnn^n', @obj_9.complement.with_cut_symbols) Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_analysis.rb 31 Dec 2006 18:46:14 -0000 1.4 --- test_analysis.rb 2 Jan 2007 06:18:07 -0000 1.5 *************** *** 31,34 **** --- 31,36 ---- @obj_4 = @t.cut('atgcatgcatgc', e1) + @obj_4bd = @t.cut('atgcatgcatgccccc', e1, 'cc^c') + e2 = @enz.new('atgcatgc', [3,5]) @obj_5 = @t.cut('atgcatgcatgc', e2) *************** *** 39,42 **** --- 41,47 ---- @obj_7 = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII') + @obj_7b = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaaccc', 'EcoRII', 'HincII', 'cc^c') + @obj_7bd = @t.cut_without_permutations('gaccaggaaaaagaccaggaaagcctggaaaagttaaccc', 'EcoRII', 'HincII', 'cc^c') + @obj_8 = @t.cut('gaccaggaaaaagaccaggaaagcctggaaaagttaac', 'EcoRII', 'HincII') *************** *** 76,83 **** --- 81,105 ---- assert_equal(["ag", "agt", "cag"], @obj_3.primary) assert_equal(["atg", "atgcatg", "catg", "catgc"], @obj_4.primary) + =begin + A T G^C A T G C + + A T G C A T G C A T G C + + A T G^C A T G^C A T G C + + A T G C A T G^C A T G C + =end + + + e1 = @enz.new('atgcatgc', [3,3]) + @obj_4 = @t.cut('atgcatgcatgc', e1) + assert_equal(["atg", "atgcatg", "catgc", "catgcatgc"], @obj_5.primary) assert_equal(["a", "ag", "g", "ga"], @obj_6.primary) assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7.primary) assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8.primary) + + assert_equal(["atg", "atgcatg", "c", "catg", "catgcc", "catgccc", "cc", "cc"], @obj_4bd.primary) + assert_equal(["gg", "gg", "ggg", "gtac", "gtacg", "gtacgg", "tac", "tacgtac"], @obj_4bd.complement) end From trevor at dev.open-bio.org Tue Jan 2 06:18:40 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range cut_ranges.rb, 1.1, 1.2 horizontal_cut_range.rb, 1.1, 1.2 Message-ID: <200701020618.l026IeZg003178@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv3143/restriction_enzyme/range Modified Files: cut_ranges.rb horizontal_cut_range.rb Log Message: Index: horizontal_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/horizontal_cut_range.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** horizontal_cut_range.rb 2 Jan 2007 00:13:07 -0000 1.1 --- horizontal_cut_range.rb 2 Jan 2007 06:18:38 -0000 1.2 *************** *** 54,60 **** @c_cut_left = nil @c_cut_right = nil ! @min = nil ! @max = nil ! @range = nil @hcuts = (left..right) --- 54,61 ---- @c_cut_left = nil @c_cut_right = nil ! @min = left # NOTE this used to be 'nil', make sure all tests work ! @max = right # NOTE this used to be 'nil', make sure all tests work ! @range = (@min.. at max) unless @min == nil or @max == nil # NOTE this used to be 'nil', make sure all tests work ! @hcuts = (left..right) Index: cut_ranges.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/cut_ranges.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** cut_ranges.rb 2 Jan 2007 00:13:07 -0000 1.1 --- cut_ranges.rb 2 Jan 2007 06:18:38 -0000 1.2 *************** *** 29,32 **** --- 29,53 ---- def max; self.collect{|a| a.max}.flatten.sort.last; end def include?(i); self.collect{|a| a.include?(i)}.include?(true); end + + def min_vertical + vertical_min_max_helper( :min ) + end + + def max_vertical + vertical_min_max_helper( :max ) + end + + protected + + def vertical_min_max_helper( sym_which ) + tmp = [] + self.each do |a| + next unless a.class == Bio::RestrictionEnzyme::Range::VerticalCutRange + tmp << a.send( sym_which ) + end + z = (sym_which == :max) ? :last : :first + tmp.flatten.sort.send(z) + end + end # CutRanges end # Range From trevor at dev.open-bio.org Tue Jan 2 06:18:40 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.9, 1.10 analysis_basic.rb, 1.2, 1.3 Message-ID: <200701020618.l026IeDC003167@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3143/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.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** analysis_basic.rb 2 Jan 2007 00:13:07 -0000 1.2 --- analysis_basic.rb 2 Jan 2007 06:18:38 -0000 1.3 *************** *** 81,137 **** tmp = create_enzyme_actions( sequence, *args ) ! enzyme_actions = tmp[0].merge(tmp[1]) ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) ! enzyme_actions.each do |id, enzyme_action| enzyme_action.cut_ranges.each do |cut_range| ! sr_with_cuts.add_cut_range(cut_range) end end ! sr_with_cuts.fragments.primary = sequence ! sr_with_cuts.fragments.complement = sequence.forward_complement ! unique_fragments_for_display( {0 => sr_with_cuts} ) end - ######### - protected - ######### - UniqueFragment = Struct.new(:primary, :complement) class UniqueFragments < Array ! def primary ! tmp = [] ! self.each { |uf| tmp << uf.primary } ! tmp.sort.map { |e| e.tr(' ', '') } ! end ! def complement ! tmp = [] ! self.each { |uf| tmp << uf.complement } ! tmp.sort.map { |e| e.tr(' ', '') } end end - def unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) - uf_ary = UniqueFragments.new - return uf_ary if hash_of_sequence_ranges_with_cuts == nil or hash_of_sequence_ranges_with_cuts.empty? - - hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| - sr_with_cuts.fragments.for_display.each do |fragment| - uf = UniqueFragment.new - uf.primary = fragment.primary - uf.complement = fragment.complement ! duplicate = false ! uf_ary.each do |element| ! if (uf.primary == element.primary) and (uf.complement == element.complement) ! duplicate = true ! break ! end ! end ! uf_ary << uf unless duplicate end end uf_ary end --- 81,130 ---- 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| ! sequence_range.add_cut_range(cut_range) end 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 ! ! protected ! ! def strip_and_sort( sym_strand ) ! self.map {|uf| uf.send( sym_strand ).tr(' ', '') }.sort end end + + ######### + protected + ######### ! # * +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| ! # NOTE might not need tr here ! uf_ary << UniqueFragment.new(fragment.primary.tr(' ', ''), fragment.complement.tr(' ', '')) end end + uf_ary.uniq! uf_ary end *************** *** 142,193 **** # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) ! id = 0 ! enzyme_actions_that_sometimes_cut = {} ! enzyme_actions_that_always_cut = {} ! indicies_of_sometimes_cut = [] ! args.each do |enzyme| enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! #enzyme_actions_that_always_cut[id] = enzyme_to_enzyme_action( enzyme, offset ) ! enzyme_actions_that_always_cut[id] = enzyme.create_action_at( offset ) ! id += 1 end end # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut ! max = enzyme_actions_that_always_cut.size - 1 ! 0.upto(max) do |i| ! enzyme_action = enzyme_actions_that_always_cut[i] conflict = false other_cut_ranges = {} - enzyme_actions_that_always_cut.each { |key,i_ea| next if i == key; other_cut_ranges[key] = i_ea.cut_ranges } other_cut_ranges.each do |key, cut_ranges| cut_ranges.each do |cut_range| next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left = cut_range.range.first ! previous_cut_right = cut_range.range.last ! if (enzyme_action.right <= previous_cut_left) or ! (enzyme_action.left > previous_cut_right) or ! (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts # no conflict else conflict = true end ! ! indicies_of_sometimes_cut += [i, key] if conflict == true end end end ! indicies_of_sometimes_cut.uniq.each do |i| ! enzyme_actions_that_sometimes_cut[i] = enzyme_actions_that_always_cut[i] ! enzyme_actions_that_always_cut.delete(i) ! end ! ! [enzyme_actions_that_sometimes_cut, enzyme_actions_that_always_cut] end --- 135,209 ---- # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) ! require 'set' ! always_cut = [] ! indicies_of_sometimes_cut = Set.new ! args.each do |enzyme| enzyme = Bio::RestrictionEnzyme.new(enzyme) unless enzyme.class == Bio::RestrictionEnzyme::DoubleStranded + find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! always_cut << enzyme.create_action_at( offset ) end end + + # VerticalCutRange should really be called VerticalAndHorizontalCutRange + + # * always_cut is now full of EnzymeActions at specific locations across + # the sequence. + # * always_cut will now be examined to see if any EnzymeActions may + # conflict with one another, and if they do they'll be made note of in + # indicies_of_sometimes_cut. They will then be remove FIXME + # * a conflict occurs if another enzyme's bind site is compromised do due + # to another enzyme's cut. Enzyme's bind sites may overlap and not be + # 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. + + dirty = Set.new + =begin + always_cut.each_with_index do |ea, index| + + end + =end # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut ! always_cut.each_with_index do |ea, index1| conflict = false other_cut_ranges = {} + always_cut.each_with_index do |i_ea, index2| + next if index1 == index2 + other_cut_ranges[index2] = i_ea.cut_ranges + end + other_cut_ranges.each do |key, cut_ranges| + cut_ranges.each do |cut_range| next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left, previous_cut_right = cut_range.min, cut_range.max ! if (ea.right <= previous_cut_left) or ! (ea.left > previous_cut_right) or ! (ea.left > previous_cut_left and ea.right <= previous_cut_right) # in-between cuts # no conflict else conflict = true end ! indicies_of_sometimes_cut += [index1, key] if conflict == true end end end + + sometimes_cut = always_cut.values_at( *indicies_of_sometimes_cut ) + always_cut.delete_if {|x| sometimes_cut.include? x } ! #puts "Sometimes cut: #{sometimes_cut.size}" ! #puts "Always cut: #{always_cut.size}" ! #puts ! [sometimes_cut, always_cut] end Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** analysis.rb 2 Jan 2007 00:13:07 -0000 1.9 --- analysis.rb 2 Jan 2007 06:18:38 -0000 1.10 *************** *** 40,45 **** def cut( sequence, *args ) return nil if !sequence.kind_of?(String) or sequence.empty? ! hash_of_sequence_ranges_with_cuts = cut_and_return_by_permutations( sequence, *args ) ! unique_fragments_for_display( hash_of_sequence_ranges_with_cuts ) end --- 40,44 ---- 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 *************** *** 51,121 **** return {} if !sequence.kind_of?(String) or sequence.empty? sequence = Bio::Sequence::NA.new( sequence ) enzyme_actions, initial_cuts = create_enzyme_actions( sequence, *args ) ! return {} if enzyme_actions.empty? and initial_cuts.empty? if enzyme_actions.size > 1 permutations = permute(enzyme_actions.size) ! else ! permutations = [] ! end ! ! # Indexed by permutation. ! hash_of_sequence_ranges_with_cuts = {} ! ! if permutations.empty? ! sr_with_cuts = 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| sr_with_cuts.add_cut_range(cut_range) } } ! hash_of_sequence_ranges_with_cuts[0] = sr_with_cuts ! end ! ! permutations.each do |permutation| ! previous_cut_ranges = [] ! sr_with_cuts = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) ! initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } } ! permutation.each do |id| ! enzyme_action = enzyme_actions[id] ! # conflict is false if the current enzyme action may cut in it's range. ! # conflict is true if it cannot do to a previous enzyme action making ! # a cut where this enzyme action needs a whole recognition site. ! conflict = false ! # If current size of enzyme_action overlaps with previous cut_range, don't cut ! # note that the enzyme action may fall in the middle of a previous enzyme action ! # so all cut locations must be checked that would fall underneath. ! previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left = cut_range.range.first ! previous_cut_right = cut_range.range.last ! # Keep in mind: ! # * The cut location is to the immediate right of the base located at the index. ! # ex: at^gc -- the cut location is at index 1 ! # * The enzyme action location is located at the base of the index. ! # ex: atgc -- 0 => 'a', 1 => 't', 2 => 'g', 3 => 'c' ! if (enzyme_action.right <= previous_cut_left) or ! (enzyme_action.left > previous_cut_right) or ! (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts ! # no conflict ! else ! conflict = true end end ! next if conflict == true ! enzyme_action.cut_ranges.each { |cut_range| sr_with_cuts.add_cut_range(cut_range) } ! previous_cut_ranges += enzyme_action.cut_ranges end ! hash_of_sequence_ranges_with_cuts[permutation] = sr_with_cuts ! end ! hash_of_sequence_ranges_with_cuts.each do |permutation, sr_with_cuts| ! sr_with_cuts.fragments.primary = sequence ! sr_with_cuts.fragments.complement = sequence.forward_complement end ! hash_of_sequence_ranges_with_cuts end --- 50,129 ---- 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) ! ! 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| ! enzyme_action = enzyme_actions[id] ! # conflict is false if the current enzyme action may cut in it's range. ! # conflict is true if it cannot due to a previous enzyme action making ! # a cut where this enzyme action needs a whole recognition site. ! conflict = false ! # If current size of enzyme_action overlaps with previous cut_range, don't cut ! # note that the enzyme action may fall in the middle of a previous enzyme action ! # so all cut locations must be checked that would fall underneath. ! previous_cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left = cut_range.range.first ! previous_cut_right = cut_range.range.last ! # Keep in mind: ! # * The cut location is to the immediate right of the base located at the index. ! # ex: at^gc -- the cut location is at index 1 ! # * The enzyme action location is located at the base of the index. ! # ex: atgc -- 0 => 'a', 1 => 't', 2 => 'g', 3 => 'c' ! if (enzyme_action.right <= previous_cut_left) or ! (enzyme_action.left > previous_cut_right) or ! (enzyme_action.left > previous_cut_left and enzyme_action.right <= previous_cut_right) # in between cuts ! # no conflict ! else ! conflict = true ! end end + + next if conflict == true + enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } + previous_cut_ranges += enzyme_action.cut_ranges end ! sequence_range.fragments.primary = sequence ! sequence_range.fragments.complement = sequence.forward_complement ! my_hash[permutation] = sequence_range end + + 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 ! my_hash[0] = sequence_range end ! my_hash end From trevor at dev.open-bio.org Tue Jan 2 06:18:40 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 06:18:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/double_stranded cut_location_pair.rb, 1.3, 1.4 Message-ID: <200701020618.l026IeVN003173@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded In directory dev.open-bio.org:/tmp/cvs-serv3143/restriction_enzyme/double_stranded Modified Files: cut_location_pair.rb Log Message: Index: cut_location_pair.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cut_location_pair.rb 1 Jan 2007 05:07:04 -0000 1.3 --- cut_location_pair.rb 2 Jan 2007 06:18:38 -0000 1.4 *************** *** 63,67 **** a,b = init_with_array( pair[0] ) ! elsif pair[0].kind_of? Range a,b = init_with_array( [pair[0].first, pair[0].last] ) --- 63,67 ---- a,b = init_with_array( pair[0] ) ! elsif pair[0].kind_of? Range # FIXME This seems to be broken? Check tests a,b = init_with_array( [pair[0].first, pair[0].last] ) *************** *** 70,74 **** else ! raise ArgumentError, "#{pair[0].class} is an invalid class type." end --- 70,74 ---- else ! raise ArgumentError, "#{pair[0].class} is an invalid class type to initalize CutLocationPair." end From trevor at dev.open-bio.org Tue Jan 2 07:33:48 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 07:33:48 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.10, 1.11 analysis_basic.rb, 1.3, 1.4 Message-ID: <200701020733.l027Xm2G003294@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3272/lib/bio/util/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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** analysis_basic.rb 2 Jan 2007 06:18:38 -0000 1.3 --- analysis_basic.rb 2 Jan 2007 07:33:46 -0000 1.4 *************** *** 122,127 **** hsh.each do |permutation_id, sequence_range| sequence_range.fragments.for_display.each do |fragment| ! # NOTE might not need tr here ! uf_ary << UniqueFragment.new(fragment.primary.tr(' ', ''), fragment.complement.tr(' ', '')) end end --- 122,126 ---- 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 *************** *** 136,141 **** def create_enzyme_actions( sequence, *args ) require 'set' ! always_cut = [] ! indicies_of_sometimes_cut = Set.new args.each do |enzyme| --- 135,139 ---- def create_enzyme_actions( sequence, *args ) require 'set' ! all_enzyme_actions = [] args.each do |enzyme| *************** *** 143,147 **** find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! always_cut << enzyme.create_action_at( offset ) end end --- 141,145 ---- find_match_locations( sequence, enzyme.primary.to_re ).each do |offset| ! all_enzyme_actions << enzyme.create_action_at( offset ) end end *************** *** 149,155 **** # VerticalCutRange should really be called VerticalAndHorizontalCutRange ! # * always_cut is now full of EnzymeActions at specific locations across # the sequence. ! # * always_cut will now be examined to see if any EnzymeActions may # conflict with one another, and if they do they'll be made note of in # indicies_of_sometimes_cut. They will then be remove FIXME --- 147,153 ---- # VerticalCutRange should really be called VerticalAndHorizontalCutRange ! # * all_enzyme_actions is now full of EnzymeActions at specific locations across # the sequence. ! # * all_enzyme_actions will now be examined to see if any EnzymeActions may # conflict with one another, and if they do they'll be made note of in # indicies_of_sometimes_cut. They will then be remove FIXME *************** *** 163,208 **** # is competition. ! dirty = Set.new ! ! =begin ! always_cut.each_with_index do |ea, index| ! ! end ! =end ! # enzyme_actions_that_always_cut may lose members, the members to be lost are recorded in indicies_of_sometimes_cut ! ! always_cut.each_with_index do |ea, index1| ! conflict = false ! other_cut_ranges = {} ! always_cut.each_with_index do |i_ea, index2| ! next if index1 == index2 ! other_cut_ranges[index2] = i_ea.cut_ranges ! end ! other_cut_ranges.each do |key, cut_ranges| ! ! cut_ranges.each do |cut_range| ! next unless cut_range.class == Bio::RestrictionEnzyme::Range::VerticalCutRange # we aren't concerned with horizontal cuts ! previous_cut_left, previous_cut_right = cut_range.min, cut_range.max ! if (ea.right <= previous_cut_left) or ! (ea.left > previous_cut_right) or ! (ea.left > previous_cut_left and ea.right <= previous_cut_right) # in-between cuts ! # no conflict ! else ! conflict = true ! end ! indicies_of_sometimes_cut += [index1, key] if conflict == true end end end ! ! sometimes_cut = always_cut.values_at( *indicies_of_sometimes_cut ) always_cut.delete_if {|x| sometimes_cut.include? x } - #puts "Sometimes cut: #{sometimes_cut.size}" - #puts "Always cut: #{always_cut.size}" - #puts [sometimes_cut, always_cut] end --- 161,199 ---- # 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 ! # since trailing horizontal cuts would have no influence on the bind site. ! # ! # If example Enzyme A makes this cut pattern (cut range 2..5): ! # ! # 0 1 2|3 4 5 6 7 ! # +-----+ ! # 0 1 2 3 4 5|6 7 ! # ! # 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 ! all_enzyme_actions[0..-2].each_with_index do |current_enzyme_action, i| ! next if competition_indexes.include? i ! all_enzyme_actions[i+1..-1].each_with_index do |comparison_enzyme_action, j| ! j += (i + 1) ! next if competition_indexes.include? j ! if (current_enzyme_action.right <= comparison_enzyme_action.cut_ranges.min_vertical) or ! (current_enzyme_action.left > comparison_enzyme_action.cut_ranges.max_vertical) ! # no conflict ! else ! competition_indexes += [i, j] # merge both indexes into the flat set end end end ! ! sometimes_cut = all_enzyme_actions.values_at( *competition_indexes ) ! always_cut = all_enzyme_actions always_cut.delete_if {|x| sometimes_cut.include? x } [sometimes_cut, always_cut] end Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** analysis.rb 2 Jan 2007 06:18:38 -0000 1.10 --- analysis.rb 2 Jan 2007 07:33:46 -0000 1.11 *************** *** 69,73 **** initial_cuts.each { |enzyme_action| ! raise initial_cuts.inspect enzyme_action.cut_ranges.each { |cut_range| --- 69,73 ---- initial_cuts.each { |enzyme_action| ! #raise initial_cuts.inspect enzyme_action.cut_ranges.each { |cut_range| From trevor at dev.open-bio.org Tue Jan 2 07:33:48 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Tue, 02 Jan 2007 07:33:48 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.5, 1.6 Message-ID: <200701020733.l027Xm8l003300@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv3272/test/unit/bio/util/restriction_enzyme Modified Files: test_analysis.rb Log Message: Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_analysis.rb 2 Jan 2007 06:18:07 -0000 1.5 --- test_analysis.rb 2 Jan 2007 07:33:46 -0000 1.6 *************** *** 31,35 **** @obj_4 = @t.cut('atgcatgcatgc', e1) ! @obj_4bd = @t.cut('atgcatgcatgccccc', e1, 'cc^c') e2 = @enz.new('atgcatgc', [3,5]) --- 31,35 ---- @obj_4 = @t.cut('atgcatgcatgc', e1) ! @obj_4bd = @t.cut('atgcatgcatgccc', e1, 'cc^c') # mix of always cut and sometimes cut e2 = @enz.new('atgcatgc', [3,5]) *************** *** 91,105 **** =end - - e1 = @enz.new('atgcatgc', [3,3]) - @obj_4 = @t.cut('atgcatgcatgc', e1) - assert_equal(["atg", "atgcatg", "catgc", "catgcatgc"], @obj_5.primary) assert_equal(["a", "ag", "g", "ga"], @obj_6.primary) assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7.primary) assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8.primary) ! ! assert_equal(["atg", "atgcatg", "c", "catg", "catgcc", "catgccc", "cc", "cc"], @obj_4bd.primary) ! assert_equal(["gg", "gg", "ggg", "gtac", "gtacg", "gtacgg", "tac", "tacgtac"], @obj_4bd.complement) end --- 91,121 ---- =end assert_equal(["atg", "atgcatg", "catgc", "catgcatgc"], @obj_5.primary) assert_equal(["a", "ag", "g", "ga"], @obj_6.primary) assert_equal(["ccaggaaaaaga", "ccaggaaag", "cctggaaaagttaac", "ga"], @obj_7.primary) assert_equal(["aac", "ccaggaaaaaga", "ccaggaaag", "cctggaaaagtt", "ga"], @obj_8.primary) ! ! =begin ! e1 = @enz.new('atgcatgc', [3,3]) ! @obj_4bd = @t.cut('atgcatgcatgccc', e1, 'cc^c') # mix of sometimes cut and always cut ! ! [#, ! #, ! #, ! #, ! #] ! =end ! assert_equal(["atg", "atgcatg", "c", "catg", "catgcc"], @obj_4bd.primary) ! assert_equal(["gg", "gtac", "gtacg", "tac", "tacgtac"], @obj_4bd.complement) end From trevor at dev.open-bio.org Fri Jan 5 05:33:17 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 05:33:17 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.6, 1.7 Message-ID: <200701050533.l055XHeA015812@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15792/restriction_enzyme Modified Files: test_analysis.rb Log Message: Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_analysis.rb 2 Jan 2007 07:33:46 -0000 1.6 --- test_analysis.rb 5 Jan 2007 05:33:15 -0000 1.7 *************** *** 75,84 **** assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Analysis::UniqueFragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Analysis::UniqueFragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) assert_equal(["ag", "agt", "cag"], @obj_3.primary) assert_equal(["atg", "atgcatg", "catg", "catgc"], @obj_4.primary) =begin A T G^C A T G C --- 75,85 ---- assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) assert_equal(["ag", "agt", "cag"], @obj_3.primary) assert_equal(["atg", "atgcatg", "catg", "catgc"], @obj_4.primary) + =begin A T G^C A T G C From trevor at dev.open-bio.org Fri Jan 5 05:33:31 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 05:33:31 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.11, 1.12 analysis_basic.rb, 1.4, 1.5 Message-ID: <200701050533.l055XVsl015840@dev.open-bio.org> 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 ---- From trevor at dev.open-bio.org Fri Jan 5 06:03:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:03:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb,1.8,1.9 Message-ID: <200701050603.l0563OaL015895@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv15871 Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** restriction_enzyme.rb 1 Jan 2007 02:31:22 -0000 1.8 --- restriction_enzyme.rb 5 Jan 2007 06:03:22 -0000 1.9 *************** *** 28,31 **** --- 28,32 ---- # comments would be appreciated. # + # FIXME needs better docs # # = Description From trevor at dev.open-bio.org Fri Jan 5 06:03:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:03:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.1, 1.2 vertical_cut_range.rb, 1.1, 1.2 Message-ID: <200701050603.l0563Owf015907@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv15871/restriction_enzyme/range Modified Files: sequence_range.rb vertical_cut_range.rb Log Message: Index: vertical_cut_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/vertical_cut_range.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** vertical_cut_range.rb 2 Jan 2007 00:13:07 -0000 1.1 --- vertical_cut_range.rb 5 Jan 2007 06:03:22 -0000 1.2 *************** *** 25,28 **** --- 25,29 ---- # License:: Distributes under the same terms as Ruby # + # FIXME docs are kind of out of date. Change this to VerticalAndHorizontalCutRange class VerticalCutRange < CutRange attr_reader :p_cut_left, :p_cut_right Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sequence_range.rb 2 Jan 2007 00:13:07 -0000 1.1 --- sequence_range.rb 5 Jan 2007 06:03:22 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- # License:: Distributes under the same terms as Ruby # + # FIXME algorithm heavy, needs better docs class SequenceRange *************** *** 64,70 **** end ! =begin ! Special Case: Horizontal cuts at beginning or end of strand ! =end Bin = Struct.new(:c, :p) --- 65,69 ---- end ! # NOTE Special Case: Horizontal cuts at beginning or end of strand Bin = Struct.new(:c, :p) From trevor at dev.open-bio.org Fri Jan 5 06:03:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:03:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.12, 1.13 analysis_basic.rb, 1.5, 1.6 double_stranded.rb, 1.5, 1.6 Message-ID: <200701050603.l0563OJ4015900@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15871/restriction_enzyme Modified Files: analysis.rb analysis_basic.rb double_stranded.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.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** analysis_basic.rb 5 Jan 2007 05:33:29 -0000 1.5 --- analysis_basic.rb 5 Jan 2007 06:03:22 -0000 1.6 *************** *** 90,94 **** # * +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? --- 90,94 ---- # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 134,138 **** # View these with the 'primary' and 'complement' methods. # ! # Fragment is a simple +Struct+ object. Fragment = Struct.new(:primary, :complement) --- 134,140 ---- # View these with the 'primary' and 'complement' methods. # ! # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. ! # ! # *Note: unrelated to SequenceRange::Fragment* Fragment = Struct.new(:primary, :complement) *************** *** 144,147 **** --- 146,151 ---- # not return duplicate items and does not return the spacing that you would # find by accessing the members directly. + # + # *Note: unrelated to SequenceRange::Fragments* class Fragments < Array def primary; strip_and_sort(:primary); end *************** *** 161,170 **** # 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 --- 165,174 ---- # Take the fragments from SequenceRange objects generated from add_cut_range ! # and return unique results as a Bio::RestrictionEnzyme::Analysis::Fragment object. # # --- # *Arguments* # * +hsh+: +Hash+ Keys are a permutation ID, if any. Values are SequenceRange objects that have cuts applied. ! # *Returns*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. def fragments_for_display( hsh ) ary = Fragments.new *************** *** 182,187 **** # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. # ! # +sequence+:: The string of DNA to match the enzyme recognition sites against ! # +args+:: The enzymes to use. def create_enzyme_actions( sequence, *args ) all_enzyme_actions = [] --- 186,194 ---- # Creates an array of EnzymeActions based on the DNA sequence and supplied enzymes. # ! # --- ! # *Arguments* ! # * +sequence+: The string of DNA to match the enzyme recognition sites against ! # * +args+:: The enzymes to use. ! # *Returns*:: +Array+ with the first element being an array of EnzymeAction objects that +sometimes_cut+, and are subject to competition. The second is an array of EnzymeAction objects that +always_cut+ and are not subject to competition. def create_enzyme_actions( sequence, *args ) all_enzyme_actions = [] Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** analysis.rb 5 Jan 2007 05:33:29 -0000 1.12 --- analysis.rb 5 Jan 2007 06:03:22 -0000 1.13 *************** *** 51,55 **** # * +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? --- 51,55 ---- # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 116,119 **** --- 116,120 ---- # * The enzyme action location is located at the base of the index. # ex: atgc -- 0 => 'a', 1 => 't', 2 => 'g', 3 => 'c' + # method create_enzyme_actions has similar commentary if interested if (enzyme_action.right <= previous_cut_left) or (enzyme_action.left > previous_cut_right) or *************** *** 128,132 **** enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } previous_cut_ranges += enzyme_action.cut_ranges ! end # Fill in the source sequence for sequence_range so it knows what bases --- 129,133 ---- enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } previous_cut_ranges += enzyme_action.cut_ranges ! end # permutation.each # Fill in the source sequence for sequence_range so it knows what bases *************** *** 135,141 **** sequence_range.fragments.complement = sequence.forward_complement my_hash[permutation] = sequence_range ! end ! else # !if enzyme_actions.size > 1 sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } } --- 136,143 ---- sequence_range.fragments.complement = sequence.forward_complement my_hash[permutation] = sequence_range ! end # permutations.each ! else # if enzyme_actions.size == 1 ! # no permutations, just do it sequence_range = Bio::RestrictionEnzyme::Range::SequenceRange.new( 0, 0, sequence.size-1, sequence.size-1 ) initial_cuts.each { |enzyme_action| enzyme_action.cut_ranges.each { |cut_range| sequence_range.add_cut_range(cut_range) } } *************** *** 148,151 **** --- 150,191 ---- end + + # Returns permutation orders for a given number of elements. + # + # Examples: + # permute(0) # => [[0]] + # permute(1) # => [[0]] + # permute(2) # => [[1, 0], [0, 1]] + # permute(3) # => [[2, 1, 0], [2, 0, 1], [1, 2, 0], [0, 2, 1], [1, 0, 2], [0, 1, 2]] + # permute(4) # => [[3, 2, 1, 0], + # [3, 2, 0, 1], + # [3, 1, 2, 0], + # [3, 0, 2, 1], + # [3, 1, 0, 2], + # [3, 0, 1, 2], + # [2, 3, 1, 0], + # [2, 3, 0, 1], + # [1, 3, 2, 0], + # [0, 3, 2, 1], + # [1, 3, 0, 2], + # [0, 3, 1, 2], + # [2, 1, 3, 0], + # [2, 0, 3, 1], + # [1, 2, 3, 0], + # [0, 2, 3, 1], + # [1, 0, 3, 2], + # [0, 1, 3, 2], + # [2, 1, 0, 3], + # [2, 0, 1, 3], + # [1, 2, 0, 3], + # [0, 2, 1, 3], + # [1, 0, 2, 3], + # [0, 1, 2, 3]] + # + # --- + # *Arguments* + # * +count+: +Number+ of different elements to be permuted + # * +permutations+: ignore - for the recursive algorithm + # *Returns*:: +Array+ of +Array+ objects with different possible permutation orders. See examples. def permute(count, permutations = [[0]]) return permutations if count <= 1 Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** double_stranded.rb 2 Jan 2007 00:13:07 -0000 1.5 --- double_stranded.rb 5 Jan 2007 06:03:22 -0000 1.6 *************** *** 41,44 **** --- 41,46 ---- # * SingleStrand methods may be used on DoubleStranded and they will be passed to +primary+. # + # + # FIXME needs better docs class DoubleStranded include CutSymbol From trevor at dev.open-bio.org Fri Jan 5 06:11:17 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:11:17 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb,1.9,1.10 Message-ID: <200701050611.l056BHgZ015938@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv15916 Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** restriction_enzyme.rb 5 Jan 2007 06:03:22 -0000 1.9 --- restriction_enzyme.rb 5 Jan 2007 06:11:15 -0000 1.10 *************** *** 233,236 **** --- 233,275 ---- 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. + # + # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. + # + # *Note: unrelated to SequenceRange::Fragment* + 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. + # + # *Note: unrelated to SequenceRange::Fragments* + class Fragments < Array + def primary; strip_and_sort(:primary); end + def complement; strip_and_sort(:complement); end + + protected + + def strip_and_sort( sym_strand ) + self.map {|uf| uf.send( sym_strand ).tr(' ', '') }.sort + end + end end # RestrictionEnzyme end # Bio From trevor at dev.open-bio.org Fri Jan 5 06:11:17 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:11:17 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.13, 1.14 analysis_basic.rb, 1.6, 1.7 Message-ID: <200701050611.l056BHeg015943@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15916/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.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** analysis_basic.rb 5 Jan 2007 06:03:22 -0000 1.6 --- analysis_basic.rb 5 Jan 2007 06:11:15 -0000 1.7 *************** *** 90,94 **** # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 90,94 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 119,161 **** 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. ! # ! # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. ! # ! # *Note: unrelated to SequenceRange::Fragment* ! 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. ! # ! # *Note: unrelated to SequenceRange::Fragments* ! class Fragments < Array ! def primary; strip_and_sort(:primary); end ! def complement; strip_and_sort(:complement); end ! ! protected ! ! def strip_and_sort( sym_strand ) ! self.map {|uf| uf.send( sym_strand ).tr(' ', '') }.sort ! end ! end ######### --- 119,123 ---- end ! ######### *************** *** 177,181 **** hsh.each do |permutation_id, sequence_range| sequence_range.fragments.for_display.each do |fragment| ! ary << Fragment.new(fragment.primary, fragment.complement) end end --- 139,143 ---- hsh.each do |permutation_id, sequence_range| sequence_range.fragments.for_display.each do |fragment| ! ary << Bio::RestrictionEnzyme::Fragment.new(fragment.primary, fragment.complement) end end Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** analysis.rb 5 Jan 2007 06:03:22 -0000 1.13 --- analysis.rb 5 Jan 2007 06:11:15 -0000 1.14 *************** *** 51,55 **** # * +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*:: Bio::RestrictionEnzyme::Analysis::Fragments object populated with Bio::RestrictionEnzyme::Analysis::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 51,55 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? From trevor at dev.open-bio.org Fri Jan 5 06:11:41 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:11:41 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/util/restriction_enzyme test_analysis.rb, 1.7, 1.8 Message-ID: <200701050611.l056BfBr015972@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv15952/restriction_enzyme Modified Files: test_analysis.rb Log Message: Index: test_analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/util/restriction_enzyme/test_analysis.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_analysis.rb 5 Jan 2007 05:33:15 -0000 1.7 --- test_analysis.rb 5 Jan 2007 06:11:39 -0000 1.8 *************** *** 75,80 **** assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Analysis::Fragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) --- 75,80 ---- assert_equal(["gtc", "tc"], @obj_1.complement) assert_equal(2, @obj_1.size) ! assert_equal(Bio::RestrictionEnzyme::Fragments, @obj_1.class) ! assert_equal(Bio::RestrictionEnzyme::Fragment, @obj_1[0].class) assert_equal(["ag"], @obj_2.primary) From trevor at dev.open-bio.org Fri Jan 5 06:33:03 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:33:03 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util restriction_enzyme.rb, 1.10, 1.11 Message-ID: <200701050633.l056X3Dx016024@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util In directory dev.open-bio.org:/tmp/cvs-serv16002 Modified Files: restriction_enzyme.rb Log Message: Index: restriction_enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme.rb,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** restriction_enzyme.rb 5 Jan 2007 06:11:15 -0000 1.10 --- restriction_enzyme.rb 5 Jan 2007 06:33:01 -0000 1.11 *************** *** 233,265 **** 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. # ! # Bio::RestrictionEnzyme::Analysis::Fragment is a simple +Struct+ object. # ! # *Note: unrelated to SequenceRange::Fragment* 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. # ! # *Note: unrelated to SequenceRange::Fragments* class Fragments < Array def primary; strip_and_sort(:primary); end --- 233,277 ---- end ! # A Bio::RestrictionEnzyme::Fragment is a DNA fragment composed of fused primary and ! # complementary strands that would be found floating in solution after a full ! # sequence is digested by one or more RestrictionEnzymes. # # 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 they were cut. # # Example: # ! # Fragment 1: ! # primary = "attaca" ! # complement = " atga" # ! # Fragment 2: ! # primary = "g " ! # complement = "cta" # ! # View these with the +primary+ and +complement+ methods. # ! # Bio::RestrictionEnzyme::Fragment is a simple +Struct+ object. ! # ! # Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragment Fragment = Struct.new(:primary, :complement) ! # Bio::RestrictionEnzyme::Fragments inherits from +Array+. # ! # Bio::RestrictionEnzyme::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 in alphabetically sorted ! # order. Note that it will ! # not return duplicate items and does not return the spacing/padding ! # that you would # find by accessing the members directly. + # + # Example: # ! # primary = ['attaca', 'g'] ! # complement = ['atga', 'cta'] ! # ! # Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragments class Fragments < Array def primary; strip_and_sort(:primary); end From trevor at dev.open-bio.org Fri Jan 5 06:33:03 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Fri, 05 Jan 2007 06:33:03 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme analysis.rb, 1.14, 1.15 analysis_basic.rb, 1.7, 1.8 double_stranded.rb, 1.6, 1.7 Message-ID: <200701050633.l056X3GO016029@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme In directory dev.open-bio.org:/tmp/cvs-serv16002/restriction_enzyme Modified Files: analysis.rb analysis_basic.rb double_stranded.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.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** analysis_basic.rb 5 Jan 2007 06:11:15 -0000 1.7 --- analysis_basic.rb 5 Jan 2007 06:33:01 -0000 1.8 *************** *** 51,59 **** class Analysis - 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 ) --- 51,54 ---- *************** *** 73,77 **** # 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. --- 68,72 ---- # accurate. # ! # This code is mainly included as an academic example # without having to wade through the extra layer of complexity added by the # permutations. *************** *** 90,94 **** # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 85,89 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragments) def cut_without_permutations( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? *************** *** 118,123 **** fragments_for_display( {0 => sequence_range} ) end - - ######### --- 113,116 ---- *************** *** 125,129 **** ######### - # Take the fragments from SequenceRange objects generated from add_cut_range # and return unique results as a Bio::RestrictionEnzyme::Analysis::Fragment object. --- 118,121 ---- Index: analysis.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/analysis.rb,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** analysis.rb 5 Jan 2007 06:11:15 -0000 1.14 --- analysis.rb 5 Jan 2007 06:33:01 -0000 1.15 *************** *** 51,55 **** # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? --- 51,55 ---- # * +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*:: Bio::RestrictionEnzyme::Fragments object populated with Bio::RestrictionEnzyme::Fragment objects. (Note: unrelated to Bio::RestrictionEnzyme::Range::SequenceRange::Fragments) def cut( sequence, *args ) return fragments_for_display( {} ) if !sequence.kind_of?(String) or sequence.empty? Index: double_stranded.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/double_stranded.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** double_stranded.rb 5 Jan 2007 06:03:22 -0000 1.6 --- double_stranded.rb 5 Jan 2007 06:33:01 -0000 1.7 *************** *** 148,152 **** end ! # Returns +true+ if the cut pattern creates blunt fragments def blunt? as = aligned_strands_with_cuts --- 148,153 ---- end ! # Returns +true+ if the cut pattern creates blunt fragments. ! # (opposite of sticky) def blunt? as = aligned_strands_with_cuts *************** *** 158,162 **** end ! # Returns +true+ if the cut pattern creates sticky fragments def sticky? !blunt? --- 159,164 ---- end ! # Returns +true+ if the cut pattern creates sticky fragments. ! # (opposite of blunt) def sticky? !blunt? *************** *** 239,242 **** --- 241,250 ---- # This would be represented by two EnzymeActions - one for each # RestrictionEnzyme. + # + # This is, however, subject to competition. If the second enzyme reaches + # the target first, the the first enzyme will not be able to find the + # appropriate bind site. + # + # FIXME complete these docs # # To initialize an EnzymeAction you must first instantiate it with the *************** *** 262,266 **** # * Reflect cuts that are in enzyme notation # * 0 is not a valid enzyme index, decrement 0 and all negative - # c_cl = p_cl.collect { |n| s.length - n }.collect { |n| n <= 0 ? n - 1 : n } #wrong. c_cl = p_cl.collect {|n| (n >= s.length or n < 1) ? ((s.length - n) - 1) : (s.length - n)} --- 270,273 ---- From trevor at dev.open-bio.org Sat Jan 6 05:35:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 05:35:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range/sequence_range calculated_cuts.rb, 1.2, 1.3 Message-ID: <200701060535.l065Z7T9018352@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range In directory dev.open-bio.org:/tmp/cvs-serv18327/restriction_enzyme/range/sequence_range Modified Files: calculated_cuts.rb Log Message: Index: calculated_cuts.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** calculated_cuts.rb 2 Jan 2007 00:19:06 -0000 1.2 --- calculated_cuts.rb 6 Jan 2007 05:35:05 -0000 1.3 *************** *** 76,79 **** --- 76,82 ---- end + # Accepts an +Array+ of CutRange type objects and applies them to + # @vc_complement, @vc_primary, and @hc_between_strands. + # # --- # *Arguments* From trevor at dev.open-bio.org Sat Jan 6 05:35:07 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 05:35:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.2, 1.3 Message-ID: <200701060535.l065Z7RI018349@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv18327/restriction_enzyme/range Modified Files: sequence_range.rb Log Message: Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sequence_range.rb 5 Jan 2007 06:03:22 -0000 1.2 --- sequence_range.rb 6 Jan 2007 05:35:04 -0000 1.3 *************** *** 29,34 **** # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby - # - # FIXME algorithm heavy, needs better docs class SequenceRange --- 29,32 ---- *************** *** 65,70 **** end ! # NOTE Special Case: Horizontal cuts at beginning or end of strand Bin = Struct.new(:c, :p) --- 63,96 ---- end ! # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between 0 and 1. ! def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) ! @__fragments_current = false ! ! if p_cut_left.kind_of? CutRange ! @cut_ranges << p_cut_left ! else ! (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil ! (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil ! (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil ! (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil ! ! @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! end ! end + def add_cut_ranges(*cut_ranges) + cut_ranges.flatten! + cut_ranges.each do |cut_range| + raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange + self.add_cut_range( cut_range ) + end + end + + def add_horizontal_cut_range( left, right=left ) + @__fragments_current = false + @cut_ranges << HorizontalCutRange.new( left, right ) + end + Bin = Struct.new(:c, :p) *************** *** 72,184 **** return @__fragments if @__fragments_current == true @__fragments_current = true cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) cc.add_cuts_from_cut_ranges(@cut_ranges) cc.remove_incomplete_cuts ! p_cut = cc.vc_primary c_cut = cc.vc_complement ! h = cc.hc_between_strands ! if @circular ! # NOTE ! # if it's circular we should start at the beginning of a cut for orientation ! # scan for it, hack off the first set of hcuts and move them to the back else p_cut.unshift(-1) unless p_cut.include?(-1) c_cut.unshift(-1) unless c_cut.include?(-1) end ! if @circular ! largest_bin = 0 ! else ! largest_bin = -1 ! end ! p_bin = largest_bin ! c_bin = largest_bin ! bins = { largest_bin => Bin.new } # bin_id, bin ! bins[ largest_bin ].p = [] ! bins[ largest_bin ].c = [] ! ! x = lambda do |bin_id| ! largest_bin += 1 ! bins[ bin_id ] = Bin.new ! bins[ bin_id ].p = [] ! bins[ bin_id ].c = [] ! end ! -1.upto(@size-1) do |idx| ! # if bins are out of sync but the strands are attached ! if p_bin != c_bin and h.include?(idx) == false ! bins.delete( [p_bin, c_bin].sort.last ) ! p_bin = c_bin = [p_bin, c_bin].sort.first ! largest_bin -= 1 end ! bins[ p_bin ].p << idx ! bins[ c_bin ].c << idx ! if p_cut.include? idx ! p_bin = largest_bin + 1 ! x.call(p_bin) end ! if c_cut.include? idx ! c_bin = largest_bin + 1 ! x.call(c_bin) ! end end ! ! # Easy way to indicate the start of a strand just in case # there is a horizontal cut at position 0 bins.delete(-1) unless @circular ! ! str1 = nil ! str2 = nil ! ! num_txt_repeat = lambda { num_txt = '0123456789'; (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] } ! (str1 == nil) ? a = num_txt_repeat.call : a = str1.dup ! (str2 == nil) ? b = num_txt_repeat.call : b = str2.dup ! ! fragments = Fragments.new(a,b) ! ! bins.sort.each do |k, bin| ! fragment = Fragment.new( bin.p, bin.c ) ! fragments << fragment ! end ! ! @__fragments = fragments ! return fragments ! end ! ! # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between 0 and 1. ! def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) ! @__fragments_current = false ! ! if p_cut_left.kind_of? CutRange ! @cut_ranges << p_cut_left ! else ! (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil ! (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil ! (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil ! (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil ! ! @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) ! end ! end ! ! def add_cut_ranges(*cut_ranges) ! cut_ranges.flatten! ! cut_ranges.each do |cut_range| ! raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange ! self.add_cut_range( cut_range ) ! end end ! ! def add_horizontal_cut_range( left, right=left ) ! @__fragments_current = false ! @cut_ranges << HorizontalCutRange.new( left, right ) end end # SequenceRange end # Range --- 98,194 ---- return @__fragments if @__fragments_current == true @__fragments_current = true + + num_txt = '0123456789' + num_txt_repeat = (num_txt * ( @size / num_txt.size.to_f ).ceil)[0.. at size-1] + fragments = Fragments.new(num_txt_repeat, num_txt_repeat) cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) cc.add_cuts_from_cut_ranges(@cut_ranges) cc.remove_incomplete_cuts ! ! create_bins(cc).sort.each { |k, bin| fragments << Fragment.new( bin.p, bin.c ) } ! @__fragments = fragments ! return fragments ! end ! ! ######### ! protected ! ######### ! ! # Example: ! # cc = Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts.new(@size) ! # cc.add_cuts_from_cut_ranges(@cut_ranges) ! # cc.remove_incomplete_cuts ! # bins = create_bins(cc) ! # ! # Example return value: ! # {0=>#, ! # 2=>#, ! # 3=>#, ! # 4=>#} ! # ! # --- ! # *Arguments* ! # * +cc+: Bio::RestrictionEnzyme::Range::SequenceRange::CalculatedCuts ! # *Returns*:: +Hash+ Keys are unique, values are Bio::RestrictionEnzyme::Range::SequenceRange::Bin objects filled with indexes of the sequence locations they represent. ! def create_bins(cc) p_cut = cc.vc_primary c_cut = cc.vc_complement ! h_cut = cc.hc_between_strands ! if @circular ! # NOTE ! # if it's circular we should start at the beginning of a cut for orientation ! # scan for it, hack off the first set of hcuts and move them to the back ! ! unique_id = 0 else p_cut.unshift(-1) unless p_cut.include?(-1) c_cut.unshift(-1) unless c_cut.include?(-1) + unique_id = -1 end ! p_bin_id = c_bin_id = unique_id ! bins = {} ! setup_new_bin(bins, unique_id) ! -1.upto(@size-1) do |idx| # NOTE - circular, for the future - should '-1' be replace with 'unique_id'? ! ! # if bin_ids are out of sync but the strands are attached ! if (p_bin_id != c_bin_id) and !h_cut.include?(idx) ! min_id, max_id = [p_bin_id, c_bin_id].sort ! bins.delete(max_id) ! p_bin_id = c_bin_id = min_id end ! bins[ p_bin_id ].p << idx ! bins[ c_bin_id ].c << idx ! if p_cut.include? idx ! p_bin_id = (unique_id += 1) ! setup_new_bin(bins, p_bin_id) end ! if c_cut.include? idx # repetition ! c_bin_id = (unique_id += 1) # repetition ! setup_new_bin(bins, c_bin_id) # repetition ! end # repetition ! end ! ! # Bin "-1" is an easy way to indicate the start of a strand just in case # there is a horizontal cut at position 0 bins.delete(-1) unless @circular ! bins end ! ! # Modifies bins in place by creating a new element with key bin_id and ! # initializing the bin. ! def setup_new_bin(bins, bin_id) ! bins[ bin_id ] = Bin.new ! bins[ bin_id ].p = [] ! bins[ bin_id ].c = [] end + end # SequenceRange end # Range From trevor at dev.open-bio.org Sat Jan 6 05:52:54 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 05:52:54 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.3, 1.4 Message-ID: <200701060552.l065qsPn018382@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv18362/restriction_enzyme/range Modified Files: sequence_range.rb Log Message: Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** sequence_range.rb 6 Jan 2007 05:35:04 -0000 1.3 --- sequence_range.rb 6 Jan 2007 05:52:52 -0000 1.4 *************** *** 1,4 **** # ! # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom --- 1,4 ---- # ! # bio/util/restrction_enzyme/range/sequence_range.rb - A defined range over a nucleotide sequence # # Author:: Trevor Wennblom *************** *** 24,43 **** class Range # ! # bio/util/restrction_enzyme/range/sequence_range.rb - # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby class SequenceRange ! attr_reader :p_left, :p_right ! attr_reader :c_left, :c_right ! attr_reader :left, :right attr_reader :size attr_reader :cut_ranges def initialize( p_left = nil, p_right = nil, c_left = nil, c_right = nil ) - @__fragments_current = false raise ArgumentError if p_left == nil and c_left == nil raise ArgumentError if p_right == nil and c_right == nil --- 24,64 ---- class Range # ! # bio/util/restrction_enzyme/range/sequence_range.rb - A defined range over a nucleotide sequence # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com) # License:: Distributes under the same terms as Ruby + # + # A defined range over a nucleotide sequence. + # + # This class accomadates having cuts defined on a sequence and returning the + # fragments made by those cuts. class SequenceRange ! # Left-most index of primary strand ! attr_reader :p_left ! ! # Right-most index of primary strand ! attr_reader :p_right ! ! # Left-most index of complementary strand ! attr_reader :c_left ! ! # Right-most index of complementary strand ! attr_reader :c_right ! # Left-most index of DNA sequence ! attr_reader :left ! ! # Right-most index of DNA sequence ! attr_reader :right ! ! # Size of DNA sequence attr_reader :size + + # CutRanges in this SequenceRange attr_reader :cut_ranges def initialize( p_left = nil, p_right = nil, c_left = nil, c_right = nil ) raise ArgumentError if p_left == nil and c_left == nil raise ArgumentError if p_right == nil and c_right == nil *************** *** 45,68 **** (raise ArgumentError unless c_left <= c_right) unless c_left == nil or c_right == nil ! @p_left = p_left ! @p_right = p_right ! @c_left = c_left ! @c_right = c_right ! ! tmp = [p_left, c_left] ! tmp.delete(nil) ! @left = tmp.sort.first ! ! tmp = [p_right, c_right] ! tmp.delete(nil) ! @right = tmp.sort.last ! @size = (@right - @left) + 1 unless @left == nil or @right == nil - @cut_ranges = CutRanges.new end # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false --- 66,79 ---- (raise ArgumentError unless c_left <= c_right) unless c_left == nil or c_right == nil ! @p_left, @p_right, @c_left, @c_right = p_left, p_right, c_left, c_right ! @left = [p_left, c_left].compact.sort.first ! @right = [p_right, c_right].compact.sort.last @size = (@right - @left) + 1 unless @left == nil or @right == nil @cut_ranges = CutRanges.new + @__fragments_current = false end # Cut occurs immediately after the index supplied. ! # For example, a cut at '0' would mean a cut occurs between bases 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false *************** *** 81,86 **** def add_cut_ranges(*cut_ranges) ! cut_ranges.flatten! ! cut_ranges.each do |cut_range| raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange self.add_cut_range( cut_range ) --- 92,96 ---- def add_cut_ranges(*cut_ranges) ! cut_ranges.flatten.each do |cut_range| raise TypeError, "Not of type CutRange" unless cut_range.kind_of? CutRange self.add_cut_range( cut_range ) *************** *** 93,98 **** --- 103,137 ---- end + # A Bio::RestrictionEnzyme::Range::SequenceRange::Bin holds an +Array+ of + # indexes for the primary and complement strands (+p+ and +c+ accessors). + # + # Example hash with Bin values: + # {0=>#, + # 2=>#, + # 3=>#, + # 4=>#} Bin = Struct.new(:c, :p) + # Calculates the fragments over this sequence range as defined after using + # the methods add_cut_range, add_cut_ranges, and/or add_horizontal_cut_range + # + # Example return value: + # [#, + # #, + # #, + # #] + # + # --- + # *Arguments* + # * _none_ + # *Returns*:: Bio::RestrictionEnzyme::Range::SequenceRange::Fragments def fragments return @__fragments if @__fragments_current == true From trevor at dev.open-bio.org Sat Jan 6 06:13:24 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Sat, 06 Jan 2007 06:13:24 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/util/restriction_enzyme/range sequence_range.rb, 1.4, 1.5 Message-ID: <200701060613.l066DO2f018434@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range In directory dev.open-bio.org:/tmp/cvs-serv18414/restriction_enzyme/range Modified Files: sequence_range.rb Log Message: Index: sequence_range.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/util/restriction_enzyme/range/sequence_range.rb,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sequence_range.rb 6 Jan 2007 05:52:52 -0000 1.4 --- sequence_range.rb 6 Jan 2007 06:13:22 -0000 1.5 *************** *** 74,94 **** end # Cut occurs immediately after the index supplied. # For example, a cut at '0' would mean a cut occurs between bases 0 and 1. def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false ! ! if p_cut_left.kind_of? CutRange @cut_ranges << p_cut_left else ! (raise IndexError unless p_cut_left >= @left and p_cut_left <= @right) unless p_cut_left == nil ! (raise IndexError unless p_cut_right >= @left and p_cut_right <= @right) unless p_cut_right == nil ! (raise IndexError unless c_cut_left >= @left and c_cut_left <= @right) unless c_cut_left == nil ! (raise IndexError unless c_cut_right >= @left and c_cut_right <= @right) unless c_cut_right == nil ! @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) end end def add_cut_ranges(*cut_ranges) cut_ranges.flatten.each do |cut_range| --- 74,109 ---- end + + # If the first object is HorizontalCutRange or VerticalCutRange, that is + # added to the SequenceRange. Otherwise this method + # builds a VerticalCutRange object and adds it to the SequenceRange. + # + # Note: # Cut occurs immediately after the index supplied. # For example, a cut at '0' would mean a cut occurs between bases 0 and 1. + # + # --- + # *Arguments* + # * +p_cut_left+: (_optional_) Left-most cut on the primary strand *or* a CutRange object. +nil+ to skip + # * +p_cut_right+: (_optional_) Right-most cut on the primary strand. +nil+ to skip + # * +c_cut_left+: (_optional_) Left-most cut on the complementary strand. +nil+ to skip + # * +c_cut_right+: (_optional_) Right-most cut on the complementary strand. +nil+ to skip + # *Returns*:: nothing def add_cut_range( p_cut_left=nil, p_cut_right=nil, c_cut_left=nil, c_cut_right=nil ) @__fragments_current = false ! if p_cut_left.kind_of? CutRange # shortcut @cut_ranges << p_cut_left else ! [p_cut_left, p_cut_right, c_cut_left, c_cut_right].each { |n| (raise IndexError unless n >= @left and n <= @right) unless n == nil } @cut_ranges << VerticalCutRange.new( p_cut_left, p_cut_right, c_cut_left, c_cut_right ) end end + # Add a series of CutRange objects (HorizontalCutRange or VerticalCutRange). + # + # --- + # *Arguments* + # * +cut_ranges+: A series of CutRange objects + # *Returns*:: nothing def add_cut_ranges(*cut_ranges) cut_ranges.flatten.each do |cut_range| *************** *** 98,101 **** --- 113,123 ---- end + # Builds a HorizontalCutRange object and adds it to the SequenceRange. + # + # --- + # *Arguments* + # * +left+: Left-most cut + # * +right+: (_optional_) Right side - by default this equals the left side, default is recommended. + # *Returns*:: nothing def add_horizontal_cut_range( left, right=left ) @__fragments_current = false From trevor at dev.open-bio.org Mon Jan 8 06:38:41 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 08 Jan 2007 06:38:41 +0000 Subject: [BioRuby-cvs] bioruby/lib bio.rb,1.79,1.80 Message-ID: <200701080638.l086cfa2012151@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib In directory dev.open-bio.org:/tmp/cvs-serv12129/lib Modified Files: bio.rb Log Message: Adding Bio::Lasergene file format Index: bio.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio.rb,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** bio.rb 31 Dec 2006 20:54:25 -0000 1.79 --- bio.rb 8 Jan 2007 06:38:38 -0000 1.80 *************** *** 117,120 **** --- 117,121 ---- autoload :NBRF, 'bio/db/nbrf' autoload :REBASE, 'bio/db/rebase' + autoload :Lasergene, 'bio/db/lasergene' autoload :Newick, 'bio/db/newick' From trevor at dev.open-bio.org Mon Jan 8 06:38:41 2007 From: trevor at dev.open-bio.org (Trevor Wennblom) Date: Mon, 08 Jan 2007 06:38:41 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db test_lasergene.rb,NONE,1.1 Message-ID: <200701080638.l086cfMl012154@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db In directory dev.open-bio.org:/tmp/cvs-serv12129/test/unit/bio/db Added Files: test_lasergene.rb Log Message: Adding Bio::Lasergene file format --- NEW FILE: test_lasergene.rb --- # # test/unit/bio/db/test_rebase.rb - Unit test for Bio::Lasergene # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2007 Center for Biomedical Research Informatics, University of Minnesota (http://cbri.umn.edu) # License:: Distributes under the same terms as Ruby # # $Id: test_lasergene.rb,v 1.1 2007/01/08 06:38:39 trevor Exp $ # require 'pathname' libpath = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4, 'lib')).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) require 'test/unit' require 'bio' require 'bio/db/lasergene' module Bio #:nodoc: class TestLasergene < Test::Unit::TestCase #:nodoc: def setup file_format_1 = < Update of /home/repository/bioruby/bioruby/lib/bio/db In directory dev.open-bio.org:/tmp/cvs-serv12185/lib/bio/db Added Files: lasergene.rb Log Message: Adding Bio::Lasergene file format --- NEW FILE: lasergene.rb --- # # bio/db/lasergene.rb - Interface for DNAStar Lasergene sequence file format # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2007 Center for Biomedical Research Informatics, University of Minnesota (http://cbri.umn.edu) # License:: Distributes under the same terms as Ruby # # $Id: lasergene.rb,v 1.1 2007/01/08 06:39:14 trevor Exp $ # module Bio #:nodoc: # # bio/db/lasergene.rb - Interface for DNAStar Lasergene sequence file format # # Author:: Trevor Wennblom # Copyright:: Copyright (c) 2007 Center for Biomedical Research Informatics, University of Minnesota (http://cbri.umn.edu) # License:: Distributes under the same terms as Ruby # # = Description # # Bio::Lasergene reads DNAStar Lasergene formatted sequence files, or +.seq+ # files. It only expects to find one sequence per file. # # = Usage # # require 'bio' # filename = 'MyFile.seq' # lseq = Bio::Lasergene.new( IO.readlines(filename) ) # lseq.entry_id # => "Contig 1" # lseq.seq # => ATGACGTATCCAAAGAGGCGTTACC # # = Comments # # I'm only aware of the following three kinds of Lasergene file formats. Feel # free to send me other examples that may not currently be accounted for. # # File format 1: # # ## begin ## # "Contig 1" (1,934) # Contig Length: 934 bases # Average Length/Sequence: 467 bases # Total Sequence Length: 1869 bases # Top Strand: 2 sequences # Bottom Strand: 2 sequences # Total: 4 sequences # ^^ # ATGACGTATCCAAAGAGGCGTTACCGGAGAAGAAGACACCGCCCCCGCAGTCCTCTTGGCCAGATCCTCCGCCGCCGCCCCTGGCTCGTCCACCCCCGCCACAGTTACCGCTGGAGAAGGAAAAATGGCATCTTCAWCACCCGCCTATCCCGCAYCTTCGGAWRTACTATCAAGCGAACCACAGTCAGAACGCCCTCCTGGGCGGTGGACATGATGAGATTCAATATTAATGACTTTCTTCCCCCAGGAGGGGGCTCAAACCCCCGCTCTGTGCCCTTTGAATACTACAGAATAAGAAAGGTTAAGGTTGAATTCTGGCCCTGCTCCCCGATCACCCAGGGTGACAGGGGAATGGGCTCCAGTGCTGWTATTCTAGMTGATRRCTTKGTAACAAAGRCCACAGCCCTCACCTATGACCCCTATGTAAACTTCTCCTCCCGCCATACCATAACCCAGCCCTTCTCCTACCRCTCCCGYTACTTTACCCCCAAACCTGTCCTWGATKCCACTATKGATKACTKCCAACCAAACAACAAAAGAAACCAGCTGTGGSTGAGACTACAWACTGCTGGAAATGTAGACCWCGTAGGCCTSGGCACTGCGTKCGAAAACAGTATATACGACCAGGAATACAATATCCGTGTMACCATGTATGTACAATTCAGAGAATTTAATCTTAAAGACCCCCCRCTTMACCCKTAATGAATAATAAMAACCATTACGAAGTGATAAAAWAGWCTCAGTAATTTATTYCATATGGAAATTCWSGGCATGGGGGGGAAAGGGTGACGAACKKGCCCCCTTCCTCCSTSGMYTKTTCYGTAGCATTCYTCCAMAAYACCWAGGCAGYAMTCCTCCSATCAAGAGcYTSYACAGCTGGGACAGCAGTTGAGGAGGACCATTCAAAGGGGGTCGGATTGCTGGTAATCAGA # ## end ## # # # File format 2: # # ## begin ## # ^^: 350,935 # Contig 1 (1,935) # Contig Length: 935 bases # Average Length/Sequence: 580 bases # Total Sequence Length: 2323 bases # Top Strand: 2 sequences # Bottom Strand: 2 sequences # Total: 4 sequences # ^^ # ATGTCGGGGAAATGCTTGACCGCGGGCTACTGCTCATCATTGCTTTCTTTGTGGTATATCGTGCCGTTCTGTTTTGCTGTGCTCGTCAACGCCAGCGGCGACAGCAGCTCTCATTTTCAGTCGATTTATAACTTGACGTTATGTGAGCTGAATGGCACGAACTGGCTGGCAGACAACTTTAACTGGGCTGTGGAGACTTTTGTCATCTTCCCCGTGTTGACTCACATTGTTTCCTATGGTGCACTCACTACCAGTCATTTTCTTGACACAGTTGGTCTAGTTACTGTGTCTACCGCCGGGTTTTATCACGGGCGGTACGTCTTGAGTAGCATCTACGCGGTCTGTGCTCTGGCTGCGTTGATTTGCTTCGCCATCAGGTTTGCGAAGAACTGCATGTCCTGGCGCTACTCTTGCACTAGATACACCAACTTCCTCCTGGACACCAAGGGCAGACTCTATCGTTGGCGGTCGCCTGTCATCATAGAGAAAGGGGGTAAGGTTGAGGTCGAAGGTCATCTGATCGATCTCAAAAGAGTTGTGCTTGATGGCTCTGTGGCGACACCTTTAACCAGAGTTTCAGCGGAACAATGGGGTCGTCCCTAGACGACTTTTGCCATGATAGTACAGCCCCACAGAAGGTGCTCTTGGCGTTTTCCATCACCTACACGCCAGTGATGATATATGCCCTAAAGGTAAGCCGCGGCCGACTTTTGGGGCTTCTGCACCTTTTGATTTTTTTGAACTGTGCCTTTACTTTCGGGTACATGACATTCGTGCACTTTCGGAGCACGAACAAGGTCGCGCTCACTATGGGAGCAGTAGTCGCACTCCTTTGGGGGGTGTACTCAGCCATAGAAACCTGGAAATTCATCACCTCCAGATGCCGTTGTGCTTGCTAGGCCGCAAGTACATTCTGGCCCCTGCCCACCACGTTG # ## end ## # # File format 3 (non-standard Lasergene header): # # ## begin ## # LOCUS PRU87392 15411 bp RNA linear VRL 17-NOV-2000 # DEFINITION Porcine reproductive and respiratory syndrome virus strain VR-2332, # complete genome. # ACCESSION U87392 AF030244 U00153 # VERSION U87392.3 GI:11192298 # [...cut...] # 3'UTR 15261..15411 # polyA_site 15409 # ORIGIN # ^^ # atgacgtataggtgttggctctatgccttggcatttgtattgtcaggagctgtgaccattggcacagcccaaaacttgctgcacagaaacacccttctgtgatagcctccttcaggggagcttagggtttgtccctagcaccttgcttccggagttgcactgctttacggtctctccacccctttaaccatgtctgggatacttgatcggtgcacgtgtacccccaatgccagggtgtttatggcggagggccaagtctactgcacacgatgcctcagtgcacggtctctccttcccctgaacctccaagtttctgagctcggggtgctaggcctattctacaggcccgaagagccactccggtggacgttgccacgtgcattccccactgttgagtgctcccccgccggggcctgctggctttctgcaatctttccaatcgcacgaatgaccagtggaaacctgaacttccaacaaagaatggtacgggtcgcagctgagctttacagagccggccagctcacccctgcagtcttgaaggctctacaagtttatgaacggggttgccgctggtaccccattgttggacctgtccctggagtggccgttttcgccaattccctacatgtgagtgataaacctttcccgggagcaactcacgtgttgaccaacctgccgctcccgcagagacccaagcctgaagacttttgcccctttgagtgtgctatggctactgtctatgacattggtcatgacgccgtcatgtatgtggccgaaaggaaagtctcctgggcccctcgtggcggggatgaagtgaaatttgaagctgtccccggggagttgaagttgattgcgaaccggctccgcacctccttcccgccccaccacacagtggacatgtctaagttcgccttcacagcccctgggtgtggtgtttctatgcgggtcgaacgccaacacggctgccttcccgctgacactgtcc! ctgaaggcaactgctggtggagcttgtttgacttgcttccactggaagttcagaacaaagaaattcgccatgctaaccaatttggctaccagaccaagcatggtgtctctggcaagtacctacagcggaggctgca[...cut...] # ## end ## # class Lasergene # Entire header before the sequence attr_reader :comments # Sequence # # Bio::Sequence::NA or Bio::Sequence::AA object attr_reader :sequence # Name of sequence # * Parsed from standard Lasergene header attr_reader :name # Contig length, length of present sequence # * Parsed from standard Lasergene header attr_reader :contig_length # Average length per sequence # * Parsed from standard Lasergene header attr_reader :average_length # Length of parent sequence # * Parsed from standard Lasergene header attr_reader :total_length # Number of top strand sequences # * Parsed from standard Lasergene header attr_reader :top_strand_sequences # Number of bottom strand sequences # * Parsed from standard Lasergene header attr_reader :bottom_strand_sequences # Number of sequences # * Parsed from standard Lasergene header attr_reader :total_sequences DELIMITER_1 = '^\^\^:' # Match '^^:' at the beginning of a line DELIMITER_2 = '^\^\^' # Match '^^' at the beginning of a line def initialize(lines) process(lines) end # * +cut_locations+: The cut locations in enzyme index notation. # Is the comment header recognized as standard Lasergene format? # # --- # *Arguments* # * _none_ # *Returns*:: +true+ _or_ +false+ def standard_comment? @standard_comment end # Sequence # # Bio::Sequence::NA or Bio::Sequence::AA object def seq @sequence end # Name of sequence # * Parsed from standard Lasergene header def entry_id @name end ######### protected ######### def process(lines) delimiter_1_indices = [] delimiter_2_indices = [] # If the data from the file is passed as one big String instead of # broken into an Array, convert lines to an Array if lines.kind_of? String lines = lines.tr("\r", '').split("\n") end lines.each_with_index do |line, index| if line.match DELIMITER_1 delimiter_1_indices << index elsif line.match DELIMITER_2 delimiter_2_indices << index end end raise InputError, "More than one delimiter of type '#{DELIMITER_1}'" if delimiter_1_indices.size > 1 raise InputError, "More than one delimiter of type '#{DELIMITER_2}'" if delimiter_2_indices.size > 1 raise InputError, "No comment to data separator of type '#{DELIMITER_2}'" if delimiter_2_indices.size < 1 if !delimiter_1_indices.empty? # toss out DELIMETER_1 and anything preceding it @comments = lines[ (delimiter_1_indices[0] + 1) .. (delimiter_2_indices[0] - 1) ] else @comments = lines[ 0 .. (delimiter_2_indices[0] - 1) ] end @standard_comment = false if @comments[0] =~ %r{(.+)\s+\(\d+,\d+\)} # if we have a standard Lasergene comment @standard_comment = true @name = $1 comments.each do |comment| if comment.match('Contig Length:\s+(\d+)') @contig_length = $1.to_i elsif comment.match('Average Length/Sequence:\s+(\d+)') @average_length = $1.to_i elsif comment.match('Total Sequence Length:\s+(\d+)') @total_length = $1.to_i elsif comment.match('Top Strand:\s+(\d+)') @top_strand_sequences = $1.to_i elsif comment.match('Bottom Strand:\s+(\d+)') @bottom_strand_sequences = $1.to_i elsif comment.match('Total:\s+(\d+)') @total_sequences = $1.to_i end end end @comments = @comments.join('') @sequence = Bio::Sequence.auto( lines[ (delimiter_2_indices[0] + 1) .. -1 ].join('') ) end end # Lasergene end # Bio From ngoto at dev.open-bio.org Thu Jan 11 14:35:34 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 11 Jan 2007 14:35:34 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db test_newick.rb,1.2,1.3 Message-ID: <200701111435.l0BEZYee028351@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db In directory dev.open-bio.org:/tmp/cvs-serv28331/test/unit/bio/db Modified Files: test_newick.rb Log Message: fixed incorrect libpath Index: test_newick.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/test_newick.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_newick.rb 13 Dec 2006 16:29:37 -0000 1.2 --- test_newick.rb 11 Jan 2007 14:35:32 -0000 1.3 *************** *** 13,17 **** require 'pathname' ! libpath = Pathname.new(File.join(File.dirname(__FILE__), [".."] * 3, "lib")).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) --- 13,17 ---- require 'pathname' ! libpath = Pathname.new(File.join(File.dirname(__FILE__), [".."] * 4, "lib")).cleanpath.to_s $:.unshift(libpath) unless $:.include?(libpath) From ngoto at dev.open-bio.org Fri Jan 12 16:10:30 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Fri, 12 Jan 2007 16:10:30 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio tree.rb,1.6,1.7 Message-ID: <200701121610.l0CGAU39030867@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv30847/lib/bio Modified Files: tree.rb Log Message: * fixed a bug: clear_node did not work correctly. * NotAdjacentNodesError is removed. * insert_node is changed to raise IndexError when the edge does not found. * remove_edge is changed to raise IndexError when the edge does not found. Index: tree.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/tree.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tree.rb 15 Dec 2006 18:45:17 -0000 1.6 --- tree.rb 12 Jan 2007 16:10:28 -0000 1.7 *************** *** 26,32 **** class NoPathError < RuntimeError; end - # Error when the two nodes are not adjacent. - class NotAdjacentNodesError < RuntimeError; end - # Edge object of each node. # By default, the object doesn't contain any node information. --- 26,29 ---- *************** *** 412,415 **** --- 409,413 ---- @pathway.graph[k].delete(node) end + @pathway.graph[node].clear self end *************** *** 440,443 **** --- 438,443 ---- # Removes an edge between source and target. + # Returns self. + # If the edge does not exist, raises IndexError. #--- # If two or more edges exists between source and target, *************** *** 445,448 **** --- 445,451 ---- #+++ def remove_edge(source, target) + unless self.get_edge(source, target) then + raise IndexError, 'edge not found' + end fwd = [ source, target ] rev = [ target, source ] *************** *** 815,819 **** # # Returns self. ! # If node1 and node2 are not adjacent, raises NotAdjacentNodesError. # # If new_node already exists in the tree, the tree would become --- 818,822 ---- # # Returns self. ! # If node1 and node2 are not adjacent, raises IndexError. # # If new_node already exists in the tree, the tree would become *************** *** 822,826 **** def insert_node(node1, node2, new_node, new_distance = nil) unless edge = self.get_edge(node1, node2) then ! raise NotAdjacentNodesError, 'node1 and node2 are not adjacent.' end new_edge = Edge.new(new_distance) --- 825,829 ---- def insert_node(node1, node2, new_node, new_distance = nil) unless edge = self.get_edge(node1, node2) then ! raise IndexError, 'nodes not found or two nodes are not adjacent' end new_edge = Edge.new(new_distance) From ngoto at dev.open-bio.org Fri Jan 12 16:12:07 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Fri, 12 Jan 2007 16:12:07 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio test_tree.rb,1.3,1.4 Message-ID: <200701121612.l0CGC7Qs030895@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio In directory dev.open-bio.org:/tmp/cvs-serv30875/test/unit/bio Modified Files: test_tree.rb Log Message: Large test methods are splitted into small methods. More tests are added. Index: test_tree.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_tree.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_tree.rb 13 Dec 2006 16:29:37 -0000 1.3 --- test_tree.rb 12 Jan 2007 16:12:05 -0000 1.4 *************** *** 262,265 **** --- 262,268 ---- assert_equal([ @rodents, @primates ].sort(&@by_id), @tree.adjacent_nodes(@mammals).sort(&@by_id)) + end + + def test_adjacent_nodes_nonexistent # test for not existed nodes assert_equal([], @tree.adjacent_nodes(Bio::Tree::Node.new)) *************** *** 275,279 **** --- 278,284 ---- assert_equal([[ @chimpanzee, @primates, @edge_primates_chimpanzee ]], @tree.out_edges(@chimpanzee)) + end + def test_out_edges_rodents adjacents = [ @mouse, @rat, @mammals ] edges = [ @edge_rodents_mouse, @edge_rodents_rat, @edge_mammals_rodents ] *************** *** 287,291 **** --- 292,298 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_out_edges_primates adjacents = [ @human, @chimpanzee, @mammals ] edges = [ @edge_primates_human, @edge_primates_chimpanzee, *************** *** 300,304 **** --- 307,313 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_out_edges_mammals adjacents = [ @rodents, @primates ] edges = [ @edge_mammals_rodents, @edge_mammals_primates ] *************** *** 312,316 **** --- 321,327 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_out_edges_nonexistent # test for not existed nodes assert_equal([], @tree.out_edges(Bio::Tree::Node.new)) *************** *** 327,331 **** --- 338,344 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_rat flag = nil r = @tree.each_out_edge(@rat) do |src, tgt, edge| *************** *** 337,341 **** --- 350,356 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_human flag = nil r = @tree.each_out_edge(@human) do |src, tgt, edge| *************** *** 347,351 **** --- 362,368 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_chimpanzee flag = nil r = @tree.each_out_edge(@chimpanzee) do |src, tgt, edge| *************** *** 357,361 **** --- 374,380 ---- assert_equal(@tree, r) assert_equal(true, flag) + end + def test_each_out_edge_rodents adjacents = [ @mouse, @rat, @mammals ] edges = [ @edge_rodents_mouse, @edge_rodents_rat, @edge_mammals_rodents ] *************** *** 369,373 **** --- 388,394 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_each_out_edge_primates adjacents = [ @human, @chimpanzee, @mammals ] edges = [ @edge_primates_human, @edge_primates_chimpanzee, *************** *** 382,386 **** --- 403,409 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_each_out_edge_mammals adjacents = [ @rodents, @primates ] edges = [ @edge_mammals_rodents, @edge_mammals_primates ] *************** *** 394,398 **** --- 417,423 ---- assert_equal(true, adjacents.empty?) assert_equal(true, edges.empty?) + end + def test_each_out_edge_nonexistent # test for not existed nodes flag = nil *************** *** 405,408 **** --- 430,591 ---- end + def test_out_degree + assert_equal(1, @tree.out_degree(@mouse)) + assert_equal(1, @tree.out_degree(@rat)) + assert_equal(3, @tree.out_degree(@rodents)) + assert_equal(1, @tree.out_degree(@human)) + assert_equal(1, @tree.out_degree(@chimpanzee)) + assert_equal(3, @tree.out_degree(@primates)) + assert_equal(2, @tree.out_degree(@mammals)) + end + + def test_out_degree_nonexistent + assert_equal(0, @tree.out_degree(Bio::Tree::Node.new)) + end + + def test_get_edge + assert_not_nil(@tree.get_edge(@rodents, @mouse)) + assert_not_nil(@tree.get_edge(@mouse, @rodents)) + assert_equal(@edge_rodents_mouse, @tree.get_edge(@rodents, @mouse)) + assert_equal(@edge_rodents_mouse, @tree.get_edge(@mouse, @rodents)) + + assert_not_nil(@tree.get_edge(@rodents, @rat)) + assert_not_nil(@tree.get_edge(@rat, @rodents)) + assert_equal(@edge_rodents_rat, @tree.get_edge(@rodents, @rat)) + assert_equal(@edge_rodents_rat, @tree.get_edge(@rat, @rodents)) + + assert_not_nil(@tree.get_edge(@mammals, @rodents)) + assert_not_nil(@tree.get_edge(@rodents, @mammals)) + assert_equal(@edge_mammals_rodents, @tree.get_edge(@mammals, @rodents)) + assert_equal(@edge_mammals_rodents, @tree.get_edge(@rodents, @mammals)) + + assert_not_nil(@tree.get_edge(@primates, @human)) + assert_not_nil(@tree.get_edge(@human, @primates)) + assert_equal(@edge_primates_human, @tree.get_edge(@primates, @human)) + assert_equal(@edge_primates_human, @tree.get_edge(@human, @primates)) + + assert_not_nil(@tree.get_edge(@primates, @chimpanzee)) + assert_not_nil(@tree.get_edge(@chimpanzee, @primates)) + assert_equal(@edge_primates_chimpanzee, @tree.get_edge(@primates, @chimpanzee)) + assert_equal(@edge_primates_chimpanzee, @tree.get_edge(@chimpanzee, @primates)) + + assert_not_nil(@tree.get_edge(@mammals, @primates)) + assert_not_nil(@tree.get_edge(@primates, @mammals)) + assert_equal(@edge_mammals_primates, @tree.get_edge(@mammals, @primates)) + assert_equal(@edge_mammals_primates, @tree.get_edge(@primates, @mammals)) + end + + def test_get_edge_indirect + assert_nil(@tree.get_edge(@mouse, @rat)) + assert_nil(@tree.get_edge(@human, @chimpanzee)) + end + + def test_get_edge_nonexistent + assert_nil(@tree.get_edge(@mouse, Bio::Tree::Node.new)) + end + + def test_get_node_by_name + assert_not_nil(@tree.get_node_by_name('mouse')) + assert_not_nil(@tree.get_node_by_name('rat')) + assert_not_nil(@tree.get_node_by_name('human')) + assert_not_nil(@tree.get_node_by_name('chimpanzee')) + assert_equal(@mouse, @tree.get_node_by_name('mouse')) + assert_equal(@rat, @tree.get_node_by_name('rat')) + assert_equal(@human, @tree.get_node_by_name('human')) + assert_equal(@chimpanzee, @tree.get_node_by_name('chimpanzee')) + end + + def test_get_node_by_name_noexistent + assert_nil(@tree.get_node_by_name('frog')) + end + + def test_add_edge + amphibian = Bio::Tree::Node.new('amphibian') + edge = Bio::Tree::Edge.new(0.3123) + assert_equal(edge, @tree.add_edge(@mammals, amphibian, edge)) + + frog = Bio::Tree::Node.new('frog') + newt = Bio::Tree::Node.new('newt') + assert_instance_of(Bio::Tree::Edge, @tree.add_edge(frog, newt)) + end + + def test_add_node + frog = Bio::Tree::Node.new('frog') + # the node does not exist + assert_nil(@tree.get_node_by_name('frog')) + assert_equal(false, @tree.include?(frog)) + # add node + assert_equal(@tree, @tree.add_node(frog)) + # the node exists + assert_equal(frog, @tree.get_node_by_name('frog')) + assert_equal(true, @tree.include?(frog)) + end + + def test_include? + assert_equal(true, @tree.include?(@mouse)) + assert_equal(true, @tree.include?(@rat)) + assert_equal(true, @tree.include?(@rodents)) + assert_equal(true, @tree.include?(@human)) + assert_equal(true, @tree.include?(@chimpanzee)) + assert_equal(true, @tree.include?(@primates)) + assert_equal(true, @tree.include?(@mammals)) + end + + def test_include_nonexistent + assert_equal(false, @tree.include?(Bio::Tree::Node.new)) + end + + def test_clear_node + assert_equal(2, @tree.out_degree(@mammals)) + # clear node + assert_equal(@tree, @tree.clear_node(@mammals)) + # checks + assert_equal(true, @tree.include?(@mammals)) + assert_equal(0, @tree.out_degree(@mammals)) + assert_equal(2, @tree.out_degree(@rodents)) + assert_equal(2, @tree.out_degree(@primates)) + end + + def test_clear_node_nonexistent + assert_raise(IndexError) { @tree.clear_node(Bio::Tree::Node.new) } + end + + def test_remove_node + assert_equal(2, @tree.out_degree(@mammals)) + # remove node + assert_equal(@tree, @tree.remove_node(@mammals)) + # checks + assert_equal(false, @tree.include?(@mammals)) + assert_equal(0, @tree.out_degree(@mammals)) + assert_equal(2, @tree.out_degree(@rodents)) + assert_equal(2, @tree.out_degree(@primates)) + end + + def test_remove_node_nonexistent + assert_raise(IndexError) { @tree.remove_node(Bio::Tree::Node.new) } + end + + def test_remove_node_if + assert_equal(@tree, @tree.remove_node_if { |node| node == @mouse }) + assert_equal(false, @tree.include?(@mouse)) + end + + def test_remove_node_if_false + ary = [] + assert_equal(@tree, @tree.remove_node_if { |node| ary << node; false }) + nodes = @nodes.sort(&@by_id) + assert_equal(nodes, ary.sort(&@by_id)) + assert_equal(nodes, @tree.nodes.sort(&@by_id)) + end + + def test_remove_edge + assert_not_nil(@tree.get_edge(@mouse, @rodents)) + assert_equal(@tree, @tree.remove_edge(@mouse, @rodents)) + assert_nil(@tree.get_edge(@mouse, @rodents)) + end + + def test_remove_edge_nonexistent + assert_raise(IndexError) { @tree.remove_edge(@mouse, @rat) } + end end #class TestTree2 From ngoto at dev.open-bio.org Fri Jan 12 16:19:26 2007 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Fri, 12 Jan 2007 16:19:26 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db test_newick.rb,1.3,1.4 Message-ID: <200701121619.l0CGJQJo030925@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db In directory dev.open-bio.org:/tmp/cvs-serv30905/test/unit/bio/db Modified Files: test_newick.rb Log Message: changed to use Bio::Tree#get_node_by_name. Index: test_newick.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/test_newick.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_newick.rb 11 Jan 2007 14:35:32 -0000 1.3 --- test_newick.rb 12 Jan 2007 16:19:24 -0000 1.4 *************** *** 46,50 **** assert_equal(9, tree.descendents(tree.root).size) assert_equal(6, tree.leaves.size) ! leaf = tree.nodes.find { |x| x.name == 'HexFLZ83' } assert_equal(3, tree.ancestors(leaf).size) assert_equal(tree.path(tree.root, leaf)[1], tree.ancestors(leaf)[1]) --- 46,50 ---- assert_equal(9, tree.descendents(tree.root).size) assert_equal(6, tree.leaves.size) ! leaf = tree.get_node_by_name('HexFLZ83') assert_equal(3, tree.ancestors(leaf).size) assert_equal(tree.path(tree.root, leaf)[1], tree.ancestors(leaf)[1]) From k at dev.open-bio.org Mon Jan 15 04:33:54 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:33:54 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio db.rb,0.35,0.36 Message-ID: <200701150433.l0F4Xsa1028546@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv28542/lib/bio Modified Files: db.rb Log Message: * lines_fetch method is refined to concatenate indented sub field Index: db.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db.rb,v retrieving revision 0.35 retrieving revision 0.36 diff -C2 -d -r0.35 -r0.36 *** db.rb 19 Sep 2006 06:14:18 -0000 0.35 --- db.rb 15 Jan 2007 04:33:52 -0000 0.36 *************** *** 221,230 **** # Returns an Array containing each line of the field without a tag. # lines_fetch also stores the result in the @data hash. ! def lines_fetch(tag) ! unless @data[tag] ! @data[tag] = get(tag).split(/\n/).map{ |l| tag_cut(l) } ! end ! @data[tag] ! end end # class DB --- 221,245 ---- # Returns an Array containing each line of the field without a tag. # lines_fetch also stores the result in the @data hash. ! def lines_fetch(tag) ! unless @data[tag] ! list = [] ! lines = get(tag).split(/\n/) ! lines.each do |line| ! data = tag_cut(line) ! if data[/^\S/] # next sub field ! list << data ! else # continued sub field ! data.strip! ! if list.last[/\-$/] # folded ! list[-1] += data ! else ! list[-1] += " #{data}" # rest of list ! end ! end ! end ! @data[tag] = list ! end ! @data[tag] ! end end # class DB From k at dev.open-bio.org Mon Jan 15 04:34:34 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:34:34 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/kegg compound.rb,0.12,0.13 Message-ID: <200701150434.l0F4YYd8028589@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/kegg In directory dev.open-bio.org:/tmp/cvs-serv28585/lib/bio/db/kegg Modified Files: compound.rb Log Message: * comment method is added Index: compound.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/kegg/compound.rb,v retrieving revision 0.12 retrieving revision 0.13 diff -C2 -d -r0.12 -r0.13 *** compound.rb 19 Sep 2006 05:51:29 -0000 0.12 --- compound.rb 15 Jan 2007 04:34:32 -0000 0.13 *************** *** 2,6 **** # = bio/db/kegg/compound.rb - KEGG COMPOUND database class # ! # Copyright:: Copyright (C) 2001, 2002, 2004 Toshiaki Katayama # License:: Ruby's # --- 2,6 ---- # = bio/db/kegg/compound.rb - KEGG COMPOUND database class # ! # Copyright:: Copyright (C) 2001, 2002, 2004, 2007 Toshiaki Katayama # License:: Ruby's # *************** *** 92,95 **** --- 92,100 ---- end + # COMMENT + def comment + field_fetch('COMMENT') + end + end # COMPOUND From k at dev.open-bio.org Mon Jan 15 04:37:31 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:37:31 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/kegg genome.rb,0.15,0.16 Message-ID: <200701150437.l0F4bVg7028670@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/kegg In directory dev.open-bio.org:/tmp/cvs-serv28666/lib/bio/db/kegg Modified Files: genome.rb Log Message: * disease, data_source, original_db methods are added * scaffolds, gc, genomemap methods are obsoleted Index: genome.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/kegg/genome.rb,v retrieving revision 0.15 retrieving revision 0.16 diff -C2 -d -r0.15 -r0.16 *** genome.rb 19 Sep 2006 05:52:45 -0000 0.15 --- genome.rb 15 Jan 2007 04:37:29 -0000 0.16 *************** *** 2,6 **** # = bio/db/kegg/genome.rb - KEGG/GENOME database class # ! # Copyright:: Copyright (C) 2001, 2002 Toshiaki Katayama # License:: Ruby's # --- 2,6 ---- # = bio/db/kegg/genome.rb - KEGG/GENOME database class # ! # Copyright:: Copyright (C) 2001, 2002, 2007 Toshiaki Katayama # License:: Ruby's # *************** *** 72,75 **** --- 72,90 ---- end + # DATA_SOURCE -- Returns contents of the DATA_SOURCE record as a String. + def data_source + field_fetch('DATA_SOURCE') + end + + # ORIGINAL_DB -- Returns contents of the ORIGINAL_DB record as a String. + def original_db + field_fetch('ORIGINAL_DB') + end + + # DISEASE -- Returns contents of the COMMENT record as a String. + def disease + field_fetch('DISEASE') + end + # COMMENT -- Returns contents of the COMMENT record as a String. def comment *************** *** 99,104 **** hash['journal'] = $1 hash['volume'] = $2 ! hash['pages'] = $3 ! hash['year'] = $5 hash['medline'] = $6 else --- 114,119 ---- hash['journal'] = $1 hash['volume'] = $2 ! hash['pages'] = $3 ! hash['year'] = $5 hash['medline'] = $6 else *************** *** 145,163 **** end - # SCAFFOLD -- Returns contents of the SCAFFOLD records as an Array of Hash. - def scaffolds - unless @data['SCAFFOLD'] - @data['SCAFFOLD'] = [] - toptag2array(get('SCAFFOLD')).each do |chr| - hash = Hash.new('') - subtag2array(chr).each do |field| - hash[tag_get(field)] = truncate(tag_cut(field)) - end - @data['SCAFFOLD'].push(hash) - end - end - @data['SCAFFOLD'] - end - # STATISTICS -- Returns contents of the STATISTICS record as a Hash. def statistics --- 160,163 ---- *************** *** 167,177 **** case line when /nucleotides:\s+(\d+)/ ! hash['nalen'] = $1.to_i when /protein genes:\s+(\d+)/ hash['num_gene'] = $1.to_i when /RNA genes:\s+(\d+)/ hash['num_rna'] = $1.to_i - when /G\+C content:\s+(\d+.\d+)/ - hash['gc'] = $1.to_f end end --- 167,175 ---- case line when /nucleotides:\s+(\d+)/ ! hash['num_nuc'] = $1.to_i when /protein genes:\s+(\d+)/ hash['num_gene'] = $1.to_i when /RNA genes:\s+(\d+)/ hash['num_rna'] = $1.to_i end end *************** *** 183,187 **** # Returns number of nucleotides from the STATISTICS record as a Fixnum. def nalen ! statistics['nalen'] end alias length nalen --- 181,185 ---- # Returns number of nucleotides from the STATISTICS record as a Fixnum. def nalen ! statistics['num_nuc'] end alias length nalen *************** *** 197,210 **** end - # Returns G+C content from the STATISTICS record as a Float. - def gc - statistics['gc'] - end - - # GENOMEMAP -- Returns contents of the GENOMEMAP record as a String. - def genomemap - field_fetch('GENOMEMAP') - end - end # GENOME --- 195,198 ---- *************** *** 239,245 **** %w( CHROMOSOME chromosomes ), %w( PLASMID plasmids ), ! %w( SCAFFOLD plasmids ), ! %w( STATISTICS statistics nalen num_gene num_rna gc ), ! %w( GENOMEMAP genomemap ), ].each do |x| puts "### " + x.shift --- 227,231 ---- %w( CHROMOSOME chromosomes ), %w( PLASMID plasmids ), ! %w( STATISTICS statistics nalen num_gene num_rna ), ].each do |x| puts "### " + x.shift From k at dev.open-bio.org Mon Jan 15 04:50:08 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Mon, 15 Jan 2007 04:50:08 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/kegg enzyme.rb,0.9,0.10 Message-ID: <200701150450.l0F4o8WE028731@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/kegg In directory dev.open-bio.org:/tmp/cvs-serv28727/lib/bio/db/kegg Modified Files: enzyme.rb Log Message: * entry_id is changed to entry method as it returns a "EC x.x.x.x Enzyme" style string. Instead, entry_id method is changed to return EC number only. * obsolete? method is added, which returns boolean value (true/false) according to the ENTRY line contains Obsolete or not. * all_reac, iubmb_reactions, kegg_reactions methods are added to support new ALL_REAC field. * inhibitors and orthologs methods are added. * substrates, products, inhibitors, cofactors, pathways, orthologs, diseases, motifs methods now utilizes new lines_fetch method in db.rb to process continuous sub field. Index: enzyme.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/kegg/enzyme.rb,v retrieving revision 0.9 retrieving revision 0.10 diff -C2 -d -r0.9 -r0.10 *** enzyme.rb 19 Sep 2006 05:52:05 -0000 0.9 --- enzyme.rb 15 Jan 2007 04:50:05 -0000 0.10 *************** *** 2,6 **** # = bio/db/kegg/enzyme.rb - KEGG/ENZYME database class # ! # Copyright:: Copyright (C) 2001, 2002 Toshiaki Katayama # License:: Ruby's # --- 2,6 ---- # = bio/db/kegg/enzyme.rb - KEGG/ENZYME database class # ! # Copyright:: Copyright (C) 2001, 2002, 2007 Toshiaki Katayama # License:: Ruby's # *************** *** 23,36 **** # ENTRY ! def entry_id field_fetch('ENTRY') end # NAME def names ! lines_fetch('NAME') end def name ! names[0] end --- 23,45 ---- # ENTRY ! def entry field_fetch('ENTRY') end + def entry_id + entry[/EC (\S+)/, 1] + end + + def obsolete? + entry[/Obsolete/] ? true : false + end + # NAME def names ! field_fetch('NAME').split(/\s*;\s*/) end + def name ! names.first end *************** *** 45,66 **** end ! # REACTION ';' def reaction field_fetch('REACTION') end # SUBSTRATE def substrates ! lines_fetch('SUBSTRATE') end # PRODUCT def products ! lines_fetch('PRODUCT') end # COFACTOR def cofactors ! lines_fetch('COFACTOR') end --- 54,98 ---- end ! # REACTION def reaction field_fetch('REACTION') end + + # ALL_REAC ';' + def all_reac + field_fetch('ALL_REAC') + end + + def iubmb_reactions + all_reac.sub(/;\s*\(other\).*/, '').split(/\s*;\s*/) + end + + def kegg_reactions + reac = all_reac + if reac[/\(other\)/] + reac.sub(/.*\(other\)\s*/, '').split(/\s*;\s*/) + else + [] + end + end # SUBSTRATE def substrates ! field_fetch('SUBSTRATE').split(/\s*;\s*/) end # PRODUCT def products ! field_fetch('PRODUCT').split(/\s*;\s*/) ! end ! ! # INHIBITOR ! def inhibitors ! field_fetch('INHIBITOR').split(/\s*;\s*/) end # COFACTOR def cofactors ! field_fetch('COFACTOR').split(/\s*;\s*/) end *************** *** 75,78 **** --- 107,115 ---- end + # ORTHOLOG + def orthologs + lines_fetch('ORTHOLOG') + end + # GENES def genes *************** *** 93,102 **** def structures unless @data['STRUCTURES'] ! @data['STRUCTURES'] = ! fetch('STRUCTURES').sub(/(PDB: )*/,'').split(/\s+/) end @data['STRUCTURES'] end # DBLINKS def dblinks --- 130,140 ---- def structures unless @data['STRUCTURES'] ! @data['STRUCTURES'] = fetch('STRUCTURES').sub(/(PDB: )*/,'').split(/\s+/) end @data['STRUCTURES'] end + # REFERENCE + # DBLINKS def dblinks From k at dev.open-bio.org Tue Jan 16 05:35:39 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:35:39 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates _log.rhtml, NONE, 1.1 _result.rhtml, 1.1, NONE Message-ID: <200701160535.l0G5ZdfP031183@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates In directory dev.open-bio.org:/tmp/cvs-serv31174/templates Added Files: _log.rhtml Removed Files: _result.rhtml Log Message: * _result.rhtml is renamed to _log.rhtml --- NEW FILE: _log.rhtml ---

Input: [<%= link_to_remote @number, :url => {:action => "reload_script", :number => @number} %>]
<%=h @script %>
Result: [<%= link_to_remote "methods", :url => {:action => "list_methods", :number => @number} %>] [<%= link_to_remote "classes", :url => {:action => "list_classes", :number => @number} %>] [<%= link_to_remote "modules", :url => {:action => "list_modules", :number => @number} %>]
<%=h @result %>
<% if @output %> Output:
<%=h @output %>
<% end %>
--- _result.rhtml DELETED --- From k at dev.open-bio.org Tue Jan 16 05:35:39 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:35:39 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby bioruby_generator.rb, 1.1, 1.2 Message-ID: <200701160535.l0G5Zd1Z031180@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby In directory dev.open-bio.org:/tmp/cvs-serv31174 Modified Files: bioruby_generator.rb Log Message: * _result.rhtml is renamed to _log.rhtml Index: bioruby_generator.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/bioruby_generator.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby_generator.rb 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby_generator.rb 16 Jan 2007 05:35:37 -0000 1.2 *************** *** 13,17 **** m.file '_classes.rhtml', 'app/views/bioruby/_classes.rhtml' m.file '_modules.rhtml', 'app/views/bioruby/_modules.rhtml' ! m.file '_result.rhtml', 'app/views/bioruby/_result.rhtml' m.file '_variables.rhtml', 'app/views/bioruby/_variables.rhtml' m.file 'commands.rhtml', 'app/views/bioruby/commands.rhtml' --- 13,17 ---- m.file '_classes.rhtml', 'app/views/bioruby/_classes.rhtml' m.file '_modules.rhtml', 'app/views/bioruby/_modules.rhtml' ! m.file '_log.rhtml', 'app/views/bioruby/_log.rhtml' m.file '_variables.rhtml', 'app/views/bioruby/_variables.rhtml' m.file 'commands.rhtml', 'app/views/bioruby/commands.rhtml' From k at dev.open-bio.org Tue Jan 16 05:38:08 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:38:08 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates shell_helper.rb, 1.1, NONE Message-ID: <200701160538.l0G5c8iU031281@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates In directory dev.open-bio.org:/tmp/cvs-serv31277 Removed Files: shell_helper.rb Log Message: * This file is not used (renamed to bioruby_helper.rb) --- shell_helper.rb DELETED --- From k at dev.open-bio.org Tue Jan 16 05:47:07 2007 From: k at dev.open-bio.org (Katayama Toshiaki) Date: Tue, 16 Jan 2007 05:47:07 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates _methods.rhtml, 1.1, 1.2 bioruby.css, 1.1, 1.2 bioruby_controller.rb, 1.1, 1.2 bioruby_helper.rb, 1.1, 1.2 index.rhtml, 1.1, 1.2 Message-ID: <200701160547.l0G5l71S031360@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates In directory dev.open-bio.org:/tmp/cvs-serv31319 Modified Files: _methods.rhtml bioruby.css bioruby_controller.rb bioruby_helper.rb index.rhtml Log Message: Feature enhancements: * Input [#] is linked to action for filling textarea from history * [methods] is separated into columns for readability Fixes and improvements: * HIDE_VARIABLES is moved from helper to controller to avoid warning "already initialized constant - HIDE_VARIABLES" repeated upon reload *
is renamed to "log_#" with number for future extention *
are inserted in the
* CSS is modified and updated to follow evaluate -> log change Index: index.rhtml =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/index.rhtml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** index.rhtml 24 Dec 2006 08:27:15 -0000 1.1 --- index.rhtml 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 15,16 **** --- 15,19 ---- <%= end_form_tag %>
+
+
+ Index: bioruby_helper.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/bioruby_helper.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby_helper.rb 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby_helper.rb 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 1,8 **** module BiorubyHelper - HIDE_VARIABLES = [ - "_", "irb", "_erbout", - ] - include Bio::Shell --- 1,4 ---- *************** *** 16,20 **** def local_variables ! eval("local_variables", Bio::Shell.cache[:binding]) - HIDE_VARIABLES end --- 12,25 ---- def local_variables ! eval("local_variables", Bio::Shell.cache[:binding]) - ! BiorubyController::HIDE_VARIABLES ! end ! ! def render_log(page) ! page.insert_html :top, :logs, :partial => "log" ! page.replace_html "variables", :partial => "variables" ! page.hide "methods_#{@number}" ! page.hide "classes_#{@number}" ! page.hide "modules_#{@number}" end *************** *** 36,37 **** --- 41,43 ---- end + Index: bioruby_controller.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/bioruby_controller.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby_controller.rb 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby_controller.rb 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 1,8 **** class BiorubyController < ApplicationController ! HIDE_METHODS = Object.methods HIDE_MODULES = [ WEBrick, Base64::Deprecated, Base64, PP::ObjectMixin, ] --- 1,20 ---- class BiorubyController < ApplicationController ! HIDE_METHODS = Object.methods + [ "singleton_method_added" ] HIDE_MODULES = [ + ActiveSupport::CoreExtensions::String::Iterators, + ActiveSupport::CoreExtensions::String::StartsEndsWith, + ActiveSupport::CoreExtensions::String::Inflections, + ActiveSupport::CoreExtensions::String::Conversions, + ActiveSupport::CoreExtensions::String::Access, + ActiveSupport::CoreExtensions::Numeric::Bytes, + ActiveSupport::CoreExtensions::Numeric::Time, WEBrick, Base64::Deprecated, Base64, PP::ObjectMixin, + Bio::Shell + ] + + HIDE_VARIABLES = [ + "_", "irb", "_erbout", ] *************** *** 27,35 **** render :update do |page| ! page.insert_html :after, "console", :partial => "result" ! page.replace_html "variables", :partial => "variables" ! page.hide "methods_#{@number}" ! page.hide "classes_#{@number}" ! page.hide "modules_#{@number}" end end --- 39,43 ---- render :update do |page| ! render_log(page) end end *************** *** 37,40 **** --- 45,49 ---- def list_methods number = params[:number].to_i + script, result, output = Bio::Shell.cache[:results].restore(number) @class = result.class *************** *** 49,52 **** --- 58,62 ---- def list_classes number = params[:number].to_i + script, result, output = Bio::Shell.cache[:results].restore(number) class_name = result.class *************** *** 70,73 **** --- 80,84 ---- def list_modules number = params[:number].to_i + script, result, output = Bio::Shell.cache[:results].restore(number) @class = result.class *************** *** 80,83 **** --- 91,104 ---- end + def reload_script + number = params[:number].to_i + + script, result, output = Bio::Shell.cache[:results].restore(number) + + render :update do |page| + page.replace_html :script, script + end + end + def results if Bio::Shell.cache[:results].number > 0 *************** *** 89,93 **** render :update do |page| # delete all existing results in the current DOM for clean up ! page.select(".evaluate").each do |element| page.remove element end --- 110,115 ---- render :update do |page| # delete all existing results in the current DOM for clean up ! page.select(".log").each do |element| ! #page.hide element page.remove element end *************** *** 95,105 **** # add selected results to the current DOM min_num.upto(max_num) do |@number| @script, @result, @output = Bio::Shell.cache[:results].restore(@number) if @script ! page.insert_html :after, "console", :partial => "result" ! page.replace_html "variables", :partial => "variables" ! page.hide "methods_#{@number}" ! page.hide "classes_#{@number}" ! page.hide "modules_#{@number}" end end --- 117,124 ---- # add selected results to the current DOM min_num.upto(max_num) do |@number| + #page.show "log_#{@number}" @script, @result, @output = Bio::Shell.cache[:results].restore(@number) if @script ! render_log(page) end end Index: _methods.rhtml =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/_methods.rhtml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** _methods.rhtml 24 Dec 2006 08:27:15 -0000 1.1 --- _methods.rhtml 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 1,4 **** [ <%= @class %> ] ! <% @methods.sort.each do |x| %> ! <%= x %> ! <% end %> \ No newline at end of file --- 1,9 ---- [ <%= @class %> ] ! ! ! <%- step = @methods.size / 4 + 1 -%> ! <%- 0.step(@methods.size, step) do |i| -%> ! ! <%- end -%> ! !
<%= @methods.sort[i, step].join("
") %>
\ No newline at end of file Index: bioruby.css =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates/bioruby.css,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bioruby.css 24 Dec 2006 08:27:15 -0000 1.1 --- bioruby.css 16 Jan 2007 05:47:05 -0000 1.2 *************** *** 26,35 **** } ! div.evaluate div.input pre.script { background-color: #ffffeb; border-style: solid; } ! div.evaluate div.output div.methods { padding: 5px; background-color: #ffffdd; --- 26,35 ---- } ! div.log div.input pre.script { background-color: #ffffeb; border-style: solid; } ! div.log div.output div.methods { padding: 5px; background-color: #ffffdd; *************** *** 37,41 **** } ! div.evaluate div.output div.classes { padding: 5px; background-color: #ccffcc; --- 37,41 ---- } ! div.log div.output div.classes { padding: 5px; background-color: #ccffcc; *************** *** 43,47 **** } ! div.evaluate div.output div.modules { padding: 5px; background-color: #ffcccc; --- 43,47 ---- } ! div.log div.output div.modules { padding: 5px; background-color: #ffcccc; *************** *** 49,61 **** } ! div.evaluate div.output pre.result { border-style: dashed; } ! div.evaluate div.output pre.output { border-style: dashed; } ! div.evaluate hr.evaluate { border-style: dotted none none none; border-top-width: 1px; --- 49,61 ---- } ! div.log div.output pre.result { border-style: dashed; } ! div.log div.output pre.output { border-style: dashed; } ! div.log hr.result { border-style: dotted none none none; border-top-width: 1px; *************** *** 194,203 **** --- 194,209 ---- /* table */ + table#list_methods { + width: 680px; + } + th { vertical-align: top; + padding: 5px; } td { vertical-align: top; + padding: 5px; } *************** *** 205,208 **** --- 211,215 ---- textarea { + font-family: monospace; overflow: auto; }