spjuhel/BoARIO-MRIOT-Tools

Pipelines to parse and aggregate MRIOT data for BoARIO

Overview

Topics:

Latest release: None, Last update: 2024-08-09

Linting: linting: failed, Formatting:formatting: failed

Deployment

Step 1: Install Snakemake and Snakedeploy

Snakemake and Snakedeploy are best installed via the Mamba package manager (a drop-in replacement for conda). If you have neither Conda nor Mamba, it is recommended to install Miniforge. More details regarding Mamba can be found here.

When using Mamba, run

mamba create -c conda-forge -c bioconda --name snakemake snakemake snakedeploy

to install both Snakemake and Snakedeploy in an isolated environment. For all following commands ensure that this environment is activated via

conda activate snakemake

Step 2: Deploy workflow

With Snakemake and Snakedeploy installed, the workflow can be deployed as follows. First, create an appropriate project working directory on your system and enter it:

mkdir -p path/to/project-workdir
cd path/to/project-workdir

In all following steps, we will assume that you are inside of that directory. Then run

snakedeploy deploy-workflow https://github.com/spjuhel/BoARIO-MRIOT-Tools . --tag None

Snakedeploy will create two folders, workflow and config. The former contains the deployment of the chosen workflow as a Snakemake module, the latter contains configuration files which will be modified in the next step in order to configure the workflow to your needs.

Step 3: Configure workflow

To configure the workflow, adapt config/config.yml to your needs following the instructions below.

Step 4: Run workflow

The deployment method is controlled using the --software-deployment-method (short --sdm) argument.

To run the workflow with automatic deployment of all required software via conda/mamba, use

snakemake --cores all --sdm conda

Snakemake will automatically detect the main Snakefile in the workflow subfolder and execute the workflow module that has been defined by the deployment in step 2.

For further options such as cluster and cloud execution, see the docs.

Step 5: Generate report

After finalizing your data analysis, you can automatically generate an interactive visual HTML report for inspection of results together with parameters and code inside of the browser using

snakemake --report report.zip

Configuration

The following section is imported from the workflow’s config/README.md.

General Configuration

To configure this workflow, modify config/config.yaml according to your needs, following the explanations provided in the file.

Output folders

By default, this workflow stores the files obtained, parsed and aggregated into three different folders (downloaded/, parsed/ aggregated/) in the working directory. This behavior can be changed with the entries downloaded_mriot_dir:, parsed_mriot_dir: and aggregated_mriot_dir:.

Files corresponding to a specific MRIOT will be stored in a subfolder of the corresponding name. For instance, Exiobase 3 (in ixi system) for year 1995 aggregated to 74 sectors will be stored under parsed/exiobase3_ixi/exiobase3_ixi_1995_74_sectors.pkl.

Sector aggregation files

The workflow looks for aggregation files in the aggregation_csv_dir: (config/aggregation_files) by default.

Some existing aggregation are included in the repository, and new ones can be added. If you think an aggregation file you designed would be a valuable contribution, don't hesitate to pull-request it !

The folder structure follows the same as for outputs, for instance, the file used to aggregate Exiobase 3 to 74 sectors is looked under config/aggregation_files/exiobase3_ixi/exiobase3_ixi_74_sectors.csv

Files should be in csv format, with a first column sector with all the original sectors of the MRIOT, and group and name columns with the new ID and names to map the original sectors too.

Common aggregation

As an additional way to aggregate different MRIOTs into a common one, this workflow also embarks a config/aggregation_files/sectors_common_aggreg.ods file for this purpose.

The sheet common_aggreg of the file defines the sector to aggregate to via group_id and sector_name columns. The following sheets, <mriot_name>_to_common_aggreg, have original sector, to_id and a new sector columns auto computed from to_id.

Asking the workflow to build aggregated/icio2021/icio2021_2003_common_aggreg.pkl, for instance, will aggregate icio2021_2003_full.pkl to the sectors defined in the sheet common_aggreg based on the correspondence in icio2021_to_common_aggreg.

Disclaimer: This work is still under progress and still requires to be streamlined.

Parameters aggregation

The workflow also allows to build sector parameters files for the BoARIO model. We provide a config/mriot_params/exiobase3_ixi_full_sectors.csv "master" file that contains values we used with the model and this MRIOT, and from which similar files can be obtained for the other MRIOT, using config/aggregation_files/exiobase3_ixi/exiobase3_ixi_to_other_mrio_sectors.ods.

Linting and formatting

Linting results

Traceback (most recent call last):

  File "/home/runner/micromamba-root/envs/snakemake-workflow-catalog/lib/python3.12/site-packages/snakemake/cli.py", line 2011, in args_to_api
    any_lint = workflow_api.lint()
               ^^^^^^^^^^^^^^^^^^^

  File "/home/runner/micromamba-root/envs/snakemake-workflow-catalog/lib/python3.12/site-packages/snakemake/api.py", line 337, in _handle_no_dag
    return method(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/runner/micromamba-root/envs/snakemake-workflow-catalog/lib/python3.12/site-packages/snakemake/api.py", line 354, in lint
    workflow.include(

  File "/home/runner/micromamba-root/envs/snakemake-workflow-catalog/lib/python3.12/site-packages/snakemake/workflow.py", line 1399, in include
    exec(compile(code, snakefile.get_path_or_uri(), "exec"), self.globals)

  File "/tmp/tmpfciba8yw/workflow/Snakefile", line 6, in <module>
    from boario_tools.regex_patterns import (

ModuleNotFoundError: No module named 'boario_tools'

... (truncated)

Formatting results

[DEBUG] 
[DEBUG] 
[DEBUG] 
[DEBUG] In file "/tmp/tmpfciba8yw/workflow/Snakefile":  Formatted content is different from original
[DEBUG] 
[DEBUG] 
[DEBUG] 
[DEBUG] In file "/tmp/tmpfciba8yw/workflow/rules/mrio_treatments.smk":  Formatted content is different from original
[DEBUG] 
[DEBUG] In file "/tmp/tmpfciba8yw/workflow/rules/sectors_config.smk":  Formatted content is different from original
[INFO] 3 file(s) would be changed 😬
[INFO] 4 file(s) would be left unchanged 🎉

snakefmt version: 0.10.2