Created
May 5, 2017 09:06
-
-
Save latticetower/29b37cfe2050a890265727f8eaf21b0c to your computer and use it in GitHub Desktop.
Example code with iteration over pdb file chains with sliding window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from prody import * | |
pdb = parsePDB("1QS3") | |
def sliding_window(aminoacids, width=3): | |
""" | |
iterates over residues in given chain, returns iterator | |
with arrays containing each width elements (as a sliding window) | |
""" | |
index = 1 # prody starts iteration from 1, or at least it seems | |
aa_list = [ aminoacids[index + offset] for offset in xrange(width) ] | |
yield aa_list | |
offset = 0 | |
while width+offset < len(aminoacids): | |
aa_list.pop(0) | |
aa_list.append(aminoacids[width + offset]) | |
yield aa_list | |
offset += 1 | |
def get_angles(fragment): | |
""" | |
gets list of Aminoacid elements as an input | |
returns list of torsion angles (phi, psi) for all atoms except first and last in list | |
""" | |
return [ | |
(prody.measure.measure.calcPhi(x), prody.measure.measure.calcPsi(x)) | |
for x in fragment[1:len(fragment) - 1] | |
] | |
def get_aminoacid_sequence(fragment): | |
""" | |
gets list of Aminoacid elements as an input | |
returns aminoacid sequence as a string containing 1-letter IUPAC codes | |
""" | |
get = prody.atomic.chain.AAMAP.get | |
return ''.join([get(res.getResname(), 'X') for res in fragment]) | |
print(pdb) | |
for chain in pdb.getHierView(): | |
for fragment in sliding_window(chain): | |
print(fragment) | |
print(get_aminoacid_sequence(fragment)) # this should be converted to smiles string | |
print(get_angles(fragment)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment