Package: mgnify-pipelines-toolkit
mgnify-pipelines-toolkitThis Python package contains a collection of scripts and tools for including in MGnify pipelines. Scripts stored here are mainly for:One-off production scripts that perform specific tasks in pipelinesScripts that have few dependenciesScripts that don't have existing containers built to run themScripts for which building an entire container would be too bulky of a solution to deploy in pipelinesThis package is built and uploaded to PyPi and bioconda. The package bundles scripts and makes them executable from the command-line when this package is installed.How to installThis package is available both onPyPiand bioconda.To install from PyPi with pip:pip install mgnify-pipelines-toolkitTo install from bioconda with conda/mamba:conda install -c bioconda mgnify-pipelines-toolkitYou should then be able to run the packages from the command-line. For example to run theget_subunits.pyscript:get_subunits -i ${easel_coords} -n ${meta.id}Adding a new script to the packageNew script requirementsThere are a few requirements for your script:It needs to have a named main function of some kind. Seemgnify_pipelines_toolkit/analysis/shared/get_subunits.pyand themain()function for an exampleBecause this package is meant to be run from the command-line, make sure your script can easily pass arguments using tools likeargparseorclickA small amount of dependencies. This requirement is subjective, but for example if your script only requires a handful of basic packages likeBiopython,numpy,pandas, etc., then it's fine. However if the script has a more extensive list of dependencies, a container is probably a better fit.How to add a new scriptTo add a new Python script, first copy it over to themgnify_pipelines_toolkitdirectory in this repository, specifically to the subdirectory that makes the most sense. If none of the subdirectories make sense for your script, create a new one. If your script doesn't have amain()type function yet, write one.Then, openpyproject.tomlas you will need to add some bits. First, add any missing dependencies (include the version) to thedependenciesfield.Then, if you created a new subdirectory to add your script in, go to thepackagesline under[tool.setuptools]and add the new subdirectory following the same syntax.Then, scroll down to the[project.scripts]line. Here, you will create an alias command for running your script from the command-line. In the example line:get_subunits = "mgnify_pipelines_toolkit.analysis.shared.get_subunits:main"get_subunitsis the aliasmgnify_pipelines_toolkit.analysis.shared.get_subunitswill link the alias to the script with the pathmgnify_pipelines_toolkit/analysis/shared/get_subunits.py:mainwill specifically call the function namedmain()when the alias is run.When you have setup this command, executingget_subunitson the command-line will be the equivalent of doing:from mgnify_pipelines_toolkit.analysis.shared.get_subunits import main; main()You should then write at least one unit test for your addition. This package usespytestat the moment for this purpose. A GitHub Action workflow will run all of the unit tests whenever a commit is pushed to any branch.Finally, you will need to bump up the version in theversionline.At the moment, these should be the only steps required to setup your script in this package (which is subject to change).Building and uploading to PyPiThe building and pushing of the package is automated by GitHub Actions, which will activate only on a new release. Bioconda should then automatically pick up the new PyPi release and push it to their recipes, though it's worth keeping an eye on their automated pull requests just in casehere.