| 1 |
#! /bin/sh |
| 2 |
# |
| 3 |
# clean_jumbles file_name_root |
| 4 |
# |
| 5 |
comm=`echo $0 | sed 's&^.*/&&g'` |
| 6 |
nosummaryflag="-nosummary" |
| 7 |
summaryflag="-summary" |
| 8 |
summary=1 |
| 9 |
|
| 10 |
while echo " $1" | grep "^ -" >/dev/null; do |
| 11 |
if test $# -lt 2; then break |
| 12 |
elif test $1 = "$nosummaryflag"; then summary=0; shift |
| 13 |
elif test $1 = "-n"; then summary=0; shift |
| 14 |
elif test $1 = "$summaryflag"; then summary=1; shift |
| 15 |
elif test $1 = "-s"; then summary=1; shift |
| 16 |
elif test $1 = "-"; then shift; break |
| 17 |
else echo "Bad flag: $*"; shift $#; break |
| 18 |
fi |
| 19 |
done |
| 20 |
|
| 21 |
if test $# -ne 1; then |
| 22 |
echo "Usage: $comm [ $nosummaryflag ] file_name_root" |
| 23 |
exit |
| 24 |
fi |
| 25 |
|
| 26 |
out="$1" |
| 27 |
|
| 28 |
# Check requested name |
| 29 |
|
| 30 |
if test `ls -d $out.[0-9]* 2>/dev/null | wc -l` -eq 0; then |
| 31 |
echo "$comm: No files found of form $out.(jumble_seed)" |
| 32 |
exit |
| 33 |
elif grep '^Ln Likelihood' $out.[0-9]* >/dev/null; then : |
| 34 |
else |
| 35 |
echo "$comm: No likelihoods found in files of form $out.(jumble_seed)" |
| 36 |
exit |
| 37 |
fi |
| 38 |
|
| 39 |
# Summary exists |
| 40 |
|
| 41 |
summarized=0 |
| 42 |
if test -f "$out.summary" -a $summary -gt 0; then |
| 43 |
if test ! -f "$out.tree" -o ! -f "$out.out"; then |
| 44 |
echo " |
| 45 |
$comm: Summary file $out.summary exists, but corresponding output |
| 46 |
and tree files ($out.out and $out.tree) cannot be found. |
| 47 |
Cleaning aborted. |
| 48 |
" |
| 49 |
exit |
| 50 |
else |
| 51 |
echo " |
| 52 |
Summary file $out.summary exists. New jumbles will be added to that |
| 53 |
summary without further checking. |
| 54 |
" |
| 55 |
summarized=1 |
| 56 |
fi |
| 57 |
fi |
| 58 |
|
| 59 |
# Don't clobber an existing file |
| 60 |
|
| 61 |
if test $summarized -eq 0 -a \( -f "$out.tree" -o -f "$out.out" \); then |
| 62 |
echo " |
| 63 |
$comm: File(s) with the name(s) $out.out and/or $out.tree |
| 64 |
already exist and would be clobbered by 'cleaning' the jumble output files. |
| 65 |
Move them to a new name and try again. |
| 66 |
" |
| 67 |
exit |
| 68 |
fi |
| 69 |
|
| 70 |
# Find best file PID with the given name |
| 71 |
|
| 72 |
if test $summarized -eq 0; then |
| 73 |
pid=`grep '^Ln Likelihood' $out.[0-9]* /dev/null | |
| 74 |
sed 's/^\(.*\):Ln Like.*=\(.*\)$/\2 \1/' | |
| 75 |
sort -nr +0 | head -1 | sed -e 's/^[^ ]* //' -e 's/^.*\.//'` |
| 76 |
fi |
| 77 |
|
| 78 |
# Write score summary file, if requested |
| 79 |
|
| 80 |
if test $summary -gt 0; then |
| 81 |
if test $summarized -eq 0; then |
| 82 |
grep '^Ln Likelihood' $out.[0-9]* /dev/null | |
| 83 |
sed 's/^\(.*\):\(Ln Like.*\)$/\2 (file: \1)/' | |
| 84 |
sort -nr +3 > "$out.summary" |
| 85 |
else |
| 86 |
temp_name="$out.`uname -n`.$$" |
| 87 |
mv "$out.summary" "$temp_name" |
| 88 |
grep '^Ln Likelihood' $out.[0-9]* /dev/null | |
| 89 |
sed 's/^\(.*\):\(Ln Like.*\)$/\2 (file: \1)/' | |
| 90 |
cat "$temp_name" - | |
| 91 |
sort -nr +3 > "$out.summary" |
| 92 |
rm -f "$temp_name" |
| 93 |
fi |
| 94 |
fi |
| 95 |
|
| 96 |
# Move output and treefile to new names |
| 97 |
|
| 98 |
if test $summarized -eq 0; then |
| 99 |
oldname="$out.$pid" |
| 100 |
if grep "^Ln Likelihood" "$oldname" >/dev/null; then |
| 101 |
newname="$out.out" |
| 102 |
treenew="$out.tree" |
| 103 |
treeold="treefile.$pid" |
| 104 |
checkpt="checkpoint.$pid" |
| 105 |
|
| 106 |
if test -f "$treeold"; then mv "$treeold" "$treenew" |
| 107 |
elif test -f "$checkpt"; then tail -1 "$checkpt" >"$treenew" |
| 108 |
else echo "$comm: Cannot find tree file. Cleaning aborted."; exit |
| 109 |
fi |
| 110 |
|
| 111 |
mv "$oldname" "$newname" |
| 112 |
rm -f "$checkpt" |
| 113 |
fi |
| 114 |
fi |
| 115 |
|
| 116 |
# Remove other output, tree and checkpoint files: |
| 117 |
|
| 118 |
if test `ls -d $out.[0-9]* 2>/dev/null | wc -l` -gt 0; then |
| 119 |
pids=`grep '^Ln Likelihood' $out.[0-9]* /dev/null | |
| 120 |
sed -e 's/^\(.*\):Ln Like.*$/\1/' -e 's/^.*\.//'` |
| 121 |
|
| 122 |
for pid in $pids; do |
| 123 |
rm -f "$out.$pid" "treefile.$pid" "checkpoint.$pid" |
| 124 |
done |
| 125 |
fi |