Exemple #1
0
    def testGetAdjacentCategories(self):
        """Test case -"""

        try:
            myIo = IoAdapter(raiseExceptions=True)
            self.__containerList = myIo.readFile(inputFilePath=self.__pathPdbxDictionary)
            dApi = DictionaryApi(containerList=self.__containerList, consolidate=True, verbose=self.__verbose)
            cList = dApi.getCategoryList()
            cI = {}
            for cV in cList:
                chL = dApi.getChildCategories(cV)
                pL = dApi.getParentCategories(cV)
                for ch in chL:
                    if (ch, cV) not in cI:
                        cI[(ch, cV)] = 1
                    else:
                        cI[(ch, cV)] += 1
                for pV in pL:
                    if (cV, pV) not in cI:
                        cI[(cV, pV)] = 1
                    else:
                        cI[(cV, pV)] += 1
            linkL = []
            for tup in cI:
                dD = {"source": tup[0], "target": tup[1], "type": "link"}
                linkL.append(dD)

            if self.__verbose:
                print(json.dumps(linkL, sort_keys=True, indent=4, separators=(",", ": ")))
            self.assertGreater(len(linkL), 50)

        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemple #2
0
    def testGetUcode(self):
        """Test case - Get all data items of type ucode
        """
        print("\n")

        try:
            myIo = IoAdapter(raiseExceptions=True)
            self.__containerList = myIo.readFile(
                inputFilePath=self.__pathPdbxDictionary)
            dApi = DictionaryApi(containerList=self.__containerList,
                                 consolidate=True,
                                 verbose=self.__verbose)

            logger.debug(
                "+++++++++++++++++++++++++++++++++++++++++++++++++++++++\n")
            catNameList = dApi.getCategoryList()
            for catName in catNameList:
                itemNameList = dApi.getItemNameList(catName)
                for itemName in itemNameList:
                    categoryName = CifName.categoryPart(itemName)
                    attributeName = CifName.attributePart(itemName)
                    code = dApi.getTypeCode(categoryName, attributeName)
                    if (code == "ucode"):
                        print("Table: ", categoryName, "\tColumn: ",
                              attributeName, "\tType: ", code)
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemple #3
0
    def test_get_adjacent_categories(self, api_paths):
        myIo = IoAdapter(raiseExceptions=True)
        containerList = myIo.readFile(
            inputFilePath=str(api_paths['pathPdbxDictionary']))
        dApi = DictionaryApi(containerList=containerList, consolidate=True)

        cList = dApi.getCategoryList()
        cI = {}
        for c in cList:
            chL = dApi.getChildCategories(c)
            pL = dApi.getParentCategories(c)
            for ch in chL:
                if (ch, c) not in cI:
                    cI[(ch, c)] = 1
                else:
                    cI[(ch, c)] += 1
            for p in pL:
                if (c, p) not in cI:
                    cI[(c, p)] = 1
                else:
                    cI[(c, p)] += 1
        linkL = []
        for s, t in cI.keys():
            d = {'source': s, 'target': t, 'type': 'link'}
            linkL.append(d)

        assert len(linkL) > 50
