Skip to content

Commit

Permalink
added a check if isBB is set, otherwise set it
Browse files Browse the repository at this point in the history
  • Loading branch information
gregdp committed Dec 1, 2020
1 parent 5f086ac commit e725f50
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 33 deletions.
Binary file added download/mapq_chimera_1_6_3.zip
Binary file not shown.
102 changes: 70 additions & 32 deletions mapq_chimera/mapq.py
Expand Up @@ -78,8 +78,8 @@
isModelZ = False

dlgName = "mapqdlg"
dlgTitle = "MapQ (v1.6.2)"
dlgHelp = 'https://github.com/gregdp/segger'
dlgTitle = "MapQ (v1.6.3)"
dlgHelp = 'https://github.com/gregdp/mapq'

if isModelZ :
devMenu = False
Expand Down Expand Up @@ -110,6 +110,25 @@
}


atomColors = {'C' : chimera.MaterialColor (0.565,0.565,0.565),
'Cbb' : chimera.MaterialColor (0.2,0.6,0.2),
'S' : chimera.MaterialColor (1.000,1.000,0.188),
'O' : chimera.MaterialColor (1.000,0.051,0.051),
'N' : chimera.MaterialColor (0.188,0.314,0.973),
'P' : chimera.MaterialColor (1.0, 0.502, 0.0),
'H' : chimera.MaterialColor (0.9,.9,.9),
' ' : chimera.MaterialColor (0.2,1,.2),
"MG" : chimera.MaterialColor (0,1,0),
"NA" : chimera.MaterialColor (.6,.3,.6),
"CL" : chimera.MaterialColor (.2,.6,.2),
"CA" : chimera.MaterialColor (.4,.4,.6),
"ZN" : chimera.MaterialColor (.2,.8,.2),
"MN" : chimera.MaterialColor (.4,.4,.6),
"FE" : chimera.MaterialColor (.4,.4,.6),
"CO" : chimera.MaterialColor (.4,.4,.6),
"NI" : chimera.MaterialColor (.4,.4,.6)
}




Expand Down Expand Up @@ -468,8 +487,9 @@ def fillInUI(self, parent):
#self.showRibbon.set ( 1 )

self.showW = Tkinter.IntVar()
oft = Tkinter.Checkbutton( ff, text="W", variable=self.showW)
oft.grid(column = 43, row = 0, sticky = 'w')
if 0 :
oft = Tkinter.Checkbutton( ff, text="W", variable=self.showW)
oft.grid(column = 43, row = 0, sticky = 'w')


b = Tkinter.Button(ff, text="<", command=self.KeepBack)
Expand Down Expand Up @@ -960,9 +980,9 @@ def StrucSelected ( self, mol ) :
print "Selected ", mol.name, " - ", mol.id
if mol :

mlist = OML(modelTypes = [chimera.Molecule])
for m in mlist :
m.display = False
#mlist = OML(modelTypes = [chimera.Molecule])
#for m in mlist :
# m.display = False

mol.display = True

Expand Down Expand Up @@ -1494,6 +1514,10 @@ def SetDrawMode ( self, ress, showRibbon = None ) :
#c1 = (1.0,0.0,0.0,1)
for res in ress :
for at in res.atoms :

if not hasattr (res, 'isProt') :
SetBBAts (res.molecule)

if res.isProt or res.isNA :
at.drawMode = at.EndCap
at.display = True # not showRibbon
Expand Down Expand Up @@ -1550,15 +1574,6 @@ def ShowAts ( self ) :
for mod in chimera.openModels.list() :
if type(mod) == chimera.Molecule and mod.display == True :

#cid = "1"
#rs = [520, 521, 635, 575, 298, 550, 525, 639, 551, 303, 547, 305, 519]

cid = "4"
rs = [38, 42, 242, 244, 246, 181, 182, 135, 251, 94, 98, 91, 95, 284]

#cid = "E"
#rs = [128, 33, 136]

for res in mod.residues :
#if res.id.position in rs and res.id.chainId == cid :
if res.id.position in rs :
Expand Down Expand Up @@ -1588,6 +1603,10 @@ def HideSCs ( self ) :
#if res.id.position in rs and res.id.chainId == cid :
for at in res.atoms :
#at.drawMode = at.EndCap

if not hasattr (at, 'isBB') :
SetBBAts (at.molecule)

at.display = at.isBB
if at.residue.isNA :
at.display = at.isBB and not at.isSugar
Expand Down Expand Up @@ -2560,7 +2579,7 @@ def ShowQScores (self) :
scBB, scSC = [], []

for r in self.cur_mol.residues :
if cid == None or r.id.chainId == cid :
if cid == None or cid == "All" or r.id.chainId == cid :
if r.isProt or r.isNA :
r.score1 = r.scQ
r.score2 = r.bbQ
Expand All @@ -2577,21 +2596,20 @@ def ShowQScores (self) :
#bbRes = (self.avgScore - 6.1234) / -0.9191


#try :
scMin, scMax, scAvg = min(scSC), max(scSC), numpy.average(scSC)
bbMin, bbMax, bbAvg = min(scBB), max(scBB), numpy.average(scBB)
try :
scMin, scMax, scAvg = min(scSC), max(scSC), numpy.average(scSC)
bbMin, bbMax, bbAvg = min(scBB), max(scBB), numpy.average(scBB)


print "Average Q sc : %.2f - %.2f, avg %.2f" % (scMin, scMax, scAvg )
print "Average Q bb : %.2f - %.2f, avg %.2f" % (bbMin, bbMax, bbAvg )
print "Average Q sc : %.2f - %.2f, avg %.2f" % (scMin, scMax, scAvg )
print "Average Q bb : %.2f - %.2f, avg %.2f" % (bbMin, bbMax, bbAvg )

self.GetMaxScores()

self.GetMaxScores()
self.UpdateSeq ()

#except :
# pass
except :
pass

self.UpdateSeq ()



Expand Down Expand Up @@ -2764,7 +2782,7 @@ def GetQsFromFile (self) :
for at in ats :
if at.altLoc == aloc :
at.Q = bfac
at.bfactor = 100.0 * (1.0 - at.Q)
at.bfactor = 150.0 * (1.0 - at.Q)
#at.bfactor = 0

#at.occupancy = 1.0 # max(0,at.Q)
Expand Down Expand Up @@ -2797,7 +2815,12 @@ def GetQsFromFile (self) :
qscores.QStats1 (self.cur_mol, chainId)
qscores.SaveQStats ( self.cur_mol, self.chain.get(), self.cur_dmap, gSigma, float(self.mapRes.get()) )


if 0 :
self.SaveQsBfs ( self.cur_mol, 50.0 )
self.SaveQsBfs ( self.cur_mol, 100.0 )
self.SaveQsBfs ( self.cur_mol, 150.0 )
self.SaveQsBfs ( self.cur_mol, 200.0 )
self.SaveQsBfs ( self.cur_mol, 300.0 )

scBB, scSC = [], []

Expand Down Expand Up @@ -2847,6 +2870,20 @@ def GetQsFromFile (self) :
#self.QStatsRNA()



def SaveQsBfs ( self, mol, f ) :

for at in mol.atoms :
at.bfactor = f * (1.0 - at.Q)

molPath = os.path.splitext(mol.openedAs[0])[0]

nname = molPath + "__Bf%.0f__.pdb" % f
print " - saving %s" % nname
chimera.PDBio().writePDBfile ( [mol], nname )



def QStats ( self ) :

mol, dmap, chainId = self.cur_mol, self.cur_dmap, self.chain.get()
Expand Down Expand Up @@ -4927,7 +4964,7 @@ def Q_show (self) :


ats = [at for at in self.cur_mol.atoms if not at.element.name == "H"]
if at.showH.get() :
if self.showH.get() :
ats = self.cur_mol.atoms

points = _multiscale.get_atom_coordinates ( ats, transformed = False )
Expand Down Expand Up @@ -4981,12 +5018,12 @@ def Q_show (self) :

qs, yds, err = 0,0,0

if 1 :
if 0 :
rr = qscores.Qscore ( [selAtom], dmap, gSigma, allAtTree=allAtTree, show=1, log=1, numPts=20, toRAD=2.0, dRAD=0.5, minD=minD, maxD=maxD, fitg=1 )
qs, yds, err = rr

elif 1 :
rr = qscores.Qscore ( [selAtom], dmap, gSigma, allAtTree=allAtTree, show=0, log=1, numPts=50, toRAD=3.0, dRAD=0.1, minD=minD, maxD=maxD, fitg=1 )
rr = qscores.Qscore ( [selAtom], dmap, gSigma, allAtTree=allAtTree, show=0, log=1, numPts=30, toRAD=2.0, dRAD=0.1, minD=minD, maxD=maxD, fitg=0 )
qs, yds, err = rr

else :
Expand Down Expand Up @@ -8729,6 +8766,7 @@ def SetBBAts ( mol ) :
from chimera.resCode import nucleic3to1
from chimera.resCode import protein3to1
protein3to1['HSD'] = protein3to1['HIS']
protein3to1['HSE'] = protein3to1['HIS']

r.isProt = r.type in protein3to1
r.isNA = r.type in nucleic3to1
Expand Down
8 changes: 7 additions & 1 deletion mapq_chimera/qscores.py
Expand Up @@ -1888,9 +1888,13 @@ def CalcResQ (r, dmap, sigma, allAtTree=None, numPts=8, toRAD=2.0, dRAD=0.1, min

scQ, bbQ, Q, numSC, numBB = 0.0, 0.0, 0.0, 0.0, 0.0
for at in r.atoms :

if at.element.name == "H" :
continue

if not hasattr ( 'isBB' ) :
SetBBAts ( at.molecule )

if not hasattr ( at, 'Q' ) or not useOld :
#qs = Qscore ( [at], dmap, sigma, allAtTree=allAtTree, show=0, log=0, numPts=numPts, toRAD=toRAD, dRAD=dRAD, minD=minD, maxD=maxD )
at.Q = 0
Expand Down Expand Up @@ -2652,6 +2656,7 @@ def SetBBAts ( mol ) :
from chimera.resCode import nucleic3to1
from chimera.resCode import protein3to1
protein3to1['HSD'] = protein3to1['HIS']
protein3to1['HSE'] = protein3to1['HIS']

r.isProt = r.type in protein3to1
r.isNA = r.type in nucleic3to1
Expand Down Expand Up @@ -2705,13 +2710,14 @@ def SetBBAts ( mol ) :
if a.element.name == "H" :
a.isBB, a.isSC = False, False
continue

n = a.name

a.isBB = n=="P" or n=="O1P" or n=="O2P" or n=="OP1" or n=="OP2" or n=="O5'" or n=="C5'" or n=="O3'"
a.isSugar = n=="C1'" or n=="C2'" or n=="O4'" or n=="O2'" or n=="C3'" or n=="C4'"
a.isBB = a.isBB or a.isSugar

a.isBase = False
a.isBase = not a.isBB

if nucleic3to1[r.type] == "G" :
a.isBase = n=="N9" or n=="C8" or n=="N7" or n=="C5" or n=="C4" or n=="C6" or n=="O6" or n=="N1" or n=="C2" or n=="N2" or n=="N3"
Expand Down

0 comments on commit e725f50

Please sign in to comment.