Skip to content
Permalink
Browse files

Merge pull request #149 from blab/modular_augur

Modular augur
  • Loading branch information
trvrb committed Feb 6, 2019
2 parents 6d1a7d1 + 2c10a02 commit 8b94548bd50197b322ac1a7e1502380d8dc6476f
@@ -13,8 +13,8 @@ function calcHIsubclade(node){
calcHIsubclade(node.children[i]);
}
}else{
if (typeof titer_tree_model["avidity"][node.clade] != "undefined" && correctVirus==false){
node.HI_dist_tree+=titer_tree_model["avidity"][node.clade];
if (typeof titer_tree_model["avidity"][node.strain] != "undefined" && correctVirus==false){
node.HI_dist_tree+=titer_tree_model["avidity"][node.strain];
}
}
};
@@ -23,7 +23,7 @@ function calcHItree(node, rootNode){
if (correctPotency){
node.HI_dist_tree = 0;
}else{
node.HI_dist_tree=titer_tree_model["potency"][node.clade].mean_potency;
node.HI_dist_tree=titer_tree_model["potency"][node.strain].mean_potency;
}
if (typeof node.children != "undefined") {
for (var i=0; i<node.children.length; i++) {
@@ -32,11 +32,11 @@ function calcHItree(node, rootNode){
}
var tmp_node = node;
var pnode = tmp_node.parent;
while (tmp_node.clade != rootNode.clade){
while (tmp_node.strain != rootNode.strain){
pnode.HI_dist_tree=tmp_node.HI_dist_tree + tmp_node.attr.dTiter;
if (typeof pnode.children != "undefined") {
for (var i=0; i<pnode.children.length; i++) {
if (tmp_node.clade!=pnode.children[i].clade){
if (tmp_node.strain!=pnode.children[i].strain){
calcHIsubclade(pnode.children[i]);
}
}
@@ -45,25 +45,25 @@ function calcHItree(node, rootNode){
pnode = tmp_node.parent;
}
if (correctVirus==false){
node.HI_dist_tree += titer_tree_model["avidity"][node.clade];
node.HI_dist_tree += titer_tree_model["avidity"][node.strain];
}
};

function calcHImeasured(node, rootNode){
console.log(node.strain+ ', mean_potency: '+titer_subs_model["potency"][node.clade].mean_potency);
console.log(node.strain+ ', mean_potency: '+titer_subs_model["potency"][node.strain].mean_potency);
console.log("correcting for virus effect: "+correctVirus);
console.log("correction for serum effect: "+correctPotency);
var tmptt;
for (var i=0; i<tips.length; i+=1){
d = tips[i];
if (typeof HI_titers[node.clade][d.clade] != "undefined"){
var tmptt = HI_titers[node.clade][d.clade];
if (typeof HI_titers[node.strain][d.strain] != "undefined"){
var tmptt = HI_titers[node.strain][d.strain];
var tmp_HI=0;
var serum_count=0;
for (var tmp_serum in tmptt){
if (activeSera[tmp_serum]){
if (correctPotency&&(d.strain!=focusNode.strain)){
tmp_HI += tmptt[tmp_serum][0]-titer_subs_model["potency"][node.clade].mean_potency
tmp_HI += tmptt[tmp_serum][0]-titer_subs_model["potency"][node.strain].mean_potency
}else{
tmp_HI += tmptt[tmp_serum][0];
}
@@ -73,7 +73,7 @@ function calcHImeasured(node, rootNode){
if (serum_count){
d.HI_dist_meas = tmp_HI/serum_count
if (correctVirus){
d.HI_dist_meas -= titer_subs_model["avidity"][d.clade];
d.HI_dist_meas -= titer_subs_model["avidity"][d.strain];
}
}else{
d.HI_dist_meas = 'NaN';
@@ -86,12 +86,12 @@ function calcHImeasured(node, rootNode){

function get_mutations(node1, node2){
var gt1, gt2,muts=[];
for (var gene in cladeToSeq[node1.clade]){
for (var gene in cladeToSeq[node1.strain]){
var gene_length = cladeToSeq["root"][gene].length;
if (gene!='nuc'){
for (var pos=0; pos<gene_length; pos+=1){
gt1 = stateAtPosition(node1.clade, gene, pos)
gt2 = stateAtPosition(node2.clade, gene, pos)
gt1 = stateAtPosition(node1.strain, gene, pos)
gt2 = stateAtPosition(node2.strain, gene, pos)
if (gt1!=gt2){
muts.push(gene+':'+gt1+(pos+1)+gt2);
}
@@ -102,13 +102,13 @@ function get_mutations(node1, node2){
}

function calcHImutations(node){
console.log(node.strain+ ', mean_potency:'+titer_subs_model["potency"][node.clade].mean_potency);
console.log(node.strain+ ', mean_potency:'+titer_subs_model["potency"][node.strain].mean_potency);
nodes.map(function(d){
var mutations = get_mutations(node, d);
if (correctPotency){
d.HI_dist_mut=0;
}else{
d.HI_dist_mut=titer_subs_model["potency"][node.clade].mean_potency;
d.HI_dist_mut=titer_subs_model["potency"][node.strain].mean_potency;
}
for (var mi=0; mi<=mutations.length; mi++){
var mut = mutations[mi];
@@ -117,13 +117,13 @@ function calcHImutations(node){
}
}
if ((correctVirus==false)&&(typeof d.avidity != "undefined")){
d.HI_dist_mut += titer_subs_model["avidity"][d.clade];
d.HI_dist_mut += titer_subs_model["avidity"][d.strain];
}
});
};

function getSera(tree_tips){
return tree_tips.filter(function (d){return d.serum;})
return tree_tips.filter(function (d){return typeof(HI_titers[d.strain]) != "undefined";})
}

d3.select("#serum")
@@ -145,10 +145,10 @@ if (useTiters) {
d3.json(path + file_prefix + "titers.json", function(error, json){
HI_titers = json;
});
d3.json(path + file_prefix + "titer_tree_model.json", function(error, json){
d3.json(path + file_prefix + "titer-tree-model.json", function(error, json){
titer_tree_model = json;
});
d3.json(path + file_prefix + "titer_subs_model.json", function(error, json){
d3.json(path + file_prefix + "titer-sub-model.json", function(error, json){
titer_subs_model = json;
});
}
@@ -331,7 +331,7 @@ function colorByGenotypePosition (positions) {
var gts = nodes.map(function (d) {
var tmp = [];
for (var i=0; i<positions.length; i++){
tmp[tmp.length] = positions[i][0]+':'+(positions[i][1]+1)+stateAtPosition(d.clade, positions[i][0], positions[i][1]);
tmp[tmp.length] = positions[i][0]+':'+(positions[i][1]+1)+stateAtPosition(d.strain, positions[i][0], positions[i][1]);
}
d.coloring = tmp.join('/');
return d.coloring;});
@@ -386,12 +386,7 @@ function colorByClade() {
for (var i=0; i<unique_clades.length; i++){clade_counts[unique_clades[i]]=0;}
clades.forEach(function (d) {clade_counts[d]+=1;});
clade_counts["unassigned"] = -1;
unique_clades.sort(function (a,b){
var res;
if (clade_counts[a]>clade_counts[b]){ res=-1;}
else if (clade_counts[a]<clade_counts[b]){ res=1;}
else {res=0;}
return res;});
unique_clades.sort(function (a,b){return a>b;});

var cols = [];
for (var i=0; i<unique_clades.length; i++){
@@ -420,8 +415,8 @@ function resetFocusNode() {
var ntiters = 0, ntmp;
focusNode=sera[0];
for (var i=0; i<sera.length; i++){
if (typeof HI_titers[sera[i].clade] != "undefined"){
ntmp = Object.keys(HI_titers[sera[i].clade]).length;
if (typeof HI_titers[sera[i].strain] != "undefined"){
ntmp = Object.keys(HI_titers[sera[i].strain]).length;
}
if (ntmp>ntiters){
ntiters = ntmp;
@@ -448,7 +443,7 @@ function newFocus(){
var seraDiv = document.getElementById("sera");
var htmlStr = "";
activeSera = {};
allSera = Object.keys(titer_subs_model["potency"][focusNode.clade]).filter( function (s)
allSera = Object.keys(titer_subs_model["potency"][focusNode.strain]).filter( function (s)
{return s!="mean_potency"});

for (var i=0; i<allSera.length; i++){
@@ -458,7 +453,7 @@ function newFocus(){
activeSera[serum]=true;
}
seraDiv.innerHTML = htmlStr;
for (var serum in titer_subs_model["potency"][focusNode.clade]){
for (var serum in titer_subs_model["potency"][focusNode.strain]){
var serumID = serum.split("/").join("").replace(/[;,\*\.\(\)]/g, "_");
d3.select("#"+serumID)
.on("change", function(elem){
@@ -509,7 +504,7 @@ function colorByHIDistance(){
if (d==focusNode) {
return "30px";
} else {
var serumCount = ref_to_counts[d["clade"]];
var serumCount = ref_to_counts[d["strain"]];
return serumMarkerSizeScale(serumCount).toString() + "px";
}
})
@@ -10,9 +10,8 @@ var dfreq_cutoff = 0.01;
function calcDfreq(node, freq_ii){
if (typeof node.children != "undefined") {
for (var i1=0; i1<node.children.length; i1++) {
var label_str = "global_clade:"+node.children[i1].clade;
if (typeof frequencies != undefined && frequencies[label_str] != undefined){
var tmp_freq = get_frequencies("global", "clade:"+node.children[i1].clade)
if (typeof frequencies != undefined && get_frequencies_clade("global", node.children[i1].strain) != undefined){
var tmp_freq = get_frequencies_clade("global", node.children[i1].strain)
node.children[i1].dfreq = (tmp_freq[freq_ii] + dfreq_cutoff)/(tmp_freq[freq_ii-dfreq_dn] + dfreq_cutoff);
} else {
node.children[i1].dfreq = node.dfreq;
@@ -31,6 +30,9 @@ function get_frequencies(region, gt){
if (isAA) {
gt = "HA1:" + gt;
}
if (pivots==undefined){
pivots=frequencies["pivots"];
}
var freq = [];
for (var pi=0; pi<pivots.length; pi++){freq[freq.length]=0;}
var label_str = region+'_'+gt
@@ -44,6 +46,24 @@ function get_frequencies(region, gt){
return freq.map(function (d) {return Math.round(d*10000)/10000;});
};

function get_frequencies_clade(region, clade){
var freq = [];
if (pivots==undefined){
pivots=frequencies["pivots"];
}
for (var pi=0; pi<pivots.length; pi++){freq[freq.length]=0;}
if (frequencies[clade]!=undefined && frequencies[clade][region]!=undefined) {
for (var pi=0; pi<freq.length; pi++){
freq[pi]+=frequencies[clade][region][pi];
}
}else{
// console.log("not found "+clade+', '+region);
return undefined;
}
return freq.map(function (d) {return Math.round(d*10000)/10000;});
};


var freqDataString = "";
function make_gt_chart(gt){
var tmp_data = [];
@@ -84,10 +104,10 @@ function addClade(d) {
// console.log(d);
var plot_data = [['x'].concat(pivots)];
var reg = "global";
var label_str = 'clade:'+d.target.clade;
if (typeof frequencies[reg+"_"+label_str] !="undefined" ){
freq = get_frequencies_clade(reg, d.target.strain)
if (typeof freq !="undefined" ){

plot_data[plot_data.length] = [reg].concat(get_frequencies(reg,label_str));
plot_data[plot_data.length] = [reg].concat(freq);
}
if (plot_data.length > 1) {
if (plot_data[1][0] == reg) {
@@ -12,7 +12,7 @@ function addSequence(current_seq, current_seq_name, seqs, all_names){
suffix=" "+(name_count+1);
}else{suffix="";}
all_names.push(current_seq_name);
seqs[current_seq_name+suffix]=current_seq;
seqs[current_seq_name+suffix]=current_seq;
}

function parseSequences(){
@@ -27,7 +27,7 @@ function parseSequences(){
for (var li=0; li<lines.length; li++){
if (lines[li][0]=='>'){
if (current_seq.length){
addSequence(current_seq, current_seq_name, seqs, seq_names);
addSequence(current_seq, current_seq_name, seqs, seq_names);
}
current_seq_name = lines[li].substring(1,lines[li].length);
current_seq = "";
@@ -36,7 +36,7 @@ function parseSequences(){
}
}
if (current_seq.length){
addSequence(current_seq, current_seq_name, seqs, seq_names);
addSequence(current_seq, current_seq_name, seqs, seq_names);
}
for (current_seq_name in seqs){
var tmpclade = locateSequence(current_seq_name, seqs[current_seq_name]);
@@ -74,7 +74,7 @@ function locateSequence(name, seq){
function findClosestClade(mutations){
var bestClade=-1, bestScore=0;
var tmpScore=0;
var searchClades = tips.map(function(d){return d.clade;});
var searchClades = tips.map(function(d){return d.strain;});

for (ci=0; ci<searchClades.length; ci++){
clade = searchClades[ci];
@@ -158,10 +158,10 @@ function alignToRoot(seq){
// highlight clades in tree
function markInTreeSeqSearch(clades){
var userSeqs = nodes.filter(function(d){
var tmp=0; for (var clade in clades){tmp+= (d.clade==clade);} return tmp>0;});
var tmp=0; for (var clade in clades){tmp+= (d.strain==clade);} return tmp>0;});

for (var mi=0; mi<userSeqs.length; mi++){
userSeqs[mi].matches = clades[userSeqs[mi].clade];
userSeqs[mi].matches = clades[userSeqs[mi].strain];
}

treeplot.selectAll('.seqmatch').data(userSeqs)
@@ -180,7 +180,7 @@ function markInTreeStrainSearch(tip){
treeplot.selectAll('.strainmatch').data([tip])
.enter()
.append('text')
.attr("class", "strainmatch")
.attr("class", "strainmatch")
.text(function(d) { console.log(d.strain); return '\uf069'; })
.on('mouseover', function(d) {
virusTooltip.show(d, this);
@@ -198,7 +198,7 @@ function styleHighlight(){
.style("fill", "#555555")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.style("cursor", "default");
.style("cursor", "default");
treeplot.selectAll('.strainmatch')
.attr('text-anchor', 'middle')
.attr('dominant-baseline', 'central')
@@ -207,7 +207,7 @@ function styleHighlight(){
.style("fill", "#555555")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.style("cursor", "default");
.style("cursor", "default");
}

// callback to highlight the result of a search by strain name
@@ -225,11 +225,11 @@ var strainSearchEvent;
d3.select('#seqinput').on('keyup', function(){
if (typeof strainSearchEvent != "undefined"){clearTimeout(strainSearchEvent);}
strainSearchEvent = setTimeout(parseSequences, 100);
});
});

d3.select('#searchinputclear').on('click', function (){
treeplot.selectAll('.seqmatch').data([]).exit().remove();
treeplot.selectAll('.strainmatch').data([]).exit().remove();
treeplot.selectAll('.strainmatch').data([]).exit().remove();
document.getElementById('seqinput').value = "";
document.getElementById('bp-input').value = "";
virusTooltip.hide();
@@ -75,10 +75,10 @@ var virusTooltip = d3.tip()
string += "<div class=\"smallspacer\"></div>";
string += "<div class=\"smallnote\">"
string += '<table class="table table-condensed"><thead><tr><td>Serum</td><td>&#916log<sub>2</sub></td><td>heterol.</td><td>homol.</td></tr></thead><tbody>';
var tmp_titers = HI_titers[focusNode.clade][d.clade];
var tmp_auto_titers = HI_titers[focusNode.clade][focusNode.clade] || "nan";
var tmp_avi = titer_subs_model["avidity"][d.clade];
var tmp_pot = titer_subs_model["avidity"][d.clade];
var tmp_titers = HI_titers[focusNode.strain][d.strain];
var tmp_auto_titers = HI_titers[focusNode.strain][focusNode.strain] || "nan";
var tmp_avi = titer_subs_model["avidity"][d.strain];
var tmp_pot = titer_subs_model["avidity"][d.strain];
if (typeof tmp_titers != "undefined"){
for (var tmp_serum in tmp_titers){
var autoHI = "nan";
@@ -88,7 +88,7 @@ var virusTooltip = d3.tip()
var rawHI = tmp_titers[tmp_serum][1];
var logHI = tmp_titers[tmp_serum][0];
if (correctVirus){logHI-=tmp_avi;}
if (correctPotency){logHI-=titer_subs_model["potency"][focusNode.clade][tmp_serum];}
if (correctPotency){logHI-=titer_subs_model["potency"][focusNode.strain][tmp_serum];}
var serum_name;
if (tmp_serum.length<20){
serum_name = tmp_serum;
@@ -166,7 +166,7 @@ function calcLBI(node, allnodes){
allnodes.forEach(function (d) {
if (typeof d.children != "undefined") {
for (var i=0; i<d.children.length; i++) {
d.children[i].clock_length = d.children[i].tvalue - d.tvalue;
d.children[i].clock_length = d.children[i].attr.num_date - d.attr.num_date;
}
}
});

0 comments on commit 8b94548

Please sign in to comment.
You can’t perform that action at this time.