BIOCONVERT
Convert between bioinformatics formats
URL: https://bioconvert.readthedocs.io/
Example
This wrapper can be used in the following way:
rule test_bioconvert_explicit_conversion:
input:
"intervals.bed",
output:
"intervals.csv",
log:
"test_bioconverter_explicit_conversion.log",
threads: 1
params:
# Optional converter
converter="tsv2csv",
# Optional parameters for bioconvert, except `-t|--threads`
extra="",
wrapper:
"v9.15.0/bio/bioconvert"
rule test_bioconvert_implicit_conversion:
input:
"intervals.csv",
output:
"intervals.xls",
log:
"test_bioconverter_implicit_conversion.log",
threads: 1
params:
# Optional converter
converter="",
# Optional parameters for bioconvert, except `-t|--threads`
extra="",
wrapper:
"v9.15.0/bio/bioconvert"
rule test_bioconverter_auto_parameters:
input:
"a.bam",
ref="genome.fasta",
output:
"a.cram",
log:
"test_bioconverter_samtools_opts.log",
threads: 2
params:
# Optional converter
converter="bam2cram",
# Optional parameters for bioconvert, except `-t|--threads`
extra="--method 'samtools' --extra-arguments ' --min-MQ 10 '",
wrapper:
"v9.15.0/bio/bioconvert"
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
Optional parameters are provided to converter tool by bioconvert. Use –extra-arguments to provide additional parameters to the converter tool (samtools, bedtools, bcftools, picard, etc.)
Software dependencies
bioconvert=1.2.0snakemake-wrapper-utils=0.9.0
Input/Output
Input:
Path to the file to convert
ref: Path to reference file (optional)
Output:
Path to the converted file
Params
converter: Optional explicit converterextra: Optional parameters for bioconvert
Code
# coding: utf-8
"""Snakemake wrapper for bioconvert"""
__author__ = "Thibault Dayris"
__copyright__ = "Copyright 2025, Thibault Dayris"
__license__ = "MIT"
from snakemake.shell import shell
from tempfile import TemporaryDirectory
from snakemake_wrapper_utils.snakemake import is_arg
extra = snakemake.params.get("extra", "")
converter = snakemake.params.get("converter", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
# Some optional parameters have to be provided, but implicit
# convertion (when user does not provide any converter) may
# use odd conversion paths, especially when using `--allow-indirect-convertion`
# We're setting optional parameters only when converter is provided.
if converter:
# The `--force` argument can prevent snakemake re-run issues,
# but requires a converter to be explicitely provided by user.
if not is_arg("--force", extra):
extra += " --force"
multi_threaded_commands = {
"bam2bedgraph",
"bam2cram",
"bam2sam",
"bz22gz",
"cram2bam",
"cram2fasta",
"cram2fastq",
"cram2sam",
"dsrc2gz",
"fast52pod5",
"fastq2fasta",
"gz2bz2",
"gz2dsrc",
"sam2bam",
"sam2cram",
}
if converter in multi_threaded_commands:
extra += f" --threads {snakemake.threads}"
commands_expecting_reference = {
"bam2cram",
"cram2bam",
"cram2fasta",
"cram2fastq",
"cram2sam",
"sam2cram",
}
if converter in commands_expecting_reference:
extra += f" --reference '{snakemake.input.ref}'"
shell(
"bioconvert {converter} {extra} {snakemake.input[0]:q} "
"{snakemake.output[0]:q} {log}"
)