-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep-mb-data.sh
executable file
·67 lines (48 loc) · 2.04 KB
/
prep-mb-data.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
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -eu
# This script requires files generated by prep-ds-data.sh.
declare -A ds_roots=( [1]=15 [3]=7 [4]=8 [5]=1 [6]=6 [7]=7 [8]=4 )
declare -A priors=( ["_output"]="unconstrained:uniform(0,1)" ["_exp_output"]="unconstrained:exp(10.0)")
function prep_mb_data() {
ds=$1
root=$2
prior_path=$3
prior_str=$4
echo "### Preparing Mr. Bayes data files for ds${ds} in ${prior_path}..."
fasta_path="data/ds${ds}/ds${ds}.fasta"
data_path="data/ds${ds}/${prior_path}"
posterior_pickle_path="${data_path}/posterior.pkl"
first_tree_path="${data_path}/ds${ds}.top1.nwk"
posterior_newick_path="${data_path}/ds${ds}.mb-trees.with-fake_branches.nwk"
pp_csv="${data_path}/ds${ds}.mb-pp.csv"
pcsp_pp_csv="${data_path}/ds${ds}.pcsp-pp.csv"
subsplit_path="${data_path}/ds${ds}.subsplit.csv"
mb_run_dir="${data_path}/short_mcmc"
mb_run_path="${mb_run_dir}/run.mb"
rerooted_topologies_path="${mb_run_dir}/rerooted-topology-sequence.tab"
out_path="${mb_run_dir}/mcmc_search_sdag_stats.csv"
mkdir -p $mb_run_dir
# Create the Mr. Bayes file.
python make_mb_file.py $ds $first_tree_path $prior_str $mb_run_path \
--generations 1000000
echo "### Running Mr. Bayes..."
cd $mb_run_dir
mb run.mb | tee mb.log
echo "### Processing Mr. Bayes trees file..."
awk '$1~/tree/ {print $NF}' ds${ds}.t | nw_topology - | nw_reroot - ${root} \
| nw_order - | uniq -c | sed -e "s/^[ ]*//" -e "s/[ ]/\t/" \
> rerooted-topology-sequence.tab
cd ../../../..
echo "### Calculating statistics..."
python mb_comparison_stats.py $posterior_pickle_path $rerooted_topologies_path \
$fasta_path $first_tree_path $posterior_newick_path $pp_csv $pcsp_pp_csv \
$subsplit_path $out_path
echo "### Results written to mb_run_dir="${data_path}/short_mcmc""
}
for ds in "${!ds_roots[@]}"; do
root=${ds_roots[$ds]}
for prior_path in "${!priors[@]}"; do
prior_string=${priors[$prior_path]}
prep_mb_data $ds $root $prior_path $prior_string
done
done