Fix static explorer rendering: assets/app.js
Browse files- assets/app.js +2 -2
assets/app.js
CHANGED
|
@@ -29,7 +29,7 @@ function fillSelect(id, values, value){
|
|
| 29 |
$(id).innerHTML=values.map(v=>`<option value="${esc(v)}">${esc(v)}</option>`).join('');
|
| 30 |
if(value!==undefined) $(id).value=value;
|
| 31 |
}
|
| 32 |
-
function setSpeciesSelect(id, initial='
|
| 33 |
fillSelect(id, species().map(x=>x.slug), initial);
|
| 34 |
$(id).querySelectorAll('option').forEach(o=>{const s=speciesBySlug(o.value);o.textContent=s.label});
|
| 35 |
}
|
|
@@ -147,7 +147,7 @@ async function renderEnrichment(){
|
|
| 147 |
const terms=Object.values(byTerm).sort((a,b)=>Math.min(...a.map(x=>+x.padj))-Math.min(...b.map(x=>+x.padj))).slice(0,20);
|
| 148 |
const agg=terms.map(group=>{const total=group.reduce((s,r)=>s+Number(r.overlap||0),0);const fe=group.reduce((s,r)=>s+Number(r.fold_enrichment||0)*Number(r.overlap||0),0)/(total||1);return group.map(r=>({...r,term_description:r.name||r.term,segment_fold_enrichment:fe*Number(r.overlap||0)/(total||1),fold_enrichment_total:fe,total_overlap:total}))}).flat().sort((a,b)=>Number(a.fold_enrichment_total)-Number(b.fold_enrichment_total)||a.term_description.localeCompare(b.term_description));
|
| 149 |
const categoryOrder=[...new Set(agg.map(r=>r.term_description))];
|
| 150 |
-
Plotly.newPlot('en-plot',[{type:'bar',orientation:'h',x:agg.map(r=>r.segment_fold_enrichment),y:agg.map(r=>r.term_description),customdata:agg.map(r=>[r.direction,r.overlap,r.fold_enrichment_total,r.padj]),name:'direction',marker:{color:agg.map(r=>r.direction==='up'?'#d55e48':'#247ba0')},hovertemplate:'%{y}<br>%{customdata[0]} genes: %{customdata[1]}<br>Fold enrichment: %{customdata[2]:.2f}<br>Adjusted p-value: %{customdata[3]:.3g}<extra></extra>'}],{template:'plotly_white',paper_bgcolor:'#fff',plot_bgcolor:'#f7fbfd',font:{color:'#123b5d'},height:Math.max(520,350+terms.length*22),barmode:'stack',title:`${displaySource($('en-source').value)} 路 ${$('en-hierarchy').value}`,xaxis:{title:{text:'Fold enrichment'},range:[0,Math.max(...agg.map(r=>r.fold_enrichment_total),1)]},yaxis:{
|
| 151 |
const nEnriched=new Set(rows.map(r=>r.term)).size;
|
| 152 |
$('en-summary').innerHTML=`The frozen over-representation analysis tested <strong>${fmt(info.universe_terms)} unique terms or categories</strong>; <strong>${fmt(nEnriched)} terms</strong> pass the displayed ORA filters. Bars show fold enrichment. When both directions contribute to a term, the bar is stacked proportionally by genes with positive (<span class="up">up</span>) and negative (<span class="down">down</span>) fold change; these directions do not by themselves imply pathway activation or inhibition.`;
|
| 153 |
table('en-table',rows.sort((a,b)=>Number(a.padj)-Number(b.padj)).slice(0,500),['source_id','direction','term','name','overlap','foreground_size','term_size','background_size','fold_enrichment','pvalue','padj','genes']);
|
|
|
|
| 29 |
$(id).innerHTML=values.map(v=>`<option value="${esc(v)}">${esc(v)}</option>`).join('');
|
| 30 |
if(value!==undefined) $(id).value=value;
|
| 31 |
}
|
| 32 |
+
function setSpeciesSelect(id, initial='species01'){
|
| 33 |
fillSelect(id, species().map(x=>x.slug), initial);
|
| 34 |
$(id).querySelectorAll('option').forEach(o=>{const s=speciesBySlug(o.value);o.textContent=s.label});
|
| 35 |
}
|
|
|
|
| 147 |
const terms=Object.values(byTerm).sort((a,b)=>Math.min(...a.map(x=>+x.padj))-Math.min(...b.map(x=>+x.padj))).slice(0,20);
|
| 148 |
const agg=terms.map(group=>{const total=group.reduce((s,r)=>s+Number(r.overlap||0),0);const fe=group.reduce((s,r)=>s+Number(r.fold_enrichment||0)*Number(r.overlap||0),0)/(total||1);return group.map(r=>({...r,term_description:r.name||r.term,segment_fold_enrichment:fe*Number(r.overlap||0)/(total||1),fold_enrichment_total:fe,total_overlap:total}))}).flat().sort((a,b)=>Number(a.fold_enrichment_total)-Number(b.fold_enrichment_total)||a.term_description.localeCompare(b.term_description));
|
| 149 |
const categoryOrder=[...new Set(agg.map(r=>r.term_description))];
|
| 150 |
+
Plotly.newPlot('en-plot',[{type:'bar',orientation:'h',x:agg.map(r=>r.segment_fold_enrichment),y:agg.map(r=>r.term_description),customdata:agg.map(r=>[r.direction,r.overlap,r.fold_enrichment_total,r.padj]),name:'direction',marker:{color:agg.map(r=>r.direction==='up'?'#d55e48':'#247ba0')},hovertemplate:'%{y}<br>%{customdata[0]} genes: %{customdata[1]}<br>Fold enrichment: %{customdata[2]:.2f}<br>Adjusted p-value: %{customdata[3]:.3g}<extra></extra>'}],{template:'plotly_white',paper_bgcolor:'#fff',plot_bgcolor:'#f7fbfd',font:{color:'#123b5d'},height:Math.max(520,350+terms.length*22),barmode:'stack',title:`${displaySource($('en-source').value)} 路 ${$('en-hierarchy').value}`,xaxis:{title:{text:'Fold enrichment'},range:[0,Math.max(...agg.map(r=>r.fold_enrichment_total),1)]},yaxis:{automargin:true,categoryorder:'array',categoryarray:categoryOrder}} ,{responsive:true});
|
| 151 |
const nEnriched=new Set(rows.map(r=>r.term)).size;
|
| 152 |
$('en-summary').innerHTML=`The frozen over-representation analysis tested <strong>${fmt(info.universe_terms)} unique terms or categories</strong>; <strong>${fmt(nEnriched)} terms</strong> pass the displayed ORA filters. Bars show fold enrichment. When both directions contribute to a term, the bar is stacked proportionally by genes with positive (<span class="up">up</span>) and negative (<span class="down">down</span>) fold change; these directions do not by themselves imply pathway activation or inhibition.`;
|
| 153 |
table('en-table',rows.sort((a,b)=>Number(a.padj)-Number(b.padj)).slice(0,500),['source_id','direction','term','name','overlap','foreground_size','term_size','background_size','fold_enrichment','pvalue','padj','genes']);
|