Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clicking on nodes not in table; refactor and test node selection menu; fix "Add" button #432

Merged
merged 54 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
54a0f8a
ENH: add BiomTable.hasFeatureID
fedarko Oct 21, 2020
508d29b
Prevent errors+warn on tips not in table #314
fedarko Oct 21, 2020
7b4e70b
fix warn msg
fedarko Oct 21, 2020
f12eed7
tidy styling/stuff
fedarko Oct 21, 2020
7420d21
Make int sample presence handle bad case&test #314
fedarko Oct 22, 2020
7cb35d1
tidy up #314 int test
fedarko Oct 22, 2020
48ea781
child -> descendant tips in int sample presence
fedarko Oct 22, 2020
15d237f
TST: beef up int sample presence tests
fedarko Oct 22, 2020
5799a5a
STY: prettifififify
fedarko Oct 22, 2020
9e8ece9
Show warning for int nodes w/ all tips not in tbl
fedarko Oct 22, 2020
b4dae9d
polish selected node menu a bit
fedarko Oct 22, 2020
6379f04
TST: Add selected node menu test skeleton :D
fedarko Oct 22, 2020
8b5bed0
TST: test a sel node menu error case; chg init'ing
fedarko Oct 22, 2020
bfb2d98
TST/MNT: add + tidy up ssn tests; tidy err cases
fedarko Oct 22, 2020
22ca29c
More s.node menu tests; revamp HTML ._.
fedarko Oct 22, 2020
dd2dc10
beef up showNodeMenu tip test
fedarko Oct 22, 2020
a034b03
rename SelectedNodeMenu.notes to .smNotes
fedarko Oct 22, 2020
6877b8f
beef up tip menu test
fedarko Oct 22, 2020
9a7f2dd
MNT: simplify showing/hiding HTML eles in S.N.Menu
fedarko Oct 22, 2020
5402ce0
TODOs for menu fixing #314
fedarko Oct 22, 2020
fb96093
STY
fedarko Oct 22, 2020
88eee92
BUG: hide add ui eles after all sm fields added
fedarko Oct 22, 2020
2c01ba2
Reorganize and restyle selection menu
fedarko Oct 22, 2020
521d7c4
STY: pret
fedarko Oct 22, 2020
6a6acdf
MNT: take advantage of makeFMtable being nonstatic
fedarko Oct 22, 2020
e87b326
MNT; take advantage of sm table being nonstatic
fedarko Oct 22, 2020
b7fef8c
some #314 esque menu fixes
fedarko Oct 22, 2020
293b752
Refactor feature metadata in s.node menu
fedarko Oct 22, 2020
2c4bcac
css todo
fedarko Oct 22, 2020
72a8b4f
Refactor SM stuff :D
fedarko Oct 22, 2020
d0483e4
Fix #272 bug (...again.)
fedarko Oct 22, 2020
22fbc73
STY
fedarko Oct 22, 2020
6463f23
TST: unbreak s. node menu tests
fedarko Oct 22, 2020
76046c4
Simplify s. node menu js tests :D
fedarko Oct 22, 2020
0319f9a
TST: add an int node s node menu test
fedarko Oct 22, 2020
4683550
Apparently qunit is case sensitive wrt "teardown"
fedarko Oct 22, 2020
cbea2b5
TST: test #272 case
fedarko Oct 22, 2020
4aac741
TST: test ambiguous internal node menu case
fedarko Oct 22, 2020
257078b
MNT/TST: simplify js test code
fedarko Oct 22, 2020
3b1fc7d
MNT/TST: abstract out fm table checking in snm tst
fedarko Oct 22, 2020
98636f2
test sm table population
fedarko Oct 23, 2020
b378791
tidy up selected node menu code formatting
fedarko Oct 23, 2020
262ae93
STY: appease jshint by declaring a var in scope
fedarko Oct 23, 2020
9de9546
TST: test sm notes txt in one of the cases
fedarko Oct 23, 2020
4b359df
checktips fix
fedarko Oct 23, 2020
2a1db7f
Merge branch 'master' of https://github.com/biocore/empress into fix-314
fedarko Nov 10, 2020
4be4014
Update now-outdated-due-to-#400 comment
fedarko Nov 10, 2020
ee7411c
Update empress/support_files/js/select-node-menu.js
fedarko Nov 10, 2020
59ddc2b
HACK: Fix adjacent sm/fm section border CSS thing
fedarko Nov 10, 2020
a81c117
Merge branch 'fix-314' of https://github.com/fedarko/empress into fix…
fedarko Nov 10, 2020
5ff5133
ENH: Actually, nvm, ditch menu section borders
fedarko Nov 10, 2020
980ab68
cats can have a little <hr />, as a treat
fedarko Nov 11, 2020
6c824b6
TST: unbreak select node menu tests ._.
fedarko Nov 11, 2020
c5fd58f
STY: prettify test
fedarko Nov 11, 2020
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
14 changes: 8 additions & 6 deletions empress/support_files/css/empress.css
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ select:-moz-focusring {
background-color: darkgray;
}

