Skip to content

Commit

Permalink
Merge pull request #282 from nextstrain/map-colorby-gt
Browse files Browse the repository at this point in the history
Map colors by genotype
  • Loading branch information
colinmegill authored Mar 17, 2017
2 parents 4c26f15 + 495c5db commit d89efe2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/components/map/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import getLatLongs from "../../util/mapHelpersLatLong";
colorBy: state.controls.colorBy,
map: state.map,
geoResolution: state.controls.geoResolution,
sequences: state.sequences
};
})
class Map extends React.Component {
Expand Down Expand Up @@ -225,7 +226,8 @@ class Map extends React.Component {
this.state.map,
this.props.colorBy,
this.props.geoResolution,
this.props.colorScale.scale,
this.props.colorScale,
this.props.sequences
);
}
createMap() {
Expand Down
12 changes: 7 additions & 5 deletions src/util/mapHelpersLatLong.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {averageColors} from "./colorHelpers";
import {getTipColorAttribute} from "./treeHelpers";

const getLatLongs = (nodes, metadata, map, colorBy, geoResolution, colorScale) => {
const getLatLongs = (nodes, metadata, map, colorBy, geoResolution, colorScale, sequences) => {

const aggregatedLocations = {}; /* demes */
const aggregatedTransmissions = {}; /* edges, animation paths */
Expand Down Expand Up @@ -28,13 +29,14 @@ const getLatLongs = (nodes, metadata, map, colorBy, geoResolution, colorScale) =
aggregate locations for demes
*/
nodes.forEach((n) => {
const tipColorAttribute = getTipColorAttribute(n, colorScale, sequences);
if (!n.children) {
// look up geo1 geo2 geo3 do lat longs differ
if (aggregatedLocations[n.attr[geoResolution]]) {
aggregatedLocations[n.attr[geoResolution]].push(colorScale(n.attr[colorBy]));
aggregatedLocations[n.attr[geoResolution]].push(colorScale.scale(tipColorAttribute));
} else {
// if we haven't added this pair, add it
aggregatedLocations[n.attr[geoResolution]] = [colorScale(n.attr[colorBy])];
aggregatedLocations[n.attr[geoResolution]] = [colorScale.scale(tipColorAttribute)];
}
}
if (n.children) {
Expand All @@ -43,10 +45,10 @@ const getLatLongs = (nodes, metadata, map, colorBy, geoResolution, colorScale) =
if (n.attr[geoResolution] === child.attr[geoResolution]) { return; }
// look up in transmissions dictionary
if (aggregatedTransmissions[n.attr[geoResolution] + "/" + child.attr[geoResolution]]) {
aggregatedTransmissions[n.attr[geoResolution] + "/" + child.attr[geoResolution]].push(colorScale(n.attr[colorBy]));
aggregatedTransmissions[n.attr[geoResolution] + "/" + child.attr[geoResolution]].push(colorScale.scale(tipColorAttribute));
} else {
// we don't have it, add it
aggregatedTransmissions[n.attr[geoResolution] + "/" + child.attr[geoResolution]] = [colorScale(n.attr[colorBy])];
aggregatedTransmissions[n.attr[geoResolution] + "/" + child.attr[geoResolution]] = [colorScale.scale(tipColorAttribute)];
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/treeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const calcBranchThickness = function (nodes, rootIdx) {
return nodes.map((d) => freqScale(d.tipCount / maxTipCount));
};

const getTipColorAttribute = function (node, colorScale, sequences) {
export const getTipColorAttribute = function (node, colorScale, sequences) {
if (colorScale.colorBy.slice(0, 3) === "gt-" && colorScale.genotype) {
return getGenotype(colorScale.genotype[0][0],
colorScale.genotype[0][1],
Expand Down

0 comments on commit d89efe2

Please sign in to comment.