Commit 736027d1 authored by Blaise Li's avatar Blaise Li
Browse files

Made snakemake wrappers a submodule.

parent 36306d05
from snakemake.shell import shell
from libworkflows import SHELL_FUNCTIONS
# Define functions to be used in shell portions
shell.prefix(SHELL_FUNCTIONS)
cmd = """
# make bedtools crash if it uses too much memory
# http://cr.yp.to/daemontools/softlimit.html
# sudo apt install daemontools
converter="/pasteur/entites/Mhe/Genomes/C_elegans/Caenorhabditis_elegans/Ensembl/WBcel235/Annotation/Genes/genes_id2name.pickle"
# Put fifos in a temporary directory
workdir=$(mktemp -d)
annot="${{workdir}}/annot.bed"
# Doesn't work if fifo:
# The annot file may have only 3 columns instead of 6
# Maybe it is read before the line is complete?
#mkfifo ${{annot}}
genome_file="${{workdir}}/chrom_sizes.txt"
mkfifo ${{genome_file}}
cleanup()
{{
rm -rf ${{workdir}}
}}
> {snakemake.log.err}
# Write the fifo(s) in the background
samtools view -H {snakemake.input.sorted_bam} | awk '$1 == "@SQ" {{print $2"\t"$3}}' | sed 's/SN://g' | sed 's/LN://' > ${{genome_file}} 2>> {snakemake.log.err} || {{ cleanup && error_exit "making ${{genome_file}} failed"; }} &
#gff_merge_transcripts.sh {snakemake.params.annot} > ${{annot}} 2>> {snakemake.log.err} || {{ cleanup && error_exit "making merged transcript failed"; }}
#cmd="bedtools intersect -a ${{annot}} -b {snakemake.input.sorted_bam} -sorted -g ${{genome_file}} -c | tee {snakemake.output.counts} | id2name.py ${{converter}} > {snakemake.output.counts_converted}"
cmd="softlimit -a 4294967296 bedtools intersect -a {snakemake.params.annot} -b {snakemake.input.sorted_bam} -sorted -g ${{genome_file}} -c | tee {snakemake.output.counts} | id2name.py ${{converter}} > {snakemake.output.counts_converted}"
echo ${{cmd}} > {snakemake.log.log}
eval ${{cmd}} 1>> {snakemake.log.log} 2>> {snakemake.log.err} || {{ cleanup && error_exit "bedtools intersect failed"; }}
cleanup
"""
shell(cmd)
from snakemake.shell import shell
def mapping_command(aligner):
"""This function returns the shell commands to run given the *aligner*."""
if aligner == "hisat2":
shell_commands = """
cmd="niceload --noswap -q hisat2 -p {snakemake.threads} --dta --seed 123 -t {snakemake.params.settings} --mm -x {snakemake.params.index} -U {snakemake.input.fastq} --no-unal --un-gz {snakemake.output.nomap_fastq} -S {snakemake.output.sam}"
echo ${{cmd}} 1> {snakemake.log.log}
eval ${{cmd}} 1>> {snakemake.log.log} 2> {snakemake.log.err}
"""
elif aligner == "bowtie2":
shell_commands = """
cmd="niceload --noswap -q bowtie2 -p {snakemake.threads} --seed 123 -t {snakemake.params.settings} --mm -x {snakemake.params.index} -U {snakemake.input.fastq} --no-unal --un-gz {snakemake.output.nomap_fastq} -S {snakemake.output.sam}"
echo ${{cmd}} > {snakemake.log.log}
eval ${{cmd}} 1>> {snakemake.log.log} 2> {snakemake.log.err}
"""
elif aligner == "crac":
shell_commands = """
cmd="niceload --noswap -q crac --nb-threads {snakemake.threads} --summary %s --all %s {snakemake.params.settings} -i {snakemake.params.index} -r {snakemake.input.fastq} --sam {snakemake.output.sam}"
echo ${{cmd}} > {snakemake.log.log}
eval ${{cmd}} 1>> {snakemake.log.log} 2> {snakemake.log.err}
# TODO: extract non mappers from the sam output
> {snakemake.output.nomap_fastq}
""" % (snakemake.output.nomap_fastq.split("_unmapped")[0] + "_summary.txt", snakemake.output.nomap_fastq.split("_unmapped")[0] + "_output.txt")
else:
raise NotImplementedError("%s is not yet handled." % aligner)
return shell_commands
shell(mapping_command(snakemake.params.aligner))
from snakemake.shell import shell
cmd = """
export SAMTOOLS_THREADS={snakemake.threads}
nice -n 19 ionice -c2 -n7 sam2indexedbam.sh {snakemake.input.sam} 1> {snakemake.log.log} 2> {snakemake.log.err}
"""
shell(cmd)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment