Skip to content

Commit

Permalink
Initial commit index component
Browse files Browse the repository at this point in the history
  • Loading branch information
emmarousseau committed Mar 29, 2024
1 parent d9e7fdf commit 84c61b4
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/samtools/index/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: samtools_index
namespace: samtools
description: Index BAM files
keywords: [stats, mapping, counts, chromosome, bam, sam, cram]
links:
homepage: https://www.htslib.org/
documentation: https://www.htslib.org/doc/samtools-index.html
repository: https://github.com/samtools/samtools.git
references:
doi: 10.1093/bioinformatics/btp352, 10.1093/gigascience/giab008
license: MIT/Expat

argument_groups:
- name: Inputs
arguments:
- name: --bam
alternatives: -b
type: file
description: BAM input file.
- name: "--bam_csi_index"
type: boolean
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: Outputs
arguments:
- name: --output_bai
alternatives: [ -o, --output ]
type: file
description: BAM index
direction: output
required: true
must_exist: false
example: out.bam.bai
must_exist: false
- name: --output_csi
alternatives: [ -c, --csi ]
type: file
description: CSI index
direction: output
default: out.bam.csi
- name: --min-shift
alternatives: -m
type: integer
description: Create a CSI index, with a minimum interval size of 2^INT.
default: 0
- name: Options
arguments:
- name: --individual
alternatives: -M
type: integer
description: |
Interpret all filename arguments as alignment files to
be indexed individually. (Without -M, filename arguments
are interpreted solely as per the second synopsis.)
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: |
echo "$(samtools --version 2>&1)" > /var/software_versions.txt
runners:
- type: executable
- type: nextflow
9 changes: 9 additions & 0 deletions src/samtools/index/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```
samtools index
```

Usage: samtools index [-bc] [-m INT] <in.bam> [out.index]
Options:
-b Generate BAI-format index for BAM files [default]
-c Generate CSI-format index for BAM files
-m INT Set minimum interval size for CSI indices to 2^INT [14]
13 changes: 13 additions & 0 deletions src/samtools/index/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

## VIASH START
## VIASH END

set -e

[[ "$par_output_csi" == "false" ]] && unset par_output_csi

samtools index \
"$par_input" \
${par_output_csi:+-c} \
-o "$par_output"
27 changes: 27 additions & 0 deletions src/samtools/index/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

test_dir="${meta_resources_dir}test_data"
echo ">>> Testing $meta_functionality_name"

echo ">>> Generating BAM index"
"$meta_executable" \
--input "$test_dir/chr19.bam" \
--bam_csi_index false \
--output_bai "$test_dir/chr19.bam.bai"

echo ">>> Check whether output exists"
[ ! -f chr19.bam.bai ] && echo "File 'mapt.NA12156.altex.bam.bai' does not exist!" && exit 1
[ ! -s chr19.bam.bai ] && echo "File 'mapt.NA12156.altex.bam.bai' is empty!" && exit 1

echo ">>> Generating CSI index"
"$meta_executable" \
--input "$test_dir/chr19.bam" \
--bam_csi_index true \
--output_csi "$test_dir/chr19.bam.csi"

echo ">>> Check whether output exists"
[ ! -f "chr19.bam.csi" ] && echo "File 'mapt.NA12156.altex.bam.csi' does not exist!" && exit 1
[ ! -s "chr19.bam.csi" ] && echo "File 'mapt.NA12156.altex.bam.csi' is empty!" && exit 1

echo "All tests succeeded!"
exit 0
Binary file added src/samtools/index/test_data/a.sorted.bam
Binary file not shown.
Binary file added src/samtools/index/test_data/a_re.sorted.bam.csi
Binary file not shown.
Binary file added src/samtools/index/test_data/a_ref.sorted.bam.bai
Binary file not shown.
14 changes: 14 additions & 0 deletions src/samtools/index/test_data/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/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 idxstats a.sorted.bam > a.sorted.idxstats

# dowload test data from nf-core module
wget https://github.com/nf-core/test-datasets/raw/modules/data/genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam
wget https://github.com/nf-core/test-datasets/raw/modules/data/genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam.bai
# samtools idxstats test.paired_end.sorted.bam > test_ref.paired_end.sorted.idxstats
Binary file not shown.

0 comments on commit 84c61b4

Please sign in to comment.