forked from NickSto/dunovo
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmake-families.sh
executable file
·55 lines (47 loc) · 1.42 KB
/
make-families.sh
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
54
55
#!/usr/bin/env bash
if [ x$BASH = x ] || [ ! $BASH_VERSINFO ] || [ $BASH_VERSINFO -lt 4 ]; then
echo "Error: Must use bash version 4+." >&2
exit 1
fi
set -ue
TagLenDefault=12
InvariantDefault=5
Usage="Usage: \$ $(basename $0) [-t tag_len] [-i invariant_len] reads_1.fq reads_2.fq > families.tsv
Read raw duplex sequencing reads, extract their barcodes, and group them by barcode.
-t: The length of the barcode portion of each read. Default: $TagLenDefault
-i: The length of the invariant (ligation) portion of each read. Default: $InvariantDefault"
function main {
# Read arguments.
if [[ $# -lt 2 ]]; then
fail "$Usage"
fi
taglen=$TagLenDefault
invariant=$InvariantDefault
while getopts ":t:i:h" opt; do
case "$opt" in
t) taglen=$OPTARG;;
i) invariant=$OPTARG;;
h) echo "$USAGE"
exit;;
esac
done
# Get positionals.
fastq1="${@:$OPTIND:1}"
fastq2="${@:$OPTIND+1:1}"
# Find the actual directory this file resides in (resolving links).
if readlink -f dummy >/dev/null 2>/dev/null; then
script_path=$(readlink -f "${BASH_SOURCE[0]}")
else
script_path=$(perl -MCwd -le 'print Cwd::abs_path(shift)' "${BASH_SOURCE[0]}")
fi
script_dir=$(dirname "$script_path")
paste "$fastq1" "$fastq2" \
| paste - - - - \
| awk -f "$script_dir/make-barcodes.awk" -v TAG_LEN=$taglen -v INVARIANT=$invariant \
| sort
}
function fail {
echo "$@" >&2
exit 1
}
main "$@"