Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Deeptools bampefragmentsize #3596

Merged
merged 33 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
afa20de
Initial commit
niekwit Jan 17, 2025
d0011be
added test_deeptools_bampe_fragmentsize
niekwit Jan 17, 2025
d8b200c
Initial commit
niekwit Jan 17, 2025
32535d5
simplified parameters
niekwit Jan 17, 2025
f3ba4ca
replaced data
niekwit Jan 17, 2025
84a7eeb
added output instead of input
niekwit Jan 17, 2025
2d404da
black formatting
niekwit Jan 17, 2025
664675f
deleted
niekwit Jan 17, 2025
9d0b5b3
fixed name
niekwit Jan 20, 2025
1651866
updated table
niekwit Jan 20, 2025
3874f9c
updated params
niekwit Jan 20, 2025
6ac5725
fixed undefined variable
niekwit Jan 20, 2025
f379c2b
Initial commit
niekwit Jan 20, 2025
9979c8d
Merge branch 'master' into deeptools_bampefragmentsize
niekwit Jan 24, 2025
b966679
Suggestions by coderabbit
niekwit Jan 27, 2025
902d46a
Removed white space+changed options
niekwit Jan 28, 2025
c8117f3
let Snakemake deal with missing bam files
niekwit Jan 28, 2025
618ef92
changed link
niekwit Jan 28, 2025
a716ed9
added new line
niekwit Jan 28, 2025
fe3ca35
updated output format description and wrapper description
niekwit Jan 28, 2025
13427fb
suggested changes by fgvieira
niekwit Jan 30, 2025
d79f758
improved documentation for labels
niekwit Jan 30, 2025
959c4cf
Code tweak
fgvieira Jan 30, 2025
ecb6727
Remove spaces
fgvieira Jan 30, 2025
6473cec
fixed VALID FORMATS values
niekwit Jan 30, 2025
678e7ec
fixed VALID FORMATS values
niekwit Jan 30, 2025
552a8d4
more robust sample_label generation
niekwit Jan 30, 2025
00becbc
Fix command-line argument spacing
fgvieira Jan 30, 2025
ee7489a
Code tweak
fgvieira Jan 30, 2025
5702eff
Remove unneccessary import
fgvieira Jan 30, 2025
2f88159
Code tweak to increase readibility
fgvieira Jan 30, 2025
46f76fd
Increase readibility
fgvieira Jan 30, 2025
e0b4536
Code format
fgvieira Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bio/deeptools/bampefragmentsize/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
channels:
- conda-forge
- bioconda
- nodefaults
dependencies:
- deeptools =3.5.5
34 changes: 34 additions & 0 deletions bio/deeptools/bampefragmentsize/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: deepTools computeMatrix
url: https://deeptools.readthedocs.io/en/latest/content/tools/bamPEFragmentSize.html
niekwit marked this conversation as resolved.
Show resolved Hide resolved
description: >
``deepTools bamPEFragmentSize`` calculates the fragment sizes for read pairs given a BAM file from paired-end sequencing.
For usage information about ``deepTools bamPEFragmentSize``, please see the `documentation <https://deeptools.readthedocs.io/en/latest/content/tools/bamPEFragmentSize.html>`_.
For more information about ``deepTools``, also see the `source code <https://github.com/deeptools/deepTools>`_.

+----------------------------+-----------------------------+---------------------+-------------+
| bamPEFragmentSize | Output format | Name of output | Recommended |
| | | | |
| | | variable to be used | extension |
+============================+=============================+=====================+=============+
| --histogram, -hist, -o | gzipped matrix file | hist | ".png" |
| | | | |
| | | (required) | |
+----------------------------+-----------------------------+---------------------+-------------+
| --outRawFragmentLengths | tab-separated table of | raw | ".tab" |
| | | | |
| | fragments lengths and | | |
| | | | |
| | occurances | | |
+----------------------------+-----------------------------+---------------------+-------------+

