Re: [PyMOL] New to PyMol. Want to extract sequence from .pse file w/ colors.

2012-02-27 Thread Thomas Holder

Hi Shane,

I have a script which saves a colored sequence in HTML format. See 
attachment.


Example usage:

run save_colored_fasta.py
save_colored_fasta seq.html

It should be possible to copypaste the colored sequence from your 
browser to excel.


Cheers,
  Thomas

Shane Neeley wrote, On 02/27/12 01:45:

Hi Pymol Network,

I would appreciate someones help in extracting the sequence in the
viewer above the protein. I have gone through the sequence and
changed AAs to different colors based on their position. I would
ideally like to be able to copy that sequence with the colors that
they are coded so that I could export it to an excel file. Is this
possible? 


Thanks very much.

Shane


--
Thomas Holder
MPI for Developmental Biology
Spemannstr. 35
D-72076 Tübingen
'''
(c) 2012 Thomas Holder, MPI for Developmental Biology

License: BSD-2-Clause
'''

from pymol import cmd

def save_colored_fasta(filename, selection='(all)', gapped=1, quiet=1):
'''
DESCRIPTION

Save a html file with colored (by C-alpha atoms) fasta sequence.

USAGE

save_colored_fasta filename [, selection [, gapped ]]
'''
from pymol.exporting import _resn_to_aa as one_letter
from pymol import Scratch_Storage
gapped = int(gapped)
selection = '(%s) and guide' % (selection)
html = []
stored = Scratch_Storage()
def callback(resv, resn, color):
if stored.resv is None:
stored.resv = resv - (resv % 70)
if gapped:
while stored.resv+1  resv:
callback(stored.resv+1, '-', 25)
stored.resv += 1
if stored.resv % 70 == 1:
html.append(('/font\nbr%4d font' % (resv)).replace(' ', 'nbsp;'))
stored.color = None
c = cmd.get_color_tuple(color)
color = '#%02x%02x%02x' % (c[0]*255, c[1]*255, c[2]*255)
aa = one_letter.get(resn, '-')
if color != stored.color:
html.append('/fontfont color=' + color + '')
stored.color = color
html.append(aa)
for obj in cmd.get_object_list(selection):
for chain in cmd.get_chains('model %s and (%s)' % (obj, selection)):
sele = 'model %s and chain %s and (%s)' % (obj, chain, selection)
html.append('\nbrgt;%s_%sfont' % (obj, chain))
stored.resv = None if gapped else 0
stored.color = None
cmd.iterate(sele, 'callback(resv, resn, color)', space=locals())
html.append('/font')
handle = open(filename, 'w')
print  handle, 'htmlbody style=font-family:monospace'
print  handle, ''.join(html)
print  handle, '/body/html'
handle.close()

cmd.extend('save_colored_fasta', save_colored_fasta)

cmd.auto_arg[1].update([
('save_colored_fasta', cmd.auto_arg[0]['zoom']),
])

# vi: ts=4:sw=4:smarttab:expandtab
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Re: [PyMOL] New to PyMol. Want to extract sequence from .pse file w/ colors.

2012-02-26 Thread Shane Neeley
Hi Pymol Network,

 I would appreciate someones help in extracting the sequence in the viewer
 above the protein. I have gone through the sequence and changed AAs to
 different colors based on their position. I would ideally like to be able
 to copy that sequence with the colors that they are coded so that I could
 export it to an excel file. Is this possible?

 Thanks very much.

 Shane

--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net