-
Notifications
You must be signed in to change notification settings - Fork 0
/
anvi-script-prep-clinker.sh
executable file
·100 lines (87 loc) · 3.14 KB
/
anvi-script-prep-clinker.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
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
#!/bin/bash
print_usage() {
echo "anvi-script-prep-clinker [-a <annotation-source>] -i <in-dir> -o <out-dir>"
echo ""
echo "Description:"
echo " Takes a directory of exported locus databases (generated by"
echo " anvi-export-locus) and converts them to Genbank files to be"
echo " used with clinker. These GB files will be placed in the"
echo " provided output directory."
echo ""
echo " The optional argument -a allows the user to specify which"
echo " annotation source from the input locus databases to be added"
echo " to the resulting GB files. However, this option is incompatible"
echo " with Anvi'o versions 7.1 and earlier, where only COG_FUNCTION"
echo " can be added to the output. Only use the -a option with Anvi'o"
echo " versions later than 7.1, such as the dev environment."
echo ""
echo " Depends on the following scripts, which must be in the same"
echo " base directory as this script:"
echo " - gff_to_genbank.py"
echo " - - GFFParser.py"
echo " - clean-gff-products.sh"
}
indir=""
outdir=""
annotation=""
while getopts ":hi:o:a:" opt; do
case $opt in
h) print_usage
exit 1
;;
i) indir="${OPTARG}"
;;
o) outdir=$(realpath ${OPTARG})
;;
a) annotation="${OPTARG}"
;;
\?) echo "Invalid option: -${OPTARG}. Use the -h option for more information.">&2
exit 1
;;
:) echo "Option -$OPTARG requires an argument. Use the -h option for more information.">&2
exit 1
;;
esac
done
if [[ -z "$indir" ]]; then
echo "You must provide an input directory."
exit 1
fi
if [[ ! -d "$indir" ]]; then
echo "The provided directory does not exist: $indir"
exit 1
fi
if [[ ! $CONDA_DEFAULT_ENV =~ "anvio" ]]; then
echo "You need to activate an anvio conda environment before running this."
exit 1
fi
# Get real directory where script file is located,
# even if the script was called via a symlink
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
# Extract GFF of annotations
for f in ${indir}/*.db; do
if [[ -z "$annotation" ]]; then
anvi-get-sequences-for-gene-calls -c $f --export-gff3 -o ${f%.db}.gff
else
anvi-get-sequences-for-gene-calls -c $f --export-gff3 -o ${f%.db}.gff --annotation-source "$annotation"
fi
done
echo "Cleaning GFFs of reserved characters..."
# Clean the GFFs of reserved characters
for f in ${indir}/*.gff; do
$DIR/clean-gff-products.sh $f
done
echo "Converting to GenBank format..."
# Convert GFF to GB format
for f in ${indir}/*.gff; do
$DIR/gff_to_genbank.py $f ${f%.gff}.fa
done
# Copy GB files for clinker to the output directory
cp ${indir}/*.gb $outdir
echo "Done!"