<jupyter_start><jupyter_text>Writing your own workflowsMicom was designed to create and analyze personalized metabolic models for microbial communities. This makes it necessary to run many of the analyses in micom for many samples. As all of the methods currently implemented in micom can be run independently for each sample this workload can be parallelized pretty easily. To make this simple micom provides a workflow module that lets you run analyses for many samples in parallel. It also integrate with the micom logger and has workarounds for some memory leaks in optlang which improves memory usage. As a rule of thumb for each sample you will need one CPU and about 1GB of RAM, so if you have a server with 16 cores and 16+GB of RAM available you can run up to 16 samples in parallel.For a workflow you will need two things:1. A function that takes arguments for a single sample and performs your analysis2. A list of arguments for each sampleLet us understand this better with a short example. Let us assume that we want to run the cooperative tradeoff method for our *E. coli* example with varying numbers of *E. coli* strains.<jupyter_code>from micom.data import test_taxonomy

taxonomies = [test_taxonomy(n=n) for n in range(2, 12)]
taxonomies[2]<jupyter_output><empty_output><jupyter_text>This will be our arguments. Each entry in taxonomies defines a single sample so we have 10 samples in total. Now we need a function that takes a single samples' arguments as input (as set of abundances) and runs the cooperative tradeoff method. So let us implement that:<jupyter_code>from micom import Community

def run_tradeoff(tax):
    com = Community(tax, progress=False)
    sol = com.cooperative_tradeoff()
    return sol.members<jupyter_output><empty_output><jupyter_text>This is all we need to run the analysis in parallel.<jupyter_code>from micom.workflows import workflow

results = workflow(run_tradeoff, taxonomies, n_jobs=2)<jupyter_output><empty_output><jupyter_text>`results` is a list that contains one entry for each result (in the correct order).<jupyter_code>results[2]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.04714757190004715, 'fraction_numerical': 0.008015087223008015, 'mean_word_length': 5.3532934131736525, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '140705', 'license': 'Apache-2.0', 'n_tokens_mistral': 592, 'n_tokens_neox': 550, 'n_words': 294, 'path': 'docs/workflows.ipynb', 'repo_name': 'SantiagoMille/micom', 'size': '2121'}