Advertisement
Guest User

Untitled

a guest
May 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.37 KB | None | 0 0
  1. Q. What happens if I try to add an entity (e.g atom) to a another entity (e.g.
  2. residue) if it is already there?
  3.  
  4. A. A PyCogent Entity is a subclass of a dictionary. Adding children is
  5. essentially the same as updating a dictionary, with a minimal amount of
  6. book-keeping. It is equivalent to the following:
  7.  
  8. child.setParent(parent)
  9. child_id = child.getId()
  10. parent[child_id] = child
  11. parent.setModified(True, False)
  12.  
  13. This points the child entity to it's new parent (line 1) and adds the child to the
  14. parent dictionary (line 3). The call to ``setModified`` notifies all parents
  15. of the parent of the modification. A dictionary has unique keys and so a parent
  16. has children with unique ids. If you try to add a child which has an id clash
  17. it will update the parent and override the previous child.
  18.  
  19.  
  20. Q. Why are the short ids inside a tuple?
  21.  
  22. A. Short ids are parts of a long id. The long id is a tuple. Short ids can be
  23. concatenated to form a long id. This would not be possible if short ids were not
  24. within a tuple initially. For example:
  25.  
  26. >>> (0,) + ('A',) + (('GLY', 209, ' '),) + (('C', ' '),)
  27. (0, 'A', ('GLY', 209, ' '), ('C', ' '))
  28.  
  29. The output here is a valid long_id.
  30.  
  31. Q. How do I select children of a ``MultiEntity`` instance by some feature.
  32.  
  33. A. Selection is a common task and ``PyCogent`` has a unified syntax for this via the
  34. ``selectChildren`` method. The idea behind it is as follows:
  35.  
  36.    #. gather ""requested data" from all children.
  37.    #. compare compare each child_value to the template "value"" using the
  38.       "operator"
  39.    #. return children for which the comparison is ``True``
  40.  
  41. The signature of this method is selectChildren("value", "operator", "requested data")
  42. In the first step all children return the "requested data", the request might be
  43. the an attribute, a value corresponding to a key in the ``parent.xtra``
  44. dictionary or any other query supported by the ``getData`` method.
  45.  
  46.  
  47. >>> from cogent.parse.pdb import PDBParser
  48. >>> pdb_fh = open('1HQF.pdb')
  49. >>> pdb_structure = PDBParser(pdb_fh)
  50. >>> model = pdb_structure[(0,)]
  51. >>> chainA = model[('A',)]
  52.  
  53. Example 1: select all alanines from a chain.
  54.  
  55. >>> alanines = chainA.selectChildren('ALA', 'eq', 'name')
  56.  
  57. This requests the "name" attribute from all children in chain A and uses the
  58. "eq" (equals) operator to compare this to "ALA". It returns a list of residues
  59. which have this name.
  60.  
  61. Example 2: select all residues, which are not amino acids or nucleic acids.
  62.  
  63. >>> selection = chainA.selectChildren('H', 'eq', 'h_flag')
  64.  
  65. This requests the "h_flag" i.e. hetero-atom flag from all residues. For amino
  66. acids and nucleic acids this should be "" for all other molecular entities "H",
  67. so the function returns only ligands, waters etc.
  68.  
  69. Example 3: What if some children have data to return?
  70.  
  71. First we pick out a residue and modify it's xtra dictionary to contain some
  72. custom data. We mark lys39 as a catalytic residue.
  73.  
  74. >>> lys39 = chainA[(('LYS', 39, ' '),)]
  75. >>> lys39.xtra['CATALYTIC'] = True
  76.  
  77. All other residues do not have a value corresponding to the "CATALYTIC" key. But
  78. we still can select all "CATALYTIC" residues in chain A.
  79.  
  80. >>> catalytic = chainA.selectChildren(True, 'eq', 'CATALYTIC', xtra=True)
  81. >>> catalytic
  82. {(('LYS', 39, ' '),): <Residue LYS resseq=39 icode= >}
  83.  
  84. The difference is that we have requested a value from the "xtra" dictionary
  85. instead of a hypothetical "CATALYTIC" residue.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement