-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmauve_reorder.sh
executable file
·111 lines (94 loc) · 2.87 KB
/
mauve_reorder.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
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# mauve_reorder.sh: reorder contigs based on a reference assembly using Mauve
#
# Requirements:
# run on a unix computer installed with Mauve
# samtools installed
# draft assembly and reference genome fasta present
# + fasta sequence lines normalized using picard NormalizeFasta
#
# Stephane Plaisance (VIB-NC+BITS) 2017/04/21; v1.0
#
# visit our Git: https://github.com/Nucleomics-VIB
# check parameters for your system
version="1.0, 2017_04_21"
usage='# Usage: mauve_reorder.sh -i <draft assembly> -r <reference assembly> -p <mauve path>
# script version '${version}'
# [optional: -o <result folder>]
# [optional: -m <available RAM|1G>]
# [optional: -h <this help text>]'
while getopts "i:r:o:p:m:h" opt; do
case $opt in
i) draftassembly=${OPTARG} ;;
r) reference=${OPTARG} ;;
p) mauvepath=${OPTARG} ;;
o) outpath=${OPTARG} ;;
m) memory=${OPTARG} ;;
h) echo "${usage}" >&2; exit 0 ;;
\?) echo "Invalid option: -${OPTARG}" >&2; exit 1 ;;
*) echo "this command requires arguments, try -h" >&2; exit 1 ;;
esac
done
# defaults
startts=$(date +%s)
# test if minimal arguments were provided
if [ -z "${draftassembly}" ]
then
echo "# no draft assembly provided!"
echo "${usage}"
exit 1
fi
if [ ! -f "${draftassembly}" ]; then
echo "${draftassembly} file not found!"
exit 1
fi
if [ -z "${reference}" ]
then
echo "# no reference assembly provided!"
echo "${usage}"
exit 1
fi
if [ ! -f "${reference}" ]; then
echo "${reference} file not found!";
exit 1
fi
if [ -z "${mauvepath}" ]
then
echo "# no path to Mauve.jar provided!"
echo "${usage}"
exit 1
fi
if [ ! -f "${mauvepath}/Mauve.jar" ]; then
echo "Mauve.jar file not found at ${mauvepath}!";
exit 1
fi
# check if requirements are present
$( hash samtools 2>/dev/null ) || ( echo "# samtools not found in PATH"; exit 1 )
# other parameters or defaults
outname=$(basename ${draftassembly})
destfolder=${outpath:-"mauve_reordered-${outname%.*}"}
mkdir -p ${destfolder} || ( echo "# could not create destination folder"; exit 1 )
mem=${memory:-"1G"}
# build the command
cmd="java -Xmx${mem} -cp ${mauvepath}/Mauve.jar \
org.gel.mauve.contigs.ContigOrderer \
-output ${destfolder} \
-ref ${reference} \
-draft ${draftassembly} \
> mauve-reorder_${outname%.*}-log.txt 2>&1"
# show and execute
echo "# ${cmd}"
eval ${cmd}
# after completion, copy the final ordered assembly to <destfolder> and index it
if [ $? -eq 0 ]; then
lastfolder=$(basename $(find "${destfolder}" -type d -name "alignment*" | sort -k 1V,1r | head -1))
echo "#last iteration: ${lastfolder}"
cp ${destfolder}/${lastfolder}/${outname} \
${destfolder}/ordered-${outname} && \
samtools faidx ${destfolder}/ordered-${outname}
else
echo "Mauve ordering seems to have failed, please check the mauve-reorder_${outname}-log.txt!"
fi
endts=$(date +%s)
dur=$(echo "${endts}-${startts}" | bc)
echo "Done in ${dur} sec"