Exemplo n.º 1
0
def dictToHtml(dictionary,
               byValueFirst=False,
               addEcDescriptions=False,
               headingDescriptionForHeading=None) -> str:

    if addEcDescriptions is not False:
        from FEV_KEGG.Graph.Elements import EcNumber
        EcNumber.addEcDescriptions(addEcDescriptions)

    sortedList = prettySortDict(dictionary, byValueFirst)

    from yattag import Doc
    doc, tag, _ = Doc().tagtext()

    with tag('html'):

        # remove underline from links
        with tag('head'):
            doc.asis(
                '<style type="text/css">a {text-decoration:none;}</style>')

        with tag('body'):

            for heading, rows in sortedList:

                with tag('p'):
                    with tag('table'):
                        doc.asis(heading.toHtml())

                    if headingDescriptionForHeading is not None:
                        headingDescription = headingDescriptionForHeading.get(
                            heading, None)

                        if headingDescription is not None:
                            with tag('table'):
                                with tag('tr'):
                                    with tag('td'):
                                        doc.asis('{')

                                for line in headingDescription:
                                    with tag('tr'):
                                        doc.asis(line.toHtml(short=True))

                                with tag('tr'):
                                    with tag('td'):
                                        doc.asis('}')

                    with tag('table'):

                        for row in rows:
                            with tag('tr'):
                                doc.asis(row.toHtml(short=True))

                with tag('br'):
                    pass

    return doc.getvalue()
Exemplo n.º 2
0
    def ecNumbers(self) -> Set[EcNumber]:
        """
        GoldmanLUCA's EC numbers.
        
        Generalised to the first three levels. The last level is always a wildcard.
        
        Returns
        -------
        Set[EcNumber]
            Set of the EC numbers predicted by Goldman et al. to belong to LUCA.
        """
        lucaEcNumberStrings = [
            '1.3.1.-', '2.4.1.-', '2.7.1.-', '2.7.7.-', '3.1.2.-', '3.1.4.-',
            '3.2.1.-', '3.5.1.-', '4.1.2.-', '6.3.2.-'
        ]

        lucaEcNumbers = set()
        for string in lucaEcNumberStrings:
            lucaEcNumbers.add(EcNumber(string))

        return lucaEcNumbers
