Exemplo n.º 1
0
    def test_update_attribute(self, rw_data):
        ifn = rw_data['pathBigPdbxDataFile']
        ofn = rw_data['pathOutputFile2']
        myContainerList = []
        with open(str(ifn), "r") as ifh:
            pRd = PdbxReader(ifh)
            pRd.read(myContainerList)
        #
        dsId = "D_000000"
        atName = 'entry_id'
        for container in myContainerList:
            container.setName(dsId)
            # remove category citation
            container.remove('citation')
            for objName in container.getObjNameList():
                dcObj = container.getObj(objName)
                if dcObj.hasAttribute(atName):
                    for iRow in range(0, dcObj.getRowCount()):
                        dcObj.setValue(dsId, attributeName=atName, rowIndex=iRow)
                elif objName.lower() == 'entry':
                    dcObj.setValue(dsId, attributeName='id', rowIndex=0)

        #
        with open(str(ofn), "w") as ofh:
            pWr = PdbxWriter(ofh)
            pWr.write(myContainerList)
        assert len(myContainerList) == 1
Exemplo n.º 2
0
 def __writeFile(
     self,
     ofh,
     containerList,
     maxLineLength=900,
     columnAlignFlag=True,
     lastInOrder=None,
     selectOrder=None,
     useStopTokens=False,
     formattingStep=None,
     enforceAscii=False,
     cnvCharRefs=False,
 ):
     """Internal method mapping arguments to PDBxWriter API."""
     #
     pdbxW = PdbxWriter(ofh)
     pdbxW.setUseStopTokens(flag=useStopTokens)
     pdbxW.setMaxLineLength(numChars=maxLineLength)
     pdbxW.setAlignmentFlag(flag=columnAlignFlag)
     pdbxW.setRowPartition(numParts=formattingStep)
     pdbxW.setConvertCharRefs(flag=cnvCharRefs)
     pdbxW.setSetEnforceAscii(enforceAscii)
     pdbxW.write(containerList,
                 lastInOrder=lastInOrder,
                 selectOrder=selectOrder)
Exemplo n.º 3
0
    def test_single_row(self, rw_data):
        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.appendAttribute("details")
        aCat.append([1, 2, 3, 4, 5, 6, 7, 'data_my_big_data_file'])
        aCat.append([1, 2, 3, 4, 5, 6, 7, 'loop_my_big_data_loop'])
        aCat.append([1, 2, 3, 4, 5, 6, 7, 'save_my_big_data_saveframe'])
        aCat.append([1, 2, 3, 4, 5, 6, 7, '_category.item'])

        curContainer.append(aCat)

        bCat = curContainer.getObj("pdbx_seqtool_mapping_ref")
        print("----attribute list %r\n" % bCat.getAttributeList())
        row = bCat.getRow(0)
        print("----ROW %r\n" % row)

        with open(str(rw_data['pathOutputFile2']), "w") as ofh:
            myDataList.append(curContainer)
            pdbxW = PdbxWriter(ofh)
            pdbxW.write(myDataList)

        assert len(myDataList) == 1
Exemplo n.º 4
0
    def testSingleRowFile(self):
        """Test case -  read /write single row and null row in data file"""
        try:
            #
            myDataList = []
            ifh = open(self.__pathTestFile, "r")
            pRd = PdbxReader(ifh)
            pRd.read(myDataList)
            ifh.close()

            myBlock = myDataList[0]
            myCat = myBlock.getObj("symmetry")
            logger.debug("----attribute list %r", myCat.getAttributeList())
            row = myCat.getRow(0)
            logger.debug("----ROW %r", row)
            #
            # myCat.dumpIt()

            with open(self.__pathOutputFile2, "w") as ofh:
                pdbxW = PdbxWriter(ofh)
                pdbxW.write(myDataList)

            self.assertEqual(len(myDataList), 1)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
    def strip(self, inpPath, outPath, stripList=[]):
        """ Strip categories from inpPath and write to outPath
        """
        try:
            myDataList = []
            with open(inpPath, "r") as ifh:
                pRd = PdbxReader(ifh)
                pRd.read(myDataList)
            #
            myBlock = myDataList[0]
            myName = myBlock.getName()
            newContainer = DataContainer(myName)

            for objName in myBlock.getObjNameList():
                myObj = myBlock.getObj(objName)
                if myObj.getName() not in stripList:
                    newContainer.append(myObj)
            #
            with open(outPath, "w") as ofh:
                pWr = PdbxWriter(ofh)
                pWr.setPreferSingleQuotes()
                pWr.write([newContainer])

            return True
        except Exception as e:
            logger.exception("Failing with %s" % str(e))
            return False
