#!/bin/bash
# Create a .dot file with all the transcript overridings
#
if [ $# -ne 3 ]; then
echo "Usage: $0 commandfile radmind-transcript-dir dotty-file"
exit 1
fi
KFILE="$1"
TRANSD="$2"
DFILE="$3"
die(){
echo "$*"
exit 1
}
[ ! -r "$KFILE" ] && die "Can't read $KFILE"
[ ! -d "$TRANSD" ] && die "$TRANSD is not a directory"
T=/tmp/dupefinder.$$
get_transcripts() {
kname="`basename "$1"`"
echo "subgraph "cluster$kname" { label="$kname"" >> $T.graph
awk '$1~/^[knp]$/{print $0}' "$1" | while read type file; do
case $type in
p) echo ""$file"" >> $T.graph; echo "$file" ;;
n) echo "NEG "$file"" >> $T.graph; echo "$file" ;;
k) get_transcripts "`dirname "$1"`/$file" ;;
esac
done
echo "}" >> $T.graph
}
# Get all files from all transcripts, and sort them per file
# Note "d", you can remove that if you don't want directories
# Note the encoded tab character in the sort invocation
d=
echo Generating dupelist
get_transcripts "$KFILE" | while read file; do
awk -v OFS=' ' '$1~/^[hl'$d'cbpsDfam]$/{print "'$file'", $2}' "$TRANSD/$file"
done | sort -s -t -k2,2 > $T.all
# Generate a file that contains: transcript->previous owner
# for each overridden file
# TODO: add number of overrides to edge
echo Generating "$DFILE"
awk '{
if (file != $2) {
owner = $1
file = $2
} else {
print """ $1 "" -> "" owner """
owner = $1
}
}' $T.all | sort | uniq -c > $T.almostdot
#rm $T.all
# Create dotfile
echo 'digraph {' > "$DFILE"
echo ' style=dashed;concentrate=true' >> "$DFILE"
# dependencies
awk '{print $2,$3,$4,"[ label = "" $1 "" ];"}' $T.almostdot >> "$DFILE"
rm $T.almostdot
# kfiles
cat $T.graph | while read TRANS; do
case "$TRANS" in
*{*|*}*)
echo "$TRANS" >> "$DFILE" ;;
*)
# Strip off possible "NEG " tag of transcript name
t="${TRANS#NEG }"
if grep -qF "$t" "$DFILE"; then
if [ "$t" != "$TRANS" ]; then
# negative shapes
echo "$t [ shape = diamond ];" >> "$DFILE"
else
echo "$t;" >> "$DFILE"
fi
fi
;;
esac
done
rm $T.graph
echo '}' >> "$DFILE"