Exemple #4
0
    def testDDLApi(self):
        """Test case -  DDL API linkage counts"""
        try:
            myIo = IoAdapter(raiseExceptions=True)
            containerList = myIo.readFile(
                inputFilePath=self.__pathDdlGeneratedDictionary)
            dApi = DictionaryApi(containerList=containerList,
                                 consolidate=True,
                                 expandItemLinked=True)
            cL = dApi.getCategoryList()
            logger.info("Category length %r", len(cL))
            self.assertGreaterEqual(len(cL), 63)
            cL = dApi.getFullChildList("category", "id")
            logger.info("Children of category.id (%d)", len(cL))
            self.assertGreaterEqual(len(cL), 11)
            #
            cL = dApi.getFullDescendentList("category", "id")
            logger.info("Descendents of category.id (%d)", len(cL))
            self.assertGreaterEqual(len(cL), 13)
            #
            cL = dApi.getFullChildList("item", "name")
            logger.info("Children of item.name (%d)", len(cL))
            self.assertGreaterEqual(len(cL), 36)
            cL = dApi.getFullDescendentList("item", "name")
            logger.info("Descendents of item.name (%d)", len(cL))
            self.assertGreaterEqual(len(cL), 38)
            #

            val = dApi.getDictionaryVersion()
            self.assertEqual(val, "2.2.2")
            val = dApi.getDictionaryTitle()
            self.assertEqual(val, "mmcif_ddl.dic")
            val = dApi.getDictionaryUpdate(order="reverse")
            self.assertEqual(val, "2020-06-05")
            val = dApi.getDictionaryRevisionCount()
            self.assertGreaterEqual(val, 78)
            valL = dApi.getDictionaryHistory(order="reverse")
            self.assertGreaterEqual(len(valL), 78)
            #
            val = dApi.getDictionaryComponentCount()
            self.assertGreaterEqual(val, 6)
            #
            valL = dApi.getDictionaryComponentDetails()
            self.assertGreaterEqual(len(valL), 6)

            valL = dApi.getDictionaryComponents()
            self.assertGreaterEqual(len(valL), 6)
            for dictionaryComponentId in dApi.getDictionaryComponents():
                valL = dApi.getDictionaryComponentHistory(
                    dictionaryComponentId, order="reverse")
                self.assertGreaterEqual(len(valL), 2)

            #
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
Exemple #5
0
class DictionaryData(object):
    def __init__(self):
        basedir = os.path.join(os.path.dirname(__file__), "..", "dist")
        self.dictPath = os.path.join(basedir, "mmcif_pdbx_v5_next.dic")

    def readDictionary(self):
        myIo = IoAdapterPy()
        self.__containerList = myIo.readFile(inputFilePath=self.dictPath)
        self._dApi = DictionaryApi(containerList=self.__containerList,
                                   consolidate=True)
        assert len(self.getGroups()) > 0, "Failed to load %s" % self.dictPath

    def getGroups(self):
        groupList = self._dApi.getCategoryGroups()
        return groupList

    def getTypeRegex(self, cat, attrib):
        return self._dApi.getTypeRegex(cat, attrib)

    def getTypeRegexAlt(self, cat, attrib):
        return self._dApi.getTypeRegexAlt(cat, attrib)

    def getDataTypeList(self):
        """ Return list of tuples containing ('code','primitive_code','construct','detail' )
        """
        return self._dApi.getDataTypeList()

    def getEnumList(self, category, attribute, sortFlag=True):
        return self._dApi.getEnumList(category, attribute, sortFlag)

    def getEnumListAlt(self, category, attribute, sortFlag=True):
        return self._dApi.getEnumListAlt(category, attribute, sortFlag)

    def getEnumListAltWithDetail(self, category, attribute):
        return self._dApi.getEnumListAltWithDetail(category, attribute)

    def getAllCategory(self):
        """Returns list of all categories"""
        return self._dApi.getCategoryList()

    def getCategoryList(self):
        return self._dApi.getCategoryList()

    def getItemNameList(self, category):
        return self._dApi.getItemNameList(category)

    def wwPDBContext(self, catItem):
        """Returns true if category or item have local context"""

        category, item = catItem.split('.')
        if category[0] == "_":
            category = category[1:]

        #print "CHECKING ", category, item, self.__dictA.getCategoryContextList(category)
        if self._dApi.getCategoryContextList(category) == ['WWPDB_LOCAL']:
            return True
        if self._dApi.getContextList(category, item) == ['WWPDB_LOCAL']:
            return True

        return False

    def getCategoryItemEnum(self, itemName):
        """Returns any archive enum list"""

        categoryName = CifName.categoryPart(itemName)
        attributeName = CifName.attributePart(itemName)
        return self._dApi.getEnumList(categoryName, attributeName)

    def getCategoryPdbxItemEnum(self, itemName):
        """Returns any DepUI enum list"""

        categoryName = CifName.categoryPart(itemName)
        attributeName = CifName.attributePart(itemName)
        return self._dApi.getEnumListAlt(categoryName, attributeName)

    def getItemRelatedList(self, itemName):
        categoryName = CifName.categoryPart(itemName)
        attributeName = CifName.attributePart(itemName)

        return self._dApi.getItemRelatedList(categoryName, attributeName)
    def testClassifyByGroup(self):
        """Test case -  organize dictionary items by classes: SAMPLE, MX, NMR, EM, STRUCTURE, and DB"""
        try:
            myIo = IoAdapter(raiseExceptions=True)
            self.__containerList = myIo.readFile(
                inputFilePath=self.__pathPdbxDictionary)
            dApi = DictionaryApi(containerList=self.__containerList,
                                 consolidate=True,
                                 verbose=self.__verbose)
            #
            itemList = []
            groupList = dApi.getCategoryGroups()
            categoryList = dApi.getCategoryList()
            for category in categoryList:
                itemList.extend(dApi.getItemNameList(category))
            itemList = sorted(set(itemList))

            logger.info("Total category length %d", len(categoryList))
            logger.info("Total definition length %d", len(itemList))

            logger.info("group length %s", len(groupList))
            logger.debug("groupList %r", groupList)
            #
            findUnlinked = False
            if findUnlinked:
                tSet = set(["pdbx_group", "inclusive_group"])
                for category in categoryList:
                    gList = dApi.getCategoryGroupList(category)
                    gSet = set(gList)
                    if gSet == tSet:
                        logger.info("unqualified %s", category)

                    # logger.info("%s -> %r", category, gList)
                    if not gList:
                        logger.info("--- No category group assignment for %s",
                                    category)
            #
            classD = {}
            # Add category group members -
            for groupName, className in self.__groupClassTupL:
                categoryL = dApi.getCategoryGroupCategories(
                    groupName, followChildren=True)
                for category in categoryL:
                    classD.setdefault(className, []).extend(
                        dApi.getItemNameList(category))
            #
            # Add unlinked categories
            #
            for category, className in self.__unlinkedCategoryClassTup:
                classD.setdefault(className,
                                  []).extend(dApi.getItemNameList(category))
            #
            sumItem = 0
            classItemD = {}
            for className, itemL in classD.items():
                numItem = len(set(itemL))
                sumItem += numItem
                logger.info("class %s items %d", className, len(set(itemL)))
                for item in itemL:
                    classItemD[item] = True
            #
            logger.info("Sum classified items is %d", sumItem)
            logger.info("classified items %d", len(classItemD))
            #
            logger.debug("classItemD.items() %r",
                         list(classItemD.items())[:10])

            missingGroupL = []

            jj = 0
            for item in itemList:
                if item not in classItemD:
                    jj += 1
                    category = CifName.categoryPart(item)
                    logger.info("%d item %r category %r", jj, item, category)
                    missingGroupL.extend(dApi.getCategoryGroupList(category))
            #
            logger.info("missing groups %r", sorted(set(missingGroupL)))

        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
    def __testScanRepo(self, contentType, scanType="full"):
        """Utility method to scan repo for data type and coverage content.

        Using mock repos for tests.
        """
        try:
            containerList = self.__mU.doImport(self.__pathPdbxDictionary,
                                               fmt="mmcif-dict")
            dictApi = DictionaryApi(containerList=containerList,
                                    consolidate=True,
                                    verbose=True)

            failedFilePath = os.path.join(
                HERE, "test-output",
                "%s-failed-list-%s.txt" % (contentType, scanType))
            savedFilePath = os.path.join(
                HERE, "test-output",
                "%s-path-list-%s.txt" % (contentType, scanType))
            scanDataFilePath = os.path.join(HERE, "test-output",
                                            "%s-scan-data.pic" % (contentType))
            dataCoverageFilePath = os.path.join(
                HERE, "test-output",
                "%s-scan-data-coverage-%s.json" % (contentType, scanType))
            dataCoverageItemFilePath = os.path.join(
                HERE, "test-output",
                "%s-scan-data-item-coverage-%s.tdd" % (contentType, scanType))
            dataTypeFilePath = os.path.join(
                HERE, "test-output",
                "%s-scan-data-type-%s.json" % (contentType, scanType))
            #
            ###
            categoryList = sorted(dictApi.getCategoryList())
            dictSchema = {
                catName: sorted(dictApi.getAttributeNameList(catName))
                for catName in categoryList
            }
            attributeDataTypeD = OrderedDict()
            for catName in categoryList:
                aD = {}
                for atName in dictSchema[catName]:
                    aD[atName] = dictApi.getTypeCode(catName, atName)
                attributeDataTypeD[catName] = aD
            ###
            #
            sr = ScanRepoUtil(self.__cfgOb,
                              attributeDataTypeD=attributeDataTypeD,
                              numProc=self.__numProc,
                              chunkSize=self.__chunkSize,
                              fileLimit=self.__fileLimit,
                              workPath=self.__cachePath)
            ok = sr.scanContentType(contentType,
                                    scanType=scanType,
                                    inputPathList=None,
                                    scanDataFilePath=scanDataFilePath,
                                    failedFilePath=failedFilePath,
                                    saveInputFileListPath=savedFilePath)
            self.assertTrue(ok)
            ok = sr.evalScan(scanDataFilePath,
                             dataTypeFilePath,
                             evalType="data_type")
            self.assertTrue(ok)
            ok = sr.evalScan(scanDataFilePath,
                             dataCoverageFilePath,
                             evalType="data_coverage")
            self.assertTrue(ok)
            ok = sr.evalScanItem(scanDataFilePath, dataCoverageItemFilePath)
            self.assertTrue(ok)

            return ok
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()