diff --git a/src/actions/frequencies.js b/src/actions/frequencies.js
index b49b2bf86..8987bc1fb 100644
--- a/src/actions/frequencies.js
+++ b/src/actions/frequencies.js
@@ -1,13 +1,15 @@
import { debounce } from 'lodash';
import * as types from "./types";
import { timerStart, timerEnd } from "../util/perf";
-import { computeMatrixFromRawData, processFrequenciesJSON } from "../util/processFrequencies";
+import { computeMatrixFromRawData, checkIfNormalizableFromRawData, processFrequenciesJSON } from "../util/processFrequencies";
export const loadFrequencies = (json) => (dispatch, getState) => {
const { tree, controls } = getState();
+ const { data, pivots, matrix, projection_pivot, normalizeFrequencies } = processFrequenciesJSON(json, tree, controls);
dispatch({
type: types.LOAD_FREQUENCIES,
- frequencies: {loaded: true, version: 1, ...processFrequenciesJSON(json, tree, controls)}
+ frequencies: {loaded: true, version: 1, data, pivots, matrix, projection_pivot},
+ normalizeFrequencies
});
};
@@ -22,6 +24,10 @@ const updateFrequencyData = (dispatch, getState) => {
console.error("Race condition in updateFrequencyData. Frequencies data not in state. Matrix can't be calculated.");
return;
}
+
+ const normalizeFrequencies = controls.normalizeFrequencies &&
+ checkIfNormalizableFromRawData(frequencies.data, frequencies.pivots, tree.nodes, tree.visibility);
+
const matrix = computeMatrixFromRawData(
frequencies.data,
frequencies.pivots,
@@ -29,10 +35,10 @@ const updateFrequencyData = (dispatch, getState) => {
tree.visibility,
controls.colorScale,
controls.colorBy,
- controls.normalizeFrequencies
+ normalizeFrequencies
);
timerEnd("updateFrequencyData");
- dispatch({type: types.FREQUENCY_MATRIX, matrix});
+ dispatch({type: types.FREQUENCY_MATRIX, matrix, normalizeFrequencies});
};
/* debounce works better than throttle, as it _won't_ update while events are still coming in (e.g. dragging the date slider) */
diff --git a/src/actions/recomputeReduxState.js b/src/actions/recomputeReduxState.js
index 6fc0d02bd..d479ff0b4 100644
--- a/src/actions/recomputeReduxState.js
+++ b/src/actions/recomputeReduxState.js
@@ -12,7 +12,7 @@ import { treeJsonToState } from "../util/treeJsonProcessing";
import { entropyCreateState } from "../util/entropyCreateStateFromJsons";
import { determineColorByGenotypeMutType, calcNodeColor } from "../util/colorHelpers";
import { calcColorScale, createVisibleLegendValues } from "../util/colorScale";
-import { computeMatrixFromRawData } from "../util/processFrequencies";
+import { computeMatrixFromRawData, checkIfNormalizableFromRawData } from "../util/processFrequencies";
import { applyInViewNodesToTree } from "../actions/tree";
import { isColorByGenotype, decodeColorByGenotype, decodeGenotypeFilters, encodeGenotypeFilters } from "../util/getGenotype";
import { getTraitFromNode, getDivFromNode, collectGenotypeStates } from "../util/treeMiscHelpers";
@@ -830,6 +830,18 @@ export const createStateFromQueryOrJSONs = ({
/* update frequencies if they exist (not done for new JSONs) */
if (frequencies && frequencies.loaded) {
frequencies.version++;
+
+ const allowNormalization = checkIfNormalizableFromRawData(
+ frequencies.data,
+ frequencies.pivots,
+ tree.nodes,
+ tree.visibility
+ );
+
+ if (!allowNormalization) {
+ controls.normalizeFrequencies = false;
+ }
+
frequencies.matrix = computeMatrixFromRawData(
frequencies.data,
frequencies.pivots,
diff --git a/src/components/controls/frequency-normalization.js b/src/components/controls/frequency-normalization.js
index bdaa22193..e9bcbfb54 100644
--- a/src/components/controls/frequency-normalization.js
+++ b/src/components/controls/frequency-normalization.js
@@ -5,7 +5,8 @@ import { withTranslation } from "react-i18next";
import Toggle from "./toggle";
import { controlsWidth } from "../../util/globals";
import { FREQUENCY_MATRIX } from "../../actions/types";
-import { computeMatrixFromRawData } from "../../util/processFrequencies";
+import { computeMatrixFromRawData, checkIfNormalizableFromRawData } from "../../util/processFrequencies";
+import { SidebarSubtitle } from "./styles";
@connect((state) => {
return {
@@ -17,6 +18,20 @@ import { computeMatrixFromRawData } from "../../util/processFrequencies";
class NormalizeFrequencies extends React.Component {
render() {
const { t } = this.props;
+
+ const allowNormalization = this.props.frequencies.loaded && this.props.tree.loaded &&
+ checkIfNormalizableFromRawData(
+ this.props.frequencies.data,
+ this.props.frequencies.pivots,
+ this.props.tree.nodes,
+ this.props.tree.visibility
+ );
+ if (!allowNormalization) {
+ return (
+