Exemplo n.º 6
0
 def testWriteDataFile(self):
     """Test case -  write data file"""
     try:
         #
         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([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])
         aCat.append([7, 6, 5, 4, 3, 2, 1])
         # aCat.printIt()
         curContainer.append(aCat)
         # curContainer.printIt()
         #
         myDataList.append(curContainer)
         with open(self.__pathOutputFile1, "w") as ofh:
             pdbxW = PdbxWriter(ofh)
             pdbxW.write(myDataList)
         self.assertEqual(len(myDataList), 1)
     except Exception as e:
         logger.exception("Failing with %s", str(e))
         self.fail()
Exemplo n.º 7
0
    def testUpdateAttribute(self):
        """Test case -  udpdate entry_id"""
        ifn = self.__pathBigPdbxDataFile
        ofn = self.__pathOutputFile2
        try:
            #
            myContainerList = []
            with open(ifn, "r") as ifh:
                pRd = PdbxReader(ifh)
                pRd.read(myContainerList)
            #
            dsId = "D_000000"
            atName = "entry_id"
            for container in myContainerList:
                container.setName(dsId)
                # remove category citation
                container.remove("citation")
                for objName in container.getObjNameList():
                    dcObj = container.getObj(objName)
                    if dcObj.hasAttribute(atName):
                        for iRow in range(0, dcObj.getRowCount()):
                            dcObj.setValue(dsId, attributeName=atName, rowIndex=iRow)
                    elif objName.lower() == "entry":
                        dcObj.setValue(dsId, attributeName="id", rowIndex=0)

            #
            with open(ofn, "w") as ofh:
                pWr = PdbxWriter(ofh)
                pWr.write(myContainerList)
            self.assertEqual(len(myContainerList), 1)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemplo n.º 8
0
 def WriteCif(self, outputFilePath=None):
     """Write out cif file"""
     if not outputFilePath:
         return
     #
     ofh = open(outputFilePath, "w")
     pdbxW = PdbxWriter(ofh)
     pdbxW.write(self.__dataList)
     ofh.close()
Exemplo n.º 9
0
    def test_read_write_data_file_stop(self, rw_data):
        myDataList = []
        with open(str(rw_data['pathTestFileStop']), "r") as ifh:
            pRd = PdbxReader(ifh)
            pRd.read(myDataList)

        with open(str(rw_data['pathOutputFile3']), "w") as ofh:
            pWr = PdbxWriter(ofh)
            pWr.write(myDataList)
        assert len(myDataList) == 1
Exemplo n.º 10
0
    def test_read_write_data_file(self, writer_paths):
        myDataList = []
        with open(str(writer_paths['pathPdbxDataFile']), "r") as ifh:
            pRd = PdbxReader(ifh)
            pRd.read(myDataList)

        with open(str(writer_paths['pathOutputFile1']), "w") as ofh:
            pWr = PdbxWriter(ofh)
            pWr.write(myDataList)

        assert len(myDataList) == 1
