Skip to content

Commit

Permalink
Bedtools bamtobed (#109)
Browse files Browse the repository at this point in the history
* adding back my work

* adding more tests

- fixing bug
- more tests

* Final test added

* Update CHANGELOG.md

* minor change

- license name
- help file

* small changes on config

* small changes

* adding more links

* Update script.sh

* Adding $TMPDIR to test.sh

---------

Co-authored-by: Emma Rousseau <[email protected]>
Co-authored-by: Robrecht Cannoodt <[email protected]>
  • Loading branch information
3 people authored Oct 26, 2024
1 parent 11118fb commit f96bd72
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

* `bd_rhapsody/bd_rhapsody_sequence_analysis`: BD Rhapsody Sequence Analysis CWL pipeline (PR #96).

* `bedtools`:
- `bedtools/bedtools_bamtobed`: Converts BAM alignments to BED6 or BEDPE format (PR #109).

* `rsem/rsem_calculate_expression`: Calculate expression levels (PR #93).

* `nanoplot`: Plotting tool for long read sequencing data and alignments (PR #95).


## BREAKING CHANGES

* `falco`: Fix a typo in the `--reverse_complement` argument (PR #157).
Expand Down
118 changes: 118 additions & 0 deletions src/bedtools/bedtools_bamtobed/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: bedtools_bamtobed
namespace: bedtools
description: Converts BAM alignments to BED6 or BEDPE format.
keywords: [Converts, BAM, BED, BED6, BEDPE]
links:
documentation: https://bedtools.readthedocs.io/en/latest/content/tools/bamtobed.html
repository: https://github.com/arq5x/bedtools2
homepage: https://bedtools.readthedocs.io/en/latest/#
issue_tracker: https://github.com/arq5x/bedtools2/issues
references:
doi: 10.1093/bioinformatics/btq033
license: MIT
requirements:
commands: [bedtools]
authors:
- __merge__: /src/_authors/theodoro_gasperin.yaml
roles: [ author, maintainer ]

argument_groups:
- name: Inputs
arguments:
- name: --input
alternatives: -i
type: file
description: Input BAM file.
required: true

- name: Outputs
arguments:
- name: --output
alternatives: -o
required: true
type: file
direction: output
description: Output BED file.

- name: Options
arguments:
- name: --bedpe
type: boolean_true
description: |
Write BEDPE format. Requires BAM to be grouped or sorted by query.
- name: --mate1
type: boolean_true
description: |
When writing BEDPE (-bedpe) format, always report mate one as the first BEDPE "block".
- name: --bed12
type: boolean_true
description: |
Write "blocked" BED format (aka "BED12"). Forces -split.
See http://genome-test.cse.ucsc.edu/FAQ/FAQformat#format1
- name: --split
type: boolean_true
description: |
Report "split" BAM alignments as separate BED entries.
Splits only on N CIGAR operations.
- name: --splitD
type: boolean_true
description: |
Split alignments based on N and D CIGAR operators.
Forces -split.
- name: --edit_distance
alternatives: -ed
type: boolean_true
description: |
Use BAM edit distance (NM tag) for BED score.
- Default for BED is to use mapping quality.
- Default for BEDPE is to use the minimum of
the two mapping qualities for the pair.
- When -ed is used with -bedpe, the total edit
distance from the two mates is reported.
- name: --tag
type: string
description: |
Use other NUMERIC BAM alignment tag for BED score.
Default for BED is to use mapping quality. Disallowed with BEDPE output.
example: "SM"

- name: --color
type: string
description: |
An R,G,B string for the color used with BED12 format.
Default is (255,0,0).
example: "250,250,250"

- name: --cigar
type: boolean_true
description: |
Add the CIGAR string to the BED entry as a 7th column.
resources:
- type: bash_script
path: script.sh

test_resources:
- type: bash_script
path: test.sh
- path: test_data

engines:
- type: docker
image: debian:stable-slim
setup:
- type: apt
packages: [bedtools, procps]
- type: docker
run: |
echo "bedtools: \"$(bedtools --version | sed -n 's/^bedtools //p')\"" > /var/software_versions.txt
runners:
- type: executable
- type: nextflow
43 changes: 43 additions & 0 deletions src/bedtools/bedtools_bamtobed/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
```bash
bedtools bamtobed
```

Tool: bedtools bamtobed (aka bamToBed)
Version: v2.30.0
Summary: Converts BAM alignments to BED6 or BEDPE format.

Usage: bedtools bamtobed [OPTIONS] -i <bam>

Options:
-bedpe Write BEDPE format.
- Requires BAM to be grouped or sorted by query.

-mate1 When writing BEDPE (-bedpe) format,
always report mate one as the first BEDPE "block".

-bed12 Write "blocked" BED format (aka "BED12"). Forces -split.

http://genome-test.cse.ucsc.edu/FAQ/FAQformat#format1

-split Report "split" BAM alignments as separate BED entries.
Splits only on N CIGAR operations.

-splitD Split alignments based on N and D CIGAR operators.
Forces -split.

-ed Use BAM edit distance (NM tag) for BED score.
- Default for BED is to use mapping quality.
- Default for BEDPE is to use the minimum of
the two mapping qualities for the pair.
- When -ed is used with -bedpe, the total edit
distance from the two mates is reported.

-tag Use other NUMERIC BAM alignment tag for BED score.
- Default for BED is to use mapping quality.
Disallowed with BEDPE output.

-color An R,G,B string for the color used with BED12 format.
Default is (255,0,0).

-cigar Add the CIGAR string to the BED entry as a 7th column.

39 changes: 39 additions & 0 deletions src/bedtools/bedtools_bamtobed/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

## VIASH START
## VIASH END

set -eo pipefail

# Unset parameters
unset_if_false=(
par_bedpe
par_mate1
par_bed12
par_split
par_splitD
par_edit_distance
par_tag
par_color
par_cigar
)

for par in ${unset_if_false[@]}; do
test_val="${!par}"
[[ "$test_val" == "false" ]] && unset $par
done

# Execute bedtools sort with the provided arguments
bedtools bamtobed \
${par_bedpe:+-bedpe} \
${par_mate1:+-mate1} \
${par_bed12:+-bed12} \
${par_split:+-split} \
${par_splitD:+-splitD} \
${par_edit_distance:+-ed} \
${par_tag:+-tag "$par_tag"} \
${par_cigar:+-cigar} \
${par_color:+-color "$par_color"} \
-i "$par_input" \
> "$par_output"

Loading

0 comments on commit f96bd72

Please sign in to comment.