authors:
- Niek Wit
input:
- bams: List of BAM files (.bam)
- blacklist: Optional BED file with regions to skip (.bed)
output:
- hist: Fragment size histogram (.png)
- raw: Raw fragment lengths (.tab) (optional)
params:
- title: Title of the plot
- extra: Optional parameters given to computeMatrix
niekwit marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions bio/deeptools/bampefragmentsize/test/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rule deeptools_bampe_fragmentsize:
input:
# Input BAM file(s)
bams=["a.bam", "b.bam"],
# Optional blacklist file
# blacklist="",
output:
# Please note that -o/hist/--histogram and --outRawFragmentLengths are exclusively defined via output files.
# Usable output variables, their extensions and which option they implicitly call are listed here:
# https://snakemake-wrappers.readthedocs.io/en/stable/wrappers/deeptools/bamPEFragmentSize.html.
# Required
hist="results/histogram.png",
# Optional output files
raw="results/raw.tab",
log:
"logs/deeptools/bampe_fragmentsize.log",
threads: 4
params:
# Labels can be changed to anything
# If left empty, the sample name will be used
# (without path and .bam extension)
labels="",
extra="--logScale",
wrapper:
"master/bio/deeptools/bampefragmentsize"
Binary file added bio/deeptools/bampefragmentsize/test/a.bam
Binary file not shown.
Binary file added bio/deeptools/bampefragmentsize/test/a.bam.bai
Binary file not shown.
Binary file added bio/deeptools/bampefragmentsize/test/b.bam
Binary file not shown.
Binary file added bio/deeptools/bampefragmentsize/test/b.bam.bai
Binary file not shown.
51 changes: 51 additions & 0 deletions bio/deeptools/bampefragmentsize/wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
__author__ = "Niek Wit"
__copyright__ = "Copyright 2025, Niek Wit"
__email__ = "niekwit@gmail.com"
__license__ = "MIT"

import os
fgvieira marked this conversation as resolved.
Show resolved Hide resolved
from snakemake.shell import shell

log = snakemake.log_fmt_shell(stdout=True, stderr=True)

# Get input files
bam_files = snakemake.input.get("bams", "")
niekwit marked this conversation as resolved.
Show resolved Hide resolved
blacklist = snakemake.input.get("blacklist", "")
if blacklist:
blacklist = f"--blackListFileName {blacklist}"

# Get/create sample labels (remove .bam extension and dir)
# If no labels are provided, use the basename of the bam file
sample_label = snakemake.params.get("labels", "")
if not sample_label:
sample_label = [os.path.basename(bam.replace(".bam", "")) for bam in bam_files]
niekwit marked this conversation as resolved.
Show resolved Hide resolved

# Check if the number of labels is equal to the number of bam files
assert len(sample_label) == len(
bam_files
), "Number of labels must be equal to the number of bam files"

out_file = snakemake.output.get("hist")

# Check output format
out_format = out_file.split(".")[-1]
if not out_format in ["png", "pdf", "svg", "eps", "plotly"]:
raise ValueError(
"Output format must be either 'png', 'pdf', 'svg', 'eps', or 'plotly'"
)

# Optional output
out_raw = snakemake.output.get("raw", "")
if out_raw:
optional_output = " --outRawFragmentLengths {out_tab} ".format(out_tab=out_raw)

niekwit marked this conversation as resolved.
Show resolved Hide resolved
# Parameters
extra = snakemake.params.get("extra", "")

shell(
"bamPEFragmentSize "
"--numberOfProcessors {snakemake.threads} "
"-b {bam_files} "
"-o {out_file} "
niekwit marked this conversation as resolved.
Show resolved Hide resolved
"{blacklist} {optional_output} {extra} {log}"
niekwit marked this conversation as resolved.
Show resolved Hide resolved
)
7 changes: 7 additions & 0 deletions test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2777,6 +2777,13 @@ def test_deeptools_bamcoverage(run):
)


def test_deeptools_bampe_fragmentsize(run):
run(
"bio/deeptools/bampefragmentsize",
["snakemake", "--cores", "1", "results/histogram.png", "--use-conda", "-F"],
)


def test_deeptools_multibigwigsummary(run):
run(
"bio/deeptools/multibigwigsummary",
Expand Down
Loading