Exemplo n.º 11
0
    def testUpdateDataFile(self):
        """Test case -  update data file
        """
        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])

            curContainer.append(aCat)
            myDataList.append(curContainer)
            ofh = open(self.__pathOutputFile1, "w")
            pdbxW = PdbxWriter(ofh)
            pdbxW.write(myDataList)
            ofh.close()
            #
            #
            # Read and update the data -
            #
            myDataList = []
            ifh = open(self.__pathOutputFile1, "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 range(0, myCat.getRowCount()):
                myCat.setValue("some value", "ref_mon_id", iRow)
                myCat.setValue(100, "ref_mon_num", iRow)
            with open(self.__pathOutputFile2, "w") as ofh:
                pdbxW = PdbxWriter(ofh)
                pdbxW.write(myDataList)

            #
            self.assertEqual(len(myDataList), 1)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemplo n.º 12
0
    def testRowListInitialization(self):
        """Test case -  Row list initialization of a data category and data block"""
        try:
            #
            fn = self.__pathOutputFile4
            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()
                    logger.debug("Recovered data category  %s", name)
                    logger.debug("Attribute list           %r", repr(aList))
                    logger.debug("Row list                 %r", repr(rList))
            self.assertEqual(len(myContainerList), 1)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemplo n.º 13
0
    def write(self):
        """
        Given a file name, a pdbx writer is used to write data stored in self.__dataList
        :return written: a boolean; True when pdf writer is finished
        """
        written = False
        if self.filename:
            ofh = open(self.filename, "w")
            pdbx_writer = PdbxWriter(ofh)
            pdbx_writer.write(self.__dataList)
            ofh.close()
            written = True

        return written
Exemplo n.º 14
0
    def testReadWriteDataFileStop(self):
        """Test case -  data file read write test with stop tokens"""
        try:
            myDataList = []
            with open(self.__pathTestFileStop, "r") as ifh:
                pRd = PdbxReader(ifh)
                pRd.read(myDataList)

            with open(self.__pathOutputFile3, "w") as ofh:
                pWr = PdbxWriter(ofh)
                pWr.write(myDataList)
            self.assertEqual(len(myDataList), 1)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemplo n.º 15
0
    def _createfile1(pathout):
        my_data_list = []

        cur_container = DataContainer("myblock")

        acat = DataCategory("pdbx_item_enumeration")
        acat.appendAttribute("name")
        acat.appendAttribute("value")
        acat.appendAttribute("detail")
        acat.append(("1", "2", "3"))

        cur_container.append(acat)

        acat = DataCategory("exptl")
        acat.appendAttribute("absorpt_coefficient_mu")
        acat.appendAttribute("entry_id")
        acat.appendAttribute("method")
        acat.appendAttribute("details")
        acat.append(("?", "D_12345", "X-RAY DIFFRACTION", "some details"))

        cur_container.append(acat)

        acat = DataCategory("struct")
        acat.appendAttribute("title")
        acat.appendAttribute("pdbx_descriptor")
        acat.append(("Start title", "Start Descriptor"))

        cur_container.append(acat)

        my_data_list.append(cur_container)

        # Second block
        cur_container = DataContainer("secondblock")

        acat = DataCategory("pdbx_item_enumeration")
        acat.appendAttribute("name")
        acat.appendAttribute("value")
        acat.appendAttribute("detail")
        acat.append(("3", "2", "1"))

        cur_container.append(acat)

        my_data_list.append(cur_container)

        with open(pathout, "w") as ofh:
            pdbxw = PdbxWriter(ofh)
            pdbxw.setAlignmentFlag(flag=True)
            pdbxw.write(my_data_list)
Exemplo n.º 16
0
    def _createfile1(pathout):
        my_data_list = []

        cur_container = DataContainer("myblock")

        acat = DataCategory("pdbx_item_enumeration")
        acat.appendAttribute("name")
        acat.appendAttribute("value")
        acat.appendAttribute("detail")
        acat.append(('1', '2', '3'))

        cur_container.append(acat)

        acat = DataCategory("exptl")
        acat.appendAttribute('absorpt_coefficient_mu')
        acat.appendAttribute('entry_id')
        acat.appendAttribute('method')
        acat.appendAttribute('details')
        acat.append(('?', 'D_12345', 'X-RAY DIFFRACTION', 'some details'))

        cur_container.append(acat)

        acat = DataCategory("struct")
        acat.appendAttribute('title')
        acat.appendAttribute('pdbx_descriptor')
        acat.append(('Start title', 'Start Descriptor'))

        cur_container.append(acat)

        my_data_list.append(cur_container)

        # Second block
        cur_container = DataContainer("secondblock")

        acat = DataCategory("pdbx_item_enumeration")
        acat.appendAttribute("name")
        acat.appendAttribute("value")
        acat.appendAttribute("detail")
        acat.append(('3', '2', '1'))

        cur_container.append(acat)

        my_data_list.append(cur_container)

        with open(pathout, "w") as ofh:
            pdbxw = PdbxWriter(ofh)
            pdbxw.setAlignmentFlag(flag=True)
            pdbxw.write(my_data_list)
Exemplo n.º 17
0
    def _createfile2(pathout):
        my_data_list = []

        cur_container = DataContainer("test")

        acat = DataCategory("new")
        acat.appendAttribute("item")
        acat.append(('1',))

        cur_container.append(acat)

        acat = DataCategory("second_category")
        acat.appendAttribute('row')
        acat.appendAttribute('rowb')
        acat.append(('1', '2'))

        cur_container.append(acat)

        acat = DataCategory("third")
        acat.appendAttribute('id')
        acat.appendAttribute('val')
        acat.append(('1', 'a'))
        acat.append(('2', 'b'))
        acat.append(('3', 'c'))

        cur_container.append(acat)

        acat = DataCategory("exptl")
        acat.appendAttribute('method')
        acat.appendAttribute('entry_id')
        acat.append(('NEW', 'something'))

        cur_container.append(acat)

        acat = DataCategory("struct")
        acat.appendAttribute('new')
        acat.appendAttribute('pdbx_descriptor')
        acat.append(('Something to add', 'Override descriptor'))

        cur_container.append(acat)

        my_data_list.append(cur_container)

        with open(pathout, "w") as ofh:
            pdbxw = PdbxWriter(ofh)
            pdbxw.setAlignmentFlag(flag=True)
            pdbxw.write(my_data_list)
Exemplo n.º 18
0
    def _createfile2(pathout):
        my_data_list = []

        cur_container = DataContainer("test")

        acat = DataCategory("new")
        acat.appendAttribute("item")
        acat.append(("1",))

        cur_container.append(acat)

        acat = DataCategory("second_category")
        acat.appendAttribute("row")
        acat.appendAttribute("rowb")
        acat.append(("1", "2"))

        cur_container.append(acat)

        acat = DataCategory("third")
        acat.appendAttribute("id")
        acat.appendAttribute("val")
        acat.append(("1", "a"))
        acat.append(("2", "b"))
        acat.append(("3", "c"))

        cur_container.append(acat)

        acat = DataCategory("exptl")
        acat.appendAttribute("method")
        acat.appendAttribute("entry_id")
        acat.append(("NEW", "something"))

        cur_container.append(acat)

        acat = DataCategory("struct")
        acat.appendAttribute("new")
        acat.appendAttribute("pdbx_descriptor")
        acat.append(("Something to add", "Override descriptor"))

        cur_container.append(acat)

        my_data_list.append(cur_container)

        with open(pathout, "w") as ofh:
            pdbxw = PdbxWriter(ofh)
            pdbxw.setAlignmentFlag(flag=True)
            pdbxw.write(my_data_list)
Exemplo n.º 19
0
    def testPdbxFileCase(self):
        """Test case sensitive PdxWriter"""

        if os.path.exists(self.__pathOutputFile):
            os.unlink(self.__pathOutputFile)

        curContainer = self.__generateData()
        myDataList = [curContainer]
        try:
            with open(self.__pathOutputFile, "w") as ofh:
                pdbxW = PdbxWriter(ofh)
                pdbxW.write(myDataList)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()

        self.__testReaders(self.__pathOutputFile)
Exemplo n.º 20
0
    def testRowDictInitialization(self):
        """Test case -  Row dictionary initialization of a data category and data block
        """
        try:
            #
            rLen = 10
            fn = self.__pathOutputFile5
            attributeNameList = ["a", "b", "c", "d"]
            rowList = [{"a": 1, "b": 2, "c": 3, "d": 4} for i in range(rLen)]
            nameCat = "myCategory"
            #
            #
            curContainer = DataContainer("myblock")
            aCat = DataCategory(nameCat, attributeNameList, rowList)
            aCat.append({"a": 1, "b": 2, "c": 3, "d": 4})
            aCat.append({"a": 1, "b": 2, "c": 3, "d": 4})
            aCat.extend(rowList)
            curContainer.append(aCat)
            aCat.renameAttributes({"a": "aa", "b": "bb", "c": "cc", "d": "dd"})
            aCat.setName("renamedCategory")
            #
            #
            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()
                    logger.debug("Recovered data category  %s", name)
                    logger.debug("Attribute list           %r", repr(aList))
                    logger.debug("Row list                 %r", repr(rList))
            self.assertEqual(len(myContainerList), 1)
            self.assertEqual(len(rList), 2 * rLen + 2)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemplo n.º 21
0
    def test_single_row_file(self, rw_data):
        myDataList = []
        with open(str(rw_data['pathTestFile']), "r") as ifh:
            pRd = PdbxReader(ifh)
            pRd.read(myDataList)

        myBlock = myDataList[0]
        myCat = myBlock.getObj('symmetry')
        print("----attribute list %r\n" % myCat.getAttributeList())
        row = myCat.getRow(0)
        print("----ROW %r\n" % row)
        #
        # myCat.dumpIt()

        with open(str(rw_data['pathOutputFile2']), "w") as ofh:
            pdbxW = PdbxWriter(ofh)
            pdbxW.write(myDataList)

        assert len(myDataList) == 1
Exemplo n.º 22
0
    def test_update_data_file(self, rw_data):
        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])

        curContainer.append(aCat)
        myDataList.append(curContainer)
        ofh = open(str(rw_data['pathOutputFile1']), "w")
        pdbxW = PdbxWriter(ofh)
        pdbxW.write(myDataList)
        ofh.close()

        myDataList = []
        ifh = open(str(rw_data['pathOutputFile1']), "r")
        pRd = PdbxReader(ifh)
        pRd.read(myDataList)
        ifh.close()
        myBlock = myDataList[0]
        myCat = myBlock.getObj('pdbx_seqtool_mapping_ref')
        for iRow in range(0, myCat.getRowCount()):
            myCat.setValue('some value', 'ref_mon_id', iRow)
            myCat.setValue(100, 'ref_mon_num', iRow)

        with open(str(rw_data['pathOutputFile2']), "w") as ofh:
            pdbxW = PdbxWriter(ofh)
            pdbxW.write(myDataList)

        assert len(myDataList) == 1