Exemplo n.º 3
0
        '4.2.1.20', '4.2.1.22', '4.2.1.24', '4.2.1.3', '4.2.1.35', '4.2.1.51',
        '4.2.1.52', '4.2.1.55', '4.2.1.60', '4.2.1.75', '4.2.1.9', '4.2.3.1',
        '4.3.1.17', '4.3.1.19', '4.3.2.1', '4.3.2.2', '4.6.1.12', '5.1.1.1',
        '5.1.1.3', '5.1.1.7', '5.3.1.1', '5.3.1.16', '5.3.1.9', '5.4.2.1',
        '5.4.2.10', '5.4.2.2', '5.4.2.7', '5.4.3.8', '5.4.99.18', '6.1.1.10',
        '6.1.1.11', '6.1.1.17', '6.1.1.4', '6.1.1.5', '6.1.1.9', '6.2.1.1',
        '6.2.1.5', '6.3.2.1', '6.3.2.10', '6.3.2.12', '6.3.2.13', '6.3.2.2',
        '6.3.2.3', '6.3.2.4', '6.3.2.6', '6.3.2.8', '6.3.2.9', '6.3.3.1',
        '6.3.3.3', '6.3.4.13', '6.3.4.14', '6.3.4.15', '6.3.4.18', '6.3.4.2',
        '6.3.4.4', '6.3.4.5', '6.3.5.2', '6.3.5.3', '6.3.5.4', '6.3.5.5',
        '6.4.1.2'
    ]
    theirECnumbers = set()

    for string in theirECnumberStrings:
        theirECnumbers.add(EcNumber(string))

    #- remove outdated EC numbers
    outdatedEcNumberStrings = [
        '1.1.1.158', '1.17.1.2', '1.17.4.2', '1.3.1.26', '1.3.3.1', '1.3.99.1',
        '2.3.1.89', '2.4.2.11', '2.7.4.14', '3.5.1.47', '3.6.1.15', '3.6.1.19',
        '4.2.1.52', '4.2.1.60', '5.4.2.1'
    ]
    outdatedEcNumbers = set()
    for string in outdatedEcNumberStrings:
        outdatedEcNumbers.add(EcNumber(string))
    theirECnumbers.difference_update(outdatedEcNumbers)

    #- reduce set of EC numbers to first three levels
    theirECnumbers = EcNumber.insertWildcards(theirECnumbers,
                                              keepLevels=3,
Exemplo n.º 4
0
    def _SubstanceReactionGraph2SubstanceEcGraph(
        self, speciesSubstanceReactionGraph: SubstanceReactionGraph
    ) -> SubstanceEcGraph:
        """
        Converts NUKA's substance-reaction graph into a substance-EC graph. Uses pathway information embedded into the graph object.
        
        Parameters
        ----------
        speciesSubstanceReactionGraph : SubstanceReactionGraph
            NUKA's substance-reaction graph.
        
        Returns
        -------
        SubstanceEcGraph
            NUKA's substance-EC graph.
        
        Warnings
        --------
        This function is special to NUKA and **MUST NOT** be used anywhere else!
        """
        # shallow-copy old graph to new graph
        graph = SubstanceEcGraph(
            speciesSubstanceReactionGraph.underlyingRawGraph)
        graph.name = 'Substance-EC NUKA'

        # create dict of replacements: reaction -> {EC numbers}
        replacementDict = dict()

        # for each embedded pathway, get list of 'enzyme' entries
        for pathway in speciesSubstanceReactionGraph.pathwaySet:
            ecEntryList = [
                e for e in pathway.entries.values() if e.type == 'enzyme'
            ]

            # for each EC number, get reactions in which it is involved
            for ecEntry in ecEntryList:
                reactionIDList = ecEntry.reaction.split()
                if len(
                        reactionIDList
                ) > 0:  # filter EC numbers not associated with any reaction
                    ecNumberList = ecEntry.name.split()

                    # replace each reaction with its associated EC number
                    for reactionID in reactionIDList:
                        reactionName = reactionID.split(':', 1)[1]
                        reaction = ReactionID(reactionName)

                        # save associated EC numbers in a set
                        ecNumberSet = set()
                        for ecNumberString in ecNumberList:
                            ecNumber = EcNumber(
                                ecNumberString.replace('ec:', ''))
                            ecNumberSet.add(ecNumber)

                        # update the replacement dict for the current reaction, adding the newly created EC number set
                        replacementSet = replacementDict.get(reaction, None)
                        if replacementSet == None or replacementSet.__class__ != set:
                            replacementSet = set()
                        replacementSet.update(ecNumberSet)
                        replacementDict[reaction] = replacementSet

        # get list of all reaction edges. Copy edge list to prevent changes in-place, which would NOT work
        edgeList = list(graph.getEdges())

        # replace reaction edges with EC number edges, using replacement dict
        for edge in edgeList:
            substrate, product, reaction = edge

            # delete old edge
            graph.removeEdge(substrate, product, reaction, False)

            # add new edges, according to replacement dict
            replacementSet = replacementDict[reaction]
            for ecNumber in replacementSet:
                graph.addEC(substrate, product, ecNumber, False)

        if init_verbosity > 0:
            print('calculated ' + graph.name)

        return graph
Exemplo n.º 5
0
            CoreLUCA.CladeType.archaeaBacteria
    ]:

        #-     get collective metabolism of clade
        coreLuca = CoreLUCA(clade)
        output.append(coreLuca.nameAbbreviation)

        #-     REPEAT for varying majority percentages
        for percentage in range(100, 0, -10):

            #-         calculate core metabolism
            ourECnumbers = coreLuca.substanceEcGraph(percentage).getECs()

            #-         reduce EC numbers to first three levels
            ourECnumbers = EcNumber.insertWildcards(ourECnumbers,
                                                    keepLevels=3,
                                                    allowHigherWildcards=False,
                                                    returnSet=True)

            onlyInTheirs = goldmanLucaEcNumbers.difference(ourECnumbers)
            inBoth = goldmanLucaEcNumbers.intersection(ourECnumbers)
            onlyInOurs = ourECnumbers.difference(goldmanLucaEcNumbers)

            output.append(
                str(percentage) + '%:\t' + str(len(onlyInTheirs)) + '\t' +
                str(len(inBoth)) + '\t' + str(len(onlyInOurs)))

        output.append("\n")

    for line in output:
        print(line)
