Skip to content

Commit 2a379bb

Browse files
author
Evgenii Osipov
committed
Merge branch 'findseq'
2 parents 83dd2e5 + c849d6e commit 2a379bb

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

findseq.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,6 @@
7070

7171

7272
def findseq(needle, haystack, selName=None, het=0, firstOnly=0):
73-
# set the name of the selection to return.
74-
if selName == None:
75-
rSelName = "foundSeq" + str(random.randint(0, 32000))
76-
selName = rSelName
77-
elif selName == "sele":
78-
rSelName = "sele"
79-
else:
80-
rSelName = selName
81-
82-
# input checking
83-
if not checkParams(needle, haystack, selName, het, firstOnly):
84-
print("There was an error with a parameter. Please see")
85-
print("the above error message for how to fix it.")
86-
return None
87-
8873
one_letter = {
8974
'00C': 'C', '01W': 'X', '0A0': 'D', '0A1': 'Y', '0A2': 'K',
9075
'0A8': 'C', '0AA': 'V', '0AB': 'V', '0AC': 'G', '0AD': 'G',
@@ -335,43 +320,58 @@ def findseq(needle, haystack, selName=None, het=0, firstOnly=0):
335320
'YG ': 'G', 'YOF': 'Y', 'YRR': 'N', 'YYG': 'G', 'Z ': 'C',
336321
'ZAD': 'A', 'ZAL': 'A', 'ZBC': 'C', 'ZCY': 'C', 'ZDU': 'U',
337322
'ZFB': 'X', 'ZGU': 'G', 'ZHP': 'N', 'ZTH': 'T', 'ZZJ': 'A'}
338-
339-
# remove hetero atoms (waters/ligands/etc) from consideration?
340-
if het:
341-
cmd.select("__h", "br. " + haystack)
323+
# set the name of the selection to return.
324+
if selName == None:
325+
rSelName = "foundSeq" + str(random.randint(0, 32000))
326+
selName = rSelName
327+
elif selName == "sele":
328+
rSelName = "sele"
342329
else:
343-
cmd.select("__h", "br. " + haystack + " and not het")
330+
rSelName = selName
331+
# make an empty selection to which we add residues
332+
cmd.select(rSelName, 'None')
333+
for obj in cmd.get_object_list(haystack):
334+
# input checking
335+
if not checkParams(needle, haystack, selName, het, firstOnly):
336+
print("There was an error with a parameter. Please see")
337+
print("the above error message for how to fix it.")
338+
return None
344339

345-
# get the AAs in the haystack
346-
aaDict = {'aaList': []}
347-
cmd.iterate("(name ca) and __h", "aaList.append((resi,resn,chain))", space=aaDict)
348340

349-
IDs = [x[0] for x in aaDict['aaList']]
350-
AAs = ''.join([one_letter[x[1]] for x in aaDict['aaList']])
351-
chains = [x[2] for x in aaDict['aaList']]
341+
# remove hetero atoms (waters/ligands/etc) from consideration?
342+
if het:
343+
cmd.select("__h", f"br. {obj} and {haystack}")
344+
else:
345+
cmd.select("__h", f"br. {obj} and {haystack} and not het")
352346

353-
reNeedle = re.compile(needle.upper())
354-
it = reNeedle.finditer(AAs)
347+
# get the AAs in the haystack
348+
aaDict = {'aaList': []}
349+
cmd.iterate("(name ca) and __h", "aaList.append((resi,resn,chain))", space=aaDict)
355350

356-
# make an empty selection to which we add residues
357-
cmd.select(rSelName, 'None')
351+
IDs = [x[0] for x in aaDict['aaList']]
352+
AAs = ''.join([one_letter[x[1]] for x in aaDict['aaList']])
353+
chains = [x[2] for x in aaDict['aaList']]
358354

359-
for i in it:
360-
(start, stop) = i.span()
361-
# we found some residues, which chains are they from?
362-
i_chains = chains[start:stop]
363-
# are all residues from one chain?
364-
if len(set(i_chains)) != 1:
365-
# now they are not, this match is not really a match, skip it
366-
continue
367-
chain = i_chains[0]
368-
# Only apply chains to selection algebra if there are defined chains.
369-
if chain:
370-
cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + " and c. " + chain + " )")
371-
else:
372-
cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + ")")
373-
if int(firstOnly):
374-
break
355+
reNeedle = re.compile(needle.upper())
356+
it = reNeedle.finditer(AAs)
357+
358+
359+
for i in it:
360+
(start, stop) = i.span()
361+
# we found some residues, which chains are they from?
362+
i_chains = chains[start:stop]
363+
# are all residues from one chain?
364+
if len(set(i_chains)) != 1:
365+
# now they are not, this match is not really a match, skip it
366+
continue
367+
chain = i_chains[0]
368+
# Only apply chains to selection algebra if there are defined chains.
369+
if chain:
370+
cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + " and c. " + chain + " )")
371+
else:
372+
cmd.select(rSelName, rSelName + " or (__h and i. " + '+'.join(IDs[ii] for ii in range(start, stop)) + ")")
373+
if int(firstOnly):
374+
break
375375
cmd.delete("__h")
376376
return rSelName
377377
cmd.extend("findseq", findseq)

0 commit comments

Comments
 (0)