Exemplo n.º 23
0
    def test_update_data_file(self, writer_paths):
        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((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)
        with open(str(writer_paths['pathOutputFile1']), "w") as ofh:
            pdbxW = PdbxWriter(ofh)
            pdbxW.write(myDataList)
        #
        # Read and update the data -
        #
        myDataList = []
        with open(str(writer_paths['pathOutputFile1']), "r") as ifh:
            pRd = PdbxReader(ifh)
            pRd.read(myDataList)
        #
        myBlock = myDataList[0]
        # myBlock.printIt()
        myCat = myBlock.getObj('pdbx_seqtool_mapping_ref')
        # myCat.printIt()
        for iRow in range(0, myCat.getRowCount()):
            myCat.setValue('some value', 'ref_mon_id', iRow)
            myCat.setValue(100, 'ref_mon_num', iRow)
        with open(str(writer_paths['pathOutputFile2']), "w") as ofh:
            pdbxW = PdbxWriter(ofh)
            pdbxW.write(myDataList)
        assert len(myDataList) == 1
Exemplo n.º 24
0
    def test_row_list_initialization(self, rw_data):
        fn = rw_data['pathOutputFile4']
        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)
        curContainer.append(aCat)

        myContainerList = []
        myContainerList.append(curContainer)
        ofh = open(str(fn), "w")
        pdbxW = PdbxWriter(ofh)
        pdbxW.write(myContainerList)
        ofh.close()

        myContainerList = []
        ifh = open(str(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()
                print("Recovered data category  %s\n" % name)
                print("Attribute list           %r\n" % repr(aList))
                print("Row list                 %r\n" % repr(rList))
        assert len(myContainerList) == 1
Exemplo n.º 25
0
    def testSingleRow(self):
        """Test case -  read /write single row and null row in data file
        """
        try:
            #
            myDataList = []
            # ofh = open(self.__pathOutputFile1, "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.appendAttribute("details")
            aCat.append([1, 2, 3, 4, 5, 6, 7, "data_my_big_data_file"])
            aCat.append([1, 2, 3, 4, 5, 6, 7, "loop_my_big_data_loop"])
            aCat.append([1, 2, 3, 4, 5, 6, 7, "save_my_big_data_saveframe"])
            aCat.append([1, 2, 3, 4, 5, 6, 7, "_category.item"])
            # aCat.dumpIt()
            curContainer.append(aCat)
            #
            bCat = curContainer.getObj("pdbx_seqtool_mapping_ref")
            logger.debug("----attribute list %r", bCat.getAttributeList())
            row = bCat.getRow(0)
            logger.debug("----ROW %r", row)
            #
            with open(self.__pathOutputFile2, "w") as ofh:
                myDataList.append(curContainer)
                pdbxW = PdbxWriter(ofh)
                pdbxW.write(myDataList)

            self.assertEqual(len(myDataList), 1)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemplo n.º 26
0
    def test_row_dict_initialization(self, rw_data):
        rLen = 10
        fn = rw_data['pathOutputFile5']
        attributeNameList = ['a', 'b', 'c', 'd']
        rowList = [{'a': 1, 'b': 2, 'c': 3, 'd': 4} for i in range(rLen)]
        nameCat = 'myCategory'
        #
        #
        curContainer = DataContainer("myblock")
        aCat = DataCategory(nameCat, attributeNameList, rowList)
        aCat.append({'a': 1, 'b': 2, 'c': 3, 'd': 4})
        aCat.append({'a': 1, 'b': 2, 'c': 3, 'd': 4})
        aCat.extend(rowList)
        curContainer.append(aCat)
        aCat.renameAttributes({'a': 'aa', 'b': 'bb', 'c': 'cc', 'd': 'dd'})
        aCat.setName('renamedCategory')
        #
        #
        myContainerList = []
        myContainerList.append(curContainer)
        ofh = open(str(fn), "w")
        pdbxW = PdbxWriter(ofh)
        pdbxW.write(myContainerList)
        ofh.close()

        myContainerList = []
        ifh = open(str(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()
                print("Recovered data category  %s\n" % name)
                print("Attribute list           %r\n" % repr(aList))
                print("Row list                 %r\n" % repr(rList))
        assert len(myContainerList) == 1
        assert len(rList) == 2 * rLen + 2
Exemplo n.º 27
0
    def test_write_data_file(self, rw_data):
        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([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])
        aCat.append([7, 6, 5, 4, 3, 2, 1])
        curContainer.append(aCat)

        myDataList.append(curContainer)
        with open(str(rw_data['pathOutputFile1']), "w") as ofh:
            pdbxW = PdbxWriter(ofh)
            pdbxW.write(myDataList)
        assert len(myDataList) == 1
Exemplo n.º 28
0
    def test_write_data_file(self, writer_paths):
        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(
            (1, 2, 3, 4, '55555555555555555555555555555555555555555555', 6, 7))
        aCat.append((1, 2, 3, 4, '5555', 6, 7))
        aCat.append((1, 2, 3, 4, '5555555555', 6, 7))
        aCat.append((1, 2, 3, 4, '5', 6, 7))
        curContainer.append(aCat)
        myDataList.append(curContainer)
        with open(str(writer_paths['pathOutputFile1']), "w") as ofh:
            pdbxW = PdbxWriter(ofh)
            pdbxW.setAlignmentFlag(flag=True)
            pdbxW.write(myDataList)
        assert len(myDataList) == 1