def test_Procheck(self): cingDirTmpTest = os.path.join(cingDirTmp, getCallerName()) mkdirs(cingDirTmpTest) self.failIf(os.chdir(cingDirTmpTest), msg="Failed to change to test directory for files: " + cingDirTmpTest) runAqua = True showProcheckResults = False #entryId = "1ai0" # Most complex molecular system in any PDB NMR entry entryId = "1bus" # entryId = "1brv_1model" # Small much studied PDB NMR entry ranges = None if entryId.startswith("1brv"): ranges = "173-186" if entryId.startswith("1ai0"): ranges = "2-20" if entryId == "2hgh": # in the case of 2hgh this is not a problem because the residue numbering doesn't # overlap between the chain A protein and chain B RNA. ranges = "2-11,13-33,35-54" # 1 and 55 are 5' and 3' terminii which are a little looser. # 12, and 34 are bases that are not basepaired. ranges += ",104-105,115-136,145-190" # 106-114 is a loop # 137-144 is a loop # 191-193 are 3 Zn ions. #This leads to a procheck ranges file like: # RESIDUES 2 B 11 B # RESIDUES 13 B 33 B # RESIDUES 35 B 54 B # RESIDUES 104 A 105 A # RESIDUES 115 A 136 A # RESIDUES 145 A 190 A cingDirTmpTest = os.path.join(cingDirTmp, getCallerName()) mkdirs(cingDirTmpTest) self.failIf(os.chdir(cingDirTmpTest), msg="Failed to change to test directory for files: " + cingDirTmpTest) project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz") self.assertTrue(project.initCyana(cyanaFolder=cyanaFile)) project.molecule.setRanges(ranges) project.save() self.failIf( project.runProcheck(createPlots=True, runAqua=runAqua) is None) if showProcheckResults: for res in project.molecule.allResidues(): nTdebug(repr(res) + " " + repr(res.procheck.secStruct))
def testMolgrapRunFromPdbFile(self): # SETUP FIRST # entryId = "1ai0" # Most complex molecular system in any PDB NMR entry # entryId = "1a4d" # Small much studied PDB NMR entry # entryId = "1zwj" # X-ray entry of CESG interest. entryId = "1brv" # Small much studied PDB NMR entry # entryId = "2hgh_1model" # does it matter to import it just now? project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz") self.assertTrue(project.initCyana(cyanaFolder=cyanaFile)) project.save() gifFileName = entryId + ".gif" pathGif = os.path.join(self.cingDirTmpTest, gifFileName) self.assertFalse(project.molecule.export2gif(pathGif, project=project)) self.assertTrue(os.path.exists(pathGif)) pathMolGifPinup = pathGif[:-4] + '_pin.gif' self.assertTrue(os.path.exists(pathMolGifPinup)) pathGifDefault = os.path.join(cingPythonCingDir, 'PluginCode', DATA_STR, 'UnknownImage.gif') self.assertFalse( os.path.getsize(pathGif) == os.path.getsize(pathGifDefault)) nTmessage("Created new molecular imagery at: %s" % self.cingDirTmpTest)
def test_Procheck(self): cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() ) mkdirs( cingDirTmpTest ) self.failIf(os.chdir(cingDirTmpTest), msg = "Failed to change to test directory for files: " + cingDirTmpTest) runAqua = True showProcheckResults = False #entryId = "1ai0" # Most complex molecular system in any PDB NMR entry entryId = "1bus" # entryId = "1brv_1model" # Small much studied PDB NMR entry ranges = None if entryId.startswith("1brv"): ranges = "173-186" if entryId.startswith("1ai0"): ranges = "2-20" if entryId == "2hgh": # in the case of 2hgh this is not a problem because the residue numbering doesn't # overlap between the chain A protein and chain B RNA. ranges = "2-11,13-33,35-54" # 1 and 55 are 5' and 3' terminii which are a little looser. # 12, and 34 are bases that are not basepaired. ranges += ",104-105,115-136,145-190" # 106-114 is a loop # 137-144 is a loop # 191-193 are 3 Zn ions. #This leads to a procheck ranges file like: # RESIDUES 2 B 11 B # RESIDUES 13 B 33 B # RESIDUES 35 B 54 B # RESIDUES 104 A 105 A # RESIDUES 115 A 136 A # RESIDUES 145 A 190 A cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() ) mkdirs( cingDirTmpTest ) self.failIf(os.chdir(cingDirTmpTest), msg = "Failed to change to test directory for files: " + cingDirTmpTest) project = Project( entryId ) self.failIf( project.removeFromDisk() ) project = Project.open( entryId, status='new' ) cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz") self.assertTrue(project.initCyana(cyanaFolder = cyanaFile)) project.molecule.setRanges(ranges) project.save() self.failIf(project.runProcheck(createPlots=True, runAqua=runAqua) is None) if showProcheckResults: for res in project.molecule.allResidues(): nTdebug(repr(res) +" "+ repr(res.procheck.secStruct))
def _testCreateCcpn(self): 'Disabled test because...' cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() ) mkdirs( cingDirTmpTest ) self.failIf(os.chdir(cingDirTmpTest), msg = "Failed to change to test directory for files: " + cingDirTmpTest) for entryId in AllChecks.entryList: # Allow pdb files to be of different naming systems for this test. project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status = 'new') cyanaFolder = os.path.join(cingDirTestsData,"cyana", entryId+".cyana.tgz") nTdebug("Reading files from: " + cyanaFolder) project.initCyana( cyanaFolder) project.save() nTmessage( "Project: %s" % project) ccpnFolder = entryId + "New" self.assertTrue(project.saveCcpn(ccpnFolder))
def _testCreateCcpn(self): 'Disabled test because...' cingDirTmpTest = os.path.join(cingDirTmp, getCallerName()) mkdirs(cingDirTmpTest) self.failIf(os.chdir(cingDirTmpTest), msg="Failed to change to test directory for files: " + cingDirTmpTest) for entryId in AllChecks.entryList: # Allow pdb files to be of different naming systems for this test. project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') cyanaFolder = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz") nTdebug("Reading files from: " + cyanaFolder) project.initCyana(cyanaFolder) project.save() nTmessage("Project: %s" % project) ccpnFolder = entryId + "New" self.assertTrue(project.saveCcpn(ccpnFolder))
def test_shiftx(self): # entryId = "1brv" # Small much studied PDB NMR entry # entryId = "2hgh_1model" RNA-protein complex. entryId = "1brv" # entryId = "1tgq_1model" # withdrawn entry cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() ) mkdirs( cingDirTmpTest ) self.failIf(os.chdir(cingDirTmpTest), msg = "Failed to change to test directory for files: " + cingDirTmpTest) project = Project( entryId ) self.failIf( project.removeFromDisk()) project = Project.open( entryId, status='new' ) cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz") self.assertTrue(project.initCyana(cyanaFolder = cyanaFile)) project.runShiftx()
def test_shiftx(self): # entryId = "1brv" # Small much studied PDB NMR entry # entryId = "2hgh_1model" RNA-protein complex. entryId = "1brv" # entryId = "1tgq_1model" # withdrawn entry cingDirTmpTest = os.path.join(cingDirTmp, getCallerName()) mkdirs(cingDirTmpTest) self.failIf(os.chdir(cingDirTmpTest), msg="Failed to change to test directory for files: " + cingDirTmpTest) project = Project(entryId) self.failIf(project.removeFromDisk()) project = Project.open(entryId, status='new') cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz") self.assertTrue(project.initCyana(cyanaFolder=cyanaFile)) project.runShiftx()
def testMolgrapRunFromPdbFile(self): # SETUP FIRST # entryId = "1ai0" # Most complex molecular system in any PDB NMR entry # entryId = "1a4d" # Small much studied PDB NMR entry # entryId = "1zwj" # X-ray entry of CESG interest. entryId = "1brv" # Small much studied PDB NMR entry # entryId = "2hgh_1model" # does it matter to import it just now? project = Project( entryId ) self.failIf( project.removeFromDisk()) project = Project.open( entryId, status='new' ) cyanaFile = os.path.join(cingDirTestsData, "cyana", entryId + ".cyana.tgz") self.assertTrue(project.initCyana(cyanaFolder = cyanaFile)) project.save() gifFileName = entryId+".gif" pathGif = os.path.join( self.cingDirTmpTest, gifFileName) self.assertFalse(project.molecule.export2gif(pathGif, project=project)) self.assertTrue(os.path.exists(pathGif)) pathMolGifPinup = pathGif[:-4] + '_pin.gif' self.assertTrue(os.path.exists(pathMolGifPinup)) pathGifDefault = os.path.join( cingPythonCingDir, 'PluginCode', DATA_STR, 'UnknownImage.gif' ) self.assertFalse(os.path.getsize(pathGif) == os.path.getsize(pathGifDefault)) nTmessage("Created new molecular imagery at: %s" % self.cingDirTmpTest)
def testResPlot(self): actuallyRunProcheck = False actuallyRunWhatif = False showValues = False modelNum = 1 # Only used when simulating data #entryId = "1ai0" # Most complex molecular system in any PDB NMR entry # entryId = "2hgh" # Small much studied PDB NMR entry; 48 models # entryId = "1bus" # Small much studied PDB NMR entry: 5 models of 57 AA.: 285 residues. entryId = "1brv" ranges = None if entryId.startswith("2hgh"): # Compile a NTlist instance with residue objects. ranges = "2-54,111-136,145-193" # 1 and 55 are 5' and 3' terminii which are a little looser. # 12, and 34 are bases that are not basepaired. # 191-193 are bound ZN ions. elif entryId.startswith("1brv"): # Truncate from Val171-Glu189 to: ranges = "176-188" project = Project( entryId ) project.removeFromDisk() project = Project.open( entryId, status='new' ) cyanaFolder = os.path.join(cingDirTestsData,"cyana", entryId+".cyana.tgz") nTdebug("Reading files from: " + cyanaFolder) project.initCyana( cyanaFolder ) project.runDssp() rangeList = project.molecule.getFixedRangeList( max_length_range = ResPlot.MAX_WIDTH_IN_RESIDUES, ranges=ranges ) if actuallyRunProcheck: self.failIf(project.procheck(createPlots=False, runAqua=False) is None) if actuallyRunWhatif: self.assertFalse(runWhatif(project)) pointsANGCHK = [] # list per res in rangeList of lists pointsBNDCHK = [] pointsQUACHK = [] pointsRAMCHK = [] pointsC12CHK = [] pointsBBCCHK = [] resNumb = 0 for resList in rangeList: for res in resList: resNumb += 1 # nTdebug(repr(res)) # if random() < 0.2: # Skip a 10% # continue whatifResDict = res.setdefault(WHATIF_STR, NTdict()) procheckResDict = res.setdefault(PROCHECK_STR, NTdict()) # if not whatifResDict: # empty dict # continue angList = NTlist() bndList = NTlist() quaList = NTlist() ramList = NTlist() c12List = NTlist() bbcList = NTlist() accList = NTlist() sstList = NTlist() sstListPossibilities='SH' # secondary structure elements. for _modelID in range(modelNum): if not actuallyRunWhatif: angList.append(random()*10-0) # Simulate abs max of Z-scores. bndList.append(random()*5+1) # offset by 1 but still want to start from zero? quaList.append(random()*5+1) ramList.append(random()*5+1) c12List.append(random()*5+1) bbcList.append(random()*5+1) accList.append(random()*4-2) if not actuallyRunProcheck: sstList.append( sstListPossibilities[ int(random()*2)]) # Simulate secondary structure if not actuallyRunWhatif: self.assertFalse ( whatifResDict.setDeepByKeys(angList, ANGCHK_STR,VALUE_LIST_STR) ) self.assertFalse ( whatifResDict.setDeepByKeys(bndList, BNDCHK_STR,VALUE_LIST_STR) ) self.assertFalse ( whatifResDict.setDeepByKeys(quaList, QUACHK_STR,VALUE_LIST_STR) ) self.assertFalse ( whatifResDict.setDeepByKeys(ramList, RAMCHK_STR,VALUE_LIST_STR) ) self.assertFalse ( whatifResDict.setDeepByKeys(c12List, C12CHK_STR,VALUE_LIST_STR) ) self.assertFalse ( whatifResDict.setDeepByKeys(bbcList, BBCCHK_STR,VALUE_LIST_STR) ) self.assertFalse ( whatifResDict.setDeepByKeys(accList, INOCHK_STR,VALUE_LIST_STR) ) if not actuallyRunProcheck: self.assertFalse ( procheckResDict.setDeepByKeys(sstList, SECSTRUCT_STR) ) for d in [whatifResDict, procheckResDict]: checkIDList = d.keys() for checkID in checkIDList: if d==whatifResDict: valueList = d.getDeepByKeys(checkID,VALUE_LIST_STR) else: valueList = d.getDeepByKeys(checkID) if checkID == ANGCHK_STR: zScore = valueList.average()[0] pointsANGCHK.append( (resNumb-.5, zScore) ) elif checkID == BNDCHK_STR: zScore = valueList.average()[0] pointsBNDCHK.append( (resNumb-.5, zScore) ) elif checkID == QUACHK_STR: zScore = valueList.average()[0] pointsQUACHK.append( (resNumb-.5, zScore) ) elif checkID == RAMCHK_STR: zScore = valueList.average()[0] pointsRAMCHK.append( (resNumb-.5, zScore) ) elif checkID == C12CHK_STR: zScore = valueList.average()[0] pointsC12CHK.append( (resNumb-.5, zScore) ) elif checkID == BBCCHK_STR: zScore = valueList.average()[0] pointsBBCCHK.append( (resNumb-.5, zScore) ) # nTdebug("pointsBBCCHK: %s", pointsBBCCHK) if showValues: nTdebug("%10s valueList: %-80s" % ( checkID, valueList)) fileNameList =[] ps = None r = 0 for resList in rangeList: r += 1 # nTdebug("resList: %s" % resList) ps = NTplotSet() # closes any previous plots ps.hardcopySize = (600,600) nrows = 2 ntPlotList = [] for i in range(nrows): ntPlotList.append( ps.createSubplot(nrows,1,i+1,useResPlot=True,molecule=project.molecule,resList=resList) ) ps.subplotsAdjust(hspace = .1) # no height spacing between plots. ps.subplotsAdjust(top = 0.9) # Accommodate icons and res types. ps.subplotsAdjust(left = 0.15) # Accommodate extra Y axis label. attr = fontVerticalAttributes() attr.fontColor = 'blue' # Left of actual yLabel. labelAxesExtraList = [ 'Backbone', 'Quality', 'Angle', '', '' ] labelAxesList = [ 'Ramachandr. Z', 'Chi 1/2. Z', 'Bond max Z', 'Restraint RMSD', '' ] for i in range(nrows): position = (-0.12, 0.5) ntPlotList[i].labelAxes( position, labelAxesExtraList[i], attributes=attr) ntPlotList[i].yLabel = labelAxesList[i] if i != nrows-1: ntPlotList[i].xLabel = None plusPoint = pointAttributes( type='plus', size=1.5, color='black' ) circlePoint = pointAttributes( type='circle', size=1.5, color='blue') plusPoint.lineColor = 'black' circlePoint.lineColor = 'blue' length = ntPlotList[0].MAX_WIDTH_IN_RESIDUES start = (r-1)*length # pointsBBCCHK = removeNulls(pointsBBCCHK) # buildin max is overridden by matplotlib # end = NTmin(start + ntPlot1.MAX_WIDTH_IN_RESIDUES,len(pointsANGCHK)) pointsANGCHKOffset = convertPointsToPlotRange(pointsANGCHK, xOffset=-start, yOffset=0, start=0, length=length) pointsBNDCHKOffset = convertPointsToPlotRange(pointsBNDCHK, xOffset=-start, yOffset=0, start=0, length=length) pointsQUACHKOffset = convertPointsToPlotRange(pointsQUACHK, xOffset=-start, yOffset=0, start=0, length=length) pointsRAMCHKOffset = convertPointsToPlotRange(pointsRAMCHK, xOffset=-start, yOffset=0, start=0, length=length) pointsC12CHKOffset = convertPointsToPlotRange(pointsC12CHK, xOffset=-start, yOffset=0, start=0, length=length) pointsBBCCHKOffset = convertPointsToPlotRange(pointsBBCCHK, xOffset=-start, yOffset=0, start=0, length=length) pointsOffsetList = [pointsRAMCHKOffset, pointsQUACHKOffset, pointsANGCHKOffset ] pointsOffsetList2 = [pointsBBCCHKOffset, pointsC12CHKOffset, pointsBNDCHKOffset ] # nTdebug("pointsRAMCHKOffset: %s" % pointsRAMCHKOffset) # nTdebug("start:end: %s %s" % (start,end)) for i in range(nrows): if i >= len( pointsOffsetList ): continue ntPlotList[i].lines(pointsOffsetList[i], plusPoint) ntPlotList[i].lines(pointsOffsetList2[i], circlePoint) ntPlotList[i].autoScaleY( pointsOffsetList[i]+pointsOffsetList2[i] ) if i == 2: # by chance ntPlotList[i].setYrange((.0, ntPlotList[i].yRange[1])) ySpaceAxisResTypes = .02 + (nrows-1) * .01 ntPlotList[0].drawResTypes(ySpaceAxis=ySpaceAxisResTypes) # Weirdly can only be called after yRange is set. for i in range(nrows): showLabels = False if i == nrows-1: showLabels = True # also sets the grid lines for major. Do last as it won't rescale with plot yet. ntPlotList[i].drawResNumbers( showLabels=showLabels) # Draw secondary structure elements and accessibility # Set x range and major ticker. # The major ticker determines the grid layout. # leave space for res types but get it right on top. # .18 at nrows = 4 # Needs to be done before re-scaling the y axis from [0,1] ??????? ySpaceAxisResIcons = .06 + (nrows-1) * .04 ntPlotList[0].iconBoxYheight = 0.16 * nrows / 3. # .16 at nrows=3 ntPlotList[0].drawResIcons( ySpaceAxis=ySpaceAxisResIcons ) # Set the grid and major tickers fileNameList.append( 'residuePlotSet%03d.pdf' % r) ps.hardcopy(fileNameList[r-1]) # end for resList in rangeList: self.assertFalse( joinPdfPages( fileNameList, 'residuePlotSetAll.pdf' )) for fileName in fileNameList: os.unlink( fileName )