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

Gradient Coloring Option for Feature Metadata #484

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
61f49b2
Add custom color
kwcantrell Feb 1, 2021
1f26583
checkpoint
kwcantrell Feb 10, 2021
dd2cfe6
added gradient coloring for feature metadata
kwcantrell Feb 10, 2021
20b369a
linter
kwcantrell Feb 10, 2021
6172f36
style fix
kwcantrell Feb 10, 2021
a3a1fe4
Show warning to user
kwcantrell Feb 22, 2021
3a69861
checkpoint
kwcantrell Feb 23, 2021
ca591ba
gradient feature metadata coloring
kwcantrell Feb 23, 2021
86ef3cf
fixed style issue
kwcantrell Feb 23, 2021
f2920c5
Merge branch 'master' of https://github.com/biocore/empress into grad…
kwcantrell Feb 24, 2021
a4052df
addressed comments
kwcantrell Mar 2, 2021
84d5b4a
style fix
kwcantrell Mar 2, 2021
8836260
Apply suggestions from code review
kwcantrell Mar 2, 2021
1431e2c
Merge branch 'master' of https://github.com/biocore/empress into grad…
kwcantrell Apr 9, 2021
743a32e
fix style
kwcantrell Apr 9, 2021
a90871c
fixed continuous error
kwcantrell Apr 9, 2021
305aa47
remove try-catch
kwcantrell Apr 12, 2021
d5426f6
Apply suggestions from code review
kwcantrell May 4, 2021
bf3f5fd
Merge branch 'master' of https://github.com/biocore/empress into grad…
kwcantrell Jun 10, 2021
aba2aa7
checkpoint
kwcantrell Jun 11, 2021
942f5b0
added test/fixed warning
kwcantrell Jun 11, 2021
9bd5961
fixed docs
kwcantrell Jun 11, 2021
6033e11
abstracted Legend class
kwcantrell Jun 13, 2021
1472ee4
Apply suggestions from code review
kwcantrell Aug 3, 2021
25ac9bd
address error 1
kwcantrell Aug 26, 2021
0add7c7
fixed conflicts
kwcantrell Aug 26, 2021
8206de8
fixed color bug
kwcantrell Aug 26, 2021
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
Prev Previous commit
Next Next commit
checkpoint
  • Loading branch information
kwcantrell committed Feb 23, 2021
commit 3a698616520c9629bcabcb686d7d73259d400f71
92 changes: 88 additions & 4 deletions empress/support_files/js/empress.js
Original file line number Diff line number Diff line change
@@ -2324,6 +2324,19 @@ define([
return keyInfo;
};


Empress.prototype._projectObservations = function (
obs,
ignoreAbsentTips,
isContinuous=false
) {
var result;
if (!isContinuous) {
result = this._projectDiscreteObservations(obs, ignoreAbsentTips);
}
return result;
};

/*
* Projects the groups in obs up the tree.
*
@@ -2333,7 +2346,7 @@ define([
*
* 2) Assigns each internal node to a group if all of its children belong
* to the same group.
*@t
*
* 3) Remove empty groups from return object.
*
* Note: All tips that are not passed into obs are considered to belong to
@@ -2348,7 +2361,10 @@ define([
to a set of keys (i.e. tree nodes) that are unique to
each group.
*/
Empress.prototype._projectObservations = function (obs, ignoreAbsentTips) {
Empress.prototype._projectDiscreteObservations = function(
obs,
ignoreAbsentTips
) {
var tree = this._tree,
categories = Object.keys(obs),
notRepresented = new Set(),
@@ -2403,7 +2419,75 @@ define([
});

return result;
};
}

/*
* This function will assign internal nodes to be the average of its tips.
*
* Note: All tips that are not passed into obs are ignored
*
* @param {Object} obs Maps categories to a set of observations (i.e. tips)
*
* @return {Object} returns A Map with the same group names that maps groups
to a set of keys (i.e. tree nodes) that are unique to
each group.
*/
Empress.prototype._projectContinuousObservations = function(obs) {
var tree = this._tree,
categories = Object.keys(obs),
notRepresented = new Set(),
i,
j;

if (!ignoreAbsentTips) {
// find "non-represented" tips
// Note: the following uses postorder traversal
for (i = 1; i < tree.size; i++) {
if (tree.isleaf(tree.postorderselect(i))) {
var represented = false;
for (j = 0; j < categories.length; j++) {
if (obs[categories[j]].has(i)) {
represented = true;
break;
}
}
if (!represented) notRepresented.add(i);
}
}
}

// assign internal nodes to appropriate category based on children
// iterate using postorder
// Note that, although we don't explicitly iterate over the
// root (at index tree.size) in this loop, we iterate over all its
// descendants; so in the event that all leaves are unique,
// the root can still get assigned to a group.
for (i = 1; i < tree.size; i++) {
var node = i;
var parent = tree.postorder(tree.parent(tree.postorderselect(i)));

for (j = 0; j < categories.length; j++) {
category = categories[j];

// add internal nodes to groups
if (obs[category].has(node)) {
obs[category].add(parent);
}
if (notRepresented.has(node)) {
notRepresented.add(parent);
}
}
}

var result = util.keepUniqueKeys(obs, notRepresented);

// remove all groups that do not contain unique features
result = _.pick(result, function (value, key) {
return value.size > 0;
});

return result;
}

/**
* Updates the tree based on obs and cm but does not draw a new tree.
@@ -2784,7 +2868,7 @@ define([
// project groups up tree
// Note: if _projectObservations was called, then if an internal node
// belongs to a group, all of its descendants will belong to the
// same group. However, this is not guaranteed if _projectOBservations
// same group. However, this is not guaranteed if _projectObservations
// was not called. Thus, this loop is used to guarantee that if an
// internal node belongs to a group then all of its descendants belong
// to the same group.