Skip to content
Dhwani Desai edited this page Jul 11, 2019 · 26 revisions

Welcome to the MH2_test wiki!

Running Microbiome Helper from Docker Image

The Microbiome Helper Docker image is based on Ubuntu and contains all the scripts, external programs and some databases used in the workflow described in the Metagenomics SOP v2 section at https://github.com/dhwanidesai/MH2_test/wiki

We have created a new user in the image called "microbiomeuser" who has permissions to run the scripts in the container. When a container of this image is run, it by default points to a location "/home/microbiomeuser". This will be the "home" location (indicated by ~).

The user ID for this user is 998. So if you already have a user with ID 998 on your system, when you copy result files out from the container, it will have ownership of that user. Otherwise, it will just be owned by 998. In either case, you should change the ownership back to your own username by using the chown and chgrp commands.

Pull Image from DockerHUb

docker pull dockerdkd/microbiomehelper:latest

Run a container from the Microbiome Helper Docker image

docker run -it dockerdkd/microbiomehelper:latest

=== Tip to change the docker installation directory (where it stores the generated image) from the default / ===

We will use systemd from Ubuntu to control Docker behaviour

Create a docker.service.d folder in /etc/systemd

sudo mkdir -p /etc/systemd/system/docker.service.d

Create a config file for controlling Docker; Open a new file in an editor such as nano

sudo nano /etc/systemd/system/docker.service.d/docker-storage.conf

paste the following lines in the docker-storage.conf file using an editor (E.g nano)

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --data-root="/path/to/new/docker_storage folder"

REstart the docker service

sudo systemctl daemon-reload

sudo systemctl restart docker

Check the change in directory by doing the following: It should now point to "/path/to/new/docker_storage folder"

docker info|grep -P "Docker Root Dir"

=== Tip to run docker without sudo everytime ===

Add a user group docker

sudo groupadd docker

Add the current user to this group

sudo gpasswd -a $USER docker

Change to the new group; You can also logout and login again

newgrp docker

Copy sequence data files into the Microbiome Helper container

This can be done in 2 ways:

1) Use docker cp

Run the Microbiome Helper Docker image

docker run -it microbiomehelper:latest

Get the container ID of the container that was run when you ran the image in the above command

docker container ls -a

Copy the sequence files into the container

docker cp ~/Downloads/mgs_tutorial_Oct2017.zip <container ID>:/home/microbiomeuser

Restart the container and re-run the container as root; You need to do this once to change the permissions of the files copied into the container

docker restart <container ID>

docker exec --user root -it <container ID> bash

Once in the container, change the ownership of the copied folder

chown -R microbiomeuser <folder name>

chgrp -R microbiomeuser <folder name>

Exit the container

exit

Now restart the container without root (with the --user microbiomeuser) to start running the workflow commands

docker exec --user microbiomeuser -it <container ID> bash

Replace with your container IDs in the above commands, e.g 29e00503e530

2) Mounting a directory with sequence data in the container

You can run a docker image with the mount (-v) option to mount a directory from your hard drive in the container. Again, you need to first mount the directory in the container as root, change the ownership of the mounted directory to "microbiomeuser" as in the previous case and then re-run the container with the "--user microbiomeuser" option. For example, if you made a folder docker_test_analysis which contains your fastq files, you could mount it first as root, change the ownership of the folder inside the container, the exit the container, restart it and re-run it again as with the "--user microbiomeuser" option as follows:

docker run --user root -it -v \ $PWD/docker_test_analysis:/home/microbiomeuser/docker_test_analysis \ dockerdkd/microbiomehelper:latest bash

Inside the container, change ownership

chown -R microbiomeuser <folder name>

chgrp -R microbiomeuser <folder name>

Exit the container

exit

Get a list of container IDs so that you know which one to restart docker container ls -a

Restart the container you want by specifying its ID docker restart <container ID>

Run it again with "microbiomeuser" docker exec --user microbiomeuser -it <container ID> bash

Pre-processing preparations

Setup the humann2 databases

humann2_databases --available

humann2_databases --download chocophlan full /home/microbiomeuser/databases

humann2_databases --download uniref uniref90_diamond /home/microbiomeuser/databases

Fix Metaphlan database errors

Sometimes you might get an error as follows:

Error message returned from metaphlan2.py :

Downloading MetaPhlAn2 database
Please note due to the size this might take a few minutes

This might be due to incorrect indexing of the Metaphlan2 mpa database by bowtie2

To fix this (modified from https://groups.google.com/forum/#!topic/metaphlan-users/7TfY_h-SELQ ): (PLease make sure you are in the Docker container)

cd ~/metaphlan2/metaphlan_databases

wget https://bitbucket.org/biobakery/metaphlan2/downloads/mpa_v20_m200.tar

tar -xvf mpa_v20_m200.tar

bzip2 -dk mpa_v20_m200.fna.bz2

bowtie2-build --threads 4 mpa_v20_m200.fna mpa_v20_m200

You are now ready to run the Microbiome Helper workflow commands in the Docker container

Clone this wiki locally