comparison 0.5.0/dbcheck @ 0:3c767f9cfd88 draft default tip

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