Skip to content

Commit

Permalink
Initial draft of flagstat component
Browse files Browse the repository at this point in the history
  • Loading branch information
emmarousseau committed Mar 22, 2024
1 parent 2db6d29 commit 8e3d5c5
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/samtools/flagstat/config.vsh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: samtools_flagstat
namespace: samtools
description: Counts the number of alignments in SAM/BAM/CRAM files for each FLAG type..
keywords: [ stats, mapping, counts, bam, sam, cram]
links:
homepage: https://www.htslib.org/
documentation: https://www.htslib.org/doc/samtools-flagstat.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
type: file
description: |
BAM input files.
- name: --bai
type: file
description: |
BAM index file.
- name: Outputs
arguments:
- name: --output
type: file
description: |
File containing samtools stats output.
direction: output
example: output.flagstat

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
13 changes: 13 additions & 0 deletions src/samtools/flagstat/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```sh
samtools flagstat --help
```
Usage: samtools flagstat [options] <in.bam>
--input-fmt-option OPT[=VAL]
Specify a single input file format option in the form
of OPTION or OPTION=VALUE
-@, --threads INT
Number of additional threads to use [0]
--verbosity INT
Set level of verbosity
-O, --output-fmt FORMAT[,OPT[=VAL]]...
Specify output format (json, tsv)
11 changes: 11 additions & 0 deletions src/samtools/flagstat/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

## VIASH START
## VIASH END

set -e

samtools flagstat \
"$par_input_bam" \
> "$par_output_stats"

23 changes: 23 additions & 0 deletions src/samtools/flagstat/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

echo ">>> Testing $meta_functionality_name"

"$meta_executable" \
--bam "$meta_resources_dir/test_data/chr19.bam" \
--bai "$meta_resources_dir/test_data/chr19.bam.bai" \
--output "$meta_resources_dir/test_data/chr19.flagstat"

echo ">>> Checking whether output exists"
[ ! -f "test_data/chr19.flagstat" ] && echo "File 'chr19.flagstat' does not exist!" && exit 1

echo ">>> Checking whether output is non-empty"
[ ! -s "test_data/chr19.flagstat" ] && echo "File 'chr19.flagstat' is empty!" && exit 1

echo ">>> Checking whether output is correct"
diff "$meta_resources_dir/test_data/chr19.flagstat" "$meta_resources_dir/test_data/chr19_ref.flagstat" || \
(echo "Output does not match expected output." && exit 1)

rm "$meta_resources_dir/test_data/chr19.flagstat"

echo "All tests succeeded!"
exit 0
Binary file added src/samtools/flagstat/test_data/chr19.bam
Binary file not shown.
Binary file added src/samtools/flagstat/test_data/chr19.bam.bai
Binary file not shown.
13 changes: 13 additions & 0 deletions src/samtools/flagstat/test_data/chr19_ref.flagstat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
55197 + 0 in total (QC-passed reads + QC-failed reads)
0 + 0 secondary
0 + 0 supplementary
0 + 0 duplicates
55197 + 0 mapped (100.00% : N/A)
0 + 0 paired in sequencing
0 + 0 read1
0 + 0 read2
0 + 0 properly paired (N/A : N/A)
0 + 0 with itself and mate mapped
0 + 0 singletons (N/A : N/A)
0 + 0 with mate mapped to a different chr
0 + 0 with mate mapped to a different chr (mapQ>=5)
6 changes: 6 additions & 0 deletions src/samtools/flagstat/test_data/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Download test data
wget https://github.com/CGATOxford/UMI-tools/raw/master/tests/chr19.bam
wget https://github.com/CGATOxford/UMI-tools/raw/master/tests/chr19.bam.bai

0 comments on commit 8e3d5c5

Please sign in to comment.