def testUpdateDataFile(self): """Test case - update data file """ self.lfh.write( "\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: # Create a initial data file -- # myDataList = [] curContainer = DataContainer("myblock") aCat = DataCategory("pdbx_seqtool_mapping_ref") aCat.appendAttribute("ordinal") aCat.appendAttribute("entity_id") aCat.appendAttribute("auth_mon_id") aCat.appendAttribute("auth_mon_num") aCat.appendAttribute("pdb_chain_id") aCat.appendAttribute("ref_mon_id") aCat.appendAttribute("ref_mon_num") aCat.append([9, 2, 3, 4, 5, 6, 7]) aCat.append([10, 2, 3, 4, 5, 6, 7]) aCat.append([11, 2, 3, 4, 5, 6, 7]) aCat.append([12, 2, 3, 4, 5, 6, 7]) #self.lfh.write("Assigned data category state-----------------\n") #aCat.dumpIt(fh=self.lfh) curContainer.append(aCat) myDataList.append(curContainer) ofh = open("test-output-1.cif", "w") pdbxW = PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() # # # Read and update the data - # myDataList = [] ifh = open("test-output-1.cif", "r") pRd = PdbxReader(ifh) pRd.read(myDataList) ifh.close() # myBlock = myDataList[0] myBlock.printIt() myCat = myBlock.getObj('pdbx_seqtool_mapping_ref') myCat.printIt() for iRow in xrange(0, myCat.getRowCount()): myCat.setValue('some value', 'ref_mon_id', iRow) myCat.setValue(100, 'ref_mon_num', iRow) ofh = open("test-output-2.cif", "w") pdbxW = PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() # except: traceback.print_exc(file=self.lfh) self.fail()
def testUpdateDataFile(self): """Test case - update data file """ self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: # Create a initial data file -- # myDataList=[] curContainer=DataContainer("myblock") aCat=DataCategory("pdbx_seqtool_mapping_ref") aCat.appendAttribute("ordinal") aCat.appendAttribute("entity_id") aCat.appendAttribute("auth_mon_id") aCat.appendAttribute("auth_mon_num") aCat.appendAttribute("pdb_chain_id") aCat.appendAttribute("ref_mon_id") aCat.appendAttribute("ref_mon_num") aCat.append([9,2,3,4,5,6,7]) aCat.append([10,2,3,4,5,6,7]) aCat.append([11,2,3,4,5,6,7]) aCat.append([12,2,3,4,5,6,7]) #self.lfh.write("Assigned data category state-----------------\n") #aCat.dumpIt(fh=self.lfh) curContainer.append(aCat) myDataList.append(curContainer) ofh = open("test-output-1.cif", "w") pdbxW=PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() # # # Read and update the data - # myDataList=[] ifh = open("test-output-1.cif", "r") pRd=PdbxReader(ifh) pRd.read(myDataList) ifh.close() # myBlock=myDataList[0] myBlock.printIt() myCat=myBlock.getObj('pdbx_seqtool_mapping_ref') myCat.printIt() for iRow in xrange(0,myCat.getRowCount()): myCat.setValue('some value', 'ref_mon_id',iRow) myCat.setValue(100, 'ref_mon_num',iRow) ofh = open("test-output-2.cif", "w") pdbxW=PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() # except: traceback.print_exc(file=self.lfh) self.fail()
def open_cif(cif_file): """ Assumes a mmCif file and returns a data block used for subsequent procedures """ # The "usual" procedure to open a mmCIF with pdbX/mmCIF with open(cif_file) as cif_fh: data = [] reader = PdbxReader(cif_fh) reader.read(data) block = data[0] return block
def testSimpleInitialization(self): """Test case - Simple initialization of a data category and data block """ self.lfh.write( "\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: # fn = "test-simple.cif" attributeNameList = [ 'aOne', 'aTwo', 'aThree', 'aFour', 'aFive', 'aSix', 'aSeven', 'aEight', 'aNine', 'aTen' ] rowList = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]] nameCat = 'myCategory' # # curContainer = DataContainer("myblock") aCat = DataCategory(nameCat, attributeNameList, rowList) aCat.printIt() curContainer.append(aCat) curContainer.printIt() # myContainerList = [] myContainerList.append(curContainer) ofh = open(fn, "w") pdbxW = PdbxWriter(ofh) pdbxW.write(myContainerList) ofh.close() myContainerList = [] ifh = open(fn, "r") pRd = PdbxReader(ifh) pRd.read(myContainerList) ifh.close() for container in myContainerList: for objName in container.getObjNameList(): name, aList, rList = container.getObj(objName).get() self.lfh.write("Recovered data category %s\n" % name) self.lfh.write("Attribute list %r\n" % repr(aList)) self.lfh.write("Row list %r\n" % repr(rList)) except: traceback.print_exc(file=self.lfh) self.fail()
def open_cif(self): """ Assumes a mmCif file and returns a data block used for subsequent procedures. """ # The "usual" procedure to open a mmCIF with pdbX/mmCIF try: with open(self.cif_path) as cif_fh: data = [] reader = PdbxReader(cif_fh) reader.read(data) return data[0] except: print "! Unexpected error during open_cif:", sys.exc_info()[0], in_file return None
def open_cif(self): """ Assumes a mmCif file and returns a data block used for subsequent procedures. """ # The "usual" procedure to open a mmCIF with pdbX/mmCIF with open(self.cif_path) as cif_fh: data = [] reader = PdbxReader(cif_fh) reader.read(data) if len(data) == 0: return None else: return data[0]
def testSimpleInitialization(self): """Test case - Simple initialization of a data category and data block """ self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: # fn="test-simple.cif" attributeNameList=['aOne','aTwo','aThree','aFour','aFive','aSix','aSeven','aEight','aNine','aTen'] rowList=[[1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10], [1,2,3,4,5,6,7,8,9,10] ] nameCat='myCategory' # # curContainer=DataContainer("myblock") aCat=DataCategory(nameCat,attributeNameList,rowList) aCat.printIt() curContainer.append(aCat) curContainer.printIt() # myContainerList=[] myContainerList.append(curContainer) ofh = open(fn, "w") pdbxW=PdbxWriter(ofh) pdbxW.write(myContainerList) ofh.close() myContainerList=[] ifh = open(fn, "r") pRd=PdbxReader(ifh) pRd.read(myContainerList) ifh.close() for container in myContainerList: for objName in container.getObjNameList(): name,aList,rList=container.getObj(objName).get() self.lfh.write("Recovered data category %s\n" % name) self.lfh.write("Attribute list %r\n" % repr(aList)) self.lfh.write("Row list %r\n" % repr(rList)) except: traceback.print_exc(file=self.lfh) self.fail()
def testReadSFDataFile(self): """Test case - read PDB structure factor data file and compute statistics on f/sig(f). """ self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: # myContainerList=[] ifh = open(self.pathSFDataFile, "r") pRd=PdbxReader(ifh) pRd.read(myContainerList) c0=myContainerList[0] # catObj=c0.getObj("refln") if catObj is None: return false nRows=catObj.getRowCount() # # Get column name index. # itDict={} itNameList=catObj.getItemNameList() for idxIt,itName in enumerate(itNameList): itDict[str(itName).lower()]=idxIt # idf=itDict['_refln.f_meas_au'] idsigf=itDict['_refln.f_meas_sigma_au'] minR=100 maxR=-1 sumR=0 icount=0 for row in catObj.getRowList(): try: f=float(row[idf]) sigf=float(row[idsigf]) ratio=sigf/f #self.lfh.write(" %f %f %f\n" % (f,sigf,ratio)) maxR=max(maxR,ratio) minR=min(minR,ratio) sumR+=ratio icount+=1 except: continue ifh.close() self.lfh.write("f/sig(f) min %f max %f avg %f count %d\n" % (minR, maxR, sumR/icount,icount)) except: traceback.print_exc(file=sys.stderr) self.fail()
def testReadDataFile(self): """Test case - read data file """ self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: # myDataList=[] ifh = open(self.pathPdbxDataFile, "r") pRd=PdbxReader(ifh) pRd.read(myDataList) ifh.close() except: traceback.print_exc(file=self.lfh) self.fail()
def testReadBigDataFile(self): """Test case - read data file """ self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: # myDataList=[] ifh = open(self.pathBigPdbxDataFile, "r") pRd=PdbxReader(ifh) pRd.read(myDataList) ifh.close() except: traceback.print_exc(file=sys.stderr) self.fail()
def testReadWriteDataFile(self): """Test case - data file read write test """ self.lfh.write( "\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name)) try: myDataList = [] ifh = open(self.pathPdbxDataFile, "r") pRd = PdbxReader(ifh) pRd.read(myDataList) ifh.close() ofh = open(self.pathOutputFile, "w") pWr = PdbxWriter(ofh) pWr.write(myDataList) ofh.close() except: traceback.print_exc(file=self.lfh) self.fail()
def open_cif(self): """ Assumes a mmCIF or gzipped mmCIF file and returns a data block used for subsequent procedures. """ # The "usual" procedure to open a mmCIF with pdbX/mmCIF data = [] try: with gzip.open(self.cif_path) as cif_fh: reader = PdbxReader(cif_fh) reader.read(data) except IOError: with open(self.cif_path) as cif_fh: reader = PdbxReader(cif_fh) reader.read(data) if len(data) == 0: return None else: return data[0]