@@ -31,6 +31,7 @@ export default {
3131 },
3232 data : () => ({
3333 currentSelectedNode: null , // Track the currently selected node
34+ unclassifiedNodes: [], // Store unclassified nodes
3435
3536 // Data for graph rendering
3637 sankeyRankColumns,
@@ -92,6 +93,7 @@ export default {
9293 const nodesByRank = {}; // Store nodes by rank
9394
9495 let rootNode = null ;
96+ this .unclassifiedNodes = [];
9597
9698 // Step 1: Create nodes and save lineage data for ALL NODES
9799 data .forEach ((d ) => {
@@ -120,6 +122,8 @@ export default {
120122 nodesByRank[" root" ] = [node];
121123 node .rank = " root" ;
122124 rootNode = node;
125+ } else if ((node .id === ' 12908' && node .name === ' unclassified sequences' ) || (node .id === ' 28384' && node .name === ' other sequences' )) {
126+ this .unclassifiedNodes .push (node);
123127 }
124128
125129 // Store lineage for each node
@@ -190,19 +194,19 @@ export default {
190194 totalClassifiedProportion = totalClassifiedProportion + targetNode .proportion ;
191195 });
192196
193- const unclassifiedCladeReads = rootNode .clade_reads - totalClassifiedCladeReads;
194- if (unclassifiedCladeReads > 0 ) {
197+ const totalUnclassifiedCladeReads = rootNode .clade_reads - totalClassifiedCladeReads;
198+ if (totalUnclassifiedCladeReads > 0 ) {
195199 const unclassifiedNode = {
196- id: " 12908 " ,
197- taxon_id: " 12908 " ,
198- name: " Unclassified Sequences " ,
200+ id: " " ,
201+ taxon_id: " " ,
202+ name: " Unclassified sequences " ,
199203 rank: this .sankeyRankColumns [this .sankeyRankColumns .indexOf (rootNode .rank )+ 1 ],
200204 trueRank: " unclassified" ,
201205 hierarchy: rootNode .hierarchy + 1 ,
202206 proportion: rootNode .proportion - totalClassifiedProportion,
203- clade_reads: unclassifiedCladeReads ,
207+ clade_reads: totalUnclassifiedCladeReads ,
204208 taxon_reads: 0 ,
205- lineage: [rootNode], // Lineage starts from the root
209+ lineage: [rootNode],
206210 type: " unclassified" ,
207211 };
208212 unclassifiedNode .lineage .push (unclassifiedNode);
@@ -213,7 +217,7 @@ export default {
213217 source: rootNode .id ,
214218 targetName: unclassifiedNode .name ,
215219 target: unclassifiedNode .id ,
216- value: unclassifiedCladeReads ,
220+ value: totalUnclassifiedCladeReads ,
217221 });
218222 }
219223 }
@@ -392,10 +396,12 @@ export default {
392396 .style (" opacity" , 1 )
393397 .html (`
394398 <div style="padding-top: 4px; padding-bottom: 4px; padding-left: 8px; padding-right: 8px;">
395- <p style="font-size: 0.6rem; margin-bottom: 0px;">#${ d .taxon_id } </p>
399+ ${ d . type !== " unclassified " ? ` <p style="font-size: 0.6rem; margin-bottom: 0px;">#${ d .taxon_id } </p>` : " " }
396400 <div style="display: flex; justify-content: space-between; align-items: center;">
397401 <div style="font-weight: bold; font-size: 0.875rem;">${ d .name } </div>
398- <span style="background-color: rgba(255, 167, 38, 0.25); color: #ffa726; font-weight: bold; padding: 4px 8px; border-radius: 12px; font-size: 0.875rem; margin-left: 10px;">${ d .trueRank } </span>
402+ ${ d .type !== " unclassified" ? ` <span style="background-color: rgba(255, 167, 38, 0.25); color: #ffa726;
403+ font-weight: bold; padding: 4px 8px; border-radius: 12px;
404+ font-size: 0.875rem; margin-left: 10px;">${ d .trueRank } </span>` : ' ' }
399405 </div>
400406 <hr style="margin: 8px 0; border: none; border-top: 1px solid #fff; opacity: 0.2;">
401407 <div style="display: flex; justify-content: space-between; align-items: center; font-size: 0.875rem;">
@@ -449,8 +455,18 @@ export default {
449455 return childrenIds;
450456 };
451457
452- // Collect all IDs
453- const allNodeIds = collectIds (d);
458+ // Collect all taxIds for children nodes
459+ let allNodeIds = [];
460+ if (d .type === " unclassified" ) {
461+ // Handle unclassified nodes
462+ allNodeIds .push (' 0' );
463+ this .unclassifiedNodes .forEach (node => {
464+ allNodeIds .push (... collectIds (node));
465+ });
466+ } else {
467+ // Collect IDs for other node types
468+ allNodeIds = collectIds (d);
469+ }
454470
455471 // Update the currently selected node
456472 this .currentSelectedNode = d;
@@ -483,7 +499,7 @@ export default {
483499 .text ((d ) => d .name )
484500 .style (" font-size" , " 9px" )
485501 .style (" cursor" , " pointer" )
486- .style (" font-weight" , (d ) => ( this . currentSelectedNodeId === d . id ? " bold " : " normal" ) );
502+ .style (" font-weight" , (d ) => " normal" );
487503
488504 // Add label above node (proportion/clade reads)
489505 nodeGroup
0 commit comments