-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbamstats
More file actions
53 lines (46 loc) · 1.2 KB
/
bamstats
File metadata and controls
53 lines (46 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/env bash
set -e
helpstr="READLEN - get read length from the first read of a FASTQ file
Usage: readlen [OPTIONS] FILE
Options:
-z: File is compressed using gzip; decompress before reading
-h: Print this help message and exit."
unset file gzipped
while [[ $OPTIND -le $# ]]; do
while getopts "zh" opt; do
case "$opt" in
z)
gzipped=true
;;
h)
echo "$helpstr"
exit
;;
*)
echo "Invalid argument:" $opt >&2
echo "$helpstr"
exit 1
esac
done
if [[ -z "$file" ]]; then
file=${@:$OPTIND:1}
OPTIND=$(expr $OPTIND + 1)
fi
done
shift $((OPTIND-1))
# Argument errors and warnings:
if [[ -z "$file" ]]; then
>&2 echo "Error: Input file required."
echo "$helpstr"
exit 1
fi
############
## SCRIPT ##
############
bn=$(basename -f "$file")
prefix=${bn%%\.*} ## remove file extensions
samtools view -b "$file" > ${prefix}.bam
samtools sort ${prefix}.bam > ${prefix}.sorted.bam
samtools index ${prefix}.sorted.bam > ${prefix}.sorted.bai
samtools idxstats ${prefix}.sorted.bam > ${prefix}.idxstats.txt
exit