def test_write_data_file(self): """ Test writing CIF file """ myDataList = [] ofh = open(self.get_fn("test-output.cif", written=True), "w") 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((1, 2, 3, 4, 5, 6, 7)) aCat.append((1, 2, 3, 4, 5, 6, 7)) aCat.append((1, 2, 3, 4, 5, 6, 7)) aCat.append((1, 2, 3, 4, 5, 6, 7)) curContainer.append(aCat) myDataList.append(curContainer) pdbxW = PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() self.assertTrue( diff_files( self.get_fn('test-output.cif', saved=True), self.get_fn('test-output.cif', written=True), ))
def test_read_write_data_file(self): """Test case - data file read write test """ 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()
def testReadWriteDataFile(self): """Test case - data file read write test """ 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()
def test_update_data_file(self): """ Test writing another CIF file """ # Create a initial data file -- # myDataList = [] ofh = open(self.get_fn("test-output-1.cif", written=True), "w") 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((1, 2, 3, 4, 5, 6, 7)) aCat.append((1, 2, 3, 4, 5, 6, 7)) aCat.append((1, 2, 3, 4, 5, 6, 7)) aCat.append((1, 2, 3, 4, 5, 6, 7)) curContainer.append(aCat) myDataList.append(curContainer) pdbxW = PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() self.assertTrue( diff_files(self.get_fn('test-output-1.cif', saved=True), self.get_fn('test-output-1.cif', written=True))) # # Read and update the data - # myDataList = [] ifh = open(self.get_fn("test-output-1.cif", written=True), "r") pRd = PdbxReader(ifh) pRd.read(myDataList) ifh.close() # myBlock = myDataList[0] dest = open(self.get_fn('test_write_1.txt', written=True), 'w') myBlock.printIt(dest) myCat = myBlock.getObj('pdbx_seqtool_mapping_ref') myCat.printIt(dest) dest.close() for iRow in range(0, myCat.getRowCount()): myCat.setValue('some value', 'ref_mon_id', iRow) myCat.setValue(100, 'ref_mon_num', iRow) ofh = open(self.get_fn("test-output-2.cif", written=True), "w") pdbxW = PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() self.assertTrue( diff_files(self.get_fn('test-output-2.cif', saved=True), self.get_fn('test-output-2.cif', written=True))) self.assertTrue( diff_files(self.get_fn('test_write_1.txt', saved=True), self.get_fn('test_write_1.txt', written=True)))
def testWriteDataFile(self): """ Test writing CIF file """ myDataList=[] ofh = open(get_fn("test-output.cif", written=True), "w") 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((1,2,3,4,5,6,7)) aCat.append((1,2,3,4,5,6,7)) aCat.append((1,2,3,4,5,6,7)) aCat.append((1,2,3,4,5,6,7)) curContainer.append(aCat) myDataList.append(curContainer) pdbxW=PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() self.assertTrue(diff_files(get_saved_fn('test-output.cif'), get_fn('test-output.cif', written=True)))
def testUpdateDataFile(self): """ Test writing another CIF file """ # Create a initial data file -- # myDataList=[] ofh = open(get_fn("test-output-1.cif", written=True), "w") 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((1,2,3,4,5,6,7)) aCat.append((1,2,3,4,5,6,7)) aCat.append((1,2,3,4,5,6,7)) aCat.append((1,2,3,4,5,6,7)) curContainer.append(aCat) myDataList.append(curContainer) pdbxW=PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() self.assertTrue(diff_files(get_saved_fn('test-output-1.cif'), get_fn('test-output-1.cif', written=True))) # # Read and update the data - # myDataList=[] ifh = open(get_fn("test-output-1.cif", written=True), "r") pRd=PdbxReader(ifh) pRd.read(myDataList) ifh.close() # myBlock=myDataList[0] dest = open(get_fn('test_write_1.txt', written=True), 'w') myBlock.printIt(dest) myCat=myBlock.getObj('pdbx_seqtool_mapping_ref') myCat.printIt(dest) dest.close() for iRow in range(0,myCat.getRowCount()): myCat.setValue('some value', 'ref_mon_id',iRow) myCat.setValue(100, 'ref_mon_num',iRow) ofh = open(get_fn("test-output-2.cif", written=True), "w") pdbxW=PdbxWriter(ofh) pdbxW.write(myDataList) ofh.close() self.assertTrue(diff_files(get_saved_fn('test-output-2.cif'), get_fn('test-output-2.cif', written=True))) self.assertTrue(diff_files(get_saved_fn('test_write_1.txt'), get_fn('test_write_1.txt', written=True)))