Commit 1e8051ab authored by qlobbe's avatar qlobbe

add convertion script

parent 11566ebf
#!/bin/bash
#
# To convert a phylo DOT file into a phylo JSON / SVG file
#
exitWithError()
{
echo "$1" 1>&2
exit 1
}
exitWithUsage()
{
echo "$1" 1>&2
usage
exit 1
}
usage()
{
cat << EOF
USAGE: ./`basename $0` options
OPTIONS:
--from (required) [path to the original phylo dot file]
--to (required) [format of the output file - json / svg]
--help (optional) [displays this message]
EOF
}
init()
{
FROM=""
TO=""
while getopts ":-:" OPTION
do
LONG_OPTION="${OPTARG%%=*}"
OPTARG="${OPTARG#*=}"
case ${LONG_OPTION} in
from)
FROM=${OPTARG}
;;
to)
TO=${OPTARG}
;;
help)
usage ;
exit 0
;;
*)
echo "Unknown option ${LONG_OPTION}" ;
usage ;
exit 1
;;
esac
done
if [ "${FROM}" == "" ] || [ "${TO}" == "" ]; then
exitWithUsage $'\nAt least one required option is missing.\n'
fi
if [ "${TO}" != "json" ] && [ "${TO}" != "svg" ]; then
exitWithUsage $'\nOutput format has to be json or svg.\n'
fi
if [ ! -f "${FROM}" ]; then
exitWithError $'\nOriginal phylo DOT file does not exist.\n'
fi
NAME=$(basename ${FROM} .dot)
FILEPATH=$(dirname "${FROM}")
}
convert()
{
if [ "${TO}" == "svg" ]; then
`dot ${FROM} -Tsvg > "${FILEPATH}/${NAME}.svg"`
fi
if [ "${TO}" == "json" ]; then
`dot -Tdot -o "tmp.dot" ${FROM}`
`dot -Txdot_json -o "${FILEPATH}/${NAME}.json" "tmp.dot"`
fi
}
init "$@"
convert
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment