From b362c20a86dffc2aaffaab5b3a8ab2b0310df19d Mon Sep 17 00:00:00 2001 From: Toni Verbeiren Date: Thu, 4 Apr 2024 13:36:56 +0200 Subject: [PATCH 1/2] Fix test and script (#35) --- src/gffread/script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gffread/script.sh b/src/gffread/script.sh index 26986fd1..9c4a2b8f 100644 --- a/src/gffread/script.sh +++ b/src/gffread/script.sh @@ -51,7 +51,7 @@ [[ "$par_cluster_only" == "false" ]] && unset par_cluster_only -gffread \ +$(which gffread) \ "$par_input" \ ${par_chr_mapping:+-m "$par_chr_mapping"} \ ${par_seq_info:+-s "$par_seq_info"} \ From bb12e1a08a07207c90bf34e1f8ee91f225d63b2e Mon Sep 17 00:00:00 2001 From: emmarousseau Date: Sat, 13 Apr 2024 08:25:37 +0100 Subject: [PATCH 2/2] Samtools index (#33) * Initial commit index component * add more tests to samtools/index * Change component name, fix version.txt text * fix indentation in yaml file * Final touches * Update src/samtools/samtools_index/config.vsh.yaml Remove the --multiple option Co-authored-by: Robrecht Cannoodt * Update CHANGELOG.md Co-authored-by: Robrecht Cannoodt * Change test and script paths * Minor changes, paths, config and script --------- Co-authored-by: Robrecht Cannoodt --- CHANGELOG.md | 5 +- src/samtools/samtools_index/config.vsh.yaml | 67 +++++++++++++ src/samtools/samtools_index/help.txt | 13 +++ src/samtools/samtools_index/script.sh | 18 ++++ src/samtools/samtools_index/test.sh | 91 ++++++++++++++++++ .../samtools_index/test_data/a.sorted.bam | Bin 0 -> 209 bytes .../test_data/a_4_ref.sorted.bam.bai | Bin 0 -> 96 bytes .../test_data/a_multiple_ref.sorted.bam.bai | Bin 0 -> 96 bytes .../test_data/a_ref.sorted.bam.bai | Bin 0 -> 96 bytes .../test_data/a_ref.sorted.bam.csi | Bin 0 -> 89 bytes .../samtools_index/test_data/script.sh | 12 +++ 11 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 src/samtools/samtools_index/config.vsh.yaml create mode 100644 src/samtools/samtools_index/help.txt create mode 100644 src/samtools/samtools_index/script.sh create mode 100644 src/samtools/samtools_index/test.sh create mode 100644 src/samtools/samtools_index/test_data/a.sorted.bam create mode 100644 src/samtools/samtools_index/test_data/a_4_ref.sorted.bam.bai create mode 100644 src/samtools/samtools_index/test_data/a_multiple_ref.sorted.bam.bai create mode 100644 src/samtools/samtools_index/test_data/a_ref.sorted.bam.bai create mode 100644 src/samtools/samtools_index/test_data/a_ref.sorted.bam.csi create mode 100755 src/samtools/samtools_index/test_data/script.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fd7f001..dd8d0a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,8 +36,9 @@ - `salmon/salmon_quant`: Transcript quantification from RNA-seq data (PR #24). * `samtools`: - - `samtools/flagstat`: Counts the number of alignments in SAM/BAM/CRAM files for each FLAG type (PR #31). - - `samtools/idxstats`: Reports alignment summary statistics for a SAM/BAM/CRAM file (PR #32). + - `samtools/samtools_flagstat`: Counts the number of alignments in SAM/BAM/CRAM files for each FLAG type (PR #31). + - `samtools/samtools_idxstats`: Reports alignment summary statistics for a SAM/BAM/CRAM file (PR #32). + - `samtools/samtools_index`: Index SAM/BAM/CRAM files (PR #35). ## MAJOR CHANGES diff --git a/src/samtools/samtools_index/config.vsh.yaml b/src/samtools/samtools_index/config.vsh.yaml new file mode 100644 index 00000000..8c59a20e --- /dev/null +++ b/src/samtools/samtools_index/config.vsh.yaml @@ -0,0 +1,67 @@ +name: samtools_index +namespace: samtools +description: Index SAM/BAM/CRAM files. +keywords: [index, bam, sam, cram] +links: + homepage: https://www.htslib.org/ + documentation: https://www.htslib.org/doc/samtools-index.html + repository: https://github.com/samtools/samtools +references: + doi: [10.1093/bioinformatics/btp352, 10.1093/gigascience/giab008] +license: MIT/Expat + +argument_groups: + - name: Inputs + arguments: + - name: --input + type: file + description: Input file name + required: true + must_exist: true + - name: Outputs + arguments: + - name: --output + alternatives: -o + type: file + description: Output file name + required: true + direction: output + example: out.bam.bai + - name: Options + arguments: + - name: --bai + alternatives: -b + type: boolean_true + description: Generate BAM index + - name: --csi + alternatives: -c + type: boolean_true + description: | + Create a CSI index for BAM files instead of the traditional BAI + index. This will be required for genomes with larger chromosome + sizes. + - name: --min_shift + alternatives: -m + type: integer + description: | + Create a CSI index, with a minimum interval size of 2^INT. + +resources: + - type: bash_script + path: script.sh +test_resources: + - type: bash_script + path: test.sh + - type: file + path: test_data +engines: + - type: docker + image: quay.io/biocontainers/samtools:1.19.2--h50ea8bc_1 + setup: + - type: docker + run: | + samtools --version 2>&1 | grep -E '^(samtools|Using htslib)' | \ + sed 's#Using ##;s# \([0-9\.]*\)$#: \1#' > /var/software_versions.txt +runners: +- type: executable +- type: nextflow \ No newline at end of file diff --git a/src/samtools/samtools_index/help.txt b/src/samtools/samtools_index/help.txt new file mode 100644 index 00000000..fdf0d12d --- /dev/null +++ b/src/samtools/samtools_index/help.txt @@ -0,0 +1,13 @@ +``` +samtools index +``` + +Usage: samtools index -M [-bc] [-m INT] ... + or: samtools index [-bc] [-m INT] [out.index] +Options: + -b, --bai Generate BAI-format index for BAM files [default] + -c, --csi Generate CSI-format index for BAM files + -m, --min-shift INT Set minimum interval size for CSI indices to 2^INT [14] + -M Interpret all filename arguments as files to be indexed + -o, --output FILE Write index to FILE [alternative to in args] + -@, --threads INT Sets the number of threads [none] \ No newline at end of file diff --git a/src/samtools/samtools_index/script.sh b/src/samtools/samtools_index/script.sh new file mode 100644 index 00000000..9db47fa4 --- /dev/null +++ b/src/samtools/samtools_index/script.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +## VIASH START +## VIASH END + +set -e +[[ "$par_multiple" == "false" ]] && unset par_multiple +[[ "$par_bai" == "false" ]] && unset par_bai +[[ "$par_csi" == "false" ]] && unset par_csi +[[ "$par_multiple" == "false" ]] && unset par_multiple + +samtools index \ + "$par_input" \ + ${par_csi:+-c} \ + ${par_bai:+-b} \ + ${par_min_shift:+-m "par_min_shift"} \ + ${par_multiple:+-M} \ + -o "$par_output" \ No newline at end of file diff --git a/src/samtools/samtools_index/test.sh b/src/samtools/samtools_index/test.sh new file mode 100644 index 00000000..f4b1d3b6 --- /dev/null +++ b/src/samtools/samtools_index/test.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +test_dir="${meta_resources_dir}/test_data" + +echo ">>> Testing $meta_functionality_name" + +echo ">>> Generating BAM index" +"$meta_executable" \ + --input "$test_dir/a.sorted.bam" \ + --bai \ + --output "$test_dir/a.sorted.bam.bai" + +echo ">>> Check whether output exists" +[ ! -f "$test_dir/a.sorted.bam.bai" ] && echo "File 'a.sorted.bam.bai' does not exist!" && exit 1 + +echo ">>> Check whether output is empty" +[ ! -s "$test_dir/a.sorted.bam.bai" ] && echo "File 'a.sorted.bam.bai' is empty!" && exit 1 + +echo ">>> Check whether output is correct" +diff "$test_dir/a.sorted.bam.bai" "$test_dir/a_ref.sorted.bam.bai" || \ + (echo "File 'a.sorted.bam.bai' does not match expected output." && exit 1) + +rm "$test_dir/a.sorted.bam.bai" + +################################################################################################# + +echo ">>> Generating CSI index" +"$meta_executable" \ + --input "$test_dir/a.sorted.bam" \ + --csi \ + --output "$test_dir/a.sorted.bam.csi" + +echo ">>> Check whether output exists" +[ ! -f "$test_dir/a.sorted.bam.csi" ] && echo "File 'a.sorted.bam.csi' does not exist!" && exit 1 + +echo ">>> Check whether output is empty" +[ ! -s "$test_dir/a.sorted.bam.csi" ] && echo "File 'a.sorted.bam.csi' is empty!" && exit 1 + +echo ">>> Check whether output is correct" +diff "$test_dir/a.sorted.bam.csi" "$test_dir/a_ref.sorted.bam.csi" || \ + (echo "File 'a.sorted.bam.csi' does not match expected output." && exit 1) + +rm "$test_dir/a.sorted.bam.csi" + +################################################################################################# + +echo ">>> Generating bam index with -M option" +"$meta_executable" \ + --input "$test_dir/a.sorted.bam" \ + --bai \ + --output "$test_dir/a_multiple.sorted.bam.bai" \ + --multiple + +echo ">>> Check whether output exists" +[ ! -f "$test_dir/a_multiple.sorted.bam.bai" ] && echo "File 'a_multiple.sorted.bam.bai' does not exist!" && exit 1 + +echo ">>> Check whether output is empty" +[ ! -s "$test_dir/a_multiple.sorted.bam.bai" ] && echo "File 'a_multiple.sorted.bam.bai' is empty!" && exit 1 + +echo ">>> Check whether output is correct" +diff "$test_dir/a_multiple.sorted.bam.bai" "$test_dir/a_multiple_ref.sorted.bam.bai" || \ + (echo "File 'a_multiple.sorted.bam.bai' does not match expected output." && exit 1) + + +################################################################################################# + +echo ">>> Generating BAM index with -m option" + +"$meta_executable" \ + --input "$test_dir/a.sorted.bam" \ + --min_shift 4 \ + --bai \ + --output "$test_dir/a_4.sorted.bam.bai" + +echo ">>> Check whether output exists" +[ ! -f "$test_dir/a_4.sorted.bam.bai" ] && echo "File 'a_4.sorted.bam.bai' does not exist!" && exit 1 + +echo ">>> Check whether output is empty" +[ ! -s "$test_dir/a_4.sorted.bam.bai" ] && echo "File 'a_4.sorted.bam.bai' is empty!" && exit 1 + +echo ">>> Check whether output is correct" +diff "$test_dir/a_4.sorted.bam.bai" "$test_dir/a_4_ref.sorted.bam.bai" || \ + (echo "File 'a_4.sorted.bam.bai' does not match expected output." && exit 1) + +rm "$test_dir/a_4.sorted.bam.bai" + +################################################################################################# + + +echo "All tests succeeded!" +exit 0 \ No newline at end of file diff --git a/src/samtools/samtools_index/test_data/a.sorted.bam b/src/samtools/samtools_index/test_data/a.sorted.bam new file mode 100644 index 0000000000000000000000000000000000000000..1c81d7cd59e70b71fce1ed9911445e08d1da7df8 GIT binary patch literal 209 zcmb2|=3rp}f&Xj_PR>jW;S9w^UsA86BqS7kD0s;8d9%?K<7YhIwtJmBukUs8jJJ;G z(;^POCp_OauUhfo%g4<|Mh}u$w9?ofb#bu?DzGxN_C$v`0F9GJGdG68IN5(1qp5~=TtV8sy)7XlJ&Z!4_mw$DOPe8#p dUFfFO@gH)s11qG+dg28RP{p004LQLv#QD literal 0 HcmV?d00001 diff --git a/src/samtools/samtools_index/test_data/a_4_ref.sorted.bam.bai b/src/samtools/samtools_index/test_data/a_4_ref.sorted.bam.bai new file mode 100644 index 0000000000000000000000000000000000000000..4f08f5d5e5e01de5042cb8f625c1d26b338c3394 GIT binary patch literal 96 vcmZ>A^kigYU|?VZVoxCk1`wNpAp%S?Fl+_WUXvj5=;CZpRWJ%wFGLgo8^r{K literal 0 HcmV?d00001 diff --git a/src/samtools/samtools_index/test_data/a_multiple_ref.sorted.bam.bai b/src/samtools/samtools_index/test_data/a_multiple_ref.sorted.bam.bai new file mode 100644 index 0000000000000000000000000000000000000000..4f08f5d5e5e01de5042cb8f625c1d26b338c3394 GIT binary patch literal 96 vcmZ>A^kigYU|?VZVoxCk1`wNpAp%S?Fl+_WUXvj5=;CZpRWJ%wFGLgo8^r{K literal 0 HcmV?d00001 diff --git a/src/samtools/samtools_index/test_data/a_ref.sorted.bam.bai b/src/samtools/samtools_index/test_data/a_ref.sorted.bam.bai new file mode 100644 index 0000000000000000000000000000000000000000..4f08f5d5e5e01de5042cb8f625c1d26b338c3394 GIT binary patch literal 96 vcmZ>A^kigYU|?VZVoxCk1`wNpAp%S?Fl+_WUXvj5=;CZpRWJ%wFGLgo8^r{K literal 0 HcmV?d00001 diff --git a/src/samtools/samtools_index/test_data/a_ref.sorted.bam.csi b/src/samtools/samtools_index/test_data/a_ref.sorted.bam.csi new file mode 100644 index 0000000000000000000000000000000000000000..e337be19114c46122bec090c290fa7f00b9656ba GIT binary patch literal 89 zcmb2|=3rp}f&Xj_PR>jWHVnml-%_3=J21Ghv9YOH=rifDB^w*$q$W57GAA!Swb?L% Xond3!grWkV9(gp)(hSUCvp@s@dy5gP literal 0 HcmV?d00001 diff --git a/src/samtools/samtools_index/test_data/script.sh b/src/samtools/samtools_index/test_data/script.sh new file mode 100755 index 00000000..ee86e514 --- /dev/null +++ b/src/samtools/samtools_index/test_data/script.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# dowload test data from snakemake wrapper +if [ ! -d /tmp/idxstats_source ]; then + git clone --depth 1 --single-branch --branch master https://github.com/snakemake/snakemake-wrappers.git /tmp/idxstats_source +fi + +cp -r /tmp/idxstats_source/bio/samtools/idxstats/test/mapped/* src/samtools/idxstats/test_data +# samtools index a_ref.sorted.bam -o a_ref.sorted.bam.bai +# samtools index a_ref.sorted.bam -c a_ref.sorted.bam.csi + +