[BioRuby-cvs] bioruby/lib/bio/db/pdb chain.rb, 1.2, 1.3 model.rb,
1.2, 1.3 pdb.rb, 1.8, 1.9 residue.rb, 1.6, 1.7 utils.rb, 1.2, 1.3
Naohisa Goto
ngoto at pub.open-bio.org
Wed Jan 4 10:41:52 EST 2006
Update of /home/repository/bioruby/bioruby/lib/bio/db/pdb
In directory pub.open-bio.org:/tmp/cvs-serv12356
Modified Files:
chain.rb model.rb pdb.rb residue.rb utils.rb
Log Message:
* There are many changes. Some changes would not be listed below.
* general
* Now, heterogens are separately treated.
* Adding "LIGAND" to the id of the heterogens are no longer available.
* Waters (resName == "HOH") are now treated as normal heterogens.
However, Model#solvents is still available.
* utils.rb
* Added new modules HetatmFinder and HeterogenFinder.
* You can use #each_hetatm and #find_hetatm for Bio::PDB, Bio::PDB::Model,
Bio::PDB::Chain, and Bio::PDB::Heterogens.
* You can use #each_heterogen and #find_heterogen for Bio::PDB,
Bio::PDB::Model, and Bio::PDB::Chain.
* pdb.rb (Bio::PDB)
* Added PDB#models.
* model.rb (Bio::PDB::Model)
* added Model#chains and Model#solvents.
* fixed typo? in <=>.
* chain.rb (Bio::PDB::Chain)
* Now, Chain#id is an alias of Chain#chain_id.
* added Chain#residues and Chain#heterogens.
* residue.rb (Bio::PDB::Residue and Bio::PDB::Heterogen)
* added Residue#atoms and Heterogen#hetatms.
* added Heterogen#each_hetatm.
Index: residue.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/residue.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** residue.rb 4 Jan 2006 14:01:14 -0000 1.6
--- residue.rb 4 Jan 2006 15:41:50 -0000 1.7
***************
*** 31,34 ****
--- 31,35 ----
include Utils
include AtomFinder
+
include Enumerable
include Comparable
***************
*** 115,119 ****
@atoms.each{ |atom| yield atom }
end
! #Alias to override AtomFinder#each_atom
alias each_atom each
--- 116,120 ----
@atoms.each{ |atom| yield atom }
end
! # Alias to override AtomFinder#each_atom
alias each_atom each
***************
*** 143,163 ****
class Heterogen < Residue
! # Creates residue id from an ATOM (or HETATM) object.
! #
! # We add 'LIGAND' to the id if it's a HETATM.
! # I think this is neccessary because some PDB files reuse
! # numbers for HETATMS.
! def self.get_residue_id_from_atom(atom)
! 'LIGAND' + super
! end
!
! # Residue id is required because resSeq doesn't uniquely identify
! # a residue. ID is constructed from resSeq and iCode and is appended
! # to 'LIGAND' if the residue is a HETATM
! def update_residue_id
! super
! @residue_id = 'LIGAND' + @residue_id if @residue_id
! end
! private :update_residue_id
# If the residue is HETATM, returns true.
--- 144,148 ----
class Heterogen < Residue
! include HetatmFinder
# If the residue is HETATM, returns true.
***************
*** 166,169 ****
--- 151,159 ----
true
end
+
+ # Alias to override HetatmFinder#each_hetatm
+ alias each_hetatm each
+
+ alias hetatms atoms
end #class Heterogen
Index: utils.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/utils.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** utils.rb 8 Sep 2005 01:22:11 -0000 1.2
--- utils.rb 4 Jan 2006 15:41:50 -0000 1.3
***************
*** 231,234 ****
--- 231,260 ----
end
+ module HetatmFinder
+ def find_hetatm()
+ array = []
+ self.each_hetatm do |hetatm|
+ array.push(hetatm) if yield(hetatm)
+ end
+ return array
+ end
+ def each_hetatm(&x) #:yields: hetatm
+ self.each_heterogen { |heterogen| heterogen.each(&x) }
+ end
+ end
+
+ module HeterogenFinder
+ def find_heterogen()
+ array = []
+ self.each_heterogen do |heterogen|
+ array.push(heterogen) if yield(heterogen)
+ end
+ return array
+ end
+ def each_heterogen(&x) #:yields: heterogen
+ self.each_chain { |chain| chain.each_heterogen(&x) }
+ end
+ end
+
end; end #module Bio; class PDB
Index: model.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/model.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** model.rb 26 Sep 2005 13:00:08 -0000 1.2
--- model.rb 4 Jan 2006 15:41:50 -0000 1.3
***************
*** 33,42 ****
include ResidueFinder
include ChainFinder
include Enumerable
include Comparable
! attr_reader :model_serial, :structure, :solvent
! attr_writer :model_serial
!
def initialize(model_serial = nil, structure = nil)
--- 33,47 ----
include ResidueFinder
include ChainFinder
+
+ include HetatmFinder
+ include HeterogenFinder
+
include Enumerable
include Comparable
! attr_accessor :model_serial
! attr_reader :structure
! attr_reader :solvents
!
def initialize(model_serial = nil, structure = nil)
***************
*** 46,52 ****
@chains = Array.new
! @solvent = Chain.new('',self)
end
#Adds a chain
--- 51,60 ----
@chains = Array.new
! @solvents = Chain.new('', self)
end
+
+ attr_reader :chains
+ attr_reader :solvents
#Adds a chain
***************
*** 60,73 ****
def addSolvent(solvent)
raise "Expecting a Bio::PDB::Residue" if not solvent.is_a? Bio::PDB::Residue
! @solvent.addResidue(solvent)
end
def removeSolvent
! @solvent = nil
end
#Chain iterator
! def each
! @chains.each{ |chain| yield chain }
end
#Alias to override ChainFinder#each_chain
--- 68,81 ----
def addSolvent(solvent)
raise "Expecting a Bio::PDB::Residue" if not solvent.is_a? Bio::PDB::Residue
! @solvents.addResidue(solvent)
end
def removeSolvent
! @solvents = nil
end
#Chain iterator
! def each(&x) #:yields: chain
! @chains.each(&x)
end
#Alias to override ChainFinder#each_chain
***************
*** 76,80 ****
#Sorts models based on serial number
def <=>(other)
! return @mode_serial <=> other.model_serial
end
--- 84,88 ----
#Sorts models based on serial number
def <=>(other)
! return @model_serial <=> other.model_serial
end
Index: pdb.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/pdb.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** pdb.rb 4 Jan 2006 14:01:14 -0000 1.8
--- pdb.rb 4 Jan 2006 15:41:50 -0000 1.9
***************
*** 40,43 ****
--- 40,47 ----
include ChainFinder
include ModelFinder
+
+ include HetatmFinder
+ include HeterogenFinder
+
include Enumerable
***************
*** 1213,1219 ****
#Empty current model
cModel = Model.new
! cChain = Chain.new
! cResidue = Residue.new
! #cCompound = Heterogen.new
#Goes through each line and replace that line with a PDB::Record
--- 1217,1223 ----
#Empty current model
cModel = Model.new
! cChain = nil #Chain.new
! cResidue = nil #Residue.new
! cLigand = nil #Heterogen.new
#Goes through each line and replace that line with a PDB::Record
***************
*** 1238,1312 ****
# Do something for ATOM and HETATM
case key
when 'ATOM'
residueID = Residue.get_residue_id_from_atom(f)
- #p f
! if f.chainID == cChain.id
! chain = cChain
! elsif !(chain = cModel[f.chainID])
! #If we don't have chain, add a new chain
! newChain = Chain.new(f.chainID, cModel)
! cModel.addChain(newChain)
! cChain = newChain
! chain = newChain
! end
!
! if !newChain and residueID == cResidue.id
residue = cResidue
! elsif newChain or !(residue = chain[residueID])
! newResidue = Residue.new(f.resName, f.resSeq, f.iCode, chain)
! chain.addResidue(newResidue)
! cResidue = newResidue
! residue = newResidue
end
!
f.residue = residue
residue.addAtom(f)
when 'HETATM'
! #Each model has a special solvent chain
! #any chain id with the solvent is lost
! #I can fix this if really needed
! if f.resName == 'HOH'
! solvent = Heterogen.new(f.resName, f.resSeq, f.iCode,
! cModel.solvent)
! #p solvent
! f.residue = solvent
! solvent.addAtom(f)
! cModel.addSolvent(solvent)
!
else
!
! residueID = Heterogen.get_residue_id_from_atom(f)
! #p f
! #p residueID
!
! if f.chainID == cChain.id
! chain = cChain
! elsif !(chain = cModel[f.chainID])
! #If we don't have chain, add a new chain
! newChain = Chain.new(f.chainID, cModel)
! cModel.addChain(newChain)
! cChain = newChain
! chain = newChain
! end
!
! if !newChain and residueID == cResidue.id
! residue = cResidue
! elsif newChain or !(residue = chain[residueID])
! newResidue = Heterogen.new(f.resName, f.resSeq, f.iCode,
! chain)
! chain.addLigand(newResidue)
! cResidue = newResidue
! residue = newResidue
end
-
- f.residue = residue
- residue.addAtom(f)
-
end
when 'MODEL'
if cModel.model_serial
--- 1242,1306 ----
# Do something for ATOM and HETATM
+ if key == 'ATOM' or key == 'HETATM' then
+ if cChain and f.chainID == cChain.id
+ chain = cChain
+ else
+ if chain = cModel[f.chainID]
+ cChain = chain unless cChain
+ else
+ # If we don't have chain, add a new chain
+ newChain = Chain.new(f.chainID, cModel)
+ cModel.addChain(newChain)
+ cChain = newChain
+ chain = newChain
+ end
+ end
+ end
+
case key
when 'ATOM'
residueID = Residue.get_residue_id_from_atom(f)
! if cResidue and residueID == cResidue.id
residue = cResidue
! else
! if residue = chain.get_residue_by_id(residueID)
! cResidue = residue unless cResidue
! else
! # add a new residue
! newResidue = Residue.new(f.resName, f.resSeq, f.iCode, chain)
! chain.addResidue(newResidue)
! cResidue = newResidue
! residue = newResidue
! end
end
!
f.residue = residue
residue.addAtom(f)
when 'HETATM'
+ residueID = Heterogen.get_residue_id_from_atom(f)
! if cLigand and residueID == cLigand.id
! ligand = cLigand
else
! if ligand = chain.get_heterogen_by_id(residueID)
! cLigand = ligand unless cLigand
! else
! # add a new heterogen
! newLigand = Heterogen.new(f.resName, f.resSeq, f.iCode, chain)
! chain.addLigand(newLigand)
! cLigand = newLigand
! ligand = newLigand
! #Each model has a special solvent chain. (for compatibility)
! if f.resName == 'HOH'
! cModel.addSolvent(newLigand)
! end
end
end
+ f.residue = ligand
+ ligand.addAtom(f)
+
when 'MODEL'
if cModel.model_serial
***************
*** 1323,1327 ****
end #def initialize
! attr_reader :data, :hash
#Adds a Bio::Model to the current strucutre
--- 1317,1324 ----
end #def initialize
! attr_reader :data
! attr_reader :hash
!
! attr_reader :models
#Adds a Bio::Model to the current strucutre
Index: chain.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/pdb/chain.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** chain.rb 26 Sep 2005 13:00:08 -0000 1.2
--- chain.rb 4 Jan 2006 15:41:50 -0000 1.3
***************
*** 31,102 ****
include AtomFinder
include ResidueFinder
include Enumerable
include Comparable
- attr_reader :id, :model
- attr_writer :id
-
def initialize(id = nil, model = nil)
! @id = id
@model = model
! @residues = Array.new
! @ligands = Array.new
!
end
! #Keyed access to residues based on ids
def [](key)
! #If you want to find HETATMS you need to add LIGAND to the id
! if key.to_s[0,6] == 'LIGAND'
! residue = @ligands.find{ |residue| key.to_s == residue.id }
! else
! residue = @residues.find{ |residue| key.to_s == residue.id }
! end
end
#Add a residue to this chain
def addResidue(residue)
! raise "Expecting a Bio::PDB::Residue" if not residue.is_a? Bio::PDB::Residue
@residues.push(residue)
self
end
! #Add a ligand to this chain
! def addLigand(residue)
! raise "Expecting a Bio::PDB::Residue" if not residue.is_a? Bio::PDB::Residue
! @ligands.push(residue)
self
end
! #Residue iterator
! def each
! @residues.each{ |residue| yield residue }
end
#Alias to override ResidueFinder#each_residue
alias each_residue each
! #Sort based on chain id
def <=>(other)
! return @id <=> other.id
end
! #Stringifies each residue
def to_s
! string = ""
! @residues.each{ |residue| string << residue.to_s }
! string = string << "TER\n"
! return string
end
def atom_seq
string = ""
last_residue_num = nil
! @residues.each{ |residue|
if last_residue_num and
! (residue.resSeq.to_i - last_residue_num).abs > 1
! (residue.resSeq.to_i - last_residue_num).abs.times{ string << 'X' }
end
tlc = residue.resName.capitalize
--- 31,124 ----
include AtomFinder
include ResidueFinder
+
+ include HetatmFinder
+ include HeterogenFinder
+
include Enumerable
include Comparable
def initialize(id = nil, model = nil)
! @chain_id = id
@model = model
! @residues = []
! @heterogens = []
end
+
+ attr_accessor :chain_id
+ attr_reader :model
+
+ alias id chain_id
+
+ # residues in this chain
+ attr_reader :residues
+
+ # heterogens in this chain
+ attr_reader :heterogens
! # 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)
! end
!
! # get the heterogen (ligand) by id
! def get_heterogen_by_id(key)
! @heterogens.find { |r| r.residue_id == key }
end
#Add a residue to this chain
def addResidue(residue)
! raise "Expecting a Bio::PDB::Residue" unless residue.is_a? Bio::PDB::Residue
@residues.push(residue)
self
end
! #Add a heterogen (ligand) to this chain
! def addLigand(ligand)
! 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
! @residues.each(&x)
end
#Alias to override ResidueFinder#each_residue
alias each_residue each
+
+ # Iterates over each hetero-compound
+ def each_heterogen(&x) #:yields: heterogen
+ @heterogens.each(&x)
+ end
! # Operator aimed to sort based on chain id
def <=>(other)
! return @chain_id <=> other.chain_id
end
! # Stringifies each residue
def to_s
! @residues.join('') + "TER\n"
end
+ # gets an amino acid sequence of the chain
def atom_seq
string = ""
last_residue_num = nil
! @residues.each do |residue|
if last_residue_num and
! (x = (residue.resSeq.to_i - last_residue_num).abs) > 1 then
! x.times { string << 'X' }
end
tlc = residue.resName.capitalize
***************
*** 106,117 ****
end
string << olc
! }
Bio::Sequence::AA.new(string)
-
end
! end
! end
! end
--- 128,138 ----
end
string << olc
! end
Bio::Sequence::AA.new(string)
end
! end #class Chain
! end #class PDB
! end #module Bio
More information about the bioruby-cvs
mailing list