#menu-sm-table {
margin-bottom: 1em;
}

#menu-select {
background-color: white;
}
Expand Down Expand Up @@ -651,15 +655,13 @@ p.side-header button:hover,
max-height: 100%;
}

#menu-box-warning {
font-size: small;
font-weight: bold;
#menu-box p {
max-width: 500px;
font-size: small;
}

#menu-box-notes {
max-width: 500px;
font-size: small;
#menu-box-node-name-warning {
font-weight: bold;
}

#menu-box-node-id {
Expand Down
18 changes: 18 additions & 0 deletions empress/support_files/js/biom-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ define(["underscore", "util"], function (_, util) {
return _.indexOf(arr, num, true) >= 0;
};

/**
* Returns true if the table contains a feature name, false otherwise.
*
* @param {String} fID
*
* @return {Boolean}
*/
BIOMTable.prototype.hasFeatureID = function (fID) {
return _.has(this._fID2Idx, fID);
};

/**
* Return the feature IDs shared by the BIOM table and input array
*
Expand Down Expand Up @@ -456,6 +467,13 @@ define(["underscore", "util"], function (_, util) {
* an object that maps each body site (oral, gut,...) to the number of
* samples in 'samples' labelled as being from that body site.
*
* The returned object is a "sparse" representation, in the sense that
* unique values in the metadata field that are not present within the
* specified samples array will be omitted. For the body site example,
* this would mean that if, say, all of the samples were gut samples, then
* the returned object would just have "gut" as the only key (even if the
* full dataset included samples from other body sites).
*
* @param {Array} samples Array of sample IDs
* @param {String} col Sample metadata column
*
Expand Down
1 change: 0 additions & 1 deletion empress/support_files/js/canvas-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ define(["glMatrix", "SelectedNodeMenu"], function (gl, SelectedNodeMenu) {
*/
this.mouseMove = false;
this.selectedNodeMenu = new SelectedNodeMenu(this.empress, this.drawer);
this.selectedNodeMenu.initialize();

// the quick search bar
this.quickSearchBar = document.getElementById("quick-search");
Expand Down
89 changes: 62 additions & 27 deletions empress/support_files/js/empress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3310,30 +3310,39 @@ define([
}
return this.getNodeInfo(node, "name");
};

/*
* Show the node menu for a node name
* Given a tip name and a list of sample metadata fields, computes the
* sample presence information: the number of samples for each unique
* value within each field that contain this tip.
*
* Calculate the number of samples in which a tip appears for the
* unique values of a metadata field across a list of metadata fields.
* If the specified tip name is not present within the BIOM table (i.e. the
* tree was not shorn just to tips in the table, and one of those
* not-in-the-table tips was clicked on) then this will return null.
*
* @param {String} nodeName Name of the (tip) node for which to calculate
* sample presence.
* @param {Array} fields Metadata fields for which to calculate tip
* sample presence.
* @return {Object} ctData Maps metadata field names to another Object,
* which in turn maps unique metadata values to
* the number of samples with this metadata value
* in this field that contain the given tip.
* @return {Object or null} ctData Maps metadata field names to another
* Object, which in turn maps unique
* metadata values to the number of samples
* with this metadata value in this field
* that contain the given tip.
* (Will just be null, instead, if the tip
* isn't present in the table.)
*/
Empress.prototype.computeTipSamplePresence = function (nodeName, fields) {
var ctData = {};

for (var f = 0; f < fields.length; f++) {
var field = fields[f];
ctData[field] = this._biom.getObsCountsBy(field, nodeName);
if (this._biom.hasFeatureID(nodeName)) {
var ctData = {};
for (var f = 0; f < fields.length; f++) {
var field = fields[f];
ctData[field] = this._biom.getObsCountsBy(field, nodeName);
}
return ctData;
} else {
return null;
}

return ctData;
};

/**
Expand All @@ -3348,21 +3357,47 @@ define([
* @return {Object} samplePresence A mapping with three entries:
* (1) fieldsMap Maps metadata field names
* to Object mapping unique metadata values
* to the number of samples with this metadata
* value in this field containing at least one
* tip in the subtree of the given nodeKey.
* (2) diff Array of tip names not present
* as features in the table.
* (3) samples Array of samples represented by
* tips present in the table.
* to the number of samples with this
* metadata value in this field containing
* at least one tip in the subtree of the
* given nodeKey. If none of the descendant
* tips of this internal node are present
* in the table, this will just be null.
* (2) diff Array of descendant tip names
* not present as features in the table.
* (3) samples Array of samples represented
* by descendant tips present in the table.
*/
Empress.prototype.computeIntSamplePresence = function (nodeKey, fields) {
// retrieve the sample data for the tips in the table
// Find the descendant tips of this internal node
var tips = this._tree.findTips(nodeKey);

// descendant tips that aren't features in the table
var diff = this._biom.getObsIDsDifference(tips);

// Handle the case where none of the descendant tips are present in the
// table specially -- the main distinguishing thing here is we return
// null for fieldsMap, which lets the caller know that they should just
// show a warning instead of a table.
if (tips.length === diff.length) {
return {
fieldsMap: null,
diff: diff,
samples: [],
};
}

// descendant tips that _are_ features in the table
var intersection = this._biom.getObsIDsIntersection(tips);
// samples represented by the "intersection" tips above
var samples = this._biom.getSamplesByObservations(intersection);

// Initialize an Object that, for each field within fields, maps each
// unique value in that field to a 0. These 0s will be updated in the
// next loop based on sample presence information for this internal
// node.
// NOTE that we could skip this step if we didn't want to show 0s in
// the table; see https://github.com/biocore/empress/issues/329.
var fieldsMap = {};
for (var i = 0; i < fields.length; i++) {
field = fields[i];
Expand All @@ -3374,16 +3409,16 @@ define([
}
}

// iterate over the samples and extract the field values
// Iterate over the fields, calling getSampleValuesCount() to get the
// sample presence information for the values within the fields
for (var k = 0; k < fields.length; k++) {
field = fields[k];

// update fields mapping object
var result = this._biom.getSampleValuesCount(samples, field);
fieldValues = Object.keys(result);
var value2cts = this._biom.getSampleValuesCount(samples, field);
var fieldValues = Object.keys(value2cts);
for (var m = 0; m < fieldValues.length; m++) {
fieldValue = fieldValues[m];
fieldsMap[field][fieldValue] += result[fieldValue];
fieldsMap[field][fieldValue] += value2cts[fieldValue];
}
}

Expand Down
Loading