Exemplo n.º 6
0
    theirECnumberStrings = [
        '1.1.1.158', '1.1.1.193', '1.1.1.25', '1.5.1.3', '1.6.4.5', '1.7.99.5',
        '2.2.1.2', '2.3.1.129', '2.3.1.39', '2.4.1.182', '2.4.1.21',
        '2.5.1.15', '2.5.1.19', '2.5.1.7', '2.5.1.9', '2.6.1.16', '2.7.1.107',
        '2.7.1.130', '2.7.1.23', '2.7.1.24', '2.7.1.26', '2.7.1.33', '2.7.2.3',
        '2.7.4.6', '2.7.4.8', '2.7.4.9', '2.7.6.3', '2.7.7.18', '2.7.7.2',
        '2.7.7.23', '2.7.7.27', '2.7.7.3', '2.7.7.38', '2.7.7.41', '2.7.8.5',
        '2.7.8.8', '3.1.3.45', '3.5.4.16', '3.5.4.25', '3.5.4.26', '3.6.1.1',
        '3.6.1.34', '3.6.1.45', '4.1.1.36', '4.1.1.65', '4.1.2.13', '4.1.2.16',
        '4.1.2.25', '4.2.1.10', '4.2.1.11', '4.6.1.3', '4.6.1.4', '5.1.1.3',
        '5.3.1.1', '5.3.1.13', '6.3.2.12', '6.3.2.13', '6.3.2.15', '6.3.2.4',
        '6.3.2.5', '6.3.2.8', '6.3.2.9'
    ]
    theirECnumbers = set()
    for string in theirECnumberStrings:
        theirECnumbers.add(EcNumber(string))

    #- get group of organisms 'Escherichia coli'
    eco = Organism.Organism('eco')

    #- calculate EC numbers occuring in eco's core metabolism
    ourECnumbersWithWildcard = eco.substanceEcGraph(
        noMultifunctional=True).getECs()
    ourECnumbers = EcNumber.removeWildcards(ourECnumbersWithWildcard)

    #- overlap Almaas' set with ours and print amount of EC numbers inside the intersection and falling off either side
    onlyInTheirs = theirECnumbers.difference(ourECnumbers)
    inBoth = theirECnumbers.intersection(ourECnumbers)
    onlyInOurs = ourECnumbers.difference(theirECnumbers)

    output.append(
Exemplo n.º 7
0
    cladePair = CladePair(archaea_clade, gammaproteobacteria_clade)

    #- export coloured graph to file, containing all three sets of differing ECs, using the default majority percentage of 80
    cladePair_graph = cladePair.unifiedMetabolism(colour=True)
    Export.forCytoscape(cladePair_graph,
                        'experiments/40/archaea_vs_gammaproteobacteria',
                        inCacheFolder=True)

    #- REPEAT for varying majority-percentages:
    for percentage in [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1]:

        #-     overlap sets and print amount of EC numbers inside the intersection and falling off either side
        only_archaea = cladePair.lostMetabolism(percentage).getECs()
        both = cladePair.conservedMetabolism(percentage).getECs()
        only_gammaproteobacteria = cladePair.addedMetabolism(
            percentage).getECs()

        #-     remove wildcard EC numbers
        only_archaea = EcNumber.removeWildcards(only_archaea)
        both = EcNumber.removeWildcards(both)
        only_gammaproteobacteria = EcNumber.removeWildcards(
            only_gammaproteobacteria)

        output.append(
            str(percentage) + '%:\t' + str(len(only_archaea)) + '\t' +
            str(len(both)) + '\t' + str(len(only_gammaproteobacteria)))

    for line in output:
        print(line)
Exemplo n.º 8
0
        '2.4.2.1', '2.4.2.1', '2.4.2.1', '2.4.2.1', '2.4.2.2', '2.4.2.1',
        '2.7.1.21', '2.1.1.45', '1.7.3.3', '2.7.1.48', '2.7.1.48', '2.7.1.48',
        '1.1.1.204', '2.4.2.22', '6.3.4.13', '6.3.3.1', '6.3.5.3', '6.3.4.2',
        '2.7.4.3', '2.4.2.7', '4.3.2.2', '4.3.2.2', '6.3.4.4', '2.1.2.3',
        '2.1.3.2', '6.3.4.2', '1.3.3.1', '3.5.2.3', '2.1.2.2', '2.7.4.8',
        '2.4.2.14', '6.3.5.2', '3.5.4.10', '1.1.1.205', '2.7.4.6', '2.4.2.10',
        '2.4.2.9', '2.7.4.3', '3.5.3.4', '3.5.4.1', '2.7.4.6', '4.1.1.23',
        '2.7.4.4', '1.1.1.204', '1.2.1.8', '1.1.99.1', '3.5.2.6', '2.1.2.9',
        '1.11.1.9', '6.1.1.10', '3.5.1.11', '1.15.1.1', '6.1.1.17', '1.11.1.6',
        '3.6.1.15', '4.2.1.1', '2.7.7.4', '1.8.1.2', '3.1.3.1', '3.6.1.1',
        '3.1.3.1', '3.6.1.2'
    ]
    theirECnumbers = set()

    for string in theirECnumberStrings:
        theirECnumbers.add(EcNumber(string))

    #- remove outdated EC numbers
    outdatedEcNumberStrings = [
        '1.1.1.118', '1.1.1.158', '1.1.1.2', '1.1.1.204', '1.1.1.21',
        '1.1.1.40', '1.1.1.57', '1.1.1.60', '1.1.99.1', '1.1.99.21',
        '1.1.99.5', '1.10.2.2', '1.13.11.24', '1.15.1.1', '1.2.1.19',
        '1.2.1.2', '1.2.1.21', '1.2.1.22', '1.2.1.25', '1.2.1.51', '1.3.1.26',
        '1.3.3.1', '1.3.3.3', '1.3.99.1', '1.3.99.2', '1.3.99.3', '1.4.3.3',
        '1.5.1.12', '1.5.1.29', '1.5.1.30', '1.5.3.1', '1.6.5.3', '1.7.99.4',
        '1.7.99.5', '1.9.3.1', '2.1.1.13', '2.3.1.41', '2.3.1.79', '2.4.2.11',
        '2.4.2.4', '2.5.1.22', '2.5.1.33', '2.6.1.2', '2.6.1.5', '2.6.1.58',
        '2.6.1.62', '2.7.1.20', '2.7.1.31', '2.7.1.34', '2.7.1.41', '2.7.1.47',
        '2.7.4.11', '2.7.4.14', '2.7.4.4', '2.7.7.1', '2.7.7.10', '2.7.7.58',
        '3.1.2.4', '3.1.3.18', '3.1.3.27', '3.1.4.14', '3.2.1.108', '3.2.1.21',
        '3.2.1.48', '3.2.2.16', '3.5.1.11', '3.5.1.19', '3.5.1.28', '3.5.1.31',
Exemplo n.º 9
0
    bacteriaClade = getBacteriaClade()
    #- build Archaea clade
    archaeaClade = getArchaeaClade()

    #- REPEAT for varying majority-percentages:
    for percentage in [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 1]:

        #-     overlap core metabolisms and print amount of EC numbers inside the intersection and falling off either side
        bacteriaECs = bacteriaClade.coreMetabolism(percentage).getECs()
        archaeaECs = archaeaClade.coreMetabolism(percentage).getECs()
        bothECs = bacteriaECs.intersection(archaeaECs)
        onlyBacteriaECs = bacteriaECs.difference(archaeaECs)
        onlyArchaeaECs = archaeaECs.difference(bacteriaECs)

        #-     remove wildcard EC numbers
        onlyBacteriaECs = EcNumber.removeWildcards(onlyBacteriaECs)
        bothECs = EcNumber.removeWildcards(bothECs)
        onlyArchaeaECs = EcNumber.removeWildcards(onlyArchaeaECs)

        output.append(
            str(percentage) + '%:\t' + str(len(onlyBacteriaECs)) + '\t' +
            str(len(bothECs)) + '\t' + str(len(onlyArchaeaECs)))

    for line in output:
        print(line)

    #- build clade pair
    cladePair = CladePair(bacteriaClade, archaeaClade)
    #- export unified metabolism, coloured by only Archaea/both/only Bacteria
    unifiedEcGraph = cladePair.unifiedMetabolism(colour=True)
    Export.forCytoscape(unifiedEcGraph,