Public
Edited
Feb 3, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
table_data = {
let count = 0;
let for_table = []
for (const key in mod_results_json ) {
let absrel_u_branches = _.filter(_.map(mod_results_json[key]['aBSREL_UNFILTERED']['branch attributes'], d=> d['Corrected P-value']), d => d != null && d < pval)
let absrel_f_branches = _.filter(_.map(mod_results_json[key]['aBSREL_FILTERED']['branch attributes'], d=> d['Corrected P-value']), d => d != null && d < pval)

// Avery LRT calc
let avery_lrt_val = -2 * (mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Log Likelihood'] - mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Log Likelihood'])
let avery_e_p_val = chisqrprob(2, avery_lrt_val) / 2
// Filter based on the pvals
let avery_filt = avery_e_p_val < pval ? ['filtered', 'BUSTED-E'] : ['unfiltered', 'BUSTED']
// end lrt calc

// AGL LRT calc
// Based on https://sites.warnercnr.colostate.edu/gwhite/wp-content/uploads/sites/73/2017/04/LikelihoodRatioTests.pdf
// Get Log likelihoods of the models
let simple_model_ll = mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Log Likelihood'];
let alternative_model_ll = mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Log Likelihood'];

// you should always see LR ≥ 0
let lrt_val = -2 * simple_model_ll + 2 * alternative_model_ll;

console.log("Simple model LL: " + simple_model_ll + " Complex model LL " + alternative_model_ll);
console.log("Avery LRT: " + avery_lrt_val);
console.log("AGL LRT: " + lrt_val);
let e_p_val = chisqrprob(2, lrt_val)/2
// Filter based on the pvals
let filt = e_p_val < pval ? ['filtered', 'BUSTED-E'] : ['unfiltered', 'BUSTED']
// end lrt calc

if (lrt_val < 0) {
count += 1;
console.log ("Potential convergence issue! Avery! " + key);
}
const obj = {}

//overall
obj["ID"] = key
obj["Total sites"] = mod_results_json[key]['BUSTED_E']['input']['number of sites']
obj["Total sequences"] = mod_results_json[key]['BUSTED_E']['input']['number of sequences']

//BUSTED-E
obj["BUSTED-E filtered sites"] = _.reduce(mod_results_json[key]['FILTER']['filter'], (count, filter) => count + _.keys(filter).length, 0)
obj["Fraction of sites filtered"] = obj["BUSTED-E filtered sites"]/(obj["Total sites"] * obj["Total sequences"])
obj["Error p-val"] = e_p_val
obj["Filtered?"] = filt[0]

//aBSREL
obj["aBSREL selected branches"] = filt[0] === 'filtered' ? absrel_f_branches.length : absrel_u_branches.length
//BUSTED
obj["BUSTED selection p-val"] = filt[0] === 'filtered' ? mod_results_json[key]['BUSTED_E']['test results']['p-value'] : mod_results_json[key]['BUSTED']['test results']['p-value']
obj["BUSTED(E?) ⍵1"] = filt[0] === 'filtered' ? mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Rate Distributions']['Test'][1]['omega'] : mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Rate Distributions']['Test'][0]['omega']
obj["BUSTED(E?) ⍵2"] = filt[0] === 'filtered' ? mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Rate Distributions']['Test'][2]['omega'] : mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Rate Distributions']['Test'][1]['omega']
obj["BUSTED(E?) ⍵3"] = filt[0] === 'filtered' ? mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Rate Distributions']['Test'][3]['omega'] : mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Rate Distributions']['Test'][2]['omega']
obj["BUSTED(E?) p1"] = filt[0] === 'filtered' ? mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Rate Distributions']['Test'][1]['proportion'] : mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Rate Distributions']['Test'][0]['proportion']
obj["BUSTED(E?) p2"] = filt[0] === 'filtered' ? mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Rate Distributions']['Test'][2]['proportion'] : mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Rate Distributions']['Test'][1]['proportion']
obj["BUSTED(E?) p3"] = filt[0] === 'filtered' ? mod_results_json[key]['BUSTED_E']['fits']['Unconstrained model']['Rate Distributions']['Test'][3]['proportion'] : mod_results_json[key]['BUSTED']['fits']['Unconstrained model']['Rate Distributions']['Test'][2]['proportion']
for_table.push(obj)
}

console.log("Issues in " + count + " files");
return for_table
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more