Radmind Dependencies

By: Wout Mertens - Revised: 2006-10-03 devin

Download Script – ZIP-File, 2.2 KB

Introduction

Scripts from Wout Mertens. One lists the files that are common to a given transcript in other transcripts, in order. The other creates a dependency graph of all transcripts, which you can read with GraphViz.

Script

create-dep-graph.sh
#!/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"

rad-find-common-transcripts.sh
#!/bin/bash
#
# Find files common between a certain transcript and other transcripts
#
#

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

help () {
    echo "Usage: $0 [-K commandfile] [-T transcriptdir] transcript"
    exit 1
}

[ $# -lt 1 ] && help

KFILE=/var/radmind/client/command.K
TRANSD=/var/radmind/client/
while getopts ':K:T:' OPT; do
    case $OPT in
        K) KFILE="$OPTARG" ;;
        T) TRANSD="$OPTARG" ;;
        *) help ;;
    esac
done
shift $(( OPTIND - 1 ))
TRANSCRIPT="$1"
TRANSNAME="`basename "$1"`"

die(){
    echo "$*"
    exit 1
}

T=/tmp/find_common.$$

# First generate a list of all files
awk '$1~/[+-*]/{n=3}$1~/[hldcbpsDfam]/{n=2}n!=0{print " " $n " ";print " " $n " "; n=0}' "$TRANSCRIPT" > $T
if [ ! -s "$T" ]; then
    rm "$T"
    die "$TRANSCRIPT: not a transcript? (no files)"
fi

get_transcripts() {
    kname="`basename "$1"`"
    awk '$1~/^[knp]$/{print $0}' "$1" | while read type file; do
        case $type in
            p)    echo "$file" ;;
            n)    echo "$file" ;;
            k)    get_transcripts "`dirname "$1"`/$file" ;;
        esac
    done
}

for i in `get_transcripts "$KFILE"`; do
    if [ "$i" != "$TRANSNAME" ]; then
        grep -Ff "$T" "$TRANSD/$i" | sed "s/^/$i    /"
    else
        echo "=== $i ==="
    fi
done
rm "$T"