Skip to main content

Setting environmental parameters in conda

Just came across this post about specifying parameters on conda


Basically, when you create an enter a new environment, this gives you the capability to save environmental variables specific to that environment.  And even better, you can deconstruct those variables once you leave that environment.

What does this mean?  It means that you can enforce relatively isolated environments, when it comes to environments.  So if you wanted to install 2 different versions of the same package in two different environments, easy!  Just specify the path variables that you want under the activate.d file, and restore the variables that you had previously in the deactivate.d file.

To see what I mean, consider the following test

conda create -n test pip
source activate test

Now we have a new conda environment, and if you check out your miniconda envs folder you should be able to see it.  For me, I can run the following to do this

ls ~/miniconda3/envs/

I'm using miniconda instead because anaconda has a lot of bloatware bundled with it, which can hamper the installation process of some programs.  See my previous post about installing qiime for more details.

Now within your test environment, you can create scripts to store all of your environmental variables.

mkdir -p ~/miniconda3/envs/test/etc/conda/activate.d
mkdir -p ~/miniconda3/envs/test/etc/conda/deactivate.d
touch ~/miniconda3/envs/test/etc/conda/activate.d/env_vars.sh
touch ~/miniconda3/envs/test/etc/conda/deactivate.d/env_vars.sh

The conda tutorial I pointed to above pretty much does this

Now, within your activate.d file, you can create an entirely new path. This should work assuming that you don't already have a variable named OLD_PATH.

#!/bin/sh

export OLD_PATH=$PATH
export PATH='foo'

And in your deactivate.d file you can restore your original environment variable
#!/bin/sh

export PATH=$OLD_PATH
unset OLDPATH

Try echoing out these variables, and you should see that your PATH variable should be changed in the test environment.  It just goes to show, conda is a really powerful tool.


Comments

Popular posts from this blog

ANCOM explained

In case you have not heard, ANCOM is another differential abundance test, designed specifically for tweezing out differentially abundance bacteria between groups.  Now, note that there are a ton of differential abundance techniques out there.  And one might ask why are there so many people focused on this seemingly simple problem. It turns out that this problem is actually impossible.   And this is rooted into the issue of relative abundances.  A change of 1 species between samples can be also explained by the change of all of the other species between samples.   Let's take a look at simple, concrete example. Here we have ten species, and 1 species doubles after the first time point.  If we know the original abundances of this species, it's pretty clear that species 1 doubled.  However, if we can only obtain the proportions of species within the environment, the message isn't so clear. Above are the proportions of the species in the e...

Installing qiime through conda

First set of posts on conda.  Its becoming increasingly difficult to sift through my inbox to find all of the proper commands, so here it goes :) Anyways, conda has proven to be quite a powerful tool.  It enables _all_ of the capabilities provided by virtualenv, plus more.  It can install C libraries such as hdf5, is my personal go-to whenever I'm installing software on a new system.  Heck you can even install different versions of Python - how cool is that? That being said, the fastest way I know of to install qiime on a new cluster is through conda. To get started, you'll first want to install Miniconda .  The reason way is because you want a minimal conda install, otherwise you'll end up breaking some of the dependencies required by qiime. After getting into your root directory, you can download python (for python 3) for linux wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh If you have a mac you can use the following...

Behind the scenes with BIOM tables

Today, I'll be covering the BIOM file format , a standardized file format for storing sequence counts in samples.  This file format is typically used in the biological sciences, most notably in amplicon sequencing technologies, such as 16S sequencing. For those of you that aren't as familiar with these technologies.  When we conduct survey studies, we like to get a broad overview of the microbes that are living within a raw sample.  But we don't need to sequence the entire bacteria's genome to identify what the bacteria is.  We can just a sequence a housekeeping gene that every bacteria as - the 16S ribosome. Its a similar strategy deployed in court.  When DNA evidence is presented in the court room, only a tiny, tiny portion of an individuals DNA is actually required to uniquely identify that person. But moving on. The BIOM file format was originally designed to store counts of 16S sequences across samples, but it has grown to become a more generalized...