comparison 0.5.0/dbcheck @ 0:97cd2f532efe

planemo upload
author kkonganti
date Mon, 31 Mar 2025 14:50:40 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:97cd2f532efe
1 #!/usr/bin/env bash
2
3 ##########################################################
4 # Constants
5 ##########################################################
6 GREEN=$(tput setaf 2)
7 RED=$(tput setaf 1)
8 CYAN=$(tput setaf 6)
9 CLRESET=$(tput sgr0)
10 prog_name="nowayout"
11 dbBuild="03182024"
12 dbPath="/hpc/db/${prog_name}/$dbBuild"
13 taxonomyPath="$dbPath/taxonomy"
14
15 usage()
16 {
17 echo
18 echo usage: "$0" [-h]
19 echo
20 echo "Check for species presence in ${prog_name} database(s)."
21 echo
22 echo 'Example usage:'
23 echo
24 echo 'dbcheck -l'
25 echo 'dbcheck -g Cathartus'
26 echo 'dbcheck -d mitomine -g Cathartus'
27 echo 'dbcheck -d mitomine -s "Cathartus quadriculus"'
28 echo
29 echo 'Options:'
30 echo " -l : List ${prog_name} databases"
31 echo ' -d : Search this database. Default: mitomine.'
32 echo ' -g : Genus to search for.'
33 echo ' -s : "Genus Species" to search for.'
34 echo ' -h : Show this help message and exit'
35 echo
36 echo "$1"
37 }
38
39 while getopts ":d:g:s:l" OPT; do
40 case "${OPT}" in
41 l)
42 listdb="list"
43 ;;
44 d)
45 dbname=${OPTARG}
46 ;;
47 g)
48 genus=${OPTARG}
49 ;;
50 s)
51 species=${OPTARG}
52 ;;
53 ?)
54 usage
55 exit 0
56 ;;
57 esac
58 done
59
60
61
62 if [ -n "$listdb" ]; then
63 num_dbs=$(find "$taxonomyPath" -type d | tail -n+2 | wc -l)
64 echo "=============================================="
65
66 db_num="1"
67 find $taxonomyPath -type d | tail -n+2 | while read -r db; do
68 dbName=$(basename "$db")
69 echo "${db_num}. $dbName"
70 db_num=$(( db_num + 1 ))
71 done
72 echo "=============================================="
73 echo "Number of ${prog_name} databases: $num_dbs"
74 echo "=============================================="
75
76 exit 0
77 fi
78
79
80
81 if [ -z "$dbname" ]; then
82 dbname="mitomine"
83 fi
84
85 if [[ -n "$genus" && -n "$species" ]]; then
86 usage "ERROR: Only one of -g or -s needs to be defined!"
87 exit 1
88 elif [ -n "$genus" ]; then
89 check="$genus"
90 elif [ -n "$species" ]; then
91 check="$species"
92 else
93 check=""
94 fi
95
96 if [ -z "$check" ]; then
97 usage "ERROR: -g or -s is required! check:$check"
98 exit 1
99 fi
100
101 lineages="$taxonomyPath/$dbname/lineages.csv"
102
103 echo
104 echo -e "Checking ${dbname} for ${CYAN}${check}${CLRESET}...\nPlease wait..."
105 echo
106
107 num=$(grep -F ",$check," "$lineages" | cut -f1 -d, | sort -u | wc -l)
108 num_species=$(tail -n+2 "$lineages" | cut -f8 -d, | sort -u | wc -l)
109 num_entries=$(tail -n+2 "$lineages" | wc -l)
110
111 echo "$dbname brief stats"
112 echo "=============================================="
113 echo "DB Build: $dbBuild"
114 echo "Number of unique species: $num_species"
115 echo "Number of accessions in database: $num_entries"
116 echo "=============================================="
117
118
119 if [ "$num" -gt 0 ]; then
120 echo
121 echo "${GREEN}$check is present in ${dbname}${CLRESET}."
122 echo "Number of accessions representing $check: $num"
123 echo "=============================================="
124 else
125 echo "${RED}$check is absent in ${dbname}${CLRESET}."
126 echo -e "No worries. Please request the developer of\n${prog_name} to augment the database!"
127 echo "=============================================="
128 fi