-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouchbashcli.sh
More file actions
executable file
·107 lines (83 loc) · 2.22 KB
/
Copy pathtouchbashcli.sh
File metadata and controls
executable file
·107 lines (83 loc) · 2.22 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/bash
filename=$1
if [[ $# -eq 0 ]]; then
echo "Error: no arguments provided"
echo "USAGE: $(basename $0) [NEW_FILE_NAME]"
exit 1
fi
touch ${filename}.sh
chmod u+x ${filename}.sh
# Guts of template
template() {
cat <<'EOF'
#!/usr/bin/bash
# AUTHOR: James Lingford (james.lingford@monash.edu)
# DESC: A bash script to add annotations to protein fasta headers from a .tsv file
# -------------------------------------------
# init vars
input1="" # path to input file1
input2="" # path to input file2
param1="" # column of interest to map info to faafile headers
# -------------------------------------------
# helper functions
usage="USAGE: $(basename "$0") [-h] -i input1 -d input2
DESCRIPTION:
OPTIONS:
-i path to input (required)
-d path to input (required)
-h show this help text
REQUIRES: seqkit
EXAMPLE USAGE:
$(basename $0) -i path/to/tsv.tsv -d path/to/tsv2.tsv > path/to/new_faa_file
"
# print help anyway if no args provided
if [[ $# -eq 0 ]]; then
echo "$usage"
exit 1
fi
# getops stuff
while getopts 'i:d:h' option; do
case "$option" in
h)
echo "$usage"
exit
;;
i)
input1=$OPTARG
;;
d)
input2=$OPTARG
;;
\?)
printf "[WARNING]: illegal option: -%s\n" "$OPTARG" >&2
echo "For help, see: $(basename $0) -h"
exit 1
;;
esac
done
shift $((OPTIND - 1))
# -------------------------------------------
# sanity checks
# check all vars are set
if [[ -z "$input1" || -z "$input2" ]]; then
echo "[WARNING]: some options not set."
echo "For help, see: $(basename $0) -h"
exit 1
fi
# check input files acutally exist
if [[ ! -f "$input1" || ! -f "$input2" ]]; then
echo "[WARNING]: the .tsv or .faa file does not exist. Double check input filepaths"
echo "For help, see: $(basename $0) -h"
exit 1
fi
# check that DEPENDENCY is installed and on PATH
if ! command -v seqkit &>/dev/null; then
echo "[WARNING]: seqkit not found on PATH"
echo "See seqkit installation docs: https://bioinf.shenwei.me/seqkit/download/#installation"
exit 1
fi
# -------------------------------------------
# main function
EOF
}
template >"${filename}.sh"