class Bio::PDB
This is the main PDB class which takes care of parsing, annotations and is the entry way to the co-ordinate data held in models.
There are many related classes.
Bio::PDB::Model Bio::PDB::Chain Bio::PDB::Residue Bio::PDB::Heterogen Bio::PDB::Record::ATOM Bio::PDB::Record::HETATM Bio::PDB::Record::* Bio::PDB::Coordinate
Constants
- Coordinate_fileds
- DELIMITER
delimiter for reading via Bio::FlatFile
Attributes
all records in this entry as an array.
all records in this entry as an hash accessed by record names.
models in this entry (array).
Public Class Methods
Creates a new Bio::PDB object from given str.
# File lib/bio/db/pdb/pdb.rb, line 1445 def initialize(str) #Aha! Our entry into the world of PDB parsing, we initialise a PDB #object with the whole PDB file as a string #each PDB has an array of the lines of the original file #a bit memory-tastic! A hash of records and an array of models #also has an id @data = str.split(/[\r\n]+/) @hash = {} @models = [] @id = nil #Flag to say whether the current line is part of a continuation cont = false #Empty current model cModel = Model.new cChain = nil #Chain.new cResidue = nil #Residue.new cLigand = nil #Heterogen.new c_atom = nil #Goes through each line and replace that line with a PDB::Record @data.collect! do |line| #Go to next if the previous line was contiunation able, and #add_continuation returns true. Line is added by add_continuation next if cont and cont = cont.add_continuation(line) #Make the new record f = Record.get_record_class(line).new.initialize_from_string(line) #p f #Set cont cont = f if f.continue? #Set the hash to point to this record either by adding to an #array, or on it's own key = f.record_name if a = @hash[key] then a << f else @hash[key] = [ f ] end # 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 # chain might be changed, clearing cResidue and cLigand cResidue = nil cLigand = nil end end case key when 'ATOM' c_atom = f 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' c_atom = f 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' c_atom = nil cChain = nil cResidue = nil cLigand = nil if cModel.model_serial or cModel.chains.size > 0 then self.addModel(cModel) end cModel = Model.new(f.serial) when 'TER' if c_atom c_atom.ter = f else #$stderr.puts "Warning: stray TER?" end when 'SIGATM' if c_atom #$stderr.puts "Warning: duplicated SIGATM?" if c_atom.sigatm c_atom.sigatm = f else #$stderr.puts "Warning: stray SIGATM?" end when 'ANISOU' if c_atom #$stderr.puts "Warning: duplicated ANISOU?" if c_atom.anisou c_atom.anisou = f else #$stderr.puts "Warning: stray ANISOU?" end when 'SIGUIJ' if c_atom and c_atom.anisou #$stderr.puts "Warning: duplicated SIGUIJ?" if c_atom.anisou.siguij c_atom.anisou.siguij = f else #$stderr.puts "Warning: stray SIGUIJ?" end else c_atom = nil end f end #each #At the end we need to add the final model self.addModel(cModel) @data.compact! end
Public Instance Methods
Provides keyed access to the models based on serial number returns nil if it's not there
# File lib/bio/db/pdb/pdb.rb, line 1633 def [](key) @models.find{ |model| key == model.model_serial } end
Same as Bio::PDB#entry_id
.
# File lib/bio/db/pdb/pdb.rb, line 1887 def accession self.entry_id end
Adds a Bio::Model
object to the current strucutre. Adds a
model to the current structure. Returns self.
# File lib/bio/db/pdb/pdb.rb, line 1615 def addModel(model) raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model @models.push(model) self end
Classification in “HEADER”.
# File lib/bio/db/pdb/pdb.rb, line 1863 def classification f = self.record('HEADER').first f ? f.classification : nil end
Gets DBREF records. Returns an array of Bio::PDB::Record::DBREF objects.
If chainID is given, it returns corresponding DBREF records.
# File lib/bio/db/pdb/pdb.rb, line 1848 def dbref(chainID = nil) if chainID then self.record('DBREF').find_all { |f| f.chainID == chainID } else self.record('DBREF') end end
Title of this entry in “TITLE”.
# File lib/bio/db/pdb/pdb.rb, line 1892 def definition f = self.record('TITLE').first f ? f.title : nil end
Iterates over each model. Iterates over each of the models in the
structure. Returns self
.
# File lib/bio/db/pdb/pdb.rb, line 1624 def each @models.each{ |model| yield model } self end
PDB identifier written in “HEADER”. (e.g. 1A00)
# File lib/bio/db/pdb/pdb.rb, line 1878 def entry_id unless @id f = self.record('HEADER').first @id = f ? f.idCode : nil end @id end
Gets HELIX records. If no arguments are given, it returns all HELIX
records. (Returns an array of Bio::PDB::Record::HELIX
instances.) If helixID is given, it only returns records
corresponding to given helixID. (Returns an
Bio::PDB::Record::HELIX
instance.)
# File lib/bio/db/pdb/pdb.rb, line 1749 def helix(helixID = nil) if helixID then self.record('HELIX').find { |f| f.helixID == helixID } else self.record('HELIX') end end
returns a string containing human-readable representation of this object.
# File lib/bio/db/pdb/pdb.rb, line 1905 def inspect "#<#{self.class.to_s} entry_id=#{entry_id.inspect}>" end
Gets JRNL records. If no arguments, it returns all JRNL records as a hash. If sub record name is specified, it returns only corresponding records as an array of Bio::PDB::Record instances.
# File lib/bio/db/pdb/pdb.rb, line 1730 def jrnl(sub_record = nil) unless defined?(@jrnl) @jrnl = make_hash(self.record('JRNL'), :sub_record) end sub_record ? @jrnl[sub_record] : @jrnl end
Keywords in “KEYWDS”. Returns an array of string.
# File lib/bio/db/pdb/pdb.rb, line 1858 def keywords self.record('KEYWDS').collect { |f| f.keywds }.flatten end
Gets all records whose record type is name. Returns an array of
Bio::PDB::Record::*
objects.
if name is nil, returns hash storing all record data.
Example: p pdb.record('HETATM') p pdb.record
# File lib/bio/db/pdb/pdb.rb, line 1696 def record(name = nil) name ? (@hash[name] || []) : @hash end
Gets REMARK records. If no arguments, it returns all REMARK records as a hash. If remark number is specified, returns only corresponding REMARK records. If number == 1 or 2 (“REMARK 1” or “REMARK 2”), returns an array of Bio::PDB::Record instances. Otherwise, returns an array of strings.
# File lib/bio/db/pdb/pdb.rb, line 1711 def remark(nn = nil) unless defined?(@remark) h = make_hash(self.record('REMARK'), :remarkNum) h.each do |i, a| a.shift # remove first record (= space only) if i != 1 and i != 2 then a.collect! { |f| f.text.gsub(/\s+\z/, '') } end end @remark = h end nn ? @remark[nn] : @remark end
Amino acid or nucleic acid sequence of backbone residues in “SEQRES”. If chainID is given, it returns corresponding sequence as an array of string. Otherwise, returns a hash which contains all sequences.
# File lib/bio/db/pdb/pdb.rb, line 1802 def seqres(chainID = nil) unless defined?(@seqres) h = make_hash(self.record('SEQRES'), :chainID) newHash = {} h.each do |k, a| a.collect! { |f| f.resName } a.flatten! # determine nuc or aa? tmp = Hash.new(0) a[0,13].each { |x| tmp[x.to_s.strip.size] += 1 } if tmp[3] >= tmp[1] then # amino acid sequence a.collect! do |aa| #aa is three letter code: i.e. ALA #need to look up with Ala aa = aa.capitalize (begin Bio::AminoAcid.three2one(aa) rescue ArgumentError nil end || 'X') end seq = Bio::Sequence::AA.new(a.join('')) else # nucleic acid sequence a.collect! do |na| na = na.delete('^a-zA-Z') na.size == 1 ? na : 'n' end seq = Bio::Sequence::NA.new(a.join('')) end newHash[k] = seq end @seqres = newHash end if chainID then @seqres[chainID] else @seqres end end
Gets SHEET records. If no arguments are given, it returns all SHEET records
as an array of arrays of Bio::PDB::Record::SHEET
instances. If
sheetID is given, it returns an array of
Bio::PDB::Record::SHEET
instances.
# File lib/bio/db/pdb/pdb.rb, line 1777 def sheet(sheetID = nil) unless defined?(@sheet) @sheet = make_grouping(self.record('SHEET'), :sheetID) end if sheetID then @sheet.find_all { |f| f.first.sheetID == sheetID } else @sheet end end
Gets SSBOND records.
# File lib/bio/db/pdb/pdb.rb, line 1789 def ssbond self.record('SSBOND') end
Returns a string of Bio::PDB::Models. This propogates down the heirarchy till you get to Bio::PDB::Record::ATOM which are outputed in PDB format
# File lib/bio/db/pdb/pdb.rb, line 1647 def to_s string = "" @models.each{ |model| string << model.to_s } string << "END\n" return string end
Gets TURN records. If no arguments are given, it returns all TURN records.
(Returns an array of Bio::PDB::Record::TURN
instances.) If
turnId is given, it only returns a record corresponding to given
turnId. (Returns an Bio::PDB::Record::TURN
instance.)
# File lib/bio/db/pdb/pdb.rb, line 1764 def turn(turnId = nil) if turnId then self.record('TURN').find { |f| f.turnId == turnId } else self.record('TURN') end end
Current modification number in “REVDAT”.
# File lib/bio/db/pdb/pdb.rb, line 1898 def version f = self.record('REVDAT').first f ? f.modNum : nil end
Private Instance Methods
Takes an array and returns another array of PDB::Records
# File lib/bio/db/pdb/pdb.rb, line 1670 def make_grouping(ary, meth) a = [] k_prev = nil ary.each do |f| k = f.__send__(meth) if k_prev and k_prev == k then a.last << f else a << [] a.last << f end k_prev = k end a end
Makes a hash out of an array of PDB::Records and some kind of symbol .__send__ invokes the method specified by the symbol. Essentially it ends up with a hash with keys given in the sub_record Not sure I fully understand this
# File lib/bio/db/pdb/pdb.rb, line 1658 def make_hash(ary, meth) h = {} ary.each do |f| k = f.__send__(meth) h[k] = [] unless h.has_key?(k) h[k] << f end h end