Snakemake/DahakFlot
From charlesreid1
Main repository:
Start
This tutorial is assuming you start out on a machine with a conda-based python distribution (Anaconda or Miniconda or other).
Installing Conda with Pyenv
If you don't have a version of conda, it is recommended you use Pyenv to manage versions of python.
A very simple pyenv installation script:
install_pyenv.py
#!/usr/bin/python3
import getpass
import subprocess
def install_pyenv():
user = getpass.getuser()
if(user=="root"):
raise Exception("You are root - you should run this script as a normal user.")
else:
# Install pyenv
pyenvcmd = ["curl","-L","https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer","|","/bin/bash"]
subprocess.call(pyenvcmd, shell=True)
# We don't need to add ~/.pyenv/bin to $PATH,
# it is already done.
if __name__=="__main__":
install_pyenv()
As noted in the script, you will need to add ~/.pyenv/bin to the path, as that is where the Pyenv versions of Python live.
Next, we have a python script to install snakemake:
#!/usr/bin/python3
import getpass
import tempfile
import subprocess
def install_pyenv():
user = getpass.getuser()
if(user=="root"):
raise Exception("You are root - you should run this script as a normal user.")
else:
# Install snakemake
conda_version = "miniconda3-4.3.30"
installcmd = ["pyenv","install",conda_version]
subprocess.call(installcmd)
globalcmd = ["pyenv","global",conda_version]
subprocess.call(globalcmd)
# ---------------------------
# Install snakemake
pyenvbin = os.environ['HOME']
condabin = pyenvbin+"/.pyenv/shims/conda"
subprocess.call([condabin,"update"])
subprocess.call([condabin,"config","--all","channels","r"])
subprocess.call([condabin,"config","--all","channels","default"])
subprocess.call([condabin,"config","--all","channels","conda-forge"])
subprocess.call([condabin,"config","--all","channels","bioconda"])
subprocess.call([condabin,"install","--yes","-c","bioconda","snakemake"])
# ---------------------------
# Install osf cli client
pyenvbin = os.environ['HOME']
pipbin = pyenvbin+"/.pyenv/shims/pip"
subprocess.call([pipbin,"install","--upgrade","pip"])
subprocess.call([pipbin,"install","--user","osfclient"])
if __name__=="__main__":
install_pyenv()
Get Tutorial Files
Start by getting the files needed for the tutorial:
wget https://bitbucket.org/snakemake/snakemake-tutorial/get/v3.11.0.tar.bz2 tar -xf v3.11.0.tar.bz2 --strip 1
First Snakefile
Create a Snakefile, and add the first rule:
rule bwa_map:
input:
"data/genome.fa",
"data/samples/{sample}.fastq"
output:
"mapped_reads/{sample}.bam"
shell:
"bwa mem {input} | samtools view -Sb - > {output}"
This creates a folder with data in it, and an environment.yaml file for conda.
Create the conda environment:
conda env create --name snakemake-tutorial --file environment.yaml
Now activate the conda environment:
source activate snakemake-tutorial