BAMTOOLS FILTER¶
Filters BAM files. For more information about bamtools see bamtools documentation
URL: https://github.com/pezmaster31/bamtools
Example¶
This wrapper can be used in the following way:
rule bamtools_filter:
input:
"{sample}.bam"
output:
"filtered/{sample}.bam"
params:
# optional parameters
tags = [ "NM:<4", "MQ:>=10" ], # list of key:value pair strings
min_size = "-2000",
max_size = "2000",
min_length = "10",
max_length = "20",
# to add more optional parameters (see bamtools filter --help):
additional_params = "-mapQuality \">=0\" -isMapped \"true\""
log:
"logs/bamtools/filtered/{sample}.log"
wrapper:
"v1.21.1/bio/bamtools/filter"
Note that input, output and log file paths can be chosen freely.
When running with
snakemake --use-conda
the software dependencies will be automatically deployed into an isolated environment before execution.
Notes¶
A complete usage documentation is available here: https://raw.githubusercontent.com/wiki/pezmaster31/bamtools/Tutorial_Toolkit_BamTools-1.0.pdf
This tool/wrapper does not handle multi threading
Software dependencies¶
bamtools=2.5.2
Input/Output¶
Input:
- bam files (.bam), must be in first position
Output:
- bam file (.bam), must be in first position
Params¶
tags
: filtering tagsmin_size
: minimum insert sizemax_size
: maximum insert sizemin_length
: minimum read lengthmax_length
: maximum read lengthadditional_params
: Other filtering and optional parameters
Authors¶
- Antonie Vietor
Code¶
__author__ = "Antonie Vietor"
__copyright__ = "Copyright 2020, Antonie Vietor"
__email__ = "antonie.v@gmx.de"
__license__ = "MIT"
from snakemake.shell import shell
log = snakemake.log_fmt_shell(stdout=False, stderr=True)
# extract arguments
params = ""
extra_limits = ""
tags = snakemake.params.get("tags")
min_size = snakemake.params.get("min_size")
max_size = snakemake.params.get("max_size")
min_length = snakemake.params.get("min_length")
max_length = snakemake.params.get("max_length")
additional_params = snakemake.params.get("additional_params")
if tags and tags is not None:
params = params + " " + " ".join(map('-tag "{}"'.format, tags))
if min_size and min_size is not None:
params = params + ' -insertSize ">=' + min_size + '"'
if max_size and max_size is not None:
extra_limits = extra_limits + ' -insertSize "<=' + max_size + '"'
else:
if max_size and max_size is not None:
params = params + ' -insertSize "<=' + max_size + '"'
if min_length and min_length is not None:
params = params + ' -length ">=' + min_length + '"'
if max_length and max_length is not None:
extra_limits = extra_limits + ' -length "<=' + max_length + '"'
else:
if max_length and max_length is not None:
params = params + ' -length "<=' + max_length + '"'
if additional_params and additional_params is not None:
params = params + " " + additional_params
if extra_limits:
params = params + " | bamtools filter" + extra_limits
shell(
"(bamtools filter"
" -in {snakemake.input[0]}" + params + " -out {snakemake.output[0]}) {log}"
)