diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7fa4120f05c24bc62ba67f5f4485f1bbe55159c..5b05123d022715c187d6b19c8cad995b77b51979 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,7 @@ +# IMPORTANT: running the pipeline for testing, keep in mind, re-building an +# existing package version fails! For testing, build for an old tag which does +# not have a package in the registry, yet. Delete the package after testing. + build-package: stage: deploy image: python:3.6 diff --git a/README.md b/README.md index 1ff7ec7c9e513d843c1634cb2489bac2cb99d099..04ca64eb2514ea71406a9cdc420d405ca9108317 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,56 @@ output files ...), here are some things to consider: - if running on CPUs without GPU, avoid the `lii` nodes (`--exclude=lii[02-28]`) +## Custom AF2 pipeline + +`run_af2` executes the default AlphaFold 2 pipeline. That is, in the end a +script [`run_alphafold.py`]( +https://github.com/deepmind/alphafold/blob/main/run_alphafold.py) is run. For +some studies, you may want to go by a modified version of `run_alphafold.py`. +While `run_af2` is based on containerised software in its backyard, injecting +your custom script inside the Singularity container is not terribly complicated. +In the shell, you want to run your command in, simply create an environment +variable `SINGULARITY_BINDPATH` with the mapping of your script to the original +script inside the container: + +```terminal +$ export SINGULARITY_BINDPATH="/PATH/TO/SCRIPT/run_alphafold.py:/app/alphafold/run_alphafold.py"" +``` + +Where `/PATH/TO/SCRIPT/run_alphafold.py` points to your modified +`run_alphafold.py`. After that, just run `run_af2` as described in +[Default AF2 pipeline](#default-af2-pipeline). + +Please note, this method of altering the app executed by a container defies the +main purpose of containers providing unaltered apps ready to go, out of the box. +Also note, since this method relies on internals of the pipeline beyond the +scope of af2@scicore, future updates of AF2 may break it. + + +## Custom container + +`run_af2` uses the AlphaFold 2 pipeline as provided by DeepMind. That is, we +build the vanilla Docker container as described in their [documentation]( +https://github.com/deepmind/alphafold). Simply run + +```terminal +$ docker build -f docker/Dockerfile -t alphafold:2022-01-11 . +``` + +inside a checkout of the AF2 Git repository. That creates the container tagged +with `2022-01-11`, which is the way `run_af2` indicates versions. It's simply +the date of creation of the container from a fresh checkout of the Git repository. + +This Docker container is then turned into a Singularity container: + +```terminal +$ singularity build alphafold-2022-01-11.sif docker-daemon://alphafold:2022-01-11 +``` + +`alphafold-2022-01-11.sif` can then be used with the `--singularity-image` of +`run_af2`. + + ## Interactive IPython notebook As an expert mode, we provide a notebook version of the default AF2 pipeline @@ -193,5 +243,5 @@ highly secure *my_password*. <!-- LocalWords: AlphaFold sciCORE IPython ipynb GitLab PyPI af FASTA py rtx --> -<!-- LocalWords: alphafold sbatch +<!-- LocalWords: alphafold sbatch DeepMind --> diff --git a/run_af2/src/run_af2/_shared.py b/run_af2/src/run_af2/_shared.py index 27aa8e1ce24b726aa2b13e957b844950464e5797..f2affaaddcbfddc4799fb4ce76ce1fa1baf0dda1 100644 --- a/run_af2/src/run_af2/_shared.py +++ b/run_af2/src/run_af2/_shared.py @@ -212,7 +212,7 @@ def parse_af2_arguments(parser): metavar="<FILE>", default=None, ) - opts = parser.parse_args() + opts, extra_opts = parser.parse_known_args() # check that the db_preset setting makes sense for arg in db_preset_choices[opts.db_preset]: @@ -253,7 +253,7 @@ def parse_af2_arguments(parser): ) sys.exit(1) - return opts + return opts, extra_opts # LocalWords: argparse ArgumentParser Namespace Bioinformatics Biozentrum af diff --git a/run_af2/src/run_af2/run_singularity.py b/run_af2/src/run_af2/run_singularity.py index 0e35bac2b10116eab6fa467d7f3cb59b1568d796..9b04f8d4aa18c2ac12d5b217b32ce7d7cdf5d12f 100644 --- a/run_af2/src/run_af2/run_singularity.py +++ b/run_af2/src/run_af2/run_singularity.py @@ -118,6 +118,7 @@ def _assemble_singularity_call( # pylint: disable=too-many-arguments model_preset, is_prokaryote_list, data_paths, + extra_arg_list, ): """Assemble the command to run AF2 from the Singularity image.""" # Since the number of arguments to this function is already high, we allow @@ -158,6 +159,9 @@ def _assemble_singularity_call( # pylint: disable=too-many-arguments for flag, path in data_paths.items(): snglrty_cmd.append(f"--{flag}={path}") + # append extra arguments + snglrty_cmd.extend(extra_arg_list) + return snglrty_cmd @@ -199,6 +203,7 @@ def run_af2_singularity_image( # pylint: disable=too-many-arguments af2_image_dir="/scicore/home/schwede/GROUP/alphafold_data/", snglrty_bin="/usr/bin/singularity", tmpdir_var="TMPDIR", + extra_arg_list=None, # data_dir="/scicore/data/managed/AF2params/frozen_210805T171956/", data_dir="/scicore/home/schwede/GROUP/alphafold_data/", uniref90_database_path="/scicore/data/managed/UniProt/latest/uniref/" @@ -274,6 +279,10 @@ def run_af2_singularity_image( # pylint: disable=too-many-arguments :param tmpdir_var: An environment variable defining tmp space, that is not necessarily "/tmp" on some systems. :type tmpdir_var: :class:`str` + :param extra_arg_list: List of extra arguments appended to the Singularity + call. That is for adding extra arguments in a + modified version of run_alphafold.py. + :type extra_arg_list: :class:`list` :param data_dir: Holds the params sub directory with model parameters. Corresponds to DOWNLOAD_DIR in AF2. :type data_dir: :class:`str` @@ -321,6 +330,8 @@ def run_af2_singularity_image( # pylint: disable=too-many-arguments # Since the number of arguments to this function is already high, we allow # more local variables than defined by PEP8. # pylint: disable=too-many-locals + if extra_arg_list is None: + extra_arg_list = [] tmpdir = os.getenv(tmpdir_var) if tmpdir is None: raise ValueError(f"tmpdir_var {tmpdir_var} must not be empty.") @@ -382,6 +393,7 @@ def run_af2_singularity_image( # pylint: disable=too-many-arguments model_preset, is_prokaryote_list, data_paths, + extra_arg_list, ) # set up environment @@ -412,7 +424,7 @@ def run_af2_singularity_image( # pylint: disable=too-many-arguments def main(): """Execute as script""" - opts = _parse_cmdline() + opts, extra_arg_list = _parse_cmdline() # Collect data paths into a dictionary so we can deal with default path on # the sciCORE cluster more easily. @@ -449,7 +461,8 @@ def main(): opts.db_preset, opts.model_preset, opts.is_prokaryote_list, - af2_image_file=opts.singularity_image, + opts.singularity_image, + extra_arg_list=extra_arg_list, **data_paths, ) except RuntimeError as rte: