Пример #1
0
def coreFromReactions(sources, reactionSet):
    avrxns = [rxn_kegg_to_id[e] for e in reactionSet]
    scopeMets, avScopeRxn = giveScope(rxnMat[avrxns], prodMat[avrxns],
                                      giveSeedVec(sources), sumRxnVec[avrxns])
    scopeRxns = np.nonzero(avrxns * avScopeRxn)[0]
    return set([id_to_kegg[e]
                for e in set(np.where(scopeMets)[0])]) & set(Core)
Пример #2
0
def give_ind_degree(org):
    # Getting all the reactions performable by this organism.
    can = set(np.genfromtxt('organism_reactions/' + org + '.txt').astype(int))
    can = ['R' + (5 - len(str(int(e)))) * '0' + str(int(e)) for e in can]
    can = list((set(can)) & set(rxns))
    avrxns = [rxn_kegg_to_id[e] for e in can]

    # Calculating the metabolites within the scope of
    # this organism's reaction network.
    scopeMets = giveScope(rxnMat[avrxns], prodMat[avrxns], seedVec,
                          sumRxnVec[avrxns])[0]

    # Finding how much of the core is within the network's scope.
    return list(
        set([id_to_kegg[e] for e in set(np.where(scopeMets)[0])]) & set(Core))
Пример #3
0
def propagate_rxns_for_medium(orgrxns, medium):
    # Defining the seed set to be the medium and the currency,
    seedVec = np.zeros(len(rxnMat.T))
    seedVec[[kegg_to_id[e] for e in Currency + medium]] = 1

    # Getting all the reactions performable by this organism.
    avrxns = orgrxns[:]

    # Calculating the metabolites within the scope of
    # this organism's reaction network.
    scopeMets = giveScope(rxnMat[avrxns], prodMat[avrxns], seedVec,
                          sumRxnVec[avrxns])[0]

    # Finding how much of the core is within the network's scope.
    return uniqify([id_to_kegg[e] for e in np.where(scopeMets)[0]])
Пример #4
0
def propagate_core_for_medium(corerxns, medium):
    # Defining the seed set to be the medium and the currency,
    seedVec = np.zeros(len(rxnMat.T))
    seedVec[[kegg_to_id[e] for e in Currency + medium]] = 1

    # Getting all the reactions performable by these corerxns.
    can = ['R' + (5 - len(str(int(e)))) * '0' + str(int(e)) for e in corerxns]
    can = list((set(can)) & set(rxns))
    avrxns = [rxn_kegg_to_id[e] for e in can]

    # Calculating the metabolites within the scope of 
    # this organism's reaction network. 
    scopeMets = giveScope(rxnMat[avrxns], prodMat[avrxns], seedVec, sumRxnVec[avrxns])[0]
    
    # Finding how much of the core is within the network's scope.
    return uniqify([id_to_kegg[e] for e in np.where(scopeMets)[0]])
Пример #5
0
def propagate_single_for_medium(org, medium):
    # Defining the seed set to be the medium and the currency,
    seedVec = np.zeros(len(rxnMat.T))
    seedVec[[kegg_to_id[e] for e in Currency + medium]] = 1

    # Getting all the reactions performable by this organism.
    can = ''.join(open('strain_reactions/' + org + '.txt', 'r').readlines()).split()
    can = list((set(can)) & set(rxns))
    avrxns = [rxn_kegg_to_id[e] for e in can]

    # Calculating the metabolites within the scope of 
    # this organism's reaction network. 
    scopeMets = giveScope(rxnMat[avrxns], prodMat[avrxns], seedVec, sumRxnVec[avrxns])[0]
    
    # Finding how much of the core is within the network's scope.
    return uniqify([id_to_kegg[e] for e in np.where(scopeMets)[0]])
Пример #6
0
def inferProducible(genotype, sources=defaultSeedVec):
    """
    Given a genotype, infers what reactions it can perform, and then calculates 
    all producible metabolites in a given environment. 

    If no environment is supplied, assumes a rich environment with all single 
    carbon source enrichments.
    """
    # Getting all reactions that the genotype can perform.
    can = genotypeToRxns(genotype)

    # Generating the seed vector from the environmental sources.
    currSeedVec = giveSeedVec(sources)

    avrxns = [rxn_kegg_to_id[e] for e in can]
    scopeMets = giveScope(rxnMat[avrxns], prodMat[avrxns], currSeedVec,
                          sumRxnVec[avrxns])[0]
    return set([id_to_kegg[e] for e in np.where(scopeMets)[0]])
Пример #7
0
def inferIndDegree(genotype):
    kos = [pos_to_gene_map[i] for i in np.where((genotype > 0.5) * 1)[0]]
    refDF = pd.read_csv('KOREF.txt',
                        delimiter='\t',
                        sep='delimiter',
                        header=None,
                        names=['id', 'rid'])

    def give_number(string):
        return int(string[-5:])

    refDF['id'] = refDF['id'].apply(give_number)
    refDF['rid'] = refDF['rid'].apply(give_number)
    can = refDF.loc[refDF['id'].isin(kos), :]['rid'].values
    can = ['R' + (5 - len(str(int(e)))) * '0' + str(int(e)) for e in can]
    can = list((set(can)) & set(rxns))
    avrxns = [rxn_kegg_to_id[e] for e in can]
    scopeMets = giveScope(rxnMat[avrxns], prodMat[avrxns], seedVec,
                          sumRxnVec[avrxns])[0]
    return list(
        set([id_to_kegg[e] for e in set(np.where(scopeMets)[0])]) & set(Core))