I built this to be rather flexible. You call it as:
I built this to be rather flexible. You call it as:
<source lang="python">findSeq needle, haystack[, selName[, het[, firstOnly ]]]</source> where the options are:
<source lang="python">findseq needle, haystack[, selName[, het[, firstOnly ]]]</source> where the options are:
:: '''needle''' the sequence of amino acids to find. Should be a string of one letter amino acid abbreviations. Can also be a string-style regular expression (eg. FW.*QQ).
:: '''needle''' the sequence of amino acids to find. Should be a string of one letter amino acid abbreviations. Can also be a string-style regular expression (eg. FW.*QQ).
:: '''haystack''' the PyMOL object or selection in which to search
:: '''haystack''' the PyMOL object or selection in which to search
Line 30:
Line 30:
:: '''het''' 0/1 -- if 0 then heteroatoms are not considered; if 1 then they are; defaults to 0
:: '''het''' 0/1 -- if 0 then heteroatoms are not considered; if 1 then they are; defaults to 0
:: '''firstOnly''' 0/1 -- if 0 then all matches are selected and returned; if 1 then only the first is returned
:: '''firstOnly''' 0/1 -- if 0 then all matches are selected and returned; if 1 then only the first is returned
= The Code =
<source lang="python">
# -*- coding: utf-8 -*-
#
# -- seqFinder.py
#
# Finds given amino acids in a protein & returns the selection.
# make an empty selection to which we add residues
cmd.select( rSelName, 'None')
for i in it:
(start,stop) = i.span()
cmd.select( rSelName, rSelName + " __h and i. " + str(IDs[start]) + "-" + str(IDs[stop-1]))
if int(firstOnly):
break
cmd.delete("__h")
return rSelName
cmd.extend("findSeq", seqFinder )
</source>
[[Category:Script_Library]]
[[Category:Script_Library]]
[[Category:ObjSel_Scripts]]
[[Category:ObjSel_Scripts]]
Revision as of 23:12, 13 January 2012
Overview & Motivation
Anyone ever give you a protein and then say, find the sequence "FLVEW"? Well, this script will find any string or regular expression in a given object and return that selection for you. Here's an example,
reinitializeimportfindseq# fetch two sugar-binding PDBfetch1tvn,async=0# Now, find FATEW in 1tvn, similarlyfindseqFATEW,1tvn# lower-case works, toofindseqfatew,1tvn# how about a regular expression?findseqF.*W,1tvn# Find the regular expression:# ..H[TA]LVWH# in the few proteins loaded.# I then showed them as sticks and colored them to highlight matched AAsforxincmd.get_names():findseq.findseq("..H[TA]LVWH",x,"sele_"+x,firstOnly=1)
Red residues were those matching the regular expression '..H[TA]LVWH'.
Usage
I built this to be rather flexible. You call it as:
needle the sequence of amino acids to find. Should be a string of one letter amino acid abbreviations. Can also be a string-style regular expression (eg. FW.*QQ).
haystack the PyMOL object or selection in which to search
selName the name of the returned selection. If you leave this blank, it'll be foundSeqXYZ where XYZ is some random integer (eg. foundSeq1435); if you supply sele then the usual PyMOL (sele) is used; and, finally, if it's anything else, then that will be used verbatim. Defaults to foundSeqXYZ so as not to overwrite any selections you might have in sele.
het 0/1 -- if 0 then heteroatoms are not considered; if 1 then they are; defaults to 0
firstOnly 0/1 -- if 0 then all matches are selected and returned; if 1 then only the first is returned