-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1067 from maxplanck-ie/pairtools_merge
Pairtools merge
- Loading branch information
Showing
16 changed files
with
333 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ max_thread: 25 | |
#print tools versions | ||
toolsVersion: True | ||
oldConfig: | ||
configMode: manual | ||
configMode: manual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,199 +1,167 @@ | ||
# based on https://github.com/caballero/snakemake-pairtools-phased/tree/df410ff | ||
rule generate_chromsizes: | ||
input: | ||
genome_index | ||
output: | ||
'genome/genome.chromsizes' | ||
threads: 1 | ||
shell:''' | ||
cut -f1,2 {input} > {output} | ||
''' | ||
|
||
|
||
# Define function that returns pair files (phased or unphased), based on the reference. | ||
def ret_pair(wildcards): | ||
if "diploid_genome" in wildcards.ref: | ||
# Phased setting | ||
return f"pairs/{wildcards.sample}.{wildcards.ref}_phased.pairs.gz" | ||
else: | ||
return f"pairs/{wildcards.sample}.{wildcards.ref}.pairs.gz" | ||
|
||
|
||
# different to bwa.snakefile | ||
# here we skip the expensive sorting with samtools after bwa mem | ||
# consider making this optional in bwa.snakefile | ||
rule bwa_mapping: | ||
input: | ||
fq1="FASTQ_fastp/{sample}_R1.fastq.gz", | ||
fq2="FASTQ_fastp/{sample}_R2.fastq.gz", | ||
ix="genome/{ref}.fa.gz.bwt", | ||
fq2="FASTQ_fastp/{sample}_R2.fastq.gz" | ||
output: | ||
bam="bam/{sample}.{ref}.bam", | ||
bam="bam/{sample}.bam", | ||
threads: 30 | ||
params: | ||
bwathreads=config["alignerThreads"], | ||
bwaparams=config["alignerOptions"], | ||
fna=lambda wildcards, input: Path(input.ix).with_suffix(""), | ||
bwa_index = bwa_index | ||
resources: | ||
mem_mb=3000, | ||
benchmark: | ||
"bam/.benchmark/bwa_mapping.{sample}.{ref}.benchmark" | ||
"bam/.benchmark/bwa_mapping.{sample}.benchmark" | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
bwa mem \ | ||
{params.bwaparams} \ | ||
-t {params.bwathreads} \ | ||
{params.fna} \ | ||
-t 22 \ | ||
{params.bwa_index} \ | ||
{input.fq1} \ | ||
{input.fq2} \ | ||
| samtools view -@ 8 -b \ | ||
> {output.bam} | ||
""" | ||
|
||
|
||
rule pairtools_parse: | ||
input: | ||
bam="bam/{sample}.{ref}.bam", | ||
chr_sizes="genome/{ref}.chromsizes", | ||
bam="bam/{sample}.bam", | ||
chr_sizes='genome/genome.chromsizes' | ||
output: | ||
pairs="pairs/{sample}.{ref}.pairs.gz", | ||
pairs=temp("pairs/{sample}.unsorted.pairs.gz"), | ||
params: | ||
minmapq=40, | ||
cols=lambda wildcards: ( | ||
"--add-columns XB,AS,XS" if "diploid_genome" in wildcards.ref else "" | ||
), | ||
minmapq=40 | ||
threads: 12 | ||
benchmark: | ||
"pairs/.benchmark/pairtools_parse.{sample}.{ref}.benchmark" | ||
"pairs/.benchmark/pairtools_parse.{sample}.benchmark" | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
pairtools parse \ | ||
--min-mapq {params.minmapq} \ | ||
{params.cols} \ | ||
--drop-sam \ | ||
--walks-policy 5unique \ | ||
-c {input.chr_sizes} \ | ||
{input.bam} \ | ||
-o {output.pairs} | ||
""" | ||
|
||
|
||
rule pairtools_phase: | ||
input: | ||
pairs="pairs/{sample}.diploid_genome.pairs.gz", | ||
output: | ||
pairs="pairs/{sample}.diploid_genome_phased.pairs.gz", | ||
params: | ||
hap1=strains[0], | ||
hap2=strains[1], | ||
threads: 12 | ||
benchmark: | ||
"pairs/.benchmark/pairtools_phase.{sample}.benchmark" | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
pairtools phase \ | ||
--phase-suffixes _{params.hap1} _{params.hap2} \ | ||
--tag-mode XB \ | ||
--clean-output \ | ||
{input.pairs} -o {output.pairs} | ||
""" | ||
|
||
|
||
rule pairtools_sort: | ||
input: | ||
ret_pair, | ||
pairs = "pairs/{sample}.unsorted.pairs.gz", | ||
output: | ||
pairs="pairs/{sample}.{ref}.pairs.sorted.gz", | ||
pairs = "pairs/{sample}.pairs.gz", | ||
threads: 20 | ||
benchmark: | ||
"pairs/.benchmark/pairtools_sort.{sample}.{ref}.benchmark" | ||
"pairs/.benchmark/pairtools_sort.{sample}.benchmark" | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
pairtools sort \ | ||
{input} \ | ||
{input.pairs} \ | ||
-o {output.pairs} \ | ||
--memory 20G | ||
""" | ||
|
||
|
||
rule pairtools_dedup: | ||
input: | ||
pairs="pairs/{sample}.{ref}.pairs.sorted.gz", | ||
pairs="pairs/{sample}.pairs.gz", | ||
output: | ||
pairs="pairs/{sample}.{ref}.pairs.dedup.gz", | ||
stats="pairs/{sample}.{ref}.pairs.dedup.stats", | ||
params: | ||
extra_cols=lambda wildcards: ( | ||
"--extra-col-pair phase1 phase2" if "diploid" in wildcards.ref else "" | ||
), | ||
pairs="pairs/{sample}.pairs.dedup.gz", | ||
stats="pairs/{sample}.pairs.dedup.stats" | ||
threads: 12 | ||
benchmark: | ||
"pairs/.benchmark/pairtools_dedup.{sample}.{ref}.benchmark" | ||
"pairs/.benchmark/pairtools_dedup.{sample}.benchmark" | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
pairtools dedup \ | ||
--mark-dups \ | ||
{params.extra_cols} \ | ||
--output-dups - \ | ||
--output-unmapped - \ | ||
--output-stats {output.stats} \ | ||
-o {output.pairs} \ | ||
{input.pairs} | ||
""" | ||
|
||
rule pairix: | ||
input: | ||
pairs = 'pairs/{sample}.pairs.dedup.gz' | ||
output: | ||
ix = 'pairs/{sample}.pairs.dedup.gz.px2' | ||
threads: 2 | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
pairix -f -p pairs {input.pairs} | ||
""" | ||
|
||
rule pairtools_filter_phased: | ||
rule cooler: | ||
input: | ||
pairs="pairs/{sample}.diploid_genome.pairs.dedup.gz", | ||
pairs = 'pairs/{sample}.pairs.dedup.gz', | ||
ix = 'pairs/{sample}.pairs.dedup.gz.px2', | ||
chromsizes = 'genome/genome.chromsizes' | ||
output: | ||
stats="phase_stats/{sample}.diploid_genome_{phasetype}.pairs.stats", | ||
pairs="phase_stats/{sample}.diploid_genome_{phasetype}.pairs.gz", | ||
params: | ||
filterparam=lambda wildcards: PHASEDIC[wildcards.phasetype], | ||
resources: | ||
mem_mb=1000, | ||
benchmark: | ||
"phase_stats/.benchmark/pairtools_filter_phased.{sample}.diploid_genome_{phasetype}.benchmark" | ||
threads: 12 | ||
cool = 'cooler/{sample}.5000.cool' | ||
threads: 20 | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
pairtools select \ | ||
'{params.filterparam}' \ | ||
{input.pairs} \ | ||
-o {output.pairs} | ||
pairtools stats {output.pairs} -o {output.stats} | ||
cooler cload pairix -p {threads} {input.chromsizes}:5000 {input.pairs} {output.cool} | ||
cooler balance --nproc {threads} {output.cool} | ||
""" | ||
|
||
rule mcool: | ||
input: | ||
cool = 'cooler/{sample}.5000.cool' | ||
output: | ||
mcool = 'cooler/{sample}.5000.mcool' | ||
threads: 20 | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
cooler zoomify --resolutions 5000,10000,20000,40000,80000,120000 --balance --nproc {threads} {input.cool} | ||
""" | ||
|
||
rule multiqc: | ||
input: | ||
stats=expand( | ||
"pairs/{sample}.{ref}.pairs.dedup.stats", sample=samples, ref=REFERENCES | ||
), | ||
phasedstats=expand( | ||
"phase_stats/{sample}.diploid_genome_{phasetype}.pairs.stats", | ||
sample=samples, | ||
phasetype=PHASEDIC.keys(), | ||
), | ||
cools=expand( | ||
'cooler/{sample}.5000.mcool', sample=samples | ||
) | ||
output: | ||
html="multiqc/multiqc_report.html", | ||
html="multiQC/multiqc_report.html", | ||
params: | ||
odir="multiqc", | ||
odir="multiQC", | ||
benchmark: | ||
"multiqc/.benchmark/multiqc.benchmark" | ||
"multiQC/.benchmark/multiqc.benchmark" | ||
threads: 1 | ||
conda: | ||
CONDA_MAKEPAIRS_ENV | ||
shell: | ||
""" | ||
echo input: {input.phasedstats} | ||
multiqc \ | ||
--module pairtools \ | ||
--module fastqc \ | ||
--module fastp \ | ||
-o {params.odir} \ | ||
. | ||
""" | ||
""" |
Oops, something went wrong.