Method: Bio::PDB#seqres

Defined in:
lib/bio/db/pdb/pdb.rb

#seqres(chainID = nil) ⇒ Object

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.



1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
# File 'lib/bio/db/pdb/pdb.rb', line 1801

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.to_s)
      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.to_s)
      end
      newHash[k] = seq
    end
    @seqres = newHash
  end
  if chainID then
    @seqres[chainID]
  else
    @seqres
  end
end