forked from speciationgenomics/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsc-selectbestrun.sh
executable file
·51 lines (42 loc) · 1.21 KB
/
fsc-selectbestrun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Bash script by Joana Meier to select the best fastsimcoal run of multiple runs under the same demographic model
# The script expects output files of different runs to be found in folders starting with run
m=-1000000000000000
p=$1
c=0
best="xxxx"
diff=0
diffBest=0
for i in run*;
do
a=$(ls | grep ${p}".tpl" | sed s'/.tpl//')
# if the file is in the run directory
if [ -e $i/$a.bestlhoods ]
then
l=$(cat $i/$a.bestlhoods | awk '{print $(NF-1)}' | tail -1 | cut -f 1 -d ".")
diff=$(cat $i/$a.bestlhoods | awk '{print $NF-$(NF-1)}' | tail -1 | cut -f 1 -d ".")
((c++))
else
# if the file is in a subdirectory
if [ -e $i/$a/$a.bestlhoods ]
then
l=$(cat $i/$a/$a.bestlhoods | awk '{print $(NF-1)}' | tail -1 | cut -f 1 -d ".")
diff=$(cat $i/$a/$a.bestlhoods | awk '{print $NF-$(NF-1)}' | tail -1 | cut -f 1 -d ".")
((c++))
else
echo "no .bestlhoods file found in "$i
fi
fi
if [ $l -gt $m ]
then
m=$l; x=$i; best=$i;
diffBest=$diff
fi
done
if [ -z ${x+1} ]
then echo "Error: No run with lik>-1000000000000000"
else mkdir bestrun
cp $x/* ./bestrun/
cp $x/$a/* ./bestrun/
fi
echo -e "\n"$c" bestlhoods files found, "$best" with "$diffBest" Lhood diff fits best."