def plotHisBySsTypeResTypes(): graphicsFormat = "png" doOnlyOverall = False # If set it will do a single ssType otherwise the overall. # for doOverall in [ False, True ]: for doOverall in [True]: if doOverall: ssTypeList = [None] else: ssTypeList = [' ', 'S', 'H'] for ssType in ssTypeList: #met-asp-leu for _i, resType in enumerate(common20AAList): if resType != 'PHE': continue for _j, resTypePrev in enumerate(common20AAList): if resTypePrev != 'SER': continue for _k, resTypeNext in enumerate(common20AAList): if resTypeNext != 'VAL': continue resTypeListBySequenceOrder = (resTypePrev, resType, resTypeNext) myHistList = getTripletHistogramList( resTypeListBySequenceOrder, doOnlyOverall=doOnlyOverall, ssTypeRequested=ssType, doNormalize=True) if myHistList == None: nTwarning( "Encountered an error getting the D1D2 hist for %s; skipping" % str(resTypeListBySequenceOrder)) continue if len(myHistList) != 1: nTdebug( "Expected exactly one but Found %s histogram for %s; skipping" % (len(myHistList), str(resTypeListBySequenceOrder))) continue myHist = deepcopy(myHistList[0]) # nTdebug("myHist: %s" % str(myHist)) myList = numpy.asarray(myHist).flatten() maxl = numpy.max(myList) sdl = numpy.std(myList) avl = numpy.average(myList) suml = numpy.sum(myList) n = 36 suml2 = avl * n * n if math.fabs(suml2 - suml) > 1: # Perhaps because sum is misinterpreted? msg = "Math is off for suml != suml2: %s != %s" % ( suml, suml2) nTerror(msg) if maxl > suml: msg = "Math is off for maxl > suml : %s != %s" % ( maxl, suml) nTerror(msg) vL = [] for value in (avl, sdl, maxl, suml): vL.append(locale.format('%12.3f', value, True)) strTitle = "av: %s sd: %s\nmax: %s sum: %s" % ( vL[0], vL[1], vL[2], vL[3]) nTdebug("myHist: %s" % strTitle) if True: # plot distribution itself too? clf() ps = NTplotSet() # closes any previous plots ps.hardcopySize = (500, 500) plotparams1 = plotParameters.getdefault( dihedralName1, 'dihedralDefault') plotparams2 = plotParameters.getdefault( dihedralName2, 'dihedralDefault') myplot = NTplot( title=strTitle, xRange=(plotparams1.min, plotparams1.max), xTicks=range(int(plotparams1.min), int(plotparams1.max + 1), plotparams1.ticksize), xLabel=dihedralName1, yRange=(plotparams2.min, plotparams2.max), yTicks=range(int(plotparams2.min), int(plotparams2.max + 1), plotparams2.ticksize), yLabel=dihedralName2) ps.addPlot(myplot) myplot.dihedralComboPlot([myHist], minPercentage=MIN_Z_D1D2, maxPercentage=MAX_Z_D1D2, scaleBy=SCALE_BY_Z, ssType=ssType) fn = 'd1d2_%s_%s-%s-%s' % (ssType, resTypePrev, resType, resTypeNext) if doOverall: fn += '_ov_' fn += "." + graphicsFormat ps.hardcopy(fn, graphicsFormat) if True: clf() hist(myList, 40) xlabel('triplet count') ylabel('number of occurrences') title(strTitle) fn = "plotHistOfHist_%s_%s_d1d2.%s" % ( ssType, str('-'.join(resTypeListBySequenceOrder)), graphicsFormat) savefig(fn) # end loop over ssType # end over ssType overall return
def plotHisBySsTypeResTypes(): graphicsFormat = "png" doOnlyOverall = False # If set it will do a single ssType otherwise the overall. # for doOverall in [ False, True ]: for doOverall in [ True ]: if doOverall: ssTypeList = [ None ] else: ssTypeList = [' ', 'S', 'H'] for ssType in ssTypeList: #met-asp-leu for _i, resType in enumerate(common20AAList): if resType != 'PHE': continue for _j, resTypePrev in enumerate(common20AAList): if resTypePrev != 'SER': continue for _k, resTypeNext in enumerate(common20AAList): if resTypeNext != 'VAL': continue resTypeListBySequenceOrder = (resTypePrev, resType , resTypeNext) myHistList = getTripletHistogramList(resTypeListBySequenceOrder, doOnlyOverall=doOnlyOverall, ssTypeRequested=ssType, doNormalize = True) if myHistList == None: nTwarning("Encountered an error getting the D1D2 hist for %s; skipping" % str(resTypeListBySequenceOrder)) continue if len(myHistList) != 1: nTdebug("Expected exactly one but Found %s histogram for %s; skipping" % (len(myHistList), str(resTypeListBySequenceOrder))) continue myHist = deepcopy(myHistList[0]) # nTdebug("myHist: %s" % str(myHist)) myList = numpy.asarray(myHist).flatten() maxl = numpy.max(myList) sdl = numpy.std(myList) avl = numpy.average(myList) suml = numpy.sum(myList) n = 36 suml2 = avl * n * n if math.fabs(suml2 - suml) > 1: # Perhaps because sum is misinterpreted? msg = "Math is off for suml != suml2: %s != %s" % (suml, suml2) nTerror(msg) if maxl > suml: msg = "Math is off for maxl > suml : %s != %s" % (maxl, suml) nTerror(msg) vL = [] for value in (avl, sdl, maxl, suml): vL.append( locale.format('%12.3f', value, True)) strTitle = "av: %s sd: %s\nmax: %s sum: %s" % (vL[0],vL[1],vL[2],vL[3]) nTdebug("myHist: %s" % strTitle) if True: # plot distribution itself too? clf() ps = NTplotSet() # closes any previous plots ps.hardcopySize = (500, 500) plotparams1 = plotParameters.getdefault(dihedralName1, 'dihedralDefault') plotparams2 = plotParameters.getdefault(dihedralName2, 'dihedralDefault') myplot = NTplot(title=strTitle, xRange=(plotparams1.min, plotparams1.max), xTicks=range(int(plotparams1.min), int(plotparams1.max + 1), plotparams1.ticksize), xLabel=dihedralName1, yRange=(plotparams2.min, plotparams2.max), yTicks=range(int(plotparams2.min), int(plotparams2.max + 1), plotparams2.ticksize), yLabel=dihedralName2) ps.addPlot(myplot) myplot.dihedralComboPlot([myHist], minPercentage=MIN_Z_D1D2, maxPercentage=MAX_Z_D1D2, scaleBy=SCALE_BY_Z, ssType = ssType) fn = 'd1d2_%s_%s-%s-%s' % (ssType, resTypePrev, resType, resTypeNext) if doOverall: fn += '_ov_' fn += "." + graphicsFormat ps.hardcopy(fn, graphicsFormat) if True: clf() hist(myList, 40) xlabel('triplet count') ylabel('number of occurrences') title(strTitle) fn = "plotHistOfHist_%s_%s_d1d2.%s" % (ssType, str('-'.join(resTypeListBySequenceOrder)), graphicsFormat) savefig(fn) # end loop over ssType # end over ssType overall return
def plotDihedralD1_2d(doOnlyOverall=True): graphicsFormat = "png" # minPercentage = MIN_Z_D1D2 # maxPercentage = MAX_Z_D1D2 # scaleBy = SCALE_BY_Z minPercentage = MIN_PERCENTAGE_D1D2 maxPercentage = MAX_PERCENTAGE_D1D2 scaleBy = SCALE_BY_SUM for resType in common20AAList: for resTypePrev in common20AAList: for resTypeNext in common20AAList: if resType != 'PHE': continue if resTypePrev != 'SER': continue if resTypeNext != 'VAL': continue # Plot a density background histList = [] resTypeListBySequenceOrder = [ resTypePrev, resType, resTypeNext ] titleStr = 'd1d2 %s-%s-%s' % (resTypePrev, resType, resTypeNext) # nTmessage("plotting: %s" % titleStr) # important to switch to temp space before starting to generate files for the project. # project = Project('testPlotHistoDihedrald1d2') plotparams1 = plotParameters.getdefault( dihedralName1, 'dihedralDefault') plotparams2 = plotParameters.getdefault( dihedralName2, 'dihedralDefault') hist1 = getDeepByKeys(hPlot.histd1ByResTypes, resType, resTypePrev) # hist2 = getDeepByKeys(hPlot.histd1ByResTypes, resTypeNext, resType) #L if hist1 == None: nTdebug('skipping for hist1 is empty for [%s] [%s]' % (resType, resTypePrev)) continue if hist2 == None: nTdebug('skipping for hist2 is empty for [%s] [%s]' % (resType, resTypeNext)) continue sumh1 = sum(hist1) sumh2 = sum(hist2) titleStr += ' %d-%d' % (sumh1, sumh2) # if doOnlyOverall: histList = getTripletHistogramList( resTypeListBySequenceOrder, doOnlyOverall=doOnlyOverall, ssTypeRequested=None, doNormalize=False, normalizeSeparatelyToZ=False) # else: # titleStr += '\n' # histList = getTripletHistogramList(resTypeListBySequenceOrder, doOnlyOverall = doOnlyOverall, #ssTypeRequested = None, doNormalize = True, normalizeSeparatelyToZ = True) # scaleBy = SCALE_BY_ONE ps = NTplotSet() # closes any previous plots ps.hardcopySize = (500, 500) myplot = NTplot(title=titleStr, xRange=(plotparams1.min, plotparams1.max), xTicks=range(int(plotparams1.min), int(plotparams1.max + 1), plotparams1.ticksize), xLabel=dihedralName1, yRange=(plotparams2.min, plotparams2.max), yTicks=range(int(plotparams2.min), int(plotparams2.max + 1), plotparams2.ticksize), yLabel=dihedralName2) ps.addPlot(myplot) myplot.dihedralComboPlot(histList, minPercentage=minPercentage, maxPercentage=maxPercentage, scaleBy=scaleBy) fn = 'd1d2_%s-%s-%s' % (resTypePrev, resType, resTypeNext) if doOnlyOverall: fn += '_ov_' fn += "." + graphicsFormat # savefig(fn) ps.hardcopy(fn, graphicsFormat)
def plotDihedralD1_2d(doOnlyOverall=True): graphicsFormat = "png" # minPercentage = MIN_Z_D1D2 # maxPercentage = MAX_Z_D1D2 # scaleBy = SCALE_BY_Z minPercentage = MIN_PERCENTAGE_D1D2 maxPercentage = MAX_PERCENTAGE_D1D2 scaleBy = SCALE_BY_SUM for resType in common20AAList: for resTypePrev in common20AAList: for resTypeNext in common20AAList: if resType != 'PHE': continue if resTypePrev != 'SER': continue if resTypeNext != 'VAL': continue # Plot a density background histList = [] resTypeListBySequenceOrder = [ resTypePrev, resType, resTypeNext ] titleStr = 'd1d2 %s-%s-%s' % ( resTypePrev, resType, resTypeNext ) # nTmessage("plotting: %s" % titleStr) # important to switch to temp space before starting to generate files for the project. # project = Project('testPlotHistoDihedrald1d2') plotparams1 = plotParameters.getdefault(dihedralName1, 'dihedralDefault') plotparams2 = plotParameters.getdefault(dihedralName2, 'dihedralDefault') hist1 = getDeepByKeys(hPlot.histd1ByResTypes, resType, resTypePrev) # hist2 = getDeepByKeys(hPlot.histd1ByResTypes, resTypeNext, resType) #L if hist1 == None: nTdebug('skipping for hist1 is empty for [%s] [%s]' % (resType, resTypePrev)) continue if hist2 == None: nTdebug('skipping for hist2 is empty for [%s] [%s]' % (resType, resTypeNext)) continue sumh1 = sum(hist1) sumh2 = sum(hist2) titleStr += ' %d-%d' % (sumh1, sumh2) # if doOnlyOverall: histList = getTripletHistogramList(resTypeListBySequenceOrder, doOnlyOverall = doOnlyOverall, ssTypeRequested = None, doNormalize = False, normalizeSeparatelyToZ = False) # else: # titleStr += '\n' # histList = getTripletHistogramList(resTypeListBySequenceOrder, doOnlyOverall = doOnlyOverall, #ssTypeRequested = None, doNormalize = True, normalizeSeparatelyToZ = True) # scaleBy = SCALE_BY_ONE ps = NTplotSet() # closes any previous plots ps.hardcopySize = (500, 500) myplot = NTplot(title=titleStr, xRange=(plotparams1.min, plotparams1.max), xTicks=range(int(plotparams1.min), int(plotparams1.max + 1), plotparams1.ticksize), xLabel=dihedralName1, yRange=(plotparams2.min, plotparams2.max), yTicks=range(int(plotparams2.min), int(plotparams2.max + 1), plotparams2.ticksize), yLabel=dihedralName2) ps.addPlot(myplot) myplot.dihedralComboPlot(histList, minPercentage=minPercentage, maxPercentage=maxPercentage, scaleBy=scaleBy) fn = 'd1d2_%s-%s-%s' % (resTypePrev, resType, resTypeNext) if doOnlyOverall: fn += '_ov_' fn += "." + graphicsFormat # savefig(fn) ps.hardcopy(fn, graphicsFormat)