Skip to content

Instantly share code, notes, and snippets.

@hochshi
Forked from JoaoRodrigues/diffseq.py
Created November 22, 2021 11:16
Show Gist options
  • Save hochshi/5e851679c6feb470890c9a6a1a901f08 to your computer and use it in GitHub Desktop.
Save hochshi/5e851679c6feb470890c9a6a1a901f08 to your computer and use it in GitHub Desktop.
PyMOL script to highlight mutated residues between two proteins
"""
(c) 2016 Joao Rodrigues
"""
from __future__ import print_function
from pymol import cmd
# Autocomplete
def _autocomplete():
return cmd.Shortcut(cmd.get_names())
cmd.auto_arg[0]['diffseq'] = [_autocomplete, 'object name', '']
cmd.auto_arg[1]['diffseq'] = [_autocomplete, 'object name', '']
def diffseq(objectA, objectB):
"""
DESCRIPTION
Highlight sequence differences between two proteins.
USAGE
diffseq protA, protB
"""
# Color white
cmd.color('white', '{} or {}'.format(objectA, objectB))
# Align
cmd.align(objectA, objectB, object='_aln')
# Map
def _id_to_resn(selection):
obj, at_id = selection
_s = {'_r': []}
cmd.iterate('{} and id {}'.format(obj, at_id),
'_r.append(resn)', space=_s)
return _s['_r'][0]
raw_aln = cmd.get_raw_alignment('_aln')
for resA, resB in raw_aln:
resn_A = _id_to_resn(resA)
resn_B = _id_to_resn(resB)
if resn_A != resn_B:
cmd.show('spheres', '{} and id {}'.format(*resA))
cmd.color('orange', '{} and id {}'.format(*resA))
cmd.show('spheres', '{} and id {}'.format(*resB))
cmd.color('orange', '{} and id {}'.format(*resB))
cmd.delete('_aln')
cmd.extend('diffseq', diffseq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment