Introduction to Pixi
Introduction
Different operating systems bring different challenges to bioinformatics. Windows, for instance, doesn’t really support most bioinformatics tools. One way to solve this through the use of environments. There are, of course, other ways, e.g. running virtual machines. In our experience, environments are a bit easier to manage and are more portable across different systems. There are many different kinds of environments, and for this course, we are going to use Pixi.
As you can see, you can run Pixi on all major operating systems, and you can include various platforms in your Pixi environment.
Installation
Installing Pixi is really easy and described throughouly here with separate installation guides for Windows and Mac/Linux.
To source your shell, you need to source the startup files, in Linux it’s the ~/.bashrc
file, in Mac it’s the ~/.zshrc
file.
Setting Up An Environment
You should create separate environments for each project you run, just to keep things tidy. To create an environment, you have to specify a name for your environment. You can include different platforms/operating systems in your environment, as well as different channels.
Here, we will create a project called name_sida_training
(please use your own name to avoid). We are adding the conda-forge and bioconda channels with the -c
flag.
pixi init name_sida_training -c conda-forge -c bioconda
If you want to add different platforms, you add them with the -p linux-64
flag. In this example, you are adding Linux64. See the Pixi docs for the full list of supported platforms.
If you are adding a platform that doesn’t natively run on your OS (e.g. adding Linux when running on Windows) be sure to add the OS you are running your system on as well!
When you change directories into the folder pixi created you will see two files: pixi.lock
and pixi.toml
.
Here is the code for changing directories, listing files, and viewing the contents of a file:
cd name_sida_training
ls
less pixi.toml
To exit the less
view, press q
for quit.
pixi.toml
The .toml file give your information about your project. Let’s have a look at one I made one my Mac before adding any dependencies to my environment. How is it different from the one we’ve made on HPC2N?
[workspace]
channels = ["conda-forge", "bioconda"]
name = "sida_quarto"
platforms = ["osx-arm64"]
version = "0.1.0"
[tasks]
[dependencies]
pixi.lock
The .lock file give you information on the channels you have decided to add, as well as the information on where the packages were downloaded from, license information, md5 information, and more.
Do not delete the .toml or .lock files, or you will break your environment!
Adding Dependencies
Adding dependencies is like installing a program. Instead of installing it globally, it only gets installed in the environment.
To do this, we use the pixi add
function. Let’s try adding Quarto
to our environments (we will use Quarto extensively in this course!)
You must be in the folder of the project to add software!
pixi add quarto
If you are unsure of how a function works, you can always query it, usually with the --help
or -h
flags. Here’s how it would look for the pixi add
function
pixi add --help
A general rule of thumb is that a single hyphen -
is followed by a single letter flag, while double hyphens --
are usually followed by multi-letter flags
Here is the pixi.toml from before after I have added Quarto to my environment. You can see that the dependencies have been updated to include Quarto
.
[workspace]
channels = ["conda-forge", "bioconda"]
name = "sida_test"
platforms = ["osx-arm64"]
version = "0.1.0"
[tasks]
[dependencies]
quarto = ">=1.7.32,<2"
Running a Package
Now that we have an environment with a package running in it, we actually want to use it. Let’s query the help function within Quarto.
pixi run quarto --help
To use other tools, simply substitute quarto
with the package you’ve added