import sys
import string_chem_net as scn
import itertools as it

try:
    (monos, max_pol, min_ins, max_ins, min_outs, max_outs, reps) = sys.argv[1:]
except ValueError:
    sys.exit(
        'Arguments:\nmonomers\nmax polymer length\nminimum ' +
        'number of food sources\nmaximum number of food sources\nminimum ' +
        'number of biomass precursors\nmaximum number of biomass precursors\n'
        + 'number of times to prune with each setup')

# create the universal network
SCN = scn.CreateNetwork(monos, int(max_pol))
universal_model = scn.make_cobra_model(SCN.met_list,
                                       SCN.rxn_list,
                                       allow_export=True)

# make every pair of number of environments and number of biomass precursors
conditions = list(
    it.product(
        range(int(min_ins),
              int(max_ins) + 1),  # have to add 1 because Python
        range(int(min_outs),
              int(max_outs) + 1)))

# store the reaction-to-metabolite ratio and the % of pruned reactions for each
# pruned network
output_data = list()
    data.columns = ['env', 'rxn_incl', 'growth']
    # add a column with the biomass components
    data['biomass'] = list(
        it.repeat('-'.join([met.id for met in bm_rxn.metabolites]),
                  len(food_mets)))
    # reorder columns
    data = data[['biomass', 'env', 'rxn_incl', 'growth']]
    return (data)


monos = 'ab'  # characters to use as monomers
max_len = 5  # maximum length of each string chemical
ins = 2  # number of food sources / environmental nutrients
envs = 50  # number of different sets of food sources per biomass reaction
outs = 5  # number of biomass precursors
orgs = 10  # number of different biomass reactions
combos = 50  # number of times to perturb coefficients per biomass reaction
threads = 4  # threads to use when pruning in parallel

SCN = scn.CreateNetwork(monos, max_len)
full_model = scn.make_cobra_model(SCN.met_list, SCN.rxn_list)

# prune network using many biomass reactions and environments
pool = mp.Pool(1)
data_bits = pool.map(
    prune_many_times,
    # same arguments every time for orgs times
    [[full_model, ins, outs, envs, combos] for bm in range(orgs)])
data = pd.concat(data_bits)
data.to_csv('data/figure_S6_data.csv', index=False)
    # return it
    info_df = pd.DataFrame(info_dict)
    return (info_df)


if __name__ == '__main__':
    try:
        (monos, max_len, ins, outs, reps) = sys.argv[1:]
    except ValueError:
        sys.exit(
            'Specify monomers to use, maximum length of polymer, number of ' +
            'food sources, number of biomass precursors, and number of times to '
            + 'prune')

    # setup network of specified size
    SCN = scn.CreateNetwork(monos, int(max_len))
    cobra_model = scn.make_cobra_model(SCN.met_list, SCN.rxn_list)

    # prepare dataframe to hold info from all rounds of pruning
    all_data = pd.DataFrame({
        'step': list(),
        'type': list(),
        'rxn_count': list(),
        'jaccard': list()
    })
    # prune reps times and store all information in all_data
    for i in range(int(reps)):
        if (i + 1) % 10 == 0:
            print(f'On rep {i+1} of {reps}')
        some_data = compare_nets(cobra_model, int(ins), int(outs))
        # make another column to put i in so we can separate out all the different
Beispiel #4
0
# figure_1,py
# makes the three example string chemistry graphs shown in figure 1 of the 
# paper

import string_chem_net as scn
import pygraphviz as gv
import string

# tried making all three be subgraphs of the same graph, but the resulting
# image came out very wide and oddly low resolution, so we're making 3 separate
# images

# make the three networks we want to visualize, then loop over that list
least_net = scn.CreateNetwork('a', 2)
mid_net = scn.CreateNetwork('ab', 2)
most_net = scn.CreateNetwork('ab', 3)

nets = [least_net, mid_net, most_net]

for net in nets:
    figure = gv.AGraph(
        size = '11,8', # set size of output image
        dpi = '600', # set resolution of output image
        splines = 'true' # make sure nodes aren't overlapping with each other
    )
    # start with nodes
    for met in net.met_list:
        figure.add_node(met, shape = 'box', color = 'blue')
    for rxn in net.rxn_list:
        figure.add_node(rxn, shape = 'oval', color = 'red')
    # then do edges
    output = [ins, outs, ratio, pruned_pct]
    # make everything a string so we can join it later
    return ([str(x) for x in output])


# set parameters
monos = 'ab'
max_pol = 5
min_ins = 2  # smallest number of nutrients to use
max_ins = 5  # largest number of nutrients to use
min_outs = 5  # smallest number of biomass precursors to use
max_outs = 10  # largest number of biomass precursors to use
reps = 100  # number of times to prune with each combination

# create the universal network
SCN = scn.CreateNetwork(monos, max_pol)
universal_model = scn.make_cobra_model(SCN.met_list,
                                       SCN.rxn_list,
                                       allow_export=True)

# make every pair of number of environmental metabolites and number of biomass
# precursors
conditions = list(
    it.product(
        range(min_ins, max_ins + 1),  # have to add 1 because Python
        range(min_outs, max_outs + 1)))
# add the universal model to each of the sublists so that we can map this list
# of arguments to the function
args = [(universal_model, ) + sublist for sublist in conditions]
# multiply the list by reps to make sure each pair of values is tested reps
# times