Hi Kelvin,

that "fasta" command right now only dumps the sequence to the log window, it 
doesn't return or save the sequence to a file. This is probably because for my 
use case it was always sufficient to copy and paste the sequence from the log 
window. However, it's not too difficult to improve the script and hook it up to 
PyMOL's "save" command. See attachment, after running that script (which is 
independent of psico) you can do "save FileName.fasta".

Cheers,
  Thomas

'''
(c) 2012 Thomas Holder, MPI for Developmental Biology
(c) 2014 Thomas Holder, Schrodinger Inc.

License: BSD-2-Clause
'''

import pymol
from pymol import cmd

def fasta(selection='(all)', state=-1, gapped=1, wrap=70, quiet=1, _self=cmd):
    '''
DESCRIPTION

    Print sequence in FASTA format

ARGUMENTS

    selection = string: atom selection {default: all}

    state = integer: object state {default: -1}

    gapped = integer: put missing residues as dashes into the sequence {default: 1}

    wrap = integer: wrap lines, 0 for no wrapping {default: 70}
    '''
    try:
        from psico import one_letter
    except ImportError:
        from pymol.exporting import _resn_to_aa as one_letter
    state, gapped, wrap, quiet = int(state), int(gapped), int(wrap), int(quiet)
    selection = '(%s) and guide' % (selection)
    buf = []
    for obj in _self.get_object_list(selection):
        for chain in _self.get_chains('%s and (%s)' % (obj, selection), state):
            seq = []
            model = _self.get_model('/%s//%s//CA and (%s)' % (obj, chain, selection), state)
            prev_resi = 999999999
            for atom in model.atom:
                if gapped:
                    gap_len = max(0, atom.resi_number - prev_resi - 1)
                    seq.extend('-' * gap_len)
                    prev_resi = atom.resi_number
                seq.append(one_letter.get(atom.resn, 'X'))
            buf.append('>%s_%s\n' % (obj, chain))
            if wrap < 1:
                buf.extend(seq)
                buf.append('\n')
                continue
            for i in range(0, len(seq), wrap):
                buf.extend(seq[i:i+wrap])
                buf.append('\n')
    r = ''.join(buf)
    if not quiet:
        print r
    return r

cmd.extend('fasta', fasta)

cmd.auto_arg[0].update({
    'fasta'          : cmd.auto_arg[0]['zoom'],
})

# hook this up to saving *.fasta files
cmd.get_fastastr = pymol.exporting.get_fastastr = fasta

# vi: ts=4:sw=4:smarttab:expandtab
On 14 Apr 2014, at 08:00, Kelvin Luther <klut...@access.uzh.ch> wrote:

> Hello,
> 
> I've upgraded to the new version of PyMOL and created a pymolrc file 
> containing the import command for psico.  It seems to work. However, I don't 
> seem to be able to find documentation on how I can use the fasta command to 
> produce a file containing the sequence displayed.  When I type fasta, it 
> prints the fasta sequence to the command window with gaps maintained.  I've 
> then typed Save FileName.fasta, and it saves the sequence to a file, but the 
> gaps are now gone.  Is there a syntax mistake I'm making in the save command 
> that prevents it from saving exactly what is displayed?  I've tried to 
> copy/paste the data from the command window but I don't seem to be able to do 
> that either.  I thought perhaps everything in the command window would be 
> saved when I chose to save a log file, but it only saves the commands, not 
> the additional output displayed in the window.
> 
> Thanks for your time,
> 
> Kelvin Luther
> 
> On 31/03/2014 4:51 PM, Thomas Holder wrote:
>> Hi Kelvin,
>> 
>> the "psico" module provides a "fasta" command which maintains the gaps. 
>> However, psico will not work with PyMOL 0.99 which is quite old and uses an 
>> ancient Python version (psico requires Python 2.6 and and the PyMOL 1.2 API).
>> 
>> Psico installations instructions and download link:
>> http://pymolwiki.org/index.php/Psico
>> 
>> Cheers,
>>   Thomas
>> 
>> On 31 Mar 2014, at 05:13, Kelvin Luther <klut...@access.uzh.ch> wrote:
>>> Hello,
>>> 
>>> I am using PyMOL 0.99rc6.  I am wondering if there is a means to obtain
>>> a FASTA sequence from a loaded pdb file that maintains the gaps due to
>>> missing portions of the structure?  I found one program that will strip
>>> the sequence from pdb files, but it simply reads out the amino acids
>>> that are present linearly.  Gaps in the sequence are not maintained.  I
>>> can't imagine why that would be useful.  I have a large number of pdb
>>> files to deal with and would like to avoid having to align each pdb
>>> sequence to the gene just to recover the gaps.
>>> 
>>> Thanks for your time,
>>> 
>>> -- 
>>> Kelvin Luther
>>> Physiologische Institut
>>> Universität Zürich
> 
> -- 
> Kelvin Luther Ph.D.
> Physiologische Institut
> Universität Zürich

-- 
Thomas Holder
PyMOL Developer
Schrödinger, Inc.

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
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

Reply via email to