Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions qiita_pet/templates/redbiom.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@
$("#redbiom-table").dataTable({
"dom": '<"ps">lfr<t><"footer">ip',
'footerCallback': function ( row, data, start, end, display ) {
var api = this.api(), artifacts = 0, samples = 0;

// adding total features found
api.column(0).nodes().each(function (cell, i) {
var elements = $(cell).children().children().children();
var idx = elements.length - 1;
var text = $(elements[idx]).text();
elements = text.split(" | ");
artifacts += parseInt(elements[0].split(": ")[1]);
samples += parseInt(elements[1].split(": ")[1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's actually being summed here? the number of samples in a study or artifacts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent question. In the code below (lines 48-56) we count the number of artifacts and samples per study (row). Here we are building the footer to show the total so we could recount all studies/artifacts/samples or just loop over the totals (each row) and parse out the numbers to add. The format of each row is: 'Artifacts: ## | Samples: ##'.

});

var api = this.api(), data;
var artifacts_samples = api
.column(0)
.data()
.reduce( function (a, b) {
var artifacts = 0, samples = 0;
$.each( b, function( key, value ) {
artifacts += 1;
samples += value.length;
});
return [artifacts + a[0], samples + a[1]]}, [0, 0]);
var artifacts = artifacts_samples[0];
var samples = artifacts_samples[1];
$('.footer').addClass("col-md-12 text-right");
if (artifacts == 0) {
text = '';
Expand All @@ -47,13 +42,22 @@
// render zero
{"render": function ( data, type, row, meta ) {
if (data !== null && data !== undefined){
var artifacts = 0, samples = 0;
var artifacts = 0, unique_samples = {};
for (var d in data) {
if (data.hasOwnProperty(d)) {
// to get only unique sample names we will create a dict
// and then just get the keys; by creating a dict we are
// avoiding to check if an element is already in the list
var samples = data[d];
for (var i = 0; i < samples.length; i++) {
if (! unique_samples[samples[i]] ) {
unique_samples[samples[i]] = true;
}
}
artifacts++;
samples += data[d].length
}
}
unique_samples = Object.keys(unique_samples);
if (artifacts != 0) {
return '<div class="container" style="max-width: 15em;">'+
'<div class="row justify-content-md-center">' +
Expand All @@ -62,7 +66,7 @@
{% end %}
'<div class="col-md-12 text-center">' +
'Artifacts: ' + artifacts + ' | ' +
'Samples: ' + samples +
'Samples: ' + unique_samples.length +
'</div>' +
'</div>' +
'</div>';
Expand Down