[BioRuby-cvs] bioruby/lib/bio/db/pdb model.rb, 1.5, 1.6 chain.rb, 1.4, 1.5 residue.rb, 1.8, 1.9

Naohisa Goto ngoto at pub.open-bio.org
Mon Jan 9 06:22:38 EST 2006


Update of /home/repository/bioruby/bioruby/lib/bio/db/pdb
In directory pub.open-bio.org:/tmp/cvs-serv9256

Modified Files:
	model.rb chain.rb residue.rb 
Log Message:
* model.rb (Bio::PDB::Model)
  * @chains_hash is introduced to speed up parsing.
  * added rehash method.
* chain.rb (Bio::PDB::Chain)
  * @residues_hash and @heterogens_hash are introduced to speed up parsing.
  * added rehash_residues, rehash_heterogens, and rehash methods.
* residue.rb
  * added an alias heterogen_id.


Index: residue.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/residue.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** residue.rb	8 Jan 2006 12:59:04 -0000	1.8
--- residue.rb	9 Jan 2006 11:22:36 -0000	1.9
***************
*** 179,182 ****
--- 179,185 ----
        # Alias needed for HeterogenFinder.
        alias hetatms atoms
+ 
+       # Alias to avoid confusion
+       alias heterogen_id residue_id
      end #class Heterogen
  

Index: model.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/model.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** model.rb	8 Jan 2006 12:59:04 -0000	1.5
--- model.rb	9 Jan 2006 11:22:36 -0000	1.6
***************
*** 58,61 ****
--- 58,62 ----
          @structure = structure
          @chains = []
+         @chains_hash = {}
          @solvents = Chain.new('', self)
        end
***************
*** 80,84 ****
          raise "Expecting a Bio::PDB::Chain" unless chain.is_a? Bio::PDB::Chain
          @chains.push(chain)
!         self        
        end
        
--- 81,108 ----
          raise "Expecting a Bio::PDB::Chain" unless chain.is_a? Bio::PDB::Chain
          @chains.push(chain)
!         if @chains_hash[chain.chain_id] then
!           $stderr.puts "Warning: chain_id #{chain.chain_id.inspect} is already used" if $VERBOSE
!         else
!           @chains_hash[chain.chain_id] = chain
!         end
!         self
!       end
! 
!       # rehash chains hash
!       def rehash
!         begin
!           chains_bak = @chains
!           chains_hash_bak = @chains_hash
!           @chains = []
!           @chains_hash = {}
!           chains_bak.each do |chain|
!             self.addChain(chain)
!           end
!         rescue RuntimeError
!           @chains = chains_bak
!           @chains_hash = chains_hash_bak
!           raise
!         end
!         self
        end
        
***************
*** 108,112 ****
        # Keyed access to chains
        def [](key)
!         chain = @chains.find{ |chain| key == chain.id }
        end
        
--- 132,137 ----
        # Keyed access to chains
        def [](key)
!         #chain = @chains.find{ |chain| key == chain.id }
!         @chains_hash[key]
        end
        

Index: chain.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/chain.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** chain.rb	8 Jan 2006 12:59:04 -0000	1.4
--- chain.rb	9 Jan 2006 11:22:36 -0000	1.5
***************
*** 61,65 ****
--- 61,67 ----
          
          @residues   = []
+         @residues_hash = {}
          @heterogens = []
+         @heterogens_hash = {}
        end
  
***************
*** 80,90 ****
        # get the residue by id
        def get_residue_by_id(key)
!         @residues.find { |r| r.residue_id == key }
        end
  
        # get the residue by id.
!       # Compatibility Note: now, you cannot find HETATMS in this method.
!       # To add LIGAND to the id is no longer available.
!       # To get heterogens, you must use get_heterogen_by_id.
        def [](key)
          get_residue_by_id(key)
--- 82,94 ----
        # get the residue by id
        def get_residue_by_id(key)
!         #@residues.find { |r| r.residue_id == key }
!         @residues_hash[key]
        end
  
        # get the residue by id.
!       #
!       # Compatibility Note: Now, you cannot find HETATMS in this method.
!       # To add "LIGAND" to the id is no longer available.
!       # To get heterogens, you must use <code>get_heterogen_by_id</code>.
        def [](key)
          get_residue_by_id(key)
***************
*** 93,97 ****
        # get the heterogen (ligand) by id
        def get_heterogen_by_id(key)
!         @heterogens.find { |r| r.residue_id == key }
        end
        
--- 97,102 ----
        # get the heterogen (ligand) by id
        def get_heterogen_by_id(key)
!         #@heterogens.find { |r| r.residue_id == key }
!         @heterogens_hash[key]
        end
        
***************
*** 100,103 ****
--- 105,113 ----
          raise "Expecting a Bio::PDB::Residue" unless residue.is_a? Bio::PDB::Residue
          @residues.push(residue)
+         if @residues_hash[residue.residue_id] then
+           $stderr.puts "Warning: residue_id #{residue.residue_id.inspect} is already used" if $VERBOSE
+         else
+           @residues_hash[residue.residue_id] = residue
+         end
          self
        end
***************
*** 107,113 ****
          raise "Expecting a Bio::PDB::Residue" unless ligand.is_a? Bio::PDB::Residue
          @heterogens.push(ligand)
          self
        end
!       
        # Iterates over each residue
        def each(&x) #:yields: residue
--- 117,170 ----
          raise "Expecting a Bio::PDB::Residue" unless ligand.is_a? Bio::PDB::Residue
          @heterogens.push(ligand)
+         if @heterogens_hash[ligand.residue_id] then
+           $stderr.puts "Warning: heterogen_id (residue_id) #{ligand.residue_id.inspect} is already used" if $VERBOSE
+         else
+           @heterogens_hash[ligand.residue_id] = ligand
+         end
          self
        end
! 
!       # rehash residues hash
!       def rehash_residues
!         begin
!           residues_bak = @residues
!           residues_hash_bak = @residues_hash
!           @residues = []
!           @residues_hash = {}
!           residues_bak.each do |residue|
!             self.addResidue(residue)
!           end
!         rescue RuntimeError
!           @residues = residues_bak
!           @residues_hash = residues_hash_bak
!           raise
!         end
!         self
!       end
! 
!       # rehash heterogens hash
!       def rehash_heterogens
!         begin
!           heterogens_bak = @heterogens
!           heterogens_hash_bak = @heterogens_hash
!           @heterogens = []
!           @heterogens_hash = {}
!           heterogens_bak.each do |heterogen|
!             self.addLigand(heterogen)
!           end
!         rescue RuntimeError
!           @heterogens = heterogens_bak
!           @heterogens_hash = heterogens_hash_bak
!           raise
!         end
!         self
!       end
! 
!       # rehash residues hash and heterogens hash
!       def rehash
!         rehash_residues
!         rehash_heterogens
!       end
! 
        # Iterates over each residue
        def each(&x) #:yields: residue



More information about the bioruby-cvs mailing list