-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-table summarize refactor (#306)
- Loading branch information
Showing
7 changed files
with
164 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 32 additions & 4 deletions
36
q2_feature_table/_summarize/summarize_assets/feature-frequency-detail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,37 @@ | ||
{% extends "tabbed.html" %} | ||
|
||
{% extends "tabbed.html" %} {% block head %} | ||
<script src="util.js"></script> {% endblock %} | ||
{% block tabcontent %} | ||
<div class="row"> | ||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<div class="col-lg-12"> | ||
{{ feature_frequencies_table }} | ||
<table class="table table-striped table-hover" border="0"> | ||
<thead> | ||
<tr style="text-align: right;"> | ||
<th></th> | ||
<th>Frequency</th> | ||
<th># of Samples Observed In</th> | ||
</tr> | ||
</thead> | ||
<tbody id="table-body"></tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script id="table-data" type="application/json"> | ||
{{ feature_frequencies_json }} | ||
</script> | ||
|
||
<script type="text/javascript"> | ||
const tableBody = document.getElementById("table-body"); | ||
const tableData = JSON.parse(document.getElementById("table-data").innerHTML); | ||
const featureFrequencies = tableData["Frequency"]; | ||
|
||
const sortedFeatureIDs = Object.keys(featureFrequencies).sort(function(a, b) { | ||
return sortIDs(a, b, featureFrequencies) | ||
}); | ||
|
||
formatTable(tableBody, tableData, sortedFeatureIDs); | ||
</script> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
q2_feature_table/_summarize/summarize_assets/utils/util.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Formats the number in a manner based on the locale but using latin numerals | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat | ||
const formatter = new Intl.NumberFormat({numberingSystem: "latn"}) | ||
|
||
|
||
function formatTable(tableBody, data, sortedKeys) { | ||
for (const key of sortedKeys) { | ||
let colIdx = 1; | ||
let row = tableBody.insertRow(0); | ||
|
||
let keyCell = row.insertCell(0) | ||
keyCell.innerText = key; | ||
keyCell.style.setProperty("text-align", "left"); | ||
keyCell.style.setProperty("font-weight", "bold"); | ||
|
||
for (const innerKey of Object.keys(data)) { | ||
let dataCell = row.insertCell(colIdx++); | ||
dataCell.innerText = formatter.format(data[innerKey][key]); | ||
} | ||
} | ||
} | ||
|
||
|
||
function sortIDs(a, b, data) { | ||
const diff = data[a] - data[b]; | ||
// if two samples have the same number of features then we | ||
// determine the order using the sample ID alphabetical order | ||
if (diff == 0){ | ||
return b.localeCompare(a); | ||
} | ||
|
||
return diff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters