-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabix.sh
More file actions
executable file
·29 lines (23 loc) · 792 Bytes
/
tabix.sh
File metadata and controls
executable file
·29 lines (23 loc) · 792 Bytes
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
#!/bin/bash -e
# Script that queries multiple tabix-indexed files for a specific chromosome region.
# Exit if fewer than 2 arguments are given.
# The minimum required is:
# - at least one file
# - a chromosome name
if [ "$#" -lt 2 ]; then
echo "Usage: $0 file1 [file2 ...] chromosome"
exit 1
fi
# Get the last argument as the chromosome name.
# "${!#}" expands to the value of the last positional argument.
chr="${!#}"
# Collect all arguments except the last one into an array called 'files'.
# "${@:1:$#-1}" expands from argument 1 up to argument $#-1
files=("${@:1:$#-1}")
# Loop over all input files
for file in "${files[@]}"; do
# Check that the file is non-empty
test -s "$file"
# Query the tabix-indexed file for the specified chromosome
tabix "$file" "$chr"
done