Visualizes information flow connections in humans
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

219 lines
8.8 KiB

#!/bin/sh
# This script will
# - merge the different datasets into a single dataset
# - generate a graphviz dotfile for each specified graph using "convert.py"
# - compile the dotfile to generate a PNG image and a HTML image map
# - compile a HTML file with links, the imagemap and metadata
GRAPHS="
overview nerves brain cortex cortex-compact everything \n
frontal-lobe parietal-lobe temporal-lobe occipital-lobe \n
hippocampus thalamus cerebellum brainstem \n
retina ear tongue hand nose \n
"
DONT_GENERATE=""
generate () {
export RENDERER="dot"
export COLLAPSE= NO_COLLAPSE= DELETE_NODES=
export GREEDY_COLLAPSE=0
export DEDUPLICATE_EDGES=1
export USE_CLUSTERS=0
export GENERATE_GROUP_CONNECTIONS=0
export DELETE_LONE_NODES=1
export FULL_NAMES=0
export INVISIBLE_GROUP_CONNECTIONS=1
export EDGES="openconnectome/edges.csv manual/edges.csv"
export NODES="manual/nodes.csv"
export FUNCTIONS="manual/functions.csv"
name="$1"
case "$1" in
index)
# Merge all nodes/edges/functions as a reference
tail -qn +2 $NODES > nodes.csv
tail -qn +2 $EDGES > edges.csv
tail -qn +2 $FUNCTIONS > functions.csv
;;
overview)
export EDGES=""
export RENDERER="circo -Gsep=+10 -Gsplines=curved"
export DELETE_LONE_NODES=0
export GENERATE_GROUP_CONNECTIONS=1
export INVISIBLE_GROUP_CONNECTIONS=0
;;
brain)
export COLLAPSE="body.face.tongue body.face.ear body.hand"
export RENDERER="neato -Gsplines=ortho -Gsep=+20"
export GENERATE_GROUP_CONNECTIONS=1
;;
everything)
export RENDERER="dot -Grankdir=UD"
export DELETE_LONE_NODES=1
;;
cerebellum)
export COLLAPSE="body cns.spinal cns cns.brainstem cns.nerve cns.retina"
export NO_COLLAPSE="cns.cer cns.frontal.motor cns.brainstem.ION cns.brainstem.pons.vestibular cns.spinal"
export DELETE_NODES="body.face.tongue body.face.ear CN body.hand cns cns.retina"
export DELETE_LONE_NODES=0
;;
brainstem)
export COLLAPSE="body cns cns.spinal cns.cer cns.nerve.2.nonvisual cns.retina body.face.ear body.hand body.face.tongue"
export NO_COLLAPSE="cns.brainstem CN cns.cer body.organs body.muscles"
export DELETE_NODES=""
export DELETE_LONE_NODES=1
;;
cortex)
export COLLAPSE="cns.basal cns.cer cns.retina cns.brainstem body.face.ear body.hand cns.retina body.face.tongue"
export NO_COLLAPSE="cns.frontal cns.pari cns.vis cns.temp"
export DELETE_NODES="body"
;;
cortex-compact)
export RENDERER="neato -Gsplines=ortho -Gsep=+10"
export COLLAPSE="body cns.basal cns.cer cns.brainstem cns.retina"
export DELETE_NODES="body"
export GENERATE_GROUP_CONNECTIONS=1
;;
retina)
export RENDERER="dot -Grankdir=UD"
export COLLAPSE="cns CN body cns.basal.pineal"
export NO_COLLAPSE="cns.retina cns.nerve.2 cns.brainstem.pretectum cns.basal.SCN cns.basal.thal.LGN cns.vis"
export DELETE_NODES="body cns cns.vis.lateral"
;;
ear)
export COLLAPSE="body cns cns.nerve.3"
export NO_COLLAPSE="cns.nerve.8 body.face.ear cns.brainstem.cochlear cns.brainstem.pons.vestibular cns.brainstem"
export DELETE_NODES="body cns"
export RENDERER="dot -Grankdir=UD"
;;
tongue)
export COLLAPSE="cns body cns.nerve.12 cns.nerve.7 cns.nerve.9 cns.nerve.5 cns.nerve.10 cns.brainstem.medulla.solitary"
export NO_COLLAPSE="body.face.tongue"
export DELETE_NODES="body body.face.tongue"
#export RENDERER="dot -Grankdir=UD"
#export DELETE_LONE_NODES=0
;;
nose)
export COLLAPSE="body cns cns.basal.hippocampus"
export NO_COLLAPSE="cns.olfactory cns.nerve.1 cns.basal.amg cns.basal.thal.MDN cns.basal.septal cns.basal.amg cns.temp.medial.entorhinal cns.basal.olfactory"
export DELETE_NODES="body cns cns.olfactory.bulb"
;;
hand)
export COLLAPSE="body cns cns.cer cns.basal.thal.VP"
export NO_COLLAPSE="body.hand cns.spinal"
export DELETE_NODES="body cns"
export DEDUPLICATE_EDGES=0
export RENDERER="dot -Grankdir=UD"
;;
hippocampus)
export COLLAPSE="body cns cns.frontal.pre cns.basal.septal cns.temp.medial.entorhinal cns.temp.parahippocampal cns.frontal.motor.primary"
export NO_COLLAPSE="cns.basal.hippocampus"
export DELETE_NODES="body"
export DELETE_LONE_NODES=1
;;
thalamus)
export COLLAPSE="body cns cns.spinal cns.brainstem cns.vis cns.temp cns.frontal.pre cns.frontal.motor cns.pari.posterior cns.pari.S1 cns.nerve.2 cns.nerve.5"
export NO_COLLAPSE="cns.basal.thal"
export DELETE_NODES="body.face.ear cns.retina body.face.tongue CN body.hand cns"
export DELETE_LONE_NODES=0
export RENDERER="dot -Gsplines=ortho -Gsep=+10"
;;
frontal-lobe)
export COLLAPSE="cns body cns.pari cns.vis cns.temp"
export NO_COLLAPSE="cns.frontal"
export DELETE_NODES="CN body.face.ear cns.retina body.hand"
export DELETE_LONE_NODES=0
;;
parietal-lobe)
export COLLAPSE="cns body cns.frontal cns.temp cns.vis"
export NO_COLLAPSE="cns.pari"
export DELETE_NODES="body.hand CN body.face.ear cns.retina"
export DELETE_LONE_NODES=0
;;
temporal-lobe)
export COLLAPSE="cns body cns.frontal cns.pari cns.vis"
export NO_COLLAPSE="cns.temp"
export DELETE_NODES="body.hand CN body.face.ear cns.retina"
export DELETE_LONE_NODES=0
;;
occipital-lobe)
export COLLAPSE="cns body cns.frontal cns.pari cns.temp cns.basal.thal.LGN"
export NO_COLLAPSE="cns.vis"
export DELETE_NODES="body.hand CN body.face.ear cns.retina"
export DELETE_LONE_NODES=0
;;
nerves)
export COLLAPSE="cns body body.hand body.face.ear cns.retina CN body.face.tongue body.trapezius body.SCM cns.nerve.2 body.face"
export NO_COLLAPSE="cns.nerve cns.spinal body.face.eye cns.olfactory.receptor"
export DELETE_NODES=""
export DELETE_LONE_NODES=1
;;
esac
tempdir=tmp/
target=out/
mkdir -p "$target"
mkdir -p "$tempdir"
if [[ "$name" != "index" ]]; then
# Combine the different sources to a single data set
tail -qn +2 $NODES > "${tempdir}nodes_${name}.csv"
tail -qn +2 $EDGES > "${tempdir}edges_${name}.csv"
tail -qn +2 $FUNCTIONS > "${tempdir}functions_${name}.csv"
prefix=connections_
# Generate the graphviz file
./convert.py "${tempdir}nodes_${name}.csv" "${tempdir}edges_${name}.csv" \
"${tempdir}functions_${name}.csv" > "$tempdir$prefix$name".dot
# Generate the image file in parallel
{
$RENDERER "$tempdir$prefix$name".dot -Tpng -o "$target$prefix$name".png
optipng -quiet "$target$prefix$name".png
} &
# Generate the HTML image map
$RENDERER "$tempdir$prefix$name".dot -Tcmapx -o "$tempdir$prefix$name".cmapx
fi
# Generate the HTML file
out="$target$prefix$name".html
prefix=connections_
cat _header.html > "$out"
echo "<p>" >> "$out"
for graph in $GRAPHS; do
if [[ "$graph" == "\n" ]]; then
echo "<br />" >> "$out"
continue
fi
echo "<a href='${prefix}${graph}.html'>$graph</a>" >> "$out"
done
echo "</p>" >> "$out"
if [[ "$name" != "index" ]]; then
echo "<img src='${prefix}${name}.png' usemap='#brainvis' />" >> "$out"
cat "$tempdir$prefix$name".cmapx >> "$out"
# Apppend metadata to html
echo "<hr /><table><tr><th>Compiling Option</th><th>Value</th></tr>" >> "$out"
for option in RENDERER COLLAPSE NO_COLLAPSE DELETE_NODES DEDUPLICATE_EDGES \
USE_CLUSTERS GENERATE_GROUP_CONNECTIONS INVISIBLE_GROUP_CONNECTIONS \
DELETE_LONE_NODES FULL_NAMES NODES EDGES FUNCTIONS; do
echo "<tr><td>$option</td><td>${!option}</td></tr>" >> "$out"
done
echo "</table>" >> "$out"
fi
cat _footer.html >> "$out"
}
test "$1" == "-q" || echo 'writing HTML pages and image maps to out/ in the background...'
generate index &
for graph in $GRAPHS; do
[[ "$DONT_GENERATE" == *$graph* ]] && continue
[[ "$graph" == "\n" ]] && continue
generate "$graph" &
done