From nakao at dev.open-bio.org Sun Jun 4 22:52:01 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Mon, 05 Jun 2006 02:52:01 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/io test_soapwsdl.rb,1.1,1.2 Message-ID: <200606050252.k552q1l2022218@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/io In directory dev.open-bio.org:/tmp/cvs-serv22198/test/unit/bio/io Modified Files: test_soapwsdl.rb Log Message: * updated test_methods for recently added list_methods method in lib/bio/io/soapwsdl.rb. Index: test_soapwsdl.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/io/test_soapwsdl.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_soapwsdl.rb 18 Dec 2005 17:09:53 -0000 1.1 --- test_soapwsdl.rb 5 Jun 2006 02:51:59 -0000 1.2 *************** *** 2,20 **** # test/unit/bio/io/test_soapwsdl.rb - Unit test for SOAP/WSDL # ! # Copyright (C) 2005 Mitsuteru Nakao ! # ! # This library is free software; you can redistribute it and/or ! # modify it under the terms of the GNU Lesser General Public ! # License as published by the Free Software Foundation; either ! # version 2 of the License, or (at your option) any later version. ! # ! # This library is distributed in the hope that it will be useful, ! # but WITHOUT ANY WARRANTY; without even the implied warranty of ! # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! # Lesser General Public License for more details. ! # ! # You should have received a copy of the GNU Lesser General Public ! # License along with this library; if not, write to the Free Software ! # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id$ --- 2,7 ---- # test/unit/bio/io/test_soapwsdl.rb - Unit test for SOAP/WSDL # ! # Copytight:: Copyright (C) 2005 Mitsuteru Nakao ! # License:: Ruby's # # $Id$ *************** *** 38,42 **** def test_methods ! methods = ['wsdl', 'wsdl=', 'log', 'log='] assert_equal(methods.sort, (@obj.instance_methods - Object.methods).sort) end --- 25,29 ---- def test_methods ! methods = ['list_methods','wsdl', 'wsdl=', 'log', 'log='] assert_equal(methods.sort, (@obj.instance_methods - Object.methods).sort) end From nakao at dev.open-bio.org Sun Jun 4 22:54:44 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Mon, 05 Jun 2006 02:54:44 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/appl test_pts1.rb,1.1,1.2 Message-ID: <200606050254.k552sikS022267@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/appl In directory dev.open-bio.org:/tmp/cvs-serv22247/test/unit/bio/appl Modified Files: test_pts1.rb Log Message: * added test_entry_id in TestPTS1Report class. Index: test_pts1.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/appl/test_pts1.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_pts1.rb 2 May 2006 10:29:19 -0000 1.1 --- test_pts1.rb 5 Jun 2006 02:54:42 -0000 1.2 *************** *** 106,109 **** --- 106,113 ---- end + def test_entry_id + assert_equal("hoge", @report.entry_id) + end + def test_prediction assert_equal("Targeted", @report.prediction) From nakao at dev.open-bio.org Sun Jun 4 22:55:53 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Mon, 05 Jun 2006 02:55:53 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl pts1.rb,1.2,1.3 Message-ID: <200606050255.k552trVs022316@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl In directory dev.open-bio.org:/tmp/cvs-serv22296/lib/bio/appl Modified Files: pts1.rb Log Message: * added Bio::PTS1::Report#entry_id. Index: pts1.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/pts1.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pts1.rb 9 May 2006 08:18:49 -0000 1.2 --- pts1.rb 5 Jun 2006 02:55:51 -0000 1.3 *************** *** 175,178 **** --- 175,181 ---- class Report + # Query sequence name. + attr_reader :entry_id + # Amino acids subsequence at C-terminal region. attr_reader :cterm *************** *** 229,232 **** --- 232,237 ---- @output.each do |line| case line + when /Name<\/td>(\S.+)<\/td><\/tr>/ + @entry_id = $1 when /C-terminus<\/td>(\w+)<\/td>/ @cterm = $1 From aerts at dev.open-bio.org Wed Jun 7 08:55:52 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Wed, 07 Jun 2006 12:55:52 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio map.rb,1.5,1.6 Message-ID: <200606071255.k57CtqFA003705@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv3575 Modified Files: map.rb Log Message: * Added Bio::Locations#equal? method. (Should be moved to location.rb, if approved.) * Methods add_mapping_to_marker and add_mapping_to_map renamed to add_mapping_as_map and add_mapping_as_marker, respectively, to lessen the confusion of what is mapped to what. * When adding a new mapping to a map or marker, a check is done first to see if that mapping has been added before or not. * New method: Bio::Map::ActsLikeMarker#positions_on(map) Index: map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/map.rb,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** map.rb 4 May 2006 18:41:08 -0000 1.5 --- map.rb 7 Jun 2006 12:55:50 -0000 1.6 *************** *** 6,12 **** --- 6,28 ---- # Licence:: Ruby's # + # $Id$ require 'bio/location' module Bio + + # Add a method to Bio::Locations class + class Locations + def equals?(other) + if ! other.kind_of?(Bio::Locations) + return nil + end + if self.sort == other.sort + return true + else + return false + end + end + end + # = DESCRIPTION # The Bio::Module contains classes that describe mapping information and can *************** *** 42,48 **** # my_map2 = Bio::Map::SimpleMap.new('consensus', 'linkage', 'cM') # ! # my_map1.add_mapping_to_marker(my_marker1, '17') ! # my_map1.add_mapping_to_marker(Bio::Map::Marker.new('marker2'), '5') ! # my_marker3.add_mapping_to_marker(my_map1, '9') # # puts "Does my_map1 contain marker3? => " + my_map1.contains_marker?(my_marker3).to_s --- 58,64 ---- # my_map2 = Bio::Map::SimpleMap.new('consensus', 'linkage', 'cM') # ! # my_map1.add_mapping_as_map(my_marker1, '17') ! # my_map1.add_mapping_as_map(Bio::Map::Marker.new('marker2'), '5') ! # my_marker3.add_mapping_as_marker(my_map1, '9') # # puts "Does my_map1 contain marker3? => " + my_map1.contains_marker?(my_marker3).to_s *************** *** 50,63 **** # # my_map1.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end # puts my_map1.min.marker.name # my_map2.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end - # - # = TODO - # Check if initialization of @mappings can be done in ActsLikeMap and - # ActsLikeMarker, instead of in the classes that include these modules. module Map # = DESCRIPTION --- 66,75 ---- # # my_map1.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end # puts my_map1.min.marker.name # my_map2.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end module Map # = DESCRIPTION *************** *** 67,72 **** --- 79,87 ---- # * check if a given marker is mapped to it # , and can be mixed into other classes (e.g. Bio::Map::SimpleMap) + # + # Classes that include this mixin should provide an array property called mappings_as_map. module ActsLikeMap include Enumerable + # = DESCRIPTION # Adds a Bio::Map::Mappings object to its array of mappings. *************** *** 74,78 **** # = USAGE # # suppose we have a Bio::Map::SimpleMap object called my_map ! # my_map.add_mapping_to_marker(Bio::Map::Marker.new('marker_a'), '5') # --- # *Arguments*: --- 89,93 ---- # = USAGE # # suppose we have a Bio::Map::SimpleMap object called my_map ! # my_map.add_mapping_as_map(Bio::Map::Marker.new('marker_a'), '5') # --- # *Arguments*: *************** *** 80,91 **** # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_to_marker(marker, location = nil) unless marker.class.include?(Bio::Map::ActsLikeMarker) raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker" end ! my_mapping = Bio::Map::Mapping.new(self, marker, Bio::Location.new(location)) ! @mappings.push(my_mapping) ! unless marker.mapped_to?(self) ! marker.mappings.push(my_mapping) end --- 95,117 ---- # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_as_map(marker, location = nil) unless marker.class.include?(Bio::Map::ActsLikeMarker) raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker" end ! my_mapping = ( location.nil? ) ? Bio::Map::Mapping.new(self, marker, nil) : Bio::Map::Mapping.new(self, marker, Bio::Locations.new(location)) ! if ! marker.mapped_to?(self) ! self.mappings_as_map.push(my_mapping) ! marker.mappings_as_marker.push(my_mapping) ! else ! already_mapped = false ! marker.positions_on(self).each do |loc| ! if loc.equals?(Bio::Locations.new(location)) ! already_mapped = true ! end ! end ! if ! already_mapped ! self.mappings_as_map.push(my_mapping) ! marker.mappings_as_marker.push(my_mapping) ! end end *************** *** 103,107 **** end contains = false ! @mappings.each do |mapping| if mapping.marker == marker contains = true --- 129,133 ---- end contains = false ! self.mappings_as_map.each do |mapping| if mapping.marker == marker contains = true *************** *** 114,118 **** # Go through all Bio::Map::Mapping objects linked to this Bio::Map::SimpleMap. def each ! @mappings.each do |mapping| yield mapping end --- 140,144 ---- # Go through all Bio::Map::Mapping objects linked to this Bio::Map::SimpleMap. def each ! self.mappings_as_map.each do |mapping| yield mapping end *************** *** 126,129 **** --- 152,157 ---- # * check if it's mapped to a given map # , and can be mixed into other classes (e.g. Bio::Map::Marker) + # + # Classes that include this mixin should provide an array property called mappings_as_marker. module ActsLikeMarker include Enumerable *************** *** 134,138 **** # = USAGE # # suppose we have a Bio::Map::Marker object called marker_a ! # marker_a.add_mapping_to_map(Bio::Map::SimpleMap.new('my_map'), '5') # --- # *Arguments*: --- 162,166 ---- # = USAGE # # suppose we have a Bio::Map::Marker object called marker_a ! # marker_a.add_mapping_as_marker(Bio::Map::SimpleMap.new('my_map'), '5') # --- # *Arguments*: *************** *** 140,151 **** # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_to_map(map, location = nil) unless map.class.include?(Bio::Map::ActsLikeMap) raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! my_mapping = Bio::Map::Mapping.new(map, self, Bio::Location.new(location)) ! @mappings.push(my_mapping) ! unless map.contains_marker?(self) ! map.mappings.push(my_mapping) end end --- 168,197 ---- # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_as_marker(map, location = nil) unless map.class.include?(Bio::Map::ActsLikeMap) raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! my_mapping = (location.nil?) ? Bio::Map::Mappings.new(map, self, nil) : Bio::Map::Mapping.new(map, self, Bio::Locations.new(location)) ! if ! self.mapped_to?(map) ! self.mappings_as_marker.push(my_mapping) ! map.mappings_as_map.push(my_mapping) ! else ! already_mapped = false ! self.positions_on(map).each do |loc| ! if loc.equals?(Bio::Locations.new(location)) ! already_mapped = true ! end ! end ! if ! already_mapped ! self.mappings_as_marker.push(my_mapping) ! map.mappings_as_map.push(my_mapping) ! end ! end ! end ! ! # Go through all Mapping objects linked to this marker. ! def each ! self.mappings_as_marker.each do |mapping| ! yield mapping end end *************** *** 160,166 **** raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! mapped = false ! @mappings.each do |mapping| if mapping.map == map mapped = true --- 206,212 ---- raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! mapped = false ! self.mappings_as_marker.each do |mapping| if mapping.map == map mapped = true *************** *** 168,180 **** end end return mapped end ! ! # Go through all Mapping objects linked to this marker. ! def each ! @mappings.each do |mapping| ! yield mapping end end end #ActsLikeMarker --- 214,241 ---- end end + return mapped end ! ! # Return all positions of this marker on a given map. ! # --- ! # *Arguments*: ! # * _map_: an object that mixes in Bio::Map::ActsLikeMap ! # *Returns*:: array of Bio::Location objects ! def positions_on(map) ! unless map.class.include?(Bio::Map::ActsLikeMap) ! raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" ! end ! ! positions = Array.new ! self.mappings_as_marker.each do |mapping| ! if mapping.map == map ! positions.push(mapping.location) ! end end + + return positions end + end #ActsLikeMarker *************** *** 191,195 **** # * _map_: a Bio::Map::SimpleMap object # * _marker_: a Bio::Map::Marker object ! # * _location_: a Bio::Location object def initialize (map, marker, location = nil) @map, @marker, @location = map, marker, location --- 252,257 ---- # * _map_: a Bio::Map::SimpleMap object # * _marker_: a Bio::Map::Marker object ! # * _location_: a Bio::Locations object ! def initialize (map, marker, location = nil) @map, @marker, @location = map, marker, location *************** *** 197,219 **** attr_accessor :map, :marker, :location ! # Compares the location of this mapping to another mapping. ! # --- ! # *Arguments*: ! # * other_mapping: Bio::Map::Mapping object ! # *Returns*:: ! # * 1 if self < other location ! # * -1 if self > other location ! # * 0 if both location are the same ! # * nil if the argument is not a Bio::Location object ! def <=>(other) ! unless other.kind_of?(Bio::Map::Mapping) ! raise "[Error] markers are not comparable" ! end ! unless @map.equal?(other.map) ! raise "[Error] maps have to be the same" ! end ! ! return self.location.<=>(other.location) ! end end # Mapping --- 259,280 ---- attr_accessor :map, :marker, :location ! # # Compares the location of this mapping to another mapping. ! # # --- ! # # *Arguments*: ! # # * other_mapping: Bio::Map::Mapping object ! # # *Returns*:: ! # # * 1 if self < other location ! # # * -1 if self > other location ! # # * 0 if both location are the same ! # # * nil if the argument is not a Bio::Location object ! # def <=>(other) ! # unless other.kind_of?(Bio::Map::Mapping) ! # raise "[Error] markers are not comparable" ! # end ! # unless @map.equal?(other.map) ! # raise "[Error] maps have to be the same" ! # end ! # return self.location<=>(other.location) # FIXME: no <=>-method in Bio::Locations ! # end end # Mapping *************** *** 228,232 **** # my_map1.add_marker(Bio::Map::Marker.new('marker_b', '5') class SimpleMap ! include ActsLikeMap # Builds a new Bio::Map::SimpleMap object --- 289,293 ---- # my_map1.add_marker(Bio::Map::Marker.new('marker_b', '5') class SimpleMap ! include Bio::Map::ActsLikeMap # Builds a new Bio::Map::SimpleMap object *************** *** 237,243 **** # * units: unit of the map (e.g. cM, cR, ...) # *Returns*:: new Bio::Map::SimpleMap object ! def initialize (name = nil, type = nil, units = nil) ! @name, @type, @units = name, type, units ! @mappings = Array.new end --- 298,304 ---- # * units: unit of the map (e.g. cM, cR, ...) # *Returns*:: new Bio::Map::SimpleMap object ! def initialize (name = nil, type = nil, length = nil, units = nil) ! @name, @type, @length, @units = name, type, length, units ! @mappings_as_map = Array.new end *************** *** 247,256 **** # Type of the map attr_accessor :type ! # Units of the map attr_accessor :units ! # Array of mappings for the map ! attr_accessor :mappings end # SimpleMap --- 308,321 ---- # Type of the map attr_accessor :type ! ! # Length of the map ! attr_accessor :length ! # Units of the map attr_accessor :units ! # Mappings ! attr_accessor :mappings_as_map ! end # SimpleMap *************** *** 264,268 **** # marker_b = Bio::Map::Marker.new('marker_b') class Marker ! include ActsLikeMarker # Builds a new Bio::Map::Marker object --- 329,333 ---- # marker_b = Bio::Map::Marker.new('marker_b') class Marker ! include Bio::Map::ActsLikeMarker # Builds a new Bio::Map::Marker object *************** *** 273,315 **** def initialize(name) @name = name ! @mappings = Array.new end # Name of the marker attr_accessor :name ! ! # Array of mappings for the marker ! attr_accessor :mappings end # Marker end # Map end # Bio - - if __FILE__ == $0 - my_marker1 = Bio::Map::Marker.new('marker1') - # my_marker2 = Bio::Map::Marker.new('marker2') - my_marker3 = Bio::Map::Marker.new('marker3') - - my_map1 = Bio::Map::SimpleMap.new('RH_map_ABC (2006)', 'RH', 'cR') - my_map2 = Bio::Map::SimpleMap.new('consensus', 'linkage', 'cM') - - my_map1.add_mapping_to_marker(my_marker1, '17') - my_map1.add_mapping_to_marker(Bio::Map::Marker.new('marker2'), '5') - my_marker3.add_mapping_to_map(my_map1, '9') - - my_map2.add_mapping_to_marker(my_marker1, '57') - - puts "Does my_map1 contain marker3? => " + my_map1.contains_marker?(my_marker3).to_s - puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s - - my_map1.sort.each do |mapping| - puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s - end - puts my_map1.min.marker.name - - my_map2.each do |mapping| - puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s - end - - # p my_map1.between?(my_mappable2,my_mappable3) - # p my_map1.between?(my_mappable,my_mappable2) - end --- 338,351 ---- def initialize(name) @name = name ! @mappings_as_marker = Array.new end # Name of the marker attr_accessor :name ! ! # Mappings ! attr_accessor :mappings_as_marker ! end # Marker end # Map end # Bio From aerts at dev.open-bio.org Wed Jun 7 08:56:31 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Wed, 07 Jun 2006 12:56:31 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio test_map.rb,1.1,1.2 Message-ID: <200606071256.k57CuVZC003751@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio In directory dev.open-bio.org:/tmp/cvs-serv3723 Modified Files: test_map.rb Log Message: Following changes in map.rb Index: test_map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_map.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_map.rb 4 May 2006 16:19:52 -0000 1.1 --- test_map.rb 7 Jun 2006 12:56:29 -0000 1.2 *************** *** 5,8 **** --- 5,10 ---- # Jan Aerts # License:: Ruby's + # + # $Id$ require 'pathname' *************** *** 14,102 **** module Bio ! class TestMapSimple < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 'some_unit') ! end ! def test_attributes ! assert_equal("marker1", @marker1.name) ! assert_equal("marker2", @marker2.name) ! assert_equal([], @marker1.mappings) ! assert_equal([], @marker2.mappings) ! assert_equal("map1", @map1.name) ! assert_equal("some_unit", @map1.units) ! assert_equal("some_type", @map1.type) ! assert_equal([], @map1.mappings) ! end ! end ! class TestMapping < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 'some_unit') ! end ! def test_add_mapping_to_marker ! @map1.add_mapping_to_marker(@marker2, '5') ! assert_equal(1, @map1.mappings.length) ! assert_equal(1, @marker2.mappings.length) ! assert_equal(0, @marker1.mappings.length) ! assert_kind_of(Bio::Location, @map1.mappings[0].location) ! assert_kind_of(Bio::Location, @marker2.mappings[0].location) ! end ! def test_add_mapping_to_map ! @marker1.add_mapping_to_map(@map1, '5') ! assert_equal(1, @map1.mappings.length) ! assert_equal(1, @marker1.mappings.length) ! assert_kind_of(Bio::Location, @map1.mappings[0].location) ! assert_kind_of(Bio::Location, @marker1.mappings[0].location) end ! end ! class CloneActsLikeMap ! include Bio::Map::ActsLikeMap ! end ! class TestActsLikeMap < Test::Unit::TestCase ! def test_mixin ! clone = CloneActsLikeMap.new ! assert_instance_of(CloneActsLikeMap, clone) ! assert_respond_to(clone, 'contains_marker?') ! assert_respond_to(clone, 'add_mapping_to_marker') ! end ! end ! ! class CloneActsLikeMarker ! include Bio::Map::ActsLikeMarker ! end ! class TestActsLikeMarker < Test::Unit::TestCase ! def test_mixin ! clone = CloneActsLikeMarker.new ! assert_instance_of(CloneActsLikeMarker, clone) ! assert_respond_to(clone, 'mapped_to?') ! assert_respond_to(clone, 'add_mapping_to_map') ! end ! end ! class CloneActsLikeMapAndMarker ! include Bio::Map::ActsLikeMap ! include Bio::Map::ActsLikeMarker ! end ! class TestActsLikeMapAndMarker < Test::Unit::TestCase ! def test_mixin ! clone = CloneActsLikeMapAndMarker.new ! assert_instance_of(CloneActsLikeMapAndMarker, clone) ! assert_respond_to(clone, 'contains_marker?') ! assert_respond_to(clone, 'add_mapping_to_marker') ! assert_respond_to(clone, 'mapped_to?') ! assert_respond_to(clone, 'add_mapping_to_map') ! end ! end end --- 16,184 ---- module Bio ! class TestMapSimple < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 500, 'some_unit') ! end ! def test_attributes ! assert_equal("marker1", @marker1.name) ! assert_equal("marker2", @marker2.name) ! assert_equal([], @marker1.mappings_as_marker) ! assert_equal([], @marker2.mappings_as_marker) ! assert_equal("map1", @map1.name) ! assert_equal("some_unit", @map1.units) ! assert_equal("some_type", @map1.type) ! assert_equal([], @map1.mappings_as_map) ! end ! end ! class TestMapping < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @marker3 = Bio::Map::Marker.new('marker3') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 'some_unit') ! end ! def test_add_mapping_as_map ! @map1.add_mapping_as_map(@marker2, '5') ! assert_equal(1, @map1.mappings_as_map.length) ! assert_equal(1, @marker2.mappings_as_marker.length) ! assert_equal(0, @marker1.mappings_as_marker.length) ! assert_kind_of(Bio::Locations, @map1.mappings_as_map[0].location) ! assert_kind_of(Bio::Locations, @marker2.mappings_as_marker[0].location) ! end ! def test_add_mapping_as_marker ! @marker1.add_mapping_as_marker(@map1, '5') ! assert_equal(1, @map1.mappings_as_map.length, 'Mapping as map') ! assert_equal(1, @marker1.mappings_as_marker.length, 'Mapping as marker') ! assert_kind_of(Bio::Locations, @map1.mappings_as_map[0].location) ! assert_kind_of(Bio::Locations, @marker1.mappings_as_marker[0].location) end ! ! def test_mapped_to? ! @marker1.add_mapping_as_marker(@map1, '5') ! assert_equal(true, @marker1.mapped_to?(@map1)) ! assert_equal(false, @marker3.mapped_to?(@map1)) ! end ! ! def test_contains_marker? ! @marker1.add_mapping_as_marker(@map1, '5') ! assert_equal(true, @map1.contains_marker?(@marker1)) ! assert_equal(false, @map1.contains_marker?(@marker3)) ! end ! ! def test_mappings_as_map_each ! @map1.add_mapping_as_map(@marker1, '5') ! @marker2.add_mapping_as_marker(@map1, '7') ! mappings = 0 ! @map1.mappings_as_map.each do |mapping| ! mappings += 1 ! end ! assert_equal(2, mappings) ! end ! ! def test_mappings_as_marker_each ! @map1.add_mapping_as_map(@marker1, '5') ! @marker1.add_mapping_as_marker(@map1, '7') ! mappings = 0 ! @marker1.mappings_as_marker.each do |mapping| ! mappings += 1 ! end ! assert_equal(2, mappings) ! ! end ! ! def test_multiple_mappings_between_same_marker_and_map ! @map1.add_mapping_as_map(@marker1, '5') ! @map1.add_mapping_as_map(@marker1, '37') ! @marker1.add_mapping_as_marker(@map1, '53') ! assert_equal(3, @marker1.mappings_as_marker.length) ! ! @marker1.add_mapping_as_marker(@map1, '53') # This mapping should _not_ be added, because it's already defined. ! assert_equal(3, @marker1.mappings_as_marker.length) ! end ! ! def test_positions_on ! @map1.add_mapping_as_map(@marker1, '5') ! assert_equal(1, @marker1.mappings_as_marker.length) ! assert_equal('5', @marker1.positions_on(@map1).collect{|p| p.first.from.to_s}.join(',')) # FIXME: Test is not correct (uses Location.first) ! @map1.add_mapping_as_map(@marker1, '37') ! assert_equal('5,37', @marker1.positions_on(@map1).collect{|p| p.first.from.to_s}.sort{|a,b| a.to_i <=> b.to_i}.join(',')) # FIXME: Test is not correct (uses Location.first) ! end ! end ! class CloneActsLikeMap ! include Bio::Map::ActsLikeMap ! def initialize ! @mappings_as_map = Array.new ! end ! attr_accessor :mappings_as_map ! end ! class TestActsLikeMap < Test::Unit::TestCase ! def setup ! @clone = CloneActsLikeMap.new ! end ! def test_mixin ! assert_instance_of(CloneActsLikeMap, @clone) ! assert_respond_to(@clone, 'contains_marker?') ! assert_respond_to(@clone, 'add_mapping_as_map') ! assert_equal(0, @clone.mappings_as_map.length) ! end ! end ! class CloneActsLikeMarker ! include Bio::Map::ActsLikeMarker ! def initialize ! @mappings_as_marker = Array.new ! end ! attr_accessor :mappings_as_marker ! end ! class TestActsLikeMarker < Test::Unit::TestCase ! def setup ! @clone = CloneActsLikeMarker.new ! end ! ! def test_mixin ! assert_instance_of(CloneActsLikeMarker, @clone) ! assert_respond_to(@clone, 'mapped_to?') ! assert_respond_to(@clone, 'add_mapping_as_marker') ! end ! end ! class CloneActsLikeMapAndMarker ! include Bio::Map::ActsLikeMap ! include Bio::Map::ActsLikeMarker ! def initialize ! @mappings_as_map = Array.new ! @mappings_as_marker = Array.new ! end ! attr_accessor :mappings_as_map, :mappings_as_marker ! end + class TestActsLikeMapAndMarker < Test::Unit::TestCase + def setup + @clone_a = CloneActsLikeMapAndMarker.new + @clone_b = CloneActsLikeMapAndMarker.new + @clone_a.add_mapping_as_map(@clone_b, nil) + end + + def test_mixin + assert_instance_of(CloneActsLikeMapAndMarker, @clone_a) + assert_respond_to(@clone_a, 'contains_marker?') + assert_respond_to(@clone_a, 'add_mapping_as_map') + assert_respond_to(@clone_a, 'mapped_to?') + assert_respond_to(@clone_a, 'add_mapping_as_marker') + + assert_equal(1, @clone_a.mappings_as_map.length) + assert_equal(0, @clone_a.mappings_as_marker.length) + assert_equal(0, @clone_b.mappings_as_map.length) + assert_equal(1, @clone_b.mappings_as_marker.length) + end + end end From ngoto at dev.open-bio.org Mon Jun 12 06:35:44 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Mon, 12 Jun 2006 10:35:44 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/io flatfile.rb,1.49,1.50 Message-ID: <200606121035.k5CAZiau015926@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/io In directory dev.open-bio.org:/tmp/cvs-serv15886/lib/bio/io Modified Files: flatfile.rb Log Message: Bio::FlatFile.open(klass, filename) didn't work. Index: flatfile.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/io/flatfile.rb,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** flatfile.rb 22 Mar 2006 10:19:22 -0000 1.49 --- flatfile.rb 12 Jun 2006 10:35:42 -0000 1.50 *************** *** 426,430 **** unless file.respond_to?(:gets) # 'file' is a filename ! self.open_file(file, *arg, &block) else # 'file' is a IO object --- 426,430 ---- unless file.respond_to?(:gets) # 'file' is a filename ! _open_file(dbclass, file, *arg, &block) else # 'file' is a IO object *************** *** 466,478 **** # def self.open_file(filename, *arg) if block_given? then BufferedInputStream.open_file(filename, *arg) do |stream| ! yield self.new(nil, stream) end else stream = BufferedInputStream.open_file(filename, *arg) ! self.new(nil, stream) end end # Opens URI specified as _uri_. --- 466,490 ---- # def self.open_file(filename, *arg) + _open_file(nil, filename, *arg) + end + + # Same as FlatFile.open(dbclass, filename, *arg), + # except that it only accept filename and doesn't accept IO object. + # + # It can accept a block. + # If a block is given, it returns the block's return value. + # Otherwise, it returns a new FlatFile object. + # + def self._open_file(dbclass, filename, *arg) if block_given? then BufferedInputStream.open_file(filename, *arg) do |stream| ! yield self.new(dbclass, stream) end else stream = BufferedInputStream.open_file(filename, *arg) ! self.new(dbclass, stream) end end + private_class_method :_open_file # Opens URI specified as _uri_. From ngoto at dev.open-bio.org Thu Jun 15 10:28:57 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 15 Jun 2006 14:28:57 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/io test_flatfile.rb,NONE,1.1 Message-ID: <200606151428.k5FESvlN028352@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/io In directory dev.open-bio.org:/tmp/cvs-serv28332/test/unit/bio/io Added Files: test_flatfile.rb Log Message: Unit test for Bio::FlatFile class is added but still incomplete. --- NEW FILE: test_flatfile.rb --- # # = test/unit/bio/io/test_flatfile.rb - unit test for Bio::FlatFile # # Copyright (C) 2006 Naohisa Goto # # License:: Ruby's # # $Id: test_flatfile.rb,v 1.1 2006/06/15 14:28:55 ngoto 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' require 'stringio' module Bio module TestFlatFile bioruby_root = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4)).cleanpath.to_s TestDataPath = Pathname.new(File.join(bioruby_root, 'test', 'data')).cleanpath.to_s TestDataFastaFormat01 = File.join(TestDataPath, 'fasta', 'example1.txt') class TestBufferedInputStreamClassMethod < Test::Unit::TestCase def test_self_for_io io = File.open(TestDataFastaFormat01) obj = Bio::FlatFile::BufferedInputStream.for_io(io) assert_instance_of(Bio::FlatFile::BufferedInputStream, obj) assert_equal(TestDataFastaFormat01, obj.path) end def test_self_open_file obj = Bio::FlatFile::BufferedInputStream.open_file(TestDataFastaFormat01) assert_instance_of(Bio::FlatFile::BufferedInputStream, obj) assert_equal(TestDataFastaFormat01, obj.path) end def test_self_open_file_with_block obj2 = nil Bio::FlatFile::BufferedInputStream.open_file(TestDataFastaFormat01) do |obj| assert_instance_of(Bio::FlatFile::BufferedInputStream, obj) assert_equal(TestDataFastaFormat01, obj.path) obj2 = obj end assert_raise(IOError) { obj2.close } end end #class TestBufferedInputStreamClassMethod class TestBufferedInputStream < Test::Unit::TestCase def setup io = File.open(TestDataFastaFormat01) path = TestDataFastaFormat01 @obj = Bio::FlatFile::BufferedInputStream.new(io, path) end def test_to_io assert_kind_of(IO, @obj.to_io) end def test_close assert_nil(@obj.close) end def test_rewind @obj.prefetch_gets @obj.rewind assert_equal('', @obj.prefetch_buffer) end def test_pos @obj.gets @obj.gets @obj.prefetch_gets assert_equal(117, @obj.pos) #the number depends on original data end def test_pos=() str = @obj.gets assert_equal(0, @obj.pos = 0) end def test_eof_false_first assert_equal(false, @obj.eof?) end def test_eof_false_after_prefetch while @obj.prefetch_gets; nil; end assert_equal(false, @obj.eof?) end def test_eof_true while @obj.gets; nil; end assert_equal(true, @obj.eof?) end def test_gets @obj.gets @obj.gets assert_equal("gagcaaatcgaaaaggagagatttctgcatatcaagagaaaattcgagctgagatacattccaagtgtggctactc", @obj.gets.chomp) end def test_gets_equal_prefetch_gets @obj.prefetch_gets str = @obj.prefetch_gets @obj.prefetch_gets @obj.gets assert_equal(@obj.gets, str) end def test_ungets @obj.gets @obj.gets str1 = @obj.gets str2 = @obj.gets assert_nil(@obj.ungets(str2)) assert_nil(@obj.ungets(str1)) assert_equal(str1, @obj.gets) assert_equal(str2, @obj.gets) end def test_getc assert_equal(?>, @obj.getc) end def test_getc_after_prefetch @obj.prefetch_gets assert_equal(?>, @obj.getc) end def test_ungetc c = @obj.getc assert_nil(@obj.ungetc(c)) assert_equal(c, @obj.getc) end def test_ungetc_after_prefetch str = @obj.prefetch_gets c = @obj.getc assert_nil(@obj.ungetc(c)) assert_equal(str, @obj.gets) end def test_prefetch_buffer str = @obj.prefetch_gets str += @obj.prefetch_gets assert_equal(str, @obj.prefetch_buffer) end def test_prefetch_gets @obj.prefetch_gets @obj.prefetch_gets @obj.gets str = @obj.prefetch_gets @obj.gets assert_equal(str, @obj.gets) end def test_prefetch_gets_with_arg # test @obj.gets str = @obj.prefetch_gets("\n>") assert_equal(str, @obj.gets("\n>")) # test using IO object io = @obj.to_io io.rewind assert_equal(str, io.gets("\n>")) end def test_skip_spaces @obj.gets('CDS') assert_nil(@obj.skip_spaces) assert_equal(?a, @obj.getc) end end #class TestBufferedInputStream class TestFlatFileWithCustomClass < Test::Unit::TestCase # very simple parser for tab-separated data class SimpleFormat # delimiter needed for flatfile DELIMITER = RS = nil # nil means no delimiter and reading entire file def initialize(str) @data = str.split(/\n/).collect { |x| x.to_s.split(/\t/) } end attr_reader :data end def test_simpleformat testdata = "AAA\tBBB\tCCCCC\tDDDD\n123\t456\n" testio = StringIO.new(testdata) Bio::FlatFile.open(SimpleFormat, testio) do |ff| ff.each do |entry| assert_equal([ [ 'AAA', 'BBB', 'CCCCC', 'DDDD' ], [ '123', '456' ] ], entry.data) end end end # very simple parser for "//"-separated entries class SimpleFormat2 # delimiter needed for flatfile DELIMITER = RS = "//\n" # the end of each entry is "//\n" def initialize(str) # very simple parser only to store a text data @data = str end attr_reader :data end def test_simpleformat2 testdata = <<__END_OF_TESTDATA__ test01 This is a test. // test02 This is an example. // __END_OF_TESTDATA__ a = testdata.split(/(\/\/\n)/) results = [ a[0]+a[1], a[2]+a[3] ] testio = StringIO.new(testdata) Bio::FlatFile.open(SimpleFormat2, testio) do |ff| ff.each do |entry| assert_equal(results.shift, entry.data) end end end end #class TestFlatFileWithCustomClass end #module TestFlatFile end #module Bio From nakao at dev.open-bio.org Fri Jun 16 12:51:07 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Fri, 16 Jun 2006 16:51:07 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db/embl test_sptr.rb,1.2,1.3 Message-ID: <200606161651.k5GGp7aH001256@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db/embl In directory dev.open-bio.org:/tmp/cvs-serv1236 Modified Files: test_sptr.rb Log Message: * Added a test in test_ft. Index: test_sptr.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/embl/test_sptr.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_sptr.rb 23 Nov 2005 10:06:12 -0000 1.2 --- test_sptr.rb 16 Jun 2006 16:51:05 -0000 1.3 *************** *** 234,238 **** assert(@obj.ft) name = 'DNA_BIND' ! assert_equal([{"FTId"=>nil, "From"=>102, "diff"=>[], "To"=>292, "Description"=>nil}], @obj.ft(name)) end --- 234,239 ---- assert(@obj.ft) name = 'DNA_BIND' ! assert_equal([{"FTId"=>"", "From"=>102, "diff"=>[], "To"=>292, "Description"=>""}], @obj.ft(name)) ! assert_equal([{"FTId"=>"", "From"=>102, "diff"=>[], "To"=>292, "Description"=>""}], @obj.ft[name]) end From nakao at dev.open-bio.org Fri Jun 16 13:01:03 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Fri, 16 Jun 2006 17:01:03 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/embl sptr.rb,1.31,1.32 Message-ID: <200606161701.k5GH13j4001328@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/embl In directory dev.open-bio.org:/tmp/cvs-serv1306 Modified Files: sptr.rb Log Message: * fixed a PROPEP parsing bug in Bio::SPTR#ft. (reported by Makoto Hamaguchi-san). * changed codes in the Bio::SPTR#id_line and the Bio::SPTR#dt. [refactoring] Index: sptr.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/embl/sptr.rb,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** sptr.rb 14 Apr 2006 05:52:28 -0000 1.31 --- sptr.rb 16 Jun 2006 17:01:01 -0000 1.32 *************** *** 2,6 **** # = bio/db/embl/sptr.rb - UniProt/SwissProt and TrEMBL database class # ! # Copyright:: Copyright (C) 2001-2006 Mitsuteru C. Nakao # License:: Ruby's # --- 2,6 ---- # = bio/db/embl/sptr.rb - UniProt/SwissProt and TrEMBL database class # ! # Copyright:: Copyright (C) 2001-2006 Mitsuteru C. Nakao # License:: Ruby's # *************** *** 46,50 **** @@data_class = ["STANDARD", "PRELIMINARY"] - # returns a Hash of the ID line. # --- 46,49 ---- *************** *** 57,84 **** # # === Examples ! # obj.id_line #=> {"ENTRY_NAME"=>"P53_HUMAN", "DATA_CLASS"=>"STANDARD", "SEQUENCE_LENGTH"=>393, "MOLECULE_TYPE"=>"PRT"} # # obj.id_line('ENTRY_NAME') #=> "P53_HUMAN" # def id_line(key = nil) ! unless @data['ID'] ! tmp = Hash.new ! a = @orig['ID'].split(/ +/) ! tmp['ENTRY_NAME'] = a[1] ! tmp['DATA_CLASS'] = a[2].sub(/;/,'') ! tmp['MOLECULE_TYPE'] = a[3].sub(/;/,'') ! tmp['SEQUENCE_LENGTH'] = a[4].to_i ! @data['ID'] = tmp ! end ! if key ! @data['ID'][key] # String/Int ! else ! @data['ID'] # Hash ! end end - # returns a ENTRY_NAME in the ID line. # --- 56,78 ---- # # === Examples ! # obj.id_line #=> {"ENTRY_NAME"=>"P53_HUMAN", "DATA_CLASS"=>"STANDARD", ! # "SEQUENCE_LENGTH"=>393, "MOLECULE_TYPE"=>"PRT"} # # obj.id_line('ENTRY_NAME') #=> "P53_HUMAN" # def id_line(key = nil) ! return id_line[key] if key ! return @data['ID'] if @data['ID'] ! part = @orig['ID'].split(/ +/) ! @data['ID'] = { ! 'ENTRY_NAME' => part[1], ! 'DATA_CLASS' => part[2].sub(/;/,''), ! 'MOLECULE_TYPE' => part[3].sub(/;/,''), ! 'SEQUENCE_LENGTH' => part[4].to_i ! } end # returns a ENTRY_NAME in the ID line. # *************** *** 128,145 **** # DT DD-MMM-YYY (rel. NN, Last annotation update) def dt(key = nil) ! unless @data['DT'] ! tmp = Hash.new ! a = self.get('DT').split(/\n/) ! tmp['created'] = a[0].sub(/\w{2} /,'').strip ! tmp['sequence'] = a[1].sub(/\w{2} /,'').strip ! tmp['annotation'] = a[2].sub(/\w{2} /,'').strip ! @data['DT'] = tmp ! end ! if key ! @data['DT'][key] ! else ! @data['DT'] ! end end --- 122,134 ---- # DT DD-MMM-YYY (rel. NN, Last annotation update) def dt(key = nil) ! return dt[key] if key ! return @data['DT'] if @data['DT'] ! part = self.get('DT').split(/\n/) ! @data['DT'] = { ! 'created' => part[0].sub(/\w{2} /,'').strip, ! 'sequence' => part[1].sub(/\w{2} /,'').strip, ! 'annotation' => part[2].sub(/\w{2} /,'').strip ! } end *************** *** 451,455 **** # Event, Named isoforms, Comment, [Name, Synonyms, IsoId, Sequnce]+ ! tmp = {'Event' => nil, 'Named isoforms' => nil, 'Comment' => nil, 'Variants' => []} if /Event=(.+?);/ =~ ap --- 440,445 ---- # Event, Named isoforms, Comment, [Name, Synonyms, IsoId, Sequnce]+ ! tmp = {'Event' => nil, 'Named isoforms' => nil, 'Comment' => nil, ! 'Variants' => []} if /Event=(.+?);/ =~ ap *************** *** 499,503 **** ms.each do |m| ! mass = {'MW'=>nil,'MW_ERR'=>nil,'METHOD'=>nil,'RANGE'=>nil} m.sub(/.$/,'').split(/;/).each do |line| case line --- 489,493 ---- ms.each do |m| ! mass = {'MW' => nil,'MW_ERR' => nil,'METHOD' => nil,'RANGE' => nil} m.sub(/.$/,'').split(/;/).each do |line| case line *************** *** 550,554 **** it.map {|ent| {:partner_id => ent[0].strip, ! :nbexp => ent[1].strip, :intact_acc => ent[2].split(', ') } } --- 540,544 ---- it.map {|ent| {:partner_id => ent[0].strip, ! :nbexp => ent[1].strip, :intact_acc => ent[2].split(', ') } } *************** *** 577,583 **** # returns conteins in the feature table. # * Bio::SPTR#ft -> Hash ! # {'feature_name' => [{'From' => str, 'To' => str, ! # 'Description' => str, 'FTId' => str}],...} # # returns an Array of the information about the feature_name in the feature table. --- 567,589 ---- # returns conteins in the feature table. + # + # == Examples + # + # sp = Bio::SPTR.new(entry) + # ft = sp.ft + # ft.class #=> Hash + # ft.keys.each do |feature_key| + # ft[feature_key].each do |feature| + # feature['From'] #=> '1' + # feature['To'] #=> '21' + # feature['Description'] #=> '' + # feature['FTId'] #=> '' + # feature['diff'] #=> [] + # end + # end + # # * Bio::SPTR#ft -> Hash ! # {FEATURE_KEY => [{'From' => int, 'To' => int, 'diff' => [], ! # 'Description' => aStr, 'FTId' => aStr}],...} # # returns an Array of the information about the feature_name in the feature table. *************** *** 595,692 **** # 35-75 Description (>=0 per key) # ----- ----------------- ! def ft(feature_name = nil) ! unless @data['FT'] ! table = Hash.new() ! last_feature = nil ! ! begin ! get('FT').split(/\n/).each {|line| ! ! feature = line[5..12].strip ! ! if feature == '' and line[34..74] ! tmp = ' ' + line[34..74].strip ! table[last_feature].last['Description'] << tmp ! ! next unless /\.$/ =~ line ! else ! from = line[14..19].strip ! to = line[21..26].strip ! desc = line[34..74].strip if line[34..74] ! table[feature] = [] unless table[feature] ! table[feature] << { ! 'From' => from.to_i, ! 'To' => to.to_i, ! 'Description' => desc, ! 'diff' => [], ! 'FTId' => nil } ! last_feature = feature ! next ! end ! case last_feature ! when 'VARSPLIC', 'VARIANT', 'CONFLICT' ! if /FTId=(.+?)\./ =~ line # version 41 > ! ftid = $1 ! table[last_feature].last['FTId'] = ftid ! table[last_feature].last['Description'].sub!(/ \/FTId=#{ftid}./,'') ! end ! case table[last_feature].last['Description'] ! when /(\w[\w ]*\w*) - ?> (\w[\w ]*\w*)/ ! original = $1 ! swap = $2 ! original = original.gsub(/ /,'').strip ! swap = swap.gsub(/ /,'').strip ! when /Missing/i ! original = seq.subseq(table[last_feature].last['From'], ! table[last_feature].last['To']) ! swap = '' ! else ! raise line ! end ! table[last_feature].last['diff'] = [original, swap] ! end ! } ! rescue ! raise "Invalid FT Lines(#{$!}) in #{entry_id}:, \n" + ! "'#{self.get('FT')}'\n" ! end ! table.each_key do |k| ! table[k].each do |e| ! if / -> / =~ e['Description'] ! pattern = /([A-Z][A-Z ]*[A-Z]*) -> ([A-Z][A-Z ]*[A-Z]*)/ ! e['Description'].sub!(pattern) { ! a = $1 ! b = $2 ! a.gsub(/ /,'') + " -> " + b.gsub(/ /,'') ! } ! end ! if /- [\w\d]/ =~ e['Description'] ! e['Description'].gsub!(/([\w\d]- [\w\d]+)/) { ! a = $1 ! if /- AND/ =~ a ! a ! else ! a.sub(/ /,'') ! end ! } ! end end end - @data['FT'] = table end ! ! if feature_name ! @data['FT'][feature_name] ! else ! @data['FT'] end end # returns a Hash of conteins in the SQ lines. # * Bio::SPTRL#sq -> hsh --- 601,670 ---- # 35-75 Description (>=0 per key) # ----- ----------------- ! # ! def ft(feature_key = nil) ! return ft[feature_key] if feature_key ! return @data['FT'] if @data['FT'] ! table = [] ! begin ! get('FT').split("\n").each do |line| ! if line =~ /^FT \w/ ! feature = line.chomp.ljust(74) ! table << [feature[ 5..12].strip, # Feature Name ! feature[14..19].strip, # From ! feature[21..26].strip, # To ! feature[34..74].strip ] # Description ! else ! table.last << line.chomp.sub!(/^FT +/, '') ! end ! end ! # Join Desctiption lines ! table = table.map { |feature| ! ftid = feature.pop if feature.last =~ /FTId=/ ! if feature.size > 4 ! feature = [feature[0], feature[1], feature[2], ! feature[3, feature.size - 3].join(" ")] ! end ! feature << ftid ! } ! hash = {} ! table.each do |feature| ! hash[feature[0]] = [] unless hash[feature[0]] ! hash[feature[0]] << { ! 'From' => feature[1].to_i, ! 'To' => feature[2].to_i, ! 'Description' => feature[3], ! 'FTId' => feature[4].to_s.sub(/\/FTId=/, '').sub(/\.$/, ''), ! 'diff' => [] ! } ! case feature[0] ! when 'VARSPLIC', 'VARIANT', 'VAR_SEQ', 'CONFLICT' ! case hash[feature[0]].last['Description'] ! when /(\w[\w ]*\w*) - ?> (\w[\w ]*\w*)/ ! original_res = $1 ! changed_res = $2 ! original_res = original_res.gsub(/ /,'').strip ! chenged_res = changed_res.gsub(/ /,'').strip ! when /Missing/i ! original_res = seq.subseq(hash[feature[0]].last['From'], ! hash[feature[0]].last['To']) ! changed_res = '' end + hash[feature[0]].last['diff'] = [original_res, chenged_res] end end ! rescue ! raise "Invalid FT Lines(#{$!}) in #{entry_id}:, \n'#{self.get('FT')}'\n" end + + @data['FT'] = hash end + # returns a Hash of conteins in the SQ lines. # * Bio::SPTRL#sq -> hsh *************** *** 694,698 **** # returns a value of a key given in the SQ lines. # * Bio::SPTRL#sq(key) -> int or str ! # * Keys: ['MW', 'mw', 'molecular', 'weight', 'aalen', 'len', 'length', 'CRC64'] # # === SQ Line; sequence header (1/entry) --- 672,677 ---- # returns a value of a key given in the SQ lines. # * Bio::SPTRL#sq(key) -> int or str ! # * Keys: ['MW', 'mw', 'molecular', 'weight', 'aalen', 'len', 'length', ! # 'CRC64'] # # === SQ Line; sequence header (1/entry) From ngoto at dev.open-bio.org Tue Jun 20 10:21:37 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 20 Jun 2006 14:21:37 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.7,1.8 Message-ID: <200606201421.k5KELbnB001117@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv1058 Modified Files: report.rb Log Message: Added Bio::BLAT::Report::Hit#milli_bad, #percent_identity, #protein?, and #score methods. The algorithm of these methods are described in the BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat5). Thanks to Dr. Itoshi Nikaido for help. Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** report.rb 8 May 2006 14:37:55 -0000 1.7 --- report.rb 20 Jun 2006 14:21:34 -0000 1.8 *************** *** 328,331 **** --- 328,405 ---- exons.each(&x) end + + #-- + # methods described in the BLAT FAQ at the UCSC genome browser. + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5) + #++ + + # Calculates the pslCalcMilliBad value defined in the + # BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def milli_bad + w = (self.protein? ? 3 : 1) + qalen = w * (self.query.end - self.query.start) + talen = self.target.end - self.target.start + alen = (if qalen < talen then qalen; else talen; end) + return 0 if alen <= 0 + d = qalen - talen + d = 0 if d < 0 + total = w * (self.match + self.rep_match + self.mismatch) + return 0 if total == 0 + return (1000 * (self.mismatch * w + self.query.gap_count + + (3 * Math.log(1 + d)).round) / total) + end + + # Calculates the percent identity compatible with the BLAT web server + # as described in the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def percent_identity + 100.0 - self.milli_bad * 0.1 + end + + # When the output data comes from the protein query, returns true. + # Otherwise (nucleotide query), returns false. + # It returns nil if this cannot be determined. + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def protein? + return nil if self.block_sizes.empty? + case self.strand + when '+' + if self.target.end == self.target.starts[-1] + + 3 * self.block_sizes[-1] then + true + else + false + end + when '-' + if self.target.start == self.target.size - + self.target.starts[-1] + 3 * self.block_sizes[-1] then + true + else + false + end + else + nil + end + end + + # Calculates the score compatible with the BLAT web server + # as described in the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def score + w = (self.protein? ? 3 : 1) + w * (self.match + (self.rep_match >> 1)) - + w * self.mismatch - self.query.gap_count - self.target.gap_count + end end #class Hit From ngoto at dev.open-bio.org Tue Jun 20 10:34:40 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 20 Jun 2006 14:34:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.8,1.9 Message-ID: <200606201434.k5KEYeDQ001282@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv1262 Modified Files: report.rb Log Message: Changed some documents. Reference: http://genome.ucsc.edu/goldenPath/help/blatSpec.html Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** report.rb 20 Jun 2006 14:21:34 -0000 1.8 --- report.rb 20 Jun 2006 14:34:38 -0000 1.9 *************** *** 21,25 **** # Genome Research, 12, 656--664, 2002. # http://www.genome.org/cgi/content/abstract/12/4/656 ! # require 'bio' --- 21,25 ---- # Genome Research, 12, 656--664, 2002. # http://www.genome.org/cgi/content/abstract/12/4/656 ! # * http://genome.ucsc.edu/goldenPath/help/blatSpec.html require 'bio' *************** *** 262,268 **** # Mismatch nucleotides. def mismatch; @data[1].to_i; end ! # rep. match (???) def rep_match; @data[2].to_i; end ! # N's (???) def n_s; @data[3].to_i; end --- 262,272 ---- # Mismatch nucleotides. def mismatch; @data[1].to_i; end ! ! # "rep. match". ! # Number of bases that match but are part of repeats. ! # Note that current version of BLAT always set 0. def rep_match; @data[2].to_i; end ! ! # "N's". Number of 'N' bases. def n_s; @data[3].to_i; end From ngoto at dev.open-bio.org Thu Jun 22 10:32:49 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 22 Jun 2006 14:32:49 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/io flatfile.rb,1.50,1.51 Message-ID: <200606221432.k5MEWnV4007918@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/io In directory dev.open-bio.org:/tmp/cvs-serv7898/lib/bio/io Modified Files: flatfile.rb Log Message: Fixed: failed to autodetect psLayout version 4 (Bio::BLAT::Report) Index: flatfile.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/io/flatfile.rb,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** flatfile.rb 12 Jun 2006 10:35:42 -0000 1.50 --- flatfile.rb 22 Jun 2006 14:32:47 -0000 1.51 *************** *** 1196,1200 **** blat = RuleRegexp[ 'Bio::Blat::Report', ! /^psLayout version \d+\s*$/ ], spidey = RuleRegexp[ 'Bio::Spidey::Report', /^\-\-SPIDEY version .+\-\-$/ ], --- 1196,1200 ---- blat = RuleRegexp[ 'Bio::Blat::Report', ! /^psLayout version \d+/ ], spidey = RuleRegexp[ 'Bio::Spidey::Report', /^\-\-SPIDEY version .+\-\-$/ ], From ngoto at dev.open-bio.org Tue Jun 27 01:44:59 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 05:44:59 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/sequence na.rb,1.3,1.4 Message-ID: <200606270544.k5R5ixTu007673@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/sequence In directory dev.open-bio.org:/tmp/cvs-serv7649/lib/bio/sequence Modified Files: na.rb Log Message: Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew are newly added. Bio::Sequence::NA#gc_percent are changed not to raise ZeroDivisionError and returns 0 when given sequence is empty. Index: na.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/sequence/na.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** na.rb 26 Mar 2006 02:27:59 -0000 1.3 --- na.rb 27 Jun 2006 05:44:57 -0000 1.4 *************** *** 282,286 **** # Calculate the ratio of GC / ATGC bases as a percentage rounded to ! # the nearest whole number. # # s = Bio::Sequence::NA.new('atggcgtga') --- 282,286 ---- # Calculate the ratio of GC / ATGC bases as a percentage rounded to ! # the nearest whole number. U is regarded as T. # # s = Bio::Sequence::NA.new('atggcgtga') *************** *** 292,299 **** --- 292,356 ---- at = count['a'] + count['t'] + count['u'] gc = count['g'] + count['c'] + return 0 if at + gc == 0 gc = 100 * gc / (at + gc) return gc end + # Calculate the ratio of GC / ATGC bases. U is regarded as T. + # + # s = Bio::Sequence::NA.new('atggcgtga') + # puts s.gc_content #=> 0.555555555555556 + # --- + # *Returns*:: Float + def gc_content + count = self.composition + at = count['a'] + count['t'] + count['u'] + gc = count['g'] + count['c'] + return 0.0 if at + gc == 0 + return (gc.to_f / (at + gc).to_f) + end + + # Calculate the ratio of AT / ATGC bases. U is regarded as T. + # + # s = Bio::Sequence::NA.new('atggcgtga') + # puts s.at_content #=> 0.444444444444444 + # --- + # *Returns*:: Float + def at_content + count = self.composition + at = count['a'] + count['t'] + count['u'] + gc = count['g'] + count['c'] + return 0.0 if at + gc == 0 + return (at.to_f / (at + gc).to_f) + end + + # Calculate the ratio of (G - C) / (G + C) bases. + # + # s = Bio::Sequence::NA.new('atggcgtga') + # puts s.gc_skew #=> 0.6 + # --- + # *Returns*:: Float + def gc_skew + count = self.composition + g = count['g'] + c = count['c'] + return 0.0 if g + c == 0 + return ((g - c).to_f / (g + c).to_f) + end + + # Calculate the ratio of (A - T) / (A + T) bases. U is regarded as T. + # + # s = Bio::Sequence::NA.new('atgttgttgttc') + # puts s.at_skew #=> -0.75 + # --- + # *Returns*:: Float + def at_skew + count = self.composition + a = count['a'] + t = count['t'] + count['u'] + return 0.0 if a + t == 0 + return ((a - t).to_f / (a + t).to_f) + end + # Returns an alphabetically sorted array of any non-standard bases # (other than 'atgcu'). From ngoto at dev.open-bio.org Tue Jun 27 01:44:59 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 05:44:59 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/sequence test_na.rb,1.1,1.2 Message-ID: <200606270544.k5R5ixYo007678@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/sequence In directory dev.open-bio.org:/tmp/cvs-serv7649/test/unit/bio/sequence Modified Files: test_na.rb Log Message: Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew are newly added. Bio::Sequence::NA#gc_percent are changed not to raise ZeroDivisionError and returns 0 when given sequence is empty. Index: test_na.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/sequence/test_na.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_na.rb 8 Feb 2006 07:08:22 -0000 1.1 --- test_na.rb 27 Jun 2006 05:44:57 -0000 1.2 *************** *** 99,102 **** --- 99,128 ---- end + def test_gc_content + assert_in_delta(0.4, @obj.gc_content, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(0.45, @obj.gc_content, Float::EPSILON) + end + + def test_at_content + assert_in_delta(0.6, @obj.at_content, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(0.55, @obj.at_content, Float::EPSILON) + end + + def test_gc_skew + assert_in_delta(0.0, @obj.gc_skew, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(1.0/9.0, @obj.gc_skew, Float::EPSILON) + @obj.gsub!(/a/, 'c') + assert_in_delta(-3.0/8.0, @obj.gc_skew, Float::EPSILON) + end + + def test_at_skew + assert_in_delta(1.0/3.0, @obj.at_skew, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(3.0/11.0, @obj.at_skew, Float::EPSILON) + end + def test_iliegal_bases @obj[0, 1] = 'n' From ngoto at dev.open-bio.org Tue Jun 27 01:44:59 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 05:44:59 +0000 Subject: [BioRuby-cvs] bioruby ChangeLog,1.52,1.53 Message-ID: <200606270544.k5R5ixDT007683@dev.open-bio.org> Update of /home/repository/bioruby/bioruby In directory dev.open-bio.org:/tmp/cvs-serv7649 Modified Files: ChangeLog Log Message: Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew are newly added. Bio::Sequence::NA#gc_percent are changed not to raise ZeroDivisionError and returns 0 when given sequence is empty. Index: ChangeLog =================================================================== RCS file: /home/repository/bioruby/bioruby/ChangeLog,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** ChangeLog 3 May 2006 00:07:58 -0000 1.52 --- ChangeLog 27 Jun 2006 05:44:57 -0000 1.53 *************** *** 1,2 **** --- 1,11 ---- + 2006-06-27 Naohisa Goto + + * lib/bio/sequence/na.rb + + Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew + are newly added. Bio::Sequence::NA#gc_percent are changed + not to raise ZeroDivisionError and returns 0 when given sequence + is empty. + 2006-05-02 Mitsuteru Nakao From aerts at dev.open-bio.org Tue Jun 27 08:37:44 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Tue, 27 Jun 2006 12:37:44 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio test_map.rb,1.2,1.3 Message-ID: <200606271237.k5RCbimc008730@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio In directory dev.open-bio.org:/tmp/cvs-serv8703/test/unit/bio Modified Files: test_map.rb Log Message: Removed Enumerable mixin from ActsLikeMap and ActsLikeMarker, because 'def each' would be ambiguous. Included examples for using ActsLikeMap and ActsLikeMarker. Index: test_map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_map.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_map.rb 7 Jun 2006 12:56:29 -0000 1.2 --- test_map.rb 27 Jun 2006 12:37:42 -0000 1.3 *************** *** 6,10 **** # License:: Ruby's # ! # $Id$ require 'pathname' --- 6,10 ---- # License:: Ruby's # ! # $Id: require 'pathname' *************** *** 182,184 **** --- 182,197 ---- end end + + class Clone + include Bio::Map::ActsLikeMap + include Bio::Map::ActsLikeMarker + + def initialize(name) + @name = name + @mappings_as_map = Array.new + @mappings_as_marker = Array.new + end + attr_accessor :name, :mappings_as_map, :mappings_as_marker + end + end From aerts at dev.open-bio.org Tue Jun 27 08:37:44 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Tue, 27 Jun 2006 12:37:44 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio map.rb,1.6,1.7 Message-ID: <200606271237.k5RCbiae008725@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv8703/lib/bio Modified Files: map.rb Log Message: Removed Enumerable mixin from ActsLikeMap and ActsLikeMarker, because 'def each' would be ambiguous. Included examples for using ActsLikeMap and ActsLikeMarker. Index: map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/map.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** map.rb 7 Jun 2006 12:55:50 -0000 1.6 --- map.rb 27 Jun 2006 12:37:42 -0000 1.7 *************** *** 6,10 **** # Licence:: Ruby's # ! # $Id$ require 'bio/location' --- 6,10 ---- # Licence:: Ruby's # ! # $Id: require 'bio/location' *************** *** 65,74 **** # puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s # ! # my_map1.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end ! # puts my_map1.min.marker.name ! # my_map2.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end module Map --- 65,74 ---- # puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s # ! # my_map1.mappings_as_map.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end ! # puts my_map1.mappings_as_map.min.marker.name ! # my_map2.mappings_as_map.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end module Map *************** *** 81,84 **** --- 81,94 ---- # # Classes that include this mixin should provide an array property called mappings_as_map. + # For example: + # class MyMapThing + # include Bio::Map::ActsLikeMap + # + # def initialize (name) + # @name = name + # @mappings_as_maps = Array.new + # end + # attr_accessor :name, :mappings_as_map + # end module ActsLikeMap include Enumerable *************** *** 138,147 **** end - # Go through all Bio::Map::Mapping objects linked to this Bio::Map::SimpleMap. - def each - self.mappings_as_map.each do |mapping| - yield mapping - end - end end #ActsLikeMap --- 148,151 ---- *************** *** 154,157 **** --- 158,171 ---- # # Classes that include this mixin should provide an array property called mappings_as_marker. + # For example: + # class MyMarkerThing + # include Bio::Map::ActsLikeMarker + # + # def initialize (name) + # @name = name + # @mappings_as_marker = Array.new + # end + # attr_accessor :name, :mappings_as_marker + # end module ActsLikeMarker include Enumerable *************** *** 189,199 **** end end - - # Go through all Mapping objects linked to this marker. - def each - self.mappings_as_marker.each do |mapping| - yield mapping - end - end # Check whether this marker is mapped to a given Bio::Map::SimpleMap. --- 203,206 ---- *************** *** 238,241 **** --- 245,249 ---- end + end #ActsLikeMarker *************** *** 253,257 **** # * _marker_: a Bio::Map::Marker object # * _location_: a Bio::Locations object - def initialize (map, marker, location = nil) @map, @marker, @location = map, marker, location --- 261,264 ---- *************** *** 259,280 **** attr_accessor :map, :marker, :location ! # # Compares the location of this mapping to another mapping. ! # # --- ! # # *Arguments*: ! # # * other_mapping: Bio::Map::Mapping object ! # # *Returns*:: ! # # * 1 if self < other location ! # # * -1 if self > other location ! # # * 0 if both location are the same ! # # * nil if the argument is not a Bio::Location object ! # def <=>(other) ! # unless other.kind_of?(Bio::Map::Mapping) ! # raise "[Error] markers are not comparable" ! # end ! # unless @map.equal?(other.map) ! # raise "[Error] maps have to be the same" ! # end ! # return self.location<=>(other.location) # FIXME: no <=>-method in Bio::Locations ! # end end # Mapping --- 266,288 ---- attr_accessor :map, :marker, :location ! # Compares the location of this mapping to another mapping. ! # --- ! # *Arguments*: ! # * other_mapping: Bio::Map::Mapping object ! # *Returns*:: ! # * 1 if self < other location ! # * -1 if self > other location ! # * 0 if both location are the same ! # * nil if the argument is not a Bio::Location object ! def <=>(other) ! unless other.kind_of?(Bio::Map::Mapping) ! raise "[Error] markers are not comparable" ! end ! unless @map.equal?(other.map) ! raise "[Error] maps have to be the same" ! end ! ! return self.location.<=>(other.location) ! end end # Mapping From aerts at dev.open-bio.org Tue Jun 27 08:40:17 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Tue, 27 Jun 2006 12:40:17 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio map.rb,1.7,1.8 Message-ID: <200606271240.k5RCeHJA008800@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv8780/lib/bio Modified Files: map.rb Log Message: Forgot to remove reference to Enumerable. Index: map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/map.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** map.rb 27 Jun 2006 12:37:42 -0000 1.7 --- map.rb 27 Jun 2006 12:40:15 -0000 1.8 *************** *** 6,10 **** # Licence:: Ruby's # ! # $Id: require 'bio/location' --- 6,10 ---- # Licence:: Ruby's # ! # $Id$ require 'bio/location' *************** *** 92,97 **** # end module ActsLikeMap - include Enumerable - # = DESCRIPTION # Adds a Bio::Map::Mappings object to its array of mappings. --- 92,95 ---- *************** *** 169,174 **** # end module ActsLikeMarker - include Enumerable - # = DESCRIPTION # Adds a Bio::Map::Mappings object to its array of mappings. --- 167,170 ---- From ngoto at dev.open-bio.org Tue Jun 27 10:23:47 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 14:23:47 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/pdb pdb.rb,1.15,1.16 Message-ID: <200606271423.k5RENlQb009267@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/pdb In directory dev.open-bio.org:/tmp/cvs-serv9227/lib/bio/db/pdb Modified Files: pdb.rb Log Message: Bio::PDB::ATOM#name, #resName, #iCode, #chaarge are changed to be strippedi when initializing. Bio::PDB::ATOM#segID is changed to be right-stripped when initializing. Bio::PDB::ATOM#element is changed to be left-stripped when initializing. (Because Bio::PDB::HETATM inherits Bio::PDB::ATOM, Bio::PDB::HETATM is also subject to the changes.) Index: pdb.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/pdb.rb,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** pdb.rb 20 Feb 2006 13:00:43 -0000 1.15 --- pdb.rb 27 Jun 2006 14:23:45 -0000 1.16 *************** *** 993,1002 **** return self if @parsed self.serial = @str[6..10].to_i ! self.name = @str[12..15] self.altLoc = @str[16..16] ! self.resName = @str[17..19].rstrip self.chainID = @str[21..21] self.resSeq = @str[22..25].to_i ! self.iCode = @str[26..26] self.x = @str[30..37].to_f self.y = @str[38..45].to_f --- 993,1002 ---- return self if @parsed self.serial = @str[6..10].to_i ! self.name = @str[12..15].strip self.altLoc = @str[16..16] ! self.resName = @str[17..19].strip self.chainID = @str[21..21] self.resSeq = @str[22..25].to_i ! self.iCode = @str[26..26].strip self.x = @str[30..37].to_f self.y = @str[38..45].to_f *************** *** 1004,1010 **** self.occupancy = @str[54..59].to_f self.tempFactor = @str[60..65].to_f ! self.segID = @str[72..75] ! self.element = @str[76..77] ! self.charge = @str[78..79] @parsed = true self --- 1004,1010 ---- self.occupancy = @str[54..59].to_f self.tempFactor = @str[60..65].to_f ! self.segID = @str[72..75].to_s.rstrip ! self.element = @str[76..77].to_s.lstrip ! self.charge = @str[78..79].to_s.strip @parsed = true self *************** *** 1012,1019 **** def to_s sprintf("%-6s%5d %-4s%-1s%3s %-1s%4d%-1s %8.3f%8.3f%8.3f%6.2f%6.2f %-4s%2s%-2s\n", self.record_name, self.serial, ! self.name, self.altLoc, self.resName, --- 1012,1024 ---- def to_s + atomname = self.name.to_s + elem = self.element.to_s.strip + if elem.length == 1 and atomname.lstrip[0, 1] == elem then + atomname = ' ' + atomname + end sprintf("%-6s%5d %-4s%-1s%3s %-1s%4d%-1s %8.3f%8.3f%8.3f%6.2f%6.2f %-4s%2s%-2s\n", self.record_name, self.serial, ! atomname, self.altLoc, self.resName, From ngoto at dev.open-bio.org Tue Jun 27 10:25:42 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 14:25:42 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db/pdb test_pdb.rb,1.1,1.2 Message-ID: <200606271425.k5REPgfp009296@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db/pdb In directory dev.open-bio.org:/tmp/cvs-serv9276/test/unit/bio/db/pdb Modified Files: test_pdb.rb Log Message: * License is changed to Ruby's. * Follow changes to pdb.rb (as is nearly the same behavior as bioruby-0.6.4). Index: test_pdb.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/pdb/test_pdb.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_pdb.rb 26 Jan 2006 16:06:03 -0000 1.1 --- test_pdb.rb 27 Jun 2006 14:25:40 -0000 1.2 *************** *** 5,29 **** # Naohisa Goto # ! # License:: LGPL # # $Id$ # - #-- - # This library is free software; you can redistribute it and/or - # modify it under the terms of the GNU Lesser General Public - # License as published by the Free Software Foundation; either - # version 2 of the License, or (at your option) any later version. - # - # This library is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - # Lesser General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public - # License along with this library; if not, write to the Free Software - # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - #++ - # - # require 'pathname' --- 5,12 ---- # Naohisa Goto # ! # License:: Ruby's # # $Id$ # require 'pathname' *************** *** 58,62 **** def test_name ! assert_equal(' CG2', @atom.name) end --- 41,45 ---- def test_name ! assert_equal('CG2', @atom.name) end *************** *** 78,82 **** def test_iCode ! assert_equal(' ', @atom.iCode) end --- 61,65 ---- def test_iCode ! assert_equal('', @atom.iCode) end *************** *** 102,114 **** def test_segID ! assert_equal('A1 ', @atom.segID) end def test_element ! assert_equal(' C', @atom.element) end def test_charge ! assert_equal(' ', @atom.charge) end --- 85,97 ---- def test_segID ! assert_equal('A1', @atom.segID) end def test_element ! assert_equal('C', @atom.element) end def test_charge ! assert_equal('', @atom.charge) end From ngoto at dev.open-bio.org Tue Jun 27 11:17:09 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 15:17:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.9,1.10 Message-ID: <200606271517.k5RFH9w8009506@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv9484/lib/bio/appl/blat Modified Files: report.rb Log Message: changed documents Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** report.rb 20 Jun 2006 14:34:38 -0000 1.9 --- report.rb 27 Jun 2006 15:17:07 -0000 1.10 *************** *** 34,38 **** # On the other hand, in many other homology search programs, # the start position of a sequence is numbered as 1. ! # To keep compatibility, the BLAT parser adds 1 to every position number. # # Note that Bio::Blat::Report#query_def, #query_id, #query_len methods --- 34,39 ---- # On the other hand, in many other homology search programs, # the start position of a sequence is numbered as 1. ! # To keep compatibility, the BLAT parser adds 1 to every position number ! # except Bio::Blat::Report::Seqdesc and some Bio::Blat specific methods. # # Note that Bio::Blat::Report#query_def, #query_id, #query_len methods *************** *** 335,346 **** #-- # methods described in the BLAT FAQ at the UCSC genome browser. ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5) #++ # Calculates the pslCalcMilliBad value defined in the ! # BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat5). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def milli_bad w = (self.protein? ? 3 : 1) --- 336,347 ---- #-- # methods described in the BLAT FAQ at the UCSC genome browser. ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4) #++ # Calculates the pslCalcMilliBad value defined in the ! # BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat4). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def milli_bad w = (self.protein? ? 3 : 1) *************** *** 359,366 **** # Calculates the percent identity compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def percent_identity 100.0 - self.milli_bad * 0.1 --- 360,367 ---- # Calculates the percent identity compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def percent_identity 100.0 - self.milli_bad * 0.1 *************** *** 372,376 **** # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def protein? return nil if self.block_sizes.empty? --- 373,377 ---- # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def protein? return nil if self.block_sizes.empty? *************** *** 397,404 **** # Calculates the score compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def score w = (self.protein? ? 3 : 1) --- 398,405 ---- # Calculates the score compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def score w = (self.protein? ? 3 : 1) From ngoto at dev.open-bio.org Wed Jun 28 09:43:33 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Wed, 28 Jun 2006 13:43:33 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.10,1.11 Message-ID: <200606281343.k5SDhXq7013712@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv13692/lib/bio/appl/blat Modified Files: report.rb Log Message: * Fixed a bug in Bio::Blat::Report::Hit#protein?. * Fixed: when protein query and nucleotide database, HSPs are incorrect. Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** report.rb 27 Jun 2006 15:17:07 -0000 1.10 --- report.rb 28 Jun 2006 13:43:31 -0000 1.11 *************** *** 140,149 **** # It is designed to be called internally from Bio::Blat::Report class. # Users shall not use it directly. ! def initialize(query_len, strand, ! blksize, qstart, tstart, qseq, tseq) @blocksize = blksize @qseq = qseq @hseq = hseq @hit_strand = 'plus' case strand when '-' --- 140,151 ---- # It is designed to be called internally from Bio::Blat::Report class. # Users shall not use it directly. ! def initialize(query_len, target_len, strand, ! blksize, qstart, tstart, qseq, tseq, ! protein_flag) @blocksize = blksize @qseq = qseq @hseq = hseq @hit_strand = 'plus' + w = (protein_flag ? 3 : 1) # 3 means query=protein target=dna case strand when '-' *************** *** 156,161 **** # we add 1 to each position number. @hit_from = tstart + 1 ! @hit_to = tstart + blksize # - 1 + 1 ! else #when '+' @query_strand = 'plus' # To keep compatibility with other homology search programs, --- 158,174 ---- # we add 1 to each position number. @hit_from = tstart + 1 ! @hit_to = tstart + blksize * w # - 1 + 1 ! when '+-' ! # hit is minus strand ! @query_strand = 'plus' ! @hit_strand = 'minus' ! # To keep compatibility, with other homology search programs, ! # we add 1 to each position number. ! @query_from = qstart + 1 ! @query_to = qstart + blksize # - 1 + 1 ! # convert positions ! @hit_from = target_len - tstart ! @hit_to = target_len - tstart - blksize * w + 1 ! else #when '+', '++' @query_strand = 'plus' # To keep compatibility with other homology search programs, *************** *** 164,168 **** @query_to = qstart + blksize # - 1 + 1 @hit_from = tstart + 1 ! @hit_to = tstart + blksize # - 1 + 1 end end --- 177,181 ---- @query_to = qstart + blksize # - 1 + 1 @hit_from = tstart + 1 ! @hit_to = tstart + blksize * w # - 1 + 1 end end *************** *** 298,304 **** qseqs = query.seqs tseqs = target.seqs @blocks = (0...block_count).collect do |i| ! SegmentPair.new(query.size, strand, bs[i], ! qst[i], tst[i], qseqs[i], tseqs[i]) end end --- 311,319 ---- qseqs = query.seqs tseqs = target.seqs + pflag = self.protein? @blocks = (0...block_count).collect do |i| ! SegmentPair.new(query.size, target.size, strand, bs[i], ! qst[i], tst[i], qseqs[i], tseqs[i], ! pflag) end end *************** *** 374,380 **** # The algorithm is taken from the BLAT FAQ # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def protein? return nil if self.block_sizes.empty? ! case self.strand when '+' if self.target.end == self.target.starts[-1] + --- 389,398 ---- # The algorithm is taken from the BLAT FAQ # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). + # + # Note: It seems that it returns true only when protein query + # with nucleotide database (blat options: -q=prot -t=dnax). def protein? return nil if self.block_sizes.empty? ! case self.strand[1,1] when '+' if self.target.end == self.target.starts[-1] + *************** *** 386,390 **** when '-' if self.target.start == self.target.size - ! self.target.starts[-1] + 3 * self.block_sizes[-1] then true else --- 404,408 ---- when '-' if self.target.start == self.target.size - ! self.target.starts[-1] - 3 * self.block_sizes[-1] then true else From ngoto at dev.open-bio.org Thu Jun 29 07:54:35 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 29 Jun 2006 11:54:35 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.11,1.12 Message-ID: <200606291154.k5TBsZud023085@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv23065/lib/bio/appl/blat Modified Files: report.rb Log Message: * psl without header is supported. * New attribute ``psl_version'' is added. Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** report.rb 28 Jun 2006 13:43:31 -0000 1.11 --- report.rb 29 Jun 2006 11:54:33 -0000 1.12 *************** *** 59,62 **** --- 59,67 ---- @hits << Hit.new(line) else + # for headerless data + if /^\d/ =~ line then + flag = true + redo + end line = line.chomp if /\A\-+\s*\z/ =~ line *************** *** 81,85 **** # Parses headers. def parse_header(ary) ! ary.shift # first line is removed a0 = ary.collect { |x| x.split(/\t/) } k = [] --- 86,98 ---- # Parses headers. def parse_header(ary) ! while x = ary.shift ! if /psLayout version (\S+)/ =~ x then ! @psl_version = $1 ! break ! elsif !(x.strip.empty?) ! ary.unshift(x) ! break ! end ! end a0 = ary.collect { |x| x.split(/\t/) } k = [] *************** *** 95,98 **** --- 108,114 ---- private :parse_header + # version of the psl format (String or nil). + attr_reader :psl_version + # Bio::Blat::Report::SeqDesc stores sequence information of # query or subject of the BLAT report. From nakao at dev.open-bio.org Mon Jun 5 02:52:01 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Mon, 05 Jun 2006 02:52:01 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/io test_soapwsdl.rb,1.1,1.2 Message-ID: <200606050252.k552q1l2022218@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/io In directory dev.open-bio.org:/tmp/cvs-serv22198/test/unit/bio/io Modified Files: test_soapwsdl.rb Log Message: * updated test_methods for recently added list_methods method in lib/bio/io/soapwsdl.rb. Index: test_soapwsdl.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/io/test_soapwsdl.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_soapwsdl.rb 18 Dec 2005 17:09:53 -0000 1.1 --- test_soapwsdl.rb 5 Jun 2006 02:51:59 -0000 1.2 *************** *** 2,20 **** # test/unit/bio/io/test_soapwsdl.rb - Unit test for SOAP/WSDL # ! # Copyright (C) 2005 Mitsuteru Nakao ! # ! # This library is free software; you can redistribute it and/or ! # modify it under the terms of the GNU Lesser General Public ! # License as published by the Free Software Foundation; either ! # version 2 of the License, or (at your option) any later version. ! # ! # This library is distributed in the hope that it will be useful, ! # but WITHOUT ANY WARRANTY; without even the implied warranty of ! # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! # Lesser General Public License for more details. ! # ! # You should have received a copy of the GNU Lesser General Public ! # License along with this library; if not, write to the Free Software ! # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id$ --- 2,7 ---- # test/unit/bio/io/test_soapwsdl.rb - Unit test for SOAP/WSDL # ! # Copytight:: Copyright (C) 2005 Mitsuteru Nakao ! # License:: Ruby's # # $Id$ *************** *** 38,42 **** def test_methods ! methods = ['wsdl', 'wsdl=', 'log', 'log='] assert_equal(methods.sort, (@obj.instance_methods - Object.methods).sort) end --- 25,29 ---- def test_methods ! methods = ['list_methods','wsdl', 'wsdl=', 'log', 'log='] assert_equal(methods.sort, (@obj.instance_methods - Object.methods).sort) end From nakao at dev.open-bio.org Mon Jun 5 02:54:44 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Mon, 05 Jun 2006 02:54:44 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/appl test_pts1.rb,1.1,1.2 Message-ID: <200606050254.k552sikS022267@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/appl In directory dev.open-bio.org:/tmp/cvs-serv22247/test/unit/bio/appl Modified Files: test_pts1.rb Log Message: * added test_entry_id in TestPTS1Report class. Index: test_pts1.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/appl/test_pts1.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_pts1.rb 2 May 2006 10:29:19 -0000 1.1 --- test_pts1.rb 5 Jun 2006 02:54:42 -0000 1.2 *************** *** 106,109 **** --- 106,113 ---- end + def test_entry_id + assert_equal("hoge", @report.entry_id) + end + def test_prediction assert_equal("Targeted", @report.prediction) From nakao at dev.open-bio.org Mon Jun 5 02:55:53 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Mon, 05 Jun 2006 02:55:53 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl pts1.rb,1.2,1.3 Message-ID: <200606050255.k552trVs022316@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl In directory dev.open-bio.org:/tmp/cvs-serv22296/lib/bio/appl Modified Files: pts1.rb Log Message: * added Bio::PTS1::Report#entry_id. Index: pts1.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/pts1.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pts1.rb 9 May 2006 08:18:49 -0000 1.2 --- pts1.rb 5 Jun 2006 02:55:51 -0000 1.3 *************** *** 175,178 **** --- 175,181 ---- class Report + # Query sequence name. + attr_reader :entry_id + # Amino acids subsequence at C-terminal region. attr_reader :cterm *************** *** 229,232 **** --- 232,237 ---- @output.each do |line| case line + when /Name<\/td>(\S.+)<\/td><\/tr>/ + @entry_id = $1 when /C-terminus<\/td>(\w+)<\/td>/ @cterm = $1 From aerts at dev.open-bio.org Wed Jun 7 12:55:52 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Wed, 07 Jun 2006 12:55:52 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio map.rb,1.5,1.6 Message-ID: <200606071255.k57CtqFA003705@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv3575 Modified Files: map.rb Log Message: * Added Bio::Locations#equal? method. (Should be moved to location.rb, if approved.) * Methods add_mapping_to_marker and add_mapping_to_map renamed to add_mapping_as_map and add_mapping_as_marker, respectively, to lessen the confusion of what is mapped to what. * When adding a new mapping to a map or marker, a check is done first to see if that mapping has been added before or not. * New method: Bio::Map::ActsLikeMarker#positions_on(map) Index: map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/map.rb,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** map.rb 4 May 2006 18:41:08 -0000 1.5 --- map.rb 7 Jun 2006 12:55:50 -0000 1.6 *************** *** 6,12 **** --- 6,28 ---- # Licence:: Ruby's # + # $Id$ require 'bio/location' module Bio + + # Add a method to Bio::Locations class + class Locations + def equals?(other) + if ! other.kind_of?(Bio::Locations) + return nil + end + if self.sort == other.sort + return true + else + return false + end + end + end + # = DESCRIPTION # The Bio::Module contains classes that describe mapping information and can *************** *** 42,48 **** # my_map2 = Bio::Map::SimpleMap.new('consensus', 'linkage', 'cM') # ! # my_map1.add_mapping_to_marker(my_marker1, '17') ! # my_map1.add_mapping_to_marker(Bio::Map::Marker.new('marker2'), '5') ! # my_marker3.add_mapping_to_marker(my_map1, '9') # # puts "Does my_map1 contain marker3? => " + my_map1.contains_marker?(my_marker3).to_s --- 58,64 ---- # my_map2 = Bio::Map::SimpleMap.new('consensus', 'linkage', 'cM') # ! # my_map1.add_mapping_as_map(my_marker1, '17') ! # my_map1.add_mapping_as_map(Bio::Map::Marker.new('marker2'), '5') ! # my_marker3.add_mapping_as_marker(my_map1, '9') # # puts "Does my_map1 contain marker3? => " + my_map1.contains_marker?(my_marker3).to_s *************** *** 50,63 **** # # my_map1.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end # puts my_map1.min.marker.name # my_map2.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end - # - # = TODO - # Check if initialization of @mappings can be done in ActsLikeMap and - # ActsLikeMarker, instead of in the classes that include these modules. module Map # = DESCRIPTION --- 66,75 ---- # # my_map1.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end # puts my_map1.min.marker.name # my_map2.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end module Map # = DESCRIPTION *************** *** 67,72 **** --- 79,87 ---- # * check if a given marker is mapped to it # , and can be mixed into other classes (e.g. Bio::Map::SimpleMap) + # + # Classes that include this mixin should provide an array property called mappings_as_map. module ActsLikeMap include Enumerable + # = DESCRIPTION # Adds a Bio::Map::Mappings object to its array of mappings. *************** *** 74,78 **** # = USAGE # # suppose we have a Bio::Map::SimpleMap object called my_map ! # my_map.add_mapping_to_marker(Bio::Map::Marker.new('marker_a'), '5') # --- # *Arguments*: --- 89,93 ---- # = USAGE # # suppose we have a Bio::Map::SimpleMap object called my_map ! # my_map.add_mapping_as_map(Bio::Map::Marker.new('marker_a'), '5') # --- # *Arguments*: *************** *** 80,91 **** # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_to_marker(marker, location = nil) unless marker.class.include?(Bio::Map::ActsLikeMarker) raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker" end ! my_mapping = Bio::Map::Mapping.new(self, marker, Bio::Location.new(location)) ! @mappings.push(my_mapping) ! unless marker.mapped_to?(self) ! marker.mappings.push(my_mapping) end --- 95,117 ---- # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_as_map(marker, location = nil) unless marker.class.include?(Bio::Map::ActsLikeMarker) raise "[Error] marker is not object that implements Bio::Map::ActsLikeMarker" end ! my_mapping = ( location.nil? ) ? Bio::Map::Mapping.new(self, marker, nil) : Bio::Map::Mapping.new(self, marker, Bio::Locations.new(location)) ! if ! marker.mapped_to?(self) ! self.mappings_as_map.push(my_mapping) ! marker.mappings_as_marker.push(my_mapping) ! else ! already_mapped = false ! marker.positions_on(self).each do |loc| ! if loc.equals?(Bio::Locations.new(location)) ! already_mapped = true ! end ! end ! if ! already_mapped ! self.mappings_as_map.push(my_mapping) ! marker.mappings_as_marker.push(my_mapping) ! end end *************** *** 103,107 **** end contains = false ! @mappings.each do |mapping| if mapping.marker == marker contains = true --- 129,133 ---- end contains = false ! self.mappings_as_map.each do |mapping| if mapping.marker == marker contains = true *************** *** 114,118 **** # Go through all Bio::Map::Mapping objects linked to this Bio::Map::SimpleMap. def each ! @mappings.each do |mapping| yield mapping end --- 140,144 ---- # Go through all Bio::Map::Mapping objects linked to this Bio::Map::SimpleMap. def each ! self.mappings_as_map.each do |mapping| yield mapping end *************** *** 126,129 **** --- 152,157 ---- # * check if it's mapped to a given map # , and can be mixed into other classes (e.g. Bio::Map::Marker) + # + # Classes that include this mixin should provide an array property called mappings_as_marker. module ActsLikeMarker include Enumerable *************** *** 134,138 **** # = USAGE # # suppose we have a Bio::Map::Marker object called marker_a ! # marker_a.add_mapping_to_map(Bio::Map::SimpleMap.new('my_map'), '5') # --- # *Arguments*: --- 162,166 ---- # = USAGE # # suppose we have a Bio::Map::Marker object called marker_a ! # marker_a.add_mapping_as_marker(Bio::Map::SimpleMap.new('my_map'), '5') # --- # *Arguments*: *************** *** 140,151 **** # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_to_map(map, location = nil) unless map.class.include?(Bio::Map::ActsLikeMap) raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! my_mapping = Bio::Map::Mapping.new(map, self, Bio::Location.new(location)) ! @mappings.push(my_mapping) ! unless map.contains_marker?(self) ! map.mappings.push(my_mapping) end end --- 168,197 ---- # * _location_: location of mapping. Should be a _string_, not a _number_. # *Returns*:: itself ! def add_mapping_as_marker(map, location = nil) unless map.class.include?(Bio::Map::ActsLikeMap) raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! my_mapping = (location.nil?) ? Bio::Map::Mappings.new(map, self, nil) : Bio::Map::Mapping.new(map, self, Bio::Locations.new(location)) ! if ! self.mapped_to?(map) ! self.mappings_as_marker.push(my_mapping) ! map.mappings_as_map.push(my_mapping) ! else ! already_mapped = false ! self.positions_on(map).each do |loc| ! if loc.equals?(Bio::Locations.new(location)) ! already_mapped = true ! end ! end ! if ! already_mapped ! self.mappings_as_marker.push(my_mapping) ! map.mappings_as_map.push(my_mapping) ! end ! end ! end ! ! # Go through all Mapping objects linked to this marker. ! def each ! self.mappings_as_marker.each do |mapping| ! yield mapping end end *************** *** 160,166 **** raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! mapped = false ! @mappings.each do |mapping| if mapping.map == map mapped = true --- 206,212 ---- raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" end ! mapped = false ! self.mappings_as_marker.each do |mapping| if mapping.map == map mapped = true *************** *** 168,180 **** end end return mapped end ! ! # Go through all Mapping objects linked to this marker. ! def each ! @mappings.each do |mapping| ! yield mapping end end end #ActsLikeMarker --- 214,241 ---- end end + return mapped end ! ! # Return all positions of this marker on a given map. ! # --- ! # *Arguments*: ! # * _map_: an object that mixes in Bio::Map::ActsLikeMap ! # *Returns*:: array of Bio::Location objects ! def positions_on(map) ! unless map.class.include?(Bio::Map::ActsLikeMap) ! raise "[Error] map is not object that implements Bio::Map::ActsLikeMap" ! end ! ! positions = Array.new ! self.mappings_as_marker.each do |mapping| ! if mapping.map == map ! positions.push(mapping.location) ! end end + + return positions end + end #ActsLikeMarker *************** *** 191,195 **** # * _map_: a Bio::Map::SimpleMap object # * _marker_: a Bio::Map::Marker object ! # * _location_: a Bio::Location object def initialize (map, marker, location = nil) @map, @marker, @location = map, marker, location --- 252,257 ---- # * _map_: a Bio::Map::SimpleMap object # * _marker_: a Bio::Map::Marker object ! # * _location_: a Bio::Locations object ! def initialize (map, marker, location = nil) @map, @marker, @location = map, marker, location *************** *** 197,219 **** attr_accessor :map, :marker, :location ! # Compares the location of this mapping to another mapping. ! # --- ! # *Arguments*: ! # * other_mapping: Bio::Map::Mapping object ! # *Returns*:: ! # * 1 if self < other location ! # * -1 if self > other location ! # * 0 if both location are the same ! # * nil if the argument is not a Bio::Location object ! def <=>(other) ! unless other.kind_of?(Bio::Map::Mapping) ! raise "[Error] markers are not comparable" ! end ! unless @map.equal?(other.map) ! raise "[Error] maps have to be the same" ! end ! ! return self.location.<=>(other.location) ! end end # Mapping --- 259,280 ---- attr_accessor :map, :marker, :location ! # # Compares the location of this mapping to another mapping. ! # # --- ! # # *Arguments*: ! # # * other_mapping: Bio::Map::Mapping object ! # # *Returns*:: ! # # * 1 if self < other location ! # # * -1 if self > other location ! # # * 0 if both location are the same ! # # * nil if the argument is not a Bio::Location object ! # def <=>(other) ! # unless other.kind_of?(Bio::Map::Mapping) ! # raise "[Error] markers are not comparable" ! # end ! # unless @map.equal?(other.map) ! # raise "[Error] maps have to be the same" ! # end ! # return self.location<=>(other.location) # FIXME: no <=>-method in Bio::Locations ! # end end # Mapping *************** *** 228,232 **** # my_map1.add_marker(Bio::Map::Marker.new('marker_b', '5') class SimpleMap ! include ActsLikeMap # Builds a new Bio::Map::SimpleMap object --- 289,293 ---- # my_map1.add_marker(Bio::Map::Marker.new('marker_b', '5') class SimpleMap ! include Bio::Map::ActsLikeMap # Builds a new Bio::Map::SimpleMap object *************** *** 237,243 **** # * units: unit of the map (e.g. cM, cR, ...) # *Returns*:: new Bio::Map::SimpleMap object ! def initialize (name = nil, type = nil, units = nil) ! @name, @type, @units = name, type, units ! @mappings = Array.new end --- 298,304 ---- # * units: unit of the map (e.g. cM, cR, ...) # *Returns*:: new Bio::Map::SimpleMap object ! def initialize (name = nil, type = nil, length = nil, units = nil) ! @name, @type, @length, @units = name, type, length, units ! @mappings_as_map = Array.new end *************** *** 247,256 **** # Type of the map attr_accessor :type ! # Units of the map attr_accessor :units ! # Array of mappings for the map ! attr_accessor :mappings end # SimpleMap --- 308,321 ---- # Type of the map attr_accessor :type ! ! # Length of the map ! attr_accessor :length ! # Units of the map attr_accessor :units ! # Mappings ! attr_accessor :mappings_as_map ! end # SimpleMap *************** *** 264,268 **** # marker_b = Bio::Map::Marker.new('marker_b') class Marker ! include ActsLikeMarker # Builds a new Bio::Map::Marker object --- 329,333 ---- # marker_b = Bio::Map::Marker.new('marker_b') class Marker ! include Bio::Map::ActsLikeMarker # Builds a new Bio::Map::Marker object *************** *** 273,315 **** def initialize(name) @name = name ! @mappings = Array.new end # Name of the marker attr_accessor :name ! ! # Array of mappings for the marker ! attr_accessor :mappings end # Marker end # Map end # Bio - - if __FILE__ == $0 - my_marker1 = Bio::Map::Marker.new('marker1') - # my_marker2 = Bio::Map::Marker.new('marker2') - my_marker3 = Bio::Map::Marker.new('marker3') - - my_map1 = Bio::Map::SimpleMap.new('RH_map_ABC (2006)', 'RH', 'cR') - my_map2 = Bio::Map::SimpleMap.new('consensus', 'linkage', 'cM') - - my_map1.add_mapping_to_marker(my_marker1, '17') - my_map1.add_mapping_to_marker(Bio::Map::Marker.new('marker2'), '5') - my_marker3.add_mapping_to_map(my_map1, '9') - - my_map2.add_mapping_to_marker(my_marker1, '57') - - puts "Does my_map1 contain marker3? => " + my_map1.contains_marker?(my_marker3).to_s - puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s - - my_map1.sort.each do |mapping| - puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s - end - puts my_map1.min.marker.name - - my_map2.each do |mapping| - puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s - end - - # p my_map1.between?(my_mappable2,my_mappable3) - # p my_map1.between?(my_mappable,my_mappable2) - end --- 338,351 ---- def initialize(name) @name = name ! @mappings_as_marker = Array.new end # Name of the marker attr_accessor :name ! ! # Mappings ! attr_accessor :mappings_as_marker ! end # Marker end # Map end # Bio From aerts at dev.open-bio.org Wed Jun 7 12:56:31 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Wed, 07 Jun 2006 12:56:31 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio test_map.rb,1.1,1.2 Message-ID: <200606071256.k57CuVZC003751@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio In directory dev.open-bio.org:/tmp/cvs-serv3723 Modified Files: test_map.rb Log Message: Following changes in map.rb Index: test_map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_map.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_map.rb 4 May 2006 16:19:52 -0000 1.1 --- test_map.rb 7 Jun 2006 12:56:29 -0000 1.2 *************** *** 5,8 **** --- 5,10 ---- # Jan Aerts # License:: Ruby's + # + # $Id$ require 'pathname' *************** *** 14,102 **** module Bio ! class TestMapSimple < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 'some_unit') ! end ! def test_attributes ! assert_equal("marker1", @marker1.name) ! assert_equal("marker2", @marker2.name) ! assert_equal([], @marker1.mappings) ! assert_equal([], @marker2.mappings) ! assert_equal("map1", @map1.name) ! assert_equal("some_unit", @map1.units) ! assert_equal("some_type", @map1.type) ! assert_equal([], @map1.mappings) ! end ! end ! class TestMapping < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 'some_unit') ! end ! def test_add_mapping_to_marker ! @map1.add_mapping_to_marker(@marker2, '5') ! assert_equal(1, @map1.mappings.length) ! assert_equal(1, @marker2.mappings.length) ! assert_equal(0, @marker1.mappings.length) ! assert_kind_of(Bio::Location, @map1.mappings[0].location) ! assert_kind_of(Bio::Location, @marker2.mappings[0].location) ! end ! def test_add_mapping_to_map ! @marker1.add_mapping_to_map(@map1, '5') ! assert_equal(1, @map1.mappings.length) ! assert_equal(1, @marker1.mappings.length) ! assert_kind_of(Bio::Location, @map1.mappings[0].location) ! assert_kind_of(Bio::Location, @marker1.mappings[0].location) end ! end ! class CloneActsLikeMap ! include Bio::Map::ActsLikeMap ! end ! class TestActsLikeMap < Test::Unit::TestCase ! def test_mixin ! clone = CloneActsLikeMap.new ! assert_instance_of(CloneActsLikeMap, clone) ! assert_respond_to(clone, 'contains_marker?') ! assert_respond_to(clone, 'add_mapping_to_marker') ! end ! end ! ! class CloneActsLikeMarker ! include Bio::Map::ActsLikeMarker ! end ! class TestActsLikeMarker < Test::Unit::TestCase ! def test_mixin ! clone = CloneActsLikeMarker.new ! assert_instance_of(CloneActsLikeMarker, clone) ! assert_respond_to(clone, 'mapped_to?') ! assert_respond_to(clone, 'add_mapping_to_map') ! end ! end ! class CloneActsLikeMapAndMarker ! include Bio::Map::ActsLikeMap ! include Bio::Map::ActsLikeMarker ! end ! class TestActsLikeMapAndMarker < Test::Unit::TestCase ! def test_mixin ! clone = CloneActsLikeMapAndMarker.new ! assert_instance_of(CloneActsLikeMapAndMarker, clone) ! assert_respond_to(clone, 'contains_marker?') ! assert_respond_to(clone, 'add_mapping_to_marker') ! assert_respond_to(clone, 'mapped_to?') ! assert_respond_to(clone, 'add_mapping_to_map') ! end ! end end --- 16,184 ---- module Bio ! class TestMapSimple < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 500, 'some_unit') ! end ! def test_attributes ! assert_equal("marker1", @marker1.name) ! assert_equal("marker2", @marker2.name) ! assert_equal([], @marker1.mappings_as_marker) ! assert_equal([], @marker2.mappings_as_marker) ! assert_equal("map1", @map1.name) ! assert_equal("some_unit", @map1.units) ! assert_equal("some_type", @map1.type) ! assert_equal([], @map1.mappings_as_map) ! end ! end ! class TestMapping < Test::Unit::TestCase ! def setup ! @marker1 = Bio::Map::Marker.new('marker1') ! @marker2 = Bio::Map::Marker.new('marker2') ! @marker3 = Bio::Map::Marker.new('marker3') ! @map1 = Bio::Map::SimpleMap.new('map1', 'some_type', 'some_unit') ! end ! def test_add_mapping_as_map ! @map1.add_mapping_as_map(@marker2, '5') ! assert_equal(1, @map1.mappings_as_map.length) ! assert_equal(1, @marker2.mappings_as_marker.length) ! assert_equal(0, @marker1.mappings_as_marker.length) ! assert_kind_of(Bio::Locations, @map1.mappings_as_map[0].location) ! assert_kind_of(Bio::Locations, @marker2.mappings_as_marker[0].location) ! end ! def test_add_mapping_as_marker ! @marker1.add_mapping_as_marker(@map1, '5') ! assert_equal(1, @map1.mappings_as_map.length, 'Mapping as map') ! assert_equal(1, @marker1.mappings_as_marker.length, 'Mapping as marker') ! assert_kind_of(Bio::Locations, @map1.mappings_as_map[0].location) ! assert_kind_of(Bio::Locations, @marker1.mappings_as_marker[0].location) end ! ! def test_mapped_to? ! @marker1.add_mapping_as_marker(@map1, '5') ! assert_equal(true, @marker1.mapped_to?(@map1)) ! assert_equal(false, @marker3.mapped_to?(@map1)) ! end ! ! def test_contains_marker? ! @marker1.add_mapping_as_marker(@map1, '5') ! assert_equal(true, @map1.contains_marker?(@marker1)) ! assert_equal(false, @map1.contains_marker?(@marker3)) ! end ! ! def test_mappings_as_map_each ! @map1.add_mapping_as_map(@marker1, '5') ! @marker2.add_mapping_as_marker(@map1, '7') ! mappings = 0 ! @map1.mappings_as_map.each do |mapping| ! mappings += 1 ! end ! assert_equal(2, mappings) ! end ! ! def test_mappings_as_marker_each ! @map1.add_mapping_as_map(@marker1, '5') ! @marker1.add_mapping_as_marker(@map1, '7') ! mappings = 0 ! @marker1.mappings_as_marker.each do |mapping| ! mappings += 1 ! end ! assert_equal(2, mappings) ! ! end ! ! def test_multiple_mappings_between_same_marker_and_map ! @map1.add_mapping_as_map(@marker1, '5') ! @map1.add_mapping_as_map(@marker1, '37') ! @marker1.add_mapping_as_marker(@map1, '53') ! assert_equal(3, @marker1.mappings_as_marker.length) ! ! @marker1.add_mapping_as_marker(@map1, '53') # This mapping should _not_ be added, because it's already defined. ! assert_equal(3, @marker1.mappings_as_marker.length) ! end ! ! def test_positions_on ! @map1.add_mapping_as_map(@marker1, '5') ! assert_equal(1, @marker1.mappings_as_marker.length) ! assert_equal('5', @marker1.positions_on(@map1).collect{|p| p.first.from.to_s}.join(',')) # FIXME: Test is not correct (uses Location.first) ! @map1.add_mapping_as_map(@marker1, '37') ! assert_equal('5,37', @marker1.positions_on(@map1).collect{|p| p.first.from.to_s}.sort{|a,b| a.to_i <=> b.to_i}.join(',')) # FIXME: Test is not correct (uses Location.first) ! end ! end ! class CloneActsLikeMap ! include Bio::Map::ActsLikeMap ! def initialize ! @mappings_as_map = Array.new ! end ! attr_accessor :mappings_as_map ! end ! class TestActsLikeMap < Test::Unit::TestCase ! def setup ! @clone = CloneActsLikeMap.new ! end ! def test_mixin ! assert_instance_of(CloneActsLikeMap, @clone) ! assert_respond_to(@clone, 'contains_marker?') ! assert_respond_to(@clone, 'add_mapping_as_map') ! assert_equal(0, @clone.mappings_as_map.length) ! end ! end ! class CloneActsLikeMarker ! include Bio::Map::ActsLikeMarker ! def initialize ! @mappings_as_marker = Array.new ! end ! attr_accessor :mappings_as_marker ! end ! class TestActsLikeMarker < Test::Unit::TestCase ! def setup ! @clone = CloneActsLikeMarker.new ! end ! ! def test_mixin ! assert_instance_of(CloneActsLikeMarker, @clone) ! assert_respond_to(@clone, 'mapped_to?') ! assert_respond_to(@clone, 'add_mapping_as_marker') ! end ! end ! class CloneActsLikeMapAndMarker ! include Bio::Map::ActsLikeMap ! include Bio::Map::ActsLikeMarker ! def initialize ! @mappings_as_map = Array.new ! @mappings_as_marker = Array.new ! end ! attr_accessor :mappings_as_map, :mappings_as_marker ! end + class TestActsLikeMapAndMarker < Test::Unit::TestCase + def setup + @clone_a = CloneActsLikeMapAndMarker.new + @clone_b = CloneActsLikeMapAndMarker.new + @clone_a.add_mapping_as_map(@clone_b, nil) + end + + def test_mixin + assert_instance_of(CloneActsLikeMapAndMarker, @clone_a) + assert_respond_to(@clone_a, 'contains_marker?') + assert_respond_to(@clone_a, 'add_mapping_as_map') + assert_respond_to(@clone_a, 'mapped_to?') + assert_respond_to(@clone_a, 'add_mapping_as_marker') + + assert_equal(1, @clone_a.mappings_as_map.length) + assert_equal(0, @clone_a.mappings_as_marker.length) + assert_equal(0, @clone_b.mappings_as_map.length) + assert_equal(1, @clone_b.mappings_as_marker.length) + end + end end From ngoto at dev.open-bio.org Mon Jun 12 10:35:44 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Mon, 12 Jun 2006 10:35:44 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/io flatfile.rb,1.49,1.50 Message-ID: <200606121035.k5CAZiau015926@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/io In directory dev.open-bio.org:/tmp/cvs-serv15886/lib/bio/io Modified Files: flatfile.rb Log Message: Bio::FlatFile.open(klass, filename) didn't work. Index: flatfile.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/io/flatfile.rb,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** flatfile.rb 22 Mar 2006 10:19:22 -0000 1.49 --- flatfile.rb 12 Jun 2006 10:35:42 -0000 1.50 *************** *** 426,430 **** unless file.respond_to?(:gets) # 'file' is a filename ! self.open_file(file, *arg, &block) else # 'file' is a IO object --- 426,430 ---- unless file.respond_to?(:gets) # 'file' is a filename ! _open_file(dbclass, file, *arg, &block) else # 'file' is a IO object *************** *** 466,478 **** # def self.open_file(filename, *arg) if block_given? then BufferedInputStream.open_file(filename, *arg) do |stream| ! yield self.new(nil, stream) end else stream = BufferedInputStream.open_file(filename, *arg) ! self.new(nil, stream) end end # Opens URI specified as _uri_. --- 466,490 ---- # def self.open_file(filename, *arg) + _open_file(nil, filename, *arg) + end + + # Same as FlatFile.open(dbclass, filename, *arg), + # except that it only accept filename and doesn't accept IO object. + # + # It can accept a block. + # If a block is given, it returns the block's return value. + # Otherwise, it returns a new FlatFile object. + # + def self._open_file(dbclass, filename, *arg) if block_given? then BufferedInputStream.open_file(filename, *arg) do |stream| ! yield self.new(dbclass, stream) end else stream = BufferedInputStream.open_file(filename, *arg) ! self.new(dbclass, stream) end end + private_class_method :_open_file # Opens URI specified as _uri_. From ngoto at dev.open-bio.org Thu Jun 15 14:28:57 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 15 Jun 2006 14:28:57 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/io test_flatfile.rb,NONE,1.1 Message-ID: <200606151428.k5FESvlN028352@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/io In directory dev.open-bio.org:/tmp/cvs-serv28332/test/unit/bio/io Added Files: test_flatfile.rb Log Message: Unit test for Bio::FlatFile class is added but still incomplete. --- NEW FILE: test_flatfile.rb --- # # = test/unit/bio/io/test_flatfile.rb - unit test for Bio::FlatFile # # Copyright (C) 2006 Naohisa Goto # # License:: Ruby's # # $Id: test_flatfile.rb,v 1.1 2006/06/15 14:28:55 ngoto 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' require 'stringio' module Bio module TestFlatFile bioruby_root = Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4)).cleanpath.to_s TestDataPath = Pathname.new(File.join(bioruby_root, 'test', 'data')).cleanpath.to_s TestDataFastaFormat01 = File.join(TestDataPath, 'fasta', 'example1.txt') class TestBufferedInputStreamClassMethod < Test::Unit::TestCase def test_self_for_io io = File.open(TestDataFastaFormat01) obj = Bio::FlatFile::BufferedInputStream.for_io(io) assert_instance_of(Bio::FlatFile::BufferedInputStream, obj) assert_equal(TestDataFastaFormat01, obj.path) end def test_self_open_file obj = Bio::FlatFile::BufferedInputStream.open_file(TestDataFastaFormat01) assert_instance_of(Bio::FlatFile::BufferedInputStream, obj) assert_equal(TestDataFastaFormat01, obj.path) end def test_self_open_file_with_block obj2 = nil Bio::FlatFile::BufferedInputStream.open_file(TestDataFastaFormat01) do |obj| assert_instance_of(Bio::FlatFile::BufferedInputStream, obj) assert_equal(TestDataFastaFormat01, obj.path) obj2 = obj end assert_raise(IOError) { obj2.close } end end #class TestBufferedInputStreamClassMethod class TestBufferedInputStream < Test::Unit::TestCase def setup io = File.open(TestDataFastaFormat01) path = TestDataFastaFormat01 @obj = Bio::FlatFile::BufferedInputStream.new(io, path) end def test_to_io assert_kind_of(IO, @obj.to_io) end def test_close assert_nil(@obj.close) end def test_rewind @obj.prefetch_gets @obj.rewind assert_equal('', @obj.prefetch_buffer) end def test_pos @obj.gets @obj.gets @obj.prefetch_gets assert_equal(117, @obj.pos) #the number depends on original data end def test_pos=() str = @obj.gets assert_equal(0, @obj.pos = 0) end def test_eof_false_first assert_equal(false, @obj.eof?) end def test_eof_false_after_prefetch while @obj.prefetch_gets; nil; end assert_equal(false, @obj.eof?) end def test_eof_true while @obj.gets; nil; end assert_equal(true, @obj.eof?) end def test_gets @obj.gets @obj.gets assert_equal("gagcaaatcgaaaaggagagatttctgcatatcaagagaaaattcgagctgagatacattccaagtgtggctactc", @obj.gets.chomp) end def test_gets_equal_prefetch_gets @obj.prefetch_gets str = @obj.prefetch_gets @obj.prefetch_gets @obj.gets assert_equal(@obj.gets, str) end def test_ungets @obj.gets @obj.gets str1 = @obj.gets str2 = @obj.gets assert_nil(@obj.ungets(str2)) assert_nil(@obj.ungets(str1)) assert_equal(str1, @obj.gets) assert_equal(str2, @obj.gets) end def test_getc assert_equal(?>, @obj.getc) end def test_getc_after_prefetch @obj.prefetch_gets assert_equal(?>, @obj.getc) end def test_ungetc c = @obj.getc assert_nil(@obj.ungetc(c)) assert_equal(c, @obj.getc) end def test_ungetc_after_prefetch str = @obj.prefetch_gets c = @obj.getc assert_nil(@obj.ungetc(c)) assert_equal(str, @obj.gets) end def test_prefetch_buffer str = @obj.prefetch_gets str += @obj.prefetch_gets assert_equal(str, @obj.prefetch_buffer) end def test_prefetch_gets @obj.prefetch_gets @obj.prefetch_gets @obj.gets str = @obj.prefetch_gets @obj.gets assert_equal(str, @obj.gets) end def test_prefetch_gets_with_arg # test @obj.gets str = @obj.prefetch_gets("\n>") assert_equal(str, @obj.gets("\n>")) # test using IO object io = @obj.to_io io.rewind assert_equal(str, io.gets("\n>")) end def test_skip_spaces @obj.gets('CDS') assert_nil(@obj.skip_spaces) assert_equal(?a, @obj.getc) end end #class TestBufferedInputStream class TestFlatFileWithCustomClass < Test::Unit::TestCase # very simple parser for tab-separated data class SimpleFormat # delimiter needed for flatfile DELIMITER = RS = nil # nil means no delimiter and reading entire file def initialize(str) @data = str.split(/\n/).collect { |x| x.to_s.split(/\t/) } end attr_reader :data end def test_simpleformat testdata = "AAA\tBBB\tCCCCC\tDDDD\n123\t456\n" testio = StringIO.new(testdata) Bio::FlatFile.open(SimpleFormat, testio) do |ff| ff.each do |entry| assert_equal([ [ 'AAA', 'BBB', 'CCCCC', 'DDDD' ], [ '123', '456' ] ], entry.data) end end end # very simple parser for "//"-separated entries class SimpleFormat2 # delimiter needed for flatfile DELIMITER = RS = "//\n" # the end of each entry is "//\n" def initialize(str) # very simple parser only to store a text data @data = str end attr_reader :data end def test_simpleformat2 testdata = <<__END_OF_TESTDATA__ test01 This is a test. // test02 This is an example. // __END_OF_TESTDATA__ a = testdata.split(/(\/\/\n)/) results = [ a[0]+a[1], a[2]+a[3] ] testio = StringIO.new(testdata) Bio::FlatFile.open(SimpleFormat2, testio) do |ff| ff.each do |entry| assert_equal(results.shift, entry.data) end end end end #class TestFlatFileWithCustomClass end #module TestFlatFile end #module Bio From nakao at dev.open-bio.org Fri Jun 16 16:51:07 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Fri, 16 Jun 2006 16:51:07 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db/embl test_sptr.rb,1.2,1.3 Message-ID: <200606161651.k5GGp7aH001256@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db/embl In directory dev.open-bio.org:/tmp/cvs-serv1236 Modified Files: test_sptr.rb Log Message: * Added a test in test_ft. Index: test_sptr.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/embl/test_sptr.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_sptr.rb 23 Nov 2005 10:06:12 -0000 1.2 --- test_sptr.rb 16 Jun 2006 16:51:05 -0000 1.3 *************** *** 234,238 **** assert(@obj.ft) name = 'DNA_BIND' ! assert_equal([{"FTId"=>nil, "From"=>102, "diff"=>[], "To"=>292, "Description"=>nil}], @obj.ft(name)) end --- 234,239 ---- assert(@obj.ft) name = 'DNA_BIND' ! assert_equal([{"FTId"=>"", "From"=>102, "diff"=>[], "To"=>292, "Description"=>""}], @obj.ft(name)) ! assert_equal([{"FTId"=>"", "From"=>102, "diff"=>[], "To"=>292, "Description"=>""}], @obj.ft[name]) end From nakao at dev.open-bio.org Fri Jun 16 17:01:03 2006 From: nakao at dev.open-bio.org (Mitsuteru C. Nakao) Date: Fri, 16 Jun 2006 17:01:03 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/embl sptr.rb,1.31,1.32 Message-ID: <200606161701.k5GH13j4001328@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/embl In directory dev.open-bio.org:/tmp/cvs-serv1306 Modified Files: sptr.rb Log Message: * fixed a PROPEP parsing bug in Bio::SPTR#ft. (reported by Makoto Hamaguchi-san). * changed codes in the Bio::SPTR#id_line and the Bio::SPTR#dt. [refactoring] Index: sptr.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/embl/sptr.rb,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** sptr.rb 14 Apr 2006 05:52:28 -0000 1.31 --- sptr.rb 16 Jun 2006 17:01:01 -0000 1.32 *************** *** 2,6 **** # = bio/db/embl/sptr.rb - UniProt/SwissProt and TrEMBL database class # ! # Copyright:: Copyright (C) 2001-2006 Mitsuteru C. Nakao # License:: Ruby's # --- 2,6 ---- # = bio/db/embl/sptr.rb - UniProt/SwissProt and TrEMBL database class # ! # Copyright:: Copyright (C) 2001-2006 Mitsuteru C. Nakao # License:: Ruby's # *************** *** 46,50 **** @@data_class = ["STANDARD", "PRELIMINARY"] - # returns a Hash of the ID line. # --- 46,49 ---- *************** *** 57,84 **** # # === Examples ! # obj.id_line #=> {"ENTRY_NAME"=>"P53_HUMAN", "DATA_CLASS"=>"STANDARD", "SEQUENCE_LENGTH"=>393, "MOLECULE_TYPE"=>"PRT"} # # obj.id_line('ENTRY_NAME') #=> "P53_HUMAN" # def id_line(key = nil) ! unless @data['ID'] ! tmp = Hash.new ! a = @orig['ID'].split(/ +/) ! tmp['ENTRY_NAME'] = a[1] ! tmp['DATA_CLASS'] = a[2].sub(/;/,'') ! tmp['MOLECULE_TYPE'] = a[3].sub(/;/,'') ! tmp['SEQUENCE_LENGTH'] = a[4].to_i ! @data['ID'] = tmp ! end ! if key ! @data['ID'][key] # String/Int ! else ! @data['ID'] # Hash ! end end - # returns a ENTRY_NAME in the ID line. # --- 56,78 ---- # # === Examples ! # obj.id_line #=> {"ENTRY_NAME"=>"P53_HUMAN", "DATA_CLASS"=>"STANDARD", ! # "SEQUENCE_LENGTH"=>393, "MOLECULE_TYPE"=>"PRT"} # # obj.id_line('ENTRY_NAME') #=> "P53_HUMAN" # def id_line(key = nil) ! return id_line[key] if key ! return @data['ID'] if @data['ID'] ! part = @orig['ID'].split(/ +/) ! @data['ID'] = { ! 'ENTRY_NAME' => part[1], ! 'DATA_CLASS' => part[2].sub(/;/,''), ! 'MOLECULE_TYPE' => part[3].sub(/;/,''), ! 'SEQUENCE_LENGTH' => part[4].to_i ! } end # returns a ENTRY_NAME in the ID line. # *************** *** 128,145 **** # DT DD-MMM-YYY (rel. NN, Last annotation update) def dt(key = nil) ! unless @data['DT'] ! tmp = Hash.new ! a = self.get('DT').split(/\n/) ! tmp['created'] = a[0].sub(/\w{2} /,'').strip ! tmp['sequence'] = a[1].sub(/\w{2} /,'').strip ! tmp['annotation'] = a[2].sub(/\w{2} /,'').strip ! @data['DT'] = tmp ! end ! if key ! @data['DT'][key] ! else ! @data['DT'] ! end end --- 122,134 ---- # DT DD-MMM-YYY (rel. NN, Last annotation update) def dt(key = nil) ! return dt[key] if key ! return @data['DT'] if @data['DT'] ! part = self.get('DT').split(/\n/) ! @data['DT'] = { ! 'created' => part[0].sub(/\w{2} /,'').strip, ! 'sequence' => part[1].sub(/\w{2} /,'').strip, ! 'annotation' => part[2].sub(/\w{2} /,'').strip ! } end *************** *** 451,455 **** # Event, Named isoforms, Comment, [Name, Synonyms, IsoId, Sequnce]+ ! tmp = {'Event' => nil, 'Named isoforms' => nil, 'Comment' => nil, 'Variants' => []} if /Event=(.+?);/ =~ ap --- 440,445 ---- # Event, Named isoforms, Comment, [Name, Synonyms, IsoId, Sequnce]+ ! tmp = {'Event' => nil, 'Named isoforms' => nil, 'Comment' => nil, ! 'Variants' => []} if /Event=(.+?);/ =~ ap *************** *** 499,503 **** ms.each do |m| ! mass = {'MW'=>nil,'MW_ERR'=>nil,'METHOD'=>nil,'RANGE'=>nil} m.sub(/.$/,'').split(/;/).each do |line| case line --- 489,493 ---- ms.each do |m| ! mass = {'MW' => nil,'MW_ERR' => nil,'METHOD' => nil,'RANGE' => nil} m.sub(/.$/,'').split(/;/).each do |line| case line *************** *** 550,554 **** it.map {|ent| {:partner_id => ent[0].strip, ! :nbexp => ent[1].strip, :intact_acc => ent[2].split(', ') } } --- 540,544 ---- it.map {|ent| {:partner_id => ent[0].strip, ! :nbexp => ent[1].strip, :intact_acc => ent[2].split(', ') } } *************** *** 577,583 **** # returns conteins in the feature table. # * Bio::SPTR#ft -> Hash ! # {'feature_name' => [{'From' => str, 'To' => str, ! # 'Description' => str, 'FTId' => str}],...} # # returns an Array of the information about the feature_name in the feature table. --- 567,589 ---- # returns conteins in the feature table. + # + # == Examples + # + # sp = Bio::SPTR.new(entry) + # ft = sp.ft + # ft.class #=> Hash + # ft.keys.each do |feature_key| + # ft[feature_key].each do |feature| + # feature['From'] #=> '1' + # feature['To'] #=> '21' + # feature['Description'] #=> '' + # feature['FTId'] #=> '' + # feature['diff'] #=> [] + # end + # end + # # * Bio::SPTR#ft -> Hash ! # {FEATURE_KEY => [{'From' => int, 'To' => int, 'diff' => [], ! # 'Description' => aStr, 'FTId' => aStr}],...} # # returns an Array of the information about the feature_name in the feature table. *************** *** 595,692 **** # 35-75 Description (>=0 per key) # ----- ----------------- ! def ft(feature_name = nil) ! unless @data['FT'] ! table = Hash.new() ! last_feature = nil ! ! begin ! get('FT').split(/\n/).each {|line| ! ! feature = line[5..12].strip ! ! if feature == '' and line[34..74] ! tmp = ' ' + line[34..74].strip ! table[last_feature].last['Description'] << tmp ! ! next unless /\.$/ =~ line ! else ! from = line[14..19].strip ! to = line[21..26].strip ! desc = line[34..74].strip if line[34..74] ! table[feature] = [] unless table[feature] ! table[feature] << { ! 'From' => from.to_i, ! 'To' => to.to_i, ! 'Description' => desc, ! 'diff' => [], ! 'FTId' => nil } ! last_feature = feature ! next ! end ! case last_feature ! when 'VARSPLIC', 'VARIANT', 'CONFLICT' ! if /FTId=(.+?)\./ =~ line # version 41 > ! ftid = $1 ! table[last_feature].last['FTId'] = ftid ! table[last_feature].last['Description'].sub!(/ \/FTId=#{ftid}./,'') ! end ! case table[last_feature].last['Description'] ! when /(\w[\w ]*\w*) - ?> (\w[\w ]*\w*)/ ! original = $1 ! swap = $2 ! original = original.gsub(/ /,'').strip ! swap = swap.gsub(/ /,'').strip ! when /Missing/i ! original = seq.subseq(table[last_feature].last['From'], ! table[last_feature].last['To']) ! swap = '' ! else ! raise line ! end ! table[last_feature].last['diff'] = [original, swap] ! end ! } ! rescue ! raise "Invalid FT Lines(#{$!}) in #{entry_id}:, \n" + ! "'#{self.get('FT')}'\n" ! end ! table.each_key do |k| ! table[k].each do |e| ! if / -> / =~ e['Description'] ! pattern = /([A-Z][A-Z ]*[A-Z]*) -> ([A-Z][A-Z ]*[A-Z]*)/ ! e['Description'].sub!(pattern) { ! a = $1 ! b = $2 ! a.gsub(/ /,'') + " -> " + b.gsub(/ /,'') ! } ! end ! if /- [\w\d]/ =~ e['Description'] ! e['Description'].gsub!(/([\w\d]- [\w\d]+)/) { ! a = $1 ! if /- AND/ =~ a ! a ! else ! a.sub(/ /,'') ! end ! } ! end end end - @data['FT'] = table end ! ! if feature_name ! @data['FT'][feature_name] ! else ! @data['FT'] end end # returns a Hash of conteins in the SQ lines. # * Bio::SPTRL#sq -> hsh --- 601,670 ---- # 35-75 Description (>=0 per key) # ----- ----------------- ! # ! def ft(feature_key = nil) ! return ft[feature_key] if feature_key ! return @data['FT'] if @data['FT'] ! table = [] ! begin ! get('FT').split("\n").each do |line| ! if line =~ /^FT \w/ ! feature = line.chomp.ljust(74) ! table << [feature[ 5..12].strip, # Feature Name ! feature[14..19].strip, # From ! feature[21..26].strip, # To ! feature[34..74].strip ] # Description ! else ! table.last << line.chomp.sub!(/^FT +/, '') ! end ! end ! # Join Desctiption lines ! table = table.map { |feature| ! ftid = feature.pop if feature.last =~ /FTId=/ ! if feature.size > 4 ! feature = [feature[0], feature[1], feature[2], ! feature[3, feature.size - 3].join(" ")] ! end ! feature << ftid ! } ! hash = {} ! table.each do |feature| ! hash[feature[0]] = [] unless hash[feature[0]] ! hash[feature[0]] << { ! 'From' => feature[1].to_i, ! 'To' => feature[2].to_i, ! 'Description' => feature[3], ! 'FTId' => feature[4].to_s.sub(/\/FTId=/, '').sub(/\.$/, ''), ! 'diff' => [] ! } ! case feature[0] ! when 'VARSPLIC', 'VARIANT', 'VAR_SEQ', 'CONFLICT' ! case hash[feature[0]].last['Description'] ! when /(\w[\w ]*\w*) - ?> (\w[\w ]*\w*)/ ! original_res = $1 ! changed_res = $2 ! original_res = original_res.gsub(/ /,'').strip ! chenged_res = changed_res.gsub(/ /,'').strip ! when /Missing/i ! original_res = seq.subseq(hash[feature[0]].last['From'], ! hash[feature[0]].last['To']) ! changed_res = '' end + hash[feature[0]].last['diff'] = [original_res, chenged_res] end end ! rescue ! raise "Invalid FT Lines(#{$!}) in #{entry_id}:, \n'#{self.get('FT')}'\n" end + + @data['FT'] = hash end + # returns a Hash of conteins in the SQ lines. # * Bio::SPTRL#sq -> hsh *************** *** 694,698 **** # returns a value of a key given in the SQ lines. # * Bio::SPTRL#sq(key) -> int or str ! # * Keys: ['MW', 'mw', 'molecular', 'weight', 'aalen', 'len', 'length', 'CRC64'] # # === SQ Line; sequence header (1/entry) --- 672,677 ---- # returns a value of a key given in the SQ lines. # * Bio::SPTRL#sq(key) -> int or str ! # * Keys: ['MW', 'mw', 'molecular', 'weight', 'aalen', 'len', 'length', ! # 'CRC64'] # # === SQ Line; sequence header (1/entry) From ngoto at dev.open-bio.org Tue Jun 20 14:21:37 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 20 Jun 2006 14:21:37 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.7,1.8 Message-ID: <200606201421.k5KELbnB001117@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv1058 Modified Files: report.rb Log Message: Added Bio::BLAT::Report::Hit#milli_bad, #percent_identity, #protein?, and #score methods. The algorithm of these methods are described in the BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat5). Thanks to Dr. Itoshi Nikaido for help. Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** report.rb 8 May 2006 14:37:55 -0000 1.7 --- report.rb 20 Jun 2006 14:21:34 -0000 1.8 *************** *** 328,331 **** --- 328,405 ---- exons.each(&x) end + + #-- + # methods described in the BLAT FAQ at the UCSC genome browser. + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5) + #++ + + # Calculates the pslCalcMilliBad value defined in the + # BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def milli_bad + w = (self.protein? ? 3 : 1) + qalen = w * (self.query.end - self.query.start) + talen = self.target.end - self.target.start + alen = (if qalen < talen then qalen; else talen; end) + return 0 if alen <= 0 + d = qalen - talen + d = 0 if d < 0 + total = w * (self.match + self.rep_match + self.mismatch) + return 0 if total == 0 + return (1000 * (self.mismatch * w + self.query.gap_count + + (3 * Math.log(1 + d)).round) / total) + end + + # Calculates the percent identity compatible with the BLAT web server + # as described in the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def percent_identity + 100.0 - self.milli_bad * 0.1 + end + + # When the output data comes from the protein query, returns true. + # Otherwise (nucleotide query), returns false. + # It returns nil if this cannot be determined. + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def protein? + return nil if self.block_sizes.empty? + case self.strand + when '+' + if self.target.end == self.target.starts[-1] + + 3 * self.block_sizes[-1] then + true + else + false + end + when '-' + if self.target.start == self.target.size - + self.target.starts[-1] + 3 * self.block_sizes[-1] then + true + else + false + end + else + nil + end + end + + # Calculates the score compatible with the BLAT web server + # as described in the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + # + # The algorithm is taken from the BLAT FAQ + # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). + def score + w = (self.protein? ? 3 : 1) + w * (self.match + (self.rep_match >> 1)) - + w * self.mismatch - self.query.gap_count - self.target.gap_count + end end #class Hit From ngoto at dev.open-bio.org Tue Jun 20 14:34:40 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 20 Jun 2006 14:34:40 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.8,1.9 Message-ID: <200606201434.k5KEYeDQ001282@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv1262 Modified Files: report.rb Log Message: Changed some documents. Reference: http://genome.ucsc.edu/goldenPath/help/blatSpec.html Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** report.rb 20 Jun 2006 14:21:34 -0000 1.8 --- report.rb 20 Jun 2006 14:34:38 -0000 1.9 *************** *** 21,25 **** # Genome Research, 12, 656--664, 2002. # http://www.genome.org/cgi/content/abstract/12/4/656 ! # require 'bio' --- 21,25 ---- # Genome Research, 12, 656--664, 2002. # http://www.genome.org/cgi/content/abstract/12/4/656 ! # * http://genome.ucsc.edu/goldenPath/help/blatSpec.html require 'bio' *************** *** 262,268 **** # Mismatch nucleotides. def mismatch; @data[1].to_i; end ! # rep. match (???) def rep_match; @data[2].to_i; end ! # N's (???) def n_s; @data[3].to_i; end --- 262,272 ---- # Mismatch nucleotides. def mismatch; @data[1].to_i; end ! ! # "rep. match". ! # Number of bases that match but are part of repeats. ! # Note that current version of BLAT always set 0. def rep_match; @data[2].to_i; end ! ! # "N's". Number of 'N' bases. def n_s; @data[3].to_i; end From ngoto at dev.open-bio.org Thu Jun 22 14:32:49 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 22 Jun 2006 14:32:49 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/io flatfile.rb,1.50,1.51 Message-ID: <200606221432.k5MEWnV4007918@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/io In directory dev.open-bio.org:/tmp/cvs-serv7898/lib/bio/io Modified Files: flatfile.rb Log Message: Fixed: failed to autodetect psLayout version 4 (Bio::BLAT::Report) Index: flatfile.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/io/flatfile.rb,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** flatfile.rb 12 Jun 2006 10:35:42 -0000 1.50 --- flatfile.rb 22 Jun 2006 14:32:47 -0000 1.51 *************** *** 1196,1200 **** blat = RuleRegexp[ 'Bio::Blat::Report', ! /^psLayout version \d+\s*$/ ], spidey = RuleRegexp[ 'Bio::Spidey::Report', /^\-\-SPIDEY version .+\-\-$/ ], --- 1196,1200 ---- blat = RuleRegexp[ 'Bio::Blat::Report', ! /^psLayout version \d+/ ], spidey = RuleRegexp[ 'Bio::Spidey::Report', /^\-\-SPIDEY version .+\-\-$/ ], From ngoto at dev.open-bio.org Tue Jun 27 05:44:59 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 05:44:59 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/sequence na.rb,1.3,1.4 Message-ID: <200606270544.k5R5ixTu007673@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/sequence In directory dev.open-bio.org:/tmp/cvs-serv7649/lib/bio/sequence Modified Files: na.rb Log Message: Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew are newly added. Bio::Sequence::NA#gc_percent are changed not to raise ZeroDivisionError and returns 0 when given sequence is empty. Index: na.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/sequence/na.rb,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** na.rb 26 Mar 2006 02:27:59 -0000 1.3 --- na.rb 27 Jun 2006 05:44:57 -0000 1.4 *************** *** 282,286 **** # Calculate the ratio of GC / ATGC bases as a percentage rounded to ! # the nearest whole number. # # s = Bio::Sequence::NA.new('atggcgtga') --- 282,286 ---- # Calculate the ratio of GC / ATGC bases as a percentage rounded to ! # the nearest whole number. U is regarded as T. # # s = Bio::Sequence::NA.new('atggcgtga') *************** *** 292,299 **** --- 292,356 ---- at = count['a'] + count['t'] + count['u'] gc = count['g'] + count['c'] + return 0 if at + gc == 0 gc = 100 * gc / (at + gc) return gc end + # Calculate the ratio of GC / ATGC bases. U is regarded as T. + # + # s = Bio::Sequence::NA.new('atggcgtga') + # puts s.gc_content #=> 0.555555555555556 + # --- + # *Returns*:: Float + def gc_content + count = self.composition + at = count['a'] + count['t'] + count['u'] + gc = count['g'] + count['c'] + return 0.0 if at + gc == 0 + return (gc.to_f / (at + gc).to_f) + end + + # Calculate the ratio of AT / ATGC bases. U is regarded as T. + # + # s = Bio::Sequence::NA.new('atggcgtga') + # puts s.at_content #=> 0.444444444444444 + # --- + # *Returns*:: Float + def at_content + count = self.composition + at = count['a'] + count['t'] + count['u'] + gc = count['g'] + count['c'] + return 0.0 if at + gc == 0 + return (at.to_f / (at + gc).to_f) + end + + # Calculate the ratio of (G - C) / (G + C) bases. + # + # s = Bio::Sequence::NA.new('atggcgtga') + # puts s.gc_skew #=> 0.6 + # --- + # *Returns*:: Float + def gc_skew + count = self.composition + g = count['g'] + c = count['c'] + return 0.0 if g + c == 0 + return ((g - c).to_f / (g + c).to_f) + end + + # Calculate the ratio of (A - T) / (A + T) bases. U is regarded as T. + # + # s = Bio::Sequence::NA.new('atgttgttgttc') + # puts s.at_skew #=> -0.75 + # --- + # *Returns*:: Float + def at_skew + count = self.composition + a = count['a'] + t = count['t'] + count['u'] + return 0.0 if a + t == 0 + return ((a - t).to_f / (a + t).to_f) + end + # Returns an alphabetically sorted array of any non-standard bases # (other than 'atgcu'). From ngoto at dev.open-bio.org Tue Jun 27 05:44:59 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 05:44:59 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/sequence test_na.rb,1.1,1.2 Message-ID: <200606270544.k5R5ixYo007678@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/sequence In directory dev.open-bio.org:/tmp/cvs-serv7649/test/unit/bio/sequence Modified Files: test_na.rb Log Message: Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew are newly added. Bio::Sequence::NA#gc_percent are changed not to raise ZeroDivisionError and returns 0 when given sequence is empty. Index: test_na.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/sequence/test_na.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_na.rb 8 Feb 2006 07:08:22 -0000 1.1 --- test_na.rb 27 Jun 2006 05:44:57 -0000 1.2 *************** *** 99,102 **** --- 99,128 ---- end + def test_gc_content + assert_in_delta(0.4, @obj.gc_content, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(0.45, @obj.gc_content, Float::EPSILON) + end + + def test_at_content + assert_in_delta(0.6, @obj.at_content, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(0.55, @obj.at_content, Float::EPSILON) + end + + def test_gc_skew + assert_in_delta(0.0, @obj.gc_skew, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(1.0/9.0, @obj.gc_skew, Float::EPSILON) + @obj.gsub!(/a/, 'c') + assert_in_delta(-3.0/8.0, @obj.gc_skew, Float::EPSILON) + end + + def test_at_skew + assert_in_delta(1.0/3.0, @obj.at_skew, Float::EPSILON) + @obj[0, 1] = 'g' + assert_in_delta(3.0/11.0, @obj.at_skew, Float::EPSILON) + end + def test_iliegal_bases @obj[0, 1] = 'n' From ngoto at dev.open-bio.org Tue Jun 27 05:44:59 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 05:44:59 +0000 Subject: [BioRuby-cvs] bioruby ChangeLog,1.52,1.53 Message-ID: <200606270544.k5R5ixDT007683@dev.open-bio.org> Update of /home/repository/bioruby/bioruby In directory dev.open-bio.org:/tmp/cvs-serv7649 Modified Files: ChangeLog Log Message: Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew are newly added. Bio::Sequence::NA#gc_percent are changed not to raise ZeroDivisionError and returns 0 when given sequence is empty. Index: ChangeLog =================================================================== RCS file: /home/repository/bioruby/bioruby/ChangeLog,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** ChangeLog 3 May 2006 00:07:58 -0000 1.52 --- ChangeLog 27 Jun 2006 05:44:57 -0000 1.53 *************** *** 1,2 **** --- 1,11 ---- + 2006-06-27 Naohisa Goto + + * lib/bio/sequence/na.rb + + Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew + are newly added. Bio::Sequence::NA#gc_percent are changed + not to raise ZeroDivisionError and returns 0 when given sequence + is empty. + 2006-05-02 Mitsuteru Nakao From aerts at dev.open-bio.org Tue Jun 27 12:37:44 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Tue, 27 Jun 2006 12:37:44 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio test_map.rb,1.2,1.3 Message-ID: <200606271237.k5RCbimc008730@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio In directory dev.open-bio.org:/tmp/cvs-serv8703/test/unit/bio Modified Files: test_map.rb Log Message: Removed Enumerable mixin from ActsLikeMap and ActsLikeMarker, because 'def each' would be ambiguous. Included examples for using ActsLikeMap and ActsLikeMarker. Index: test_map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/test_map.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_map.rb 7 Jun 2006 12:56:29 -0000 1.2 --- test_map.rb 27 Jun 2006 12:37:42 -0000 1.3 *************** *** 6,10 **** # License:: Ruby's # ! # $Id$ require 'pathname' --- 6,10 ---- # License:: Ruby's # ! # $Id: require 'pathname' *************** *** 182,184 **** --- 182,197 ---- end end + + class Clone + include Bio::Map::ActsLikeMap + include Bio::Map::ActsLikeMarker + + def initialize(name) + @name = name + @mappings_as_map = Array.new + @mappings_as_marker = Array.new + end + attr_accessor :name, :mappings_as_map, :mappings_as_marker + end + end From aerts at dev.open-bio.org Tue Jun 27 12:37:44 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Tue, 27 Jun 2006 12:37:44 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio map.rb,1.6,1.7 Message-ID: <200606271237.k5RCbiae008725@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv8703/lib/bio Modified Files: map.rb Log Message: Removed Enumerable mixin from ActsLikeMap and ActsLikeMarker, because 'def each' would be ambiguous. Included examples for using ActsLikeMap and ActsLikeMarker. Index: map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/map.rb,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** map.rb 7 Jun 2006 12:55:50 -0000 1.6 --- map.rb 27 Jun 2006 12:37:42 -0000 1.7 *************** *** 6,10 **** # Licence:: Ruby's # ! # $Id$ require 'bio/location' --- 6,10 ---- # Licence:: Ruby's # ! # $Id: require 'bio/location' *************** *** 65,74 **** # puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s # ! # my_map1.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end ! # puts my_map1.min.marker.name ! # my_map2.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location[0].from.to_s + ".." + mapping.location[-1].to.to_s # end module Map --- 65,74 ---- # puts "Does my_map2 contain marker3? => " + my_map2.contains_marker?(my_marker3).to_s # ! # my_map1.mappings_as_map.sort.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end ! # puts my_map1.mappings_as_map.min.marker.name ! # my_map2.mappings_as_map.each do |mapping| ! # puts mapping.map.name + "\t" + mapping.marker.name + "\t" + mapping.location.from.to_s + ".." + mapping.location.to.to_s # end module Map *************** *** 81,84 **** --- 81,94 ---- # # Classes that include this mixin should provide an array property called mappings_as_map. + # For example: + # class MyMapThing + # include Bio::Map::ActsLikeMap + # + # def initialize (name) + # @name = name + # @mappings_as_maps = Array.new + # end + # attr_accessor :name, :mappings_as_map + # end module ActsLikeMap include Enumerable *************** *** 138,147 **** end - # Go through all Bio::Map::Mapping objects linked to this Bio::Map::SimpleMap. - def each - self.mappings_as_map.each do |mapping| - yield mapping - end - end end #ActsLikeMap --- 148,151 ---- *************** *** 154,157 **** --- 158,171 ---- # # Classes that include this mixin should provide an array property called mappings_as_marker. + # For example: + # class MyMarkerThing + # include Bio::Map::ActsLikeMarker + # + # def initialize (name) + # @name = name + # @mappings_as_marker = Array.new + # end + # attr_accessor :name, :mappings_as_marker + # end module ActsLikeMarker include Enumerable *************** *** 189,199 **** end end - - # Go through all Mapping objects linked to this marker. - def each - self.mappings_as_marker.each do |mapping| - yield mapping - end - end # Check whether this marker is mapped to a given Bio::Map::SimpleMap. --- 203,206 ---- *************** *** 238,241 **** --- 245,249 ---- end + end #ActsLikeMarker *************** *** 253,257 **** # * _marker_: a Bio::Map::Marker object # * _location_: a Bio::Locations object - def initialize (map, marker, location = nil) @map, @marker, @location = map, marker, location --- 261,264 ---- *************** *** 259,280 **** attr_accessor :map, :marker, :location ! # # Compares the location of this mapping to another mapping. ! # # --- ! # # *Arguments*: ! # # * other_mapping: Bio::Map::Mapping object ! # # *Returns*:: ! # # * 1 if self < other location ! # # * -1 if self > other location ! # # * 0 if both location are the same ! # # * nil if the argument is not a Bio::Location object ! # def <=>(other) ! # unless other.kind_of?(Bio::Map::Mapping) ! # raise "[Error] markers are not comparable" ! # end ! # unless @map.equal?(other.map) ! # raise "[Error] maps have to be the same" ! # end ! # return self.location<=>(other.location) # FIXME: no <=>-method in Bio::Locations ! # end end # Mapping --- 266,288 ---- attr_accessor :map, :marker, :location ! # Compares the location of this mapping to another mapping. ! # --- ! # *Arguments*: ! # * other_mapping: Bio::Map::Mapping object ! # *Returns*:: ! # * 1 if self < other location ! # * -1 if self > other location ! # * 0 if both location are the same ! # * nil if the argument is not a Bio::Location object ! def <=>(other) ! unless other.kind_of?(Bio::Map::Mapping) ! raise "[Error] markers are not comparable" ! end ! unless @map.equal?(other.map) ! raise "[Error] maps have to be the same" ! end ! ! return self.location.<=>(other.location) ! end end # Mapping From aerts at dev.open-bio.org Tue Jun 27 12:40:17 2006 From: aerts at dev.open-bio.org (Jan Aerts) Date: Tue, 27 Jun 2006 12:40:17 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio map.rb,1.7,1.8 Message-ID: <200606271240.k5RCeHJA008800@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio In directory dev.open-bio.org:/tmp/cvs-serv8780/lib/bio Modified Files: map.rb Log Message: Forgot to remove reference to Enumerable. Index: map.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/map.rb,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** map.rb 27 Jun 2006 12:37:42 -0000 1.7 --- map.rb 27 Jun 2006 12:40:15 -0000 1.8 *************** *** 6,10 **** # Licence:: Ruby's # ! # $Id: require 'bio/location' --- 6,10 ---- # Licence:: Ruby's # ! # $Id$ require 'bio/location' *************** *** 92,97 **** # end module ActsLikeMap - include Enumerable - # = DESCRIPTION # Adds a Bio::Map::Mappings object to its array of mappings. --- 92,95 ---- *************** *** 169,174 **** # end module ActsLikeMarker - include Enumerable - # = DESCRIPTION # Adds a Bio::Map::Mappings object to its array of mappings. --- 167,170 ---- From ngoto at dev.open-bio.org Tue Jun 27 14:23:47 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 14:23:47 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/db/pdb pdb.rb,1.15,1.16 Message-ID: <200606271423.k5RENlQb009267@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/db/pdb In directory dev.open-bio.org:/tmp/cvs-serv9227/lib/bio/db/pdb Modified Files: pdb.rb Log Message: Bio::PDB::ATOM#name, #resName, #iCode, #chaarge are changed to be strippedi when initializing. Bio::PDB::ATOM#segID is changed to be right-stripped when initializing. Bio::PDB::ATOM#element is changed to be left-stripped when initializing. (Because Bio::PDB::HETATM inherits Bio::PDB::ATOM, Bio::PDB::HETATM is also subject to the changes.) Index: pdb.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/pdb.rb,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** pdb.rb 20 Feb 2006 13:00:43 -0000 1.15 --- pdb.rb 27 Jun 2006 14:23:45 -0000 1.16 *************** *** 993,1002 **** return self if @parsed self.serial = @str[6..10].to_i ! self.name = @str[12..15] self.altLoc = @str[16..16] ! self.resName = @str[17..19].rstrip self.chainID = @str[21..21] self.resSeq = @str[22..25].to_i ! self.iCode = @str[26..26] self.x = @str[30..37].to_f self.y = @str[38..45].to_f --- 993,1002 ---- return self if @parsed self.serial = @str[6..10].to_i ! self.name = @str[12..15].strip self.altLoc = @str[16..16] ! self.resName = @str[17..19].strip self.chainID = @str[21..21] self.resSeq = @str[22..25].to_i ! self.iCode = @str[26..26].strip self.x = @str[30..37].to_f self.y = @str[38..45].to_f *************** *** 1004,1010 **** self.occupancy = @str[54..59].to_f self.tempFactor = @str[60..65].to_f ! self.segID = @str[72..75] ! self.element = @str[76..77] ! self.charge = @str[78..79] @parsed = true self --- 1004,1010 ---- self.occupancy = @str[54..59].to_f self.tempFactor = @str[60..65].to_f ! self.segID = @str[72..75].to_s.rstrip ! self.element = @str[76..77].to_s.lstrip ! self.charge = @str[78..79].to_s.strip @parsed = true self *************** *** 1012,1019 **** def to_s sprintf("%-6s%5d %-4s%-1s%3s %-1s%4d%-1s %8.3f%8.3f%8.3f%6.2f%6.2f %-4s%2s%-2s\n", self.record_name, self.serial, ! self.name, self.altLoc, self.resName, --- 1012,1024 ---- def to_s + atomname = self.name.to_s + elem = self.element.to_s.strip + if elem.length == 1 and atomname.lstrip[0, 1] == elem then + atomname = ' ' + atomname + end sprintf("%-6s%5d %-4s%-1s%3s %-1s%4d%-1s %8.3f%8.3f%8.3f%6.2f%6.2f %-4s%2s%-2s\n", self.record_name, self.serial, ! atomname, self.altLoc, self.resName, From ngoto at dev.open-bio.org Tue Jun 27 14:25:42 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 14:25:42 +0000 Subject: [BioRuby-cvs] bioruby/test/unit/bio/db/pdb test_pdb.rb,1.1,1.2 Message-ID: <200606271425.k5REPgfp009296@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/test/unit/bio/db/pdb In directory dev.open-bio.org:/tmp/cvs-serv9276/test/unit/bio/db/pdb Modified Files: test_pdb.rb Log Message: * License is changed to Ruby's. * Follow changes to pdb.rb (as is nearly the same behavior as bioruby-0.6.4). Index: test_pdb.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/test/unit/bio/db/pdb/test_pdb.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_pdb.rb 26 Jan 2006 16:06:03 -0000 1.1 --- test_pdb.rb 27 Jun 2006 14:25:40 -0000 1.2 *************** *** 5,29 **** # Naohisa Goto # ! # License:: LGPL # # $Id$ # - #-- - # This library is free software; you can redistribute it and/or - # modify it under the terms of the GNU Lesser General Public - # License as published by the Free Software Foundation; either - # version 2 of the License, or (at your option) any later version. - # - # This library is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - # Lesser General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public - # License along with this library; if not, write to the Free Software - # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - #++ - # - # require 'pathname' --- 5,12 ---- # Naohisa Goto # ! # License:: Ruby's # # $Id$ # require 'pathname' *************** *** 58,62 **** def test_name ! assert_equal(' CG2', @atom.name) end --- 41,45 ---- def test_name ! assert_equal('CG2', @atom.name) end *************** *** 78,82 **** def test_iCode ! assert_equal(' ', @atom.iCode) end --- 61,65 ---- def test_iCode ! assert_equal('', @atom.iCode) end *************** *** 102,114 **** def test_segID ! assert_equal('A1 ', @atom.segID) end def test_element ! assert_equal(' C', @atom.element) end def test_charge ! assert_equal(' ', @atom.charge) end --- 85,97 ---- def test_segID ! assert_equal('A1', @atom.segID) end def test_element ! assert_equal('C', @atom.element) end def test_charge ! assert_equal('', @atom.charge) end From ngoto at dev.open-bio.org Tue Jun 27 15:17:09 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Tue, 27 Jun 2006 15:17:09 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.9,1.10 Message-ID: <200606271517.k5RFH9w8009506@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv9484/lib/bio/appl/blat Modified Files: report.rb Log Message: changed documents Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** report.rb 20 Jun 2006 14:34:38 -0000 1.9 --- report.rb 27 Jun 2006 15:17:07 -0000 1.10 *************** *** 34,38 **** # On the other hand, in many other homology search programs, # the start position of a sequence is numbered as 1. ! # To keep compatibility, the BLAT parser adds 1 to every position number. # # Note that Bio::Blat::Report#query_def, #query_id, #query_len methods --- 34,39 ---- # On the other hand, in many other homology search programs, # the start position of a sequence is numbered as 1. ! # To keep compatibility, the BLAT parser adds 1 to every position number ! # except Bio::Blat::Report::Seqdesc and some Bio::Blat specific methods. # # Note that Bio::Blat::Report#query_def, #query_id, #query_len methods *************** *** 335,346 **** #-- # methods described in the BLAT FAQ at the UCSC genome browser. ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5) #++ # Calculates the pslCalcMilliBad value defined in the ! # BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat5). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def milli_bad w = (self.protein? ? 3 : 1) --- 336,347 ---- #-- # methods described in the BLAT FAQ at the UCSC genome browser. ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4) #++ # Calculates the pslCalcMilliBad value defined in the ! # BLAT FAQ (http://genome.ucsc.edu/FAQ/FAQblat#blat4). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def milli_bad w = (self.protein? ? 3 : 1) *************** *** 359,366 **** # Calculates the percent identity compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def percent_identity 100.0 - self.milli_bad * 0.1 --- 360,367 ---- # Calculates the percent identity compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def percent_identity 100.0 - self.milli_bad * 0.1 *************** *** 372,376 **** # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def protein? return nil if self.block_sizes.empty? --- 373,377 ---- # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def protein? return nil if self.block_sizes.empty? *************** *** 397,404 **** # Calculates the score compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat5). def score w = (self.protein? ? 3 : 1) --- 398,405 ---- # Calculates the score compatible with the BLAT web server # as described in the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). # # The algorithm is taken from the BLAT FAQ ! # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def score w = (self.protein? ? 3 : 1) From ngoto at dev.open-bio.org Wed Jun 28 13:43:33 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Wed, 28 Jun 2006 13:43:33 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.10,1.11 Message-ID: <200606281343.k5SDhXq7013712@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv13692/lib/bio/appl/blat Modified Files: report.rb Log Message: * Fixed a bug in Bio::Blat::Report::Hit#protein?. * Fixed: when protein query and nucleotide database, HSPs are incorrect. Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** report.rb 27 Jun 2006 15:17:07 -0000 1.10 --- report.rb 28 Jun 2006 13:43:31 -0000 1.11 *************** *** 140,149 **** # It is designed to be called internally from Bio::Blat::Report class. # Users shall not use it directly. ! def initialize(query_len, strand, ! blksize, qstart, tstart, qseq, tseq) @blocksize = blksize @qseq = qseq @hseq = hseq @hit_strand = 'plus' case strand when '-' --- 140,151 ---- # It is designed to be called internally from Bio::Blat::Report class. # Users shall not use it directly. ! def initialize(query_len, target_len, strand, ! blksize, qstart, tstart, qseq, tseq, ! protein_flag) @blocksize = blksize @qseq = qseq @hseq = hseq @hit_strand = 'plus' + w = (protein_flag ? 3 : 1) # 3 means query=protein target=dna case strand when '-' *************** *** 156,161 **** # we add 1 to each position number. @hit_from = tstart + 1 ! @hit_to = tstart + blksize # - 1 + 1 ! else #when '+' @query_strand = 'plus' # To keep compatibility with other homology search programs, --- 158,174 ---- # we add 1 to each position number. @hit_from = tstart + 1 ! @hit_to = tstart + blksize * w # - 1 + 1 ! when '+-' ! # hit is minus strand ! @query_strand = 'plus' ! @hit_strand = 'minus' ! # To keep compatibility, with other homology search programs, ! # we add 1 to each position number. ! @query_from = qstart + 1 ! @query_to = qstart + blksize # - 1 + 1 ! # convert positions ! @hit_from = target_len - tstart ! @hit_to = target_len - tstart - blksize * w + 1 ! else #when '+', '++' @query_strand = 'plus' # To keep compatibility with other homology search programs, *************** *** 164,168 **** @query_to = qstart + blksize # - 1 + 1 @hit_from = tstart + 1 ! @hit_to = tstart + blksize # - 1 + 1 end end --- 177,181 ---- @query_to = qstart + blksize # - 1 + 1 @hit_from = tstart + 1 ! @hit_to = tstart + blksize * w # - 1 + 1 end end *************** *** 298,304 **** qseqs = query.seqs tseqs = target.seqs @blocks = (0...block_count).collect do |i| ! SegmentPair.new(query.size, strand, bs[i], ! qst[i], tst[i], qseqs[i], tseqs[i]) end end --- 311,319 ---- qseqs = query.seqs tseqs = target.seqs + pflag = self.protein? @blocks = (0...block_count).collect do |i| ! SegmentPair.new(query.size, target.size, strand, bs[i], ! qst[i], tst[i], qseqs[i], tseqs[i], ! pflag) end end *************** *** 374,380 **** # The algorithm is taken from the BLAT FAQ # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). def protein? return nil if self.block_sizes.empty? ! case self.strand when '+' if self.target.end == self.target.starts[-1] + --- 389,398 ---- # The algorithm is taken from the BLAT FAQ # (http://genome.ucsc.edu/FAQ/FAQblat#blat4). + # + # Note: It seems that it returns true only when protein query + # with nucleotide database (blat options: -q=prot -t=dnax). def protein? return nil if self.block_sizes.empty? ! case self.strand[1,1] when '+' if self.target.end == self.target.starts[-1] + *************** *** 386,390 **** when '-' if self.target.start == self.target.size - ! self.target.starts[-1] + 3 * self.block_sizes[-1] then true else --- 404,408 ---- when '-' if self.target.start == self.target.size - ! self.target.starts[-1] - 3 * self.block_sizes[-1] then true else From ngoto at dev.open-bio.org Thu Jun 29 11:54:35 2006 From: ngoto at dev.open-bio.org (Naohisa Goto) Date: Thu, 29 Jun 2006 11:54:35 +0000 Subject: [BioRuby-cvs] bioruby/lib/bio/appl/blat report.rb,1.11,1.12 Message-ID: <200606291154.k5TBsZud023085@dev.open-bio.org> Update of /home/repository/bioruby/bioruby/lib/bio/appl/blat In directory dev.open-bio.org:/tmp/cvs-serv23065/lib/bio/appl/blat Modified Files: report.rb Log Message: * psl without header is supported. * New attribute ``psl_version'' is added. Index: report.rb =================================================================== RCS file: /home/repository/bioruby/bioruby/lib/bio/appl/blat/report.rb,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** report.rb 28 Jun 2006 13:43:31 -0000 1.11 --- report.rb 29 Jun 2006 11:54:33 -0000 1.12 *************** *** 59,62 **** --- 59,67 ---- @hits << Hit.new(line) else + # for headerless data + if /^\d/ =~ line then + flag = true + redo + end line = line.chomp if /\A\-+\s*\z/ =~ line *************** *** 81,85 **** # Parses headers. def parse_header(ary) ! ary.shift # first line is removed a0 = ary.collect { |x| x.split(/\t/) } k = [] --- 86,98 ---- # Parses headers. def parse_header(ary) ! while x = ary.shift ! if /psLayout version (\S+)/ =~ x then ! @psl_version = $1 ! break ! elsif !(x.strip.empty?) ! ary.unshift(x) ! break ! end ! end a0 = ary.collect { |x| x.split(/\t/) } k = [] *************** *** 95,98 **** --- 108,114 ---- private :parse_header + # version of the psl format (String or nil). + attr_reader :psl_version + # Bio::Blat::Report::SeqDesc stores sequence information of # query or subject of the BLAT report.