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

Replace equalArrays with lodash.isEqual #1691

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
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
156 changes: 0 additions & 156 deletions post-process-ncov.py

This file was deleted.

74 changes: 70 additions & 4 deletions scripts/get-data.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,83 @@
#!/bin/bash

data_files=(
"entropy-test-data_hepB.json" \
"entropy-test-data_ncov.json" \
"dengue_all.json" "dengue_denv1.json" "dengue_denv2.json" "dengue_denv3.json" "dengue_denv4.json"\
"ebola.json" "ebola_root-sequence.json" \
"ebola_2019-09-14-no-epi-id_meta.json" "ebola_2019-09-14-no-epi-id_tree.json" \
"lassa_s_tree.json" "lassa_s_meta.json" \
"lassa_l_tree.json" "lassa_l_meta.json" \
"measles.json" \
"mers_tree.json" "mers_meta.json" \
"mumps_global.json" "mumps_na.json" \
"WNV_NA_tree.json" "WNV_NA_meta.json" \
"zika.json" \
"monkeypox_mpxv.json" \
"tb_global_meta.json" "tb_global_tree.json" \
"enterovirus_d68_genome_meta.json" "enterovirus_d68_genome_tree.json" \
"enterovirus_d68_vp1_meta.json" "enterovirus_d68_vp1_tree.json" \
############## AVIAN FLU ##############
"flu_avian_h7n9_ha.json" \
"flu_avian_h7n9_mp.json" \
"flu_avian_h7n9_na.json" \
"flu_avian_h7n9_np.json" \
"flu_avian_h7n9_ns.json" \
"flu_avian_h7n9_pa.json" \
"flu_avian_h7n9_pb1.json" \
"flu_avian_h7n9_pb2.json" \
############## SEASONAL FLU ##############
"flu_seasonal_h3n2_ha_2y.json" "flu_seasonal_h3n2_ha_2y_tip-frequencies.json" \
"flu_seasonal_h3n2_ha_3y.json" "flu_seasonal_h3n2_ha_3y_tip-frequencies.json" \
"flu_seasonal_h3n2_ha_6y.json" "flu_seasonal_h3n2_ha_6y_tip-frequencies.json" \
"flu_seasonal_h3n2_ha_12y.json" "flu_seasonal_h3n2_ha_12y_tip-frequencies.json" \
"flu_seasonal_h3n2_na_2y.json" "flu_seasonal_h3n2_na_2y_tip-frequencies.json" \
"flu_seasonal_h3n2_na_3y.json" "flu_seasonal_h3n2_na_3y_tip-frequencies.json" \
"flu_seasonal_h3n2_na_6y.json" "flu_seasonal_h3n2_na_6y_tip-frequencies.json" \
"flu_seasonal_h3n2_na_12y.json" "flu_seasonal_h3n2_na_12y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_ha_2y.json" "flu_seasonal_h1n1pdm_ha_2y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_ha_3y.json" "flu_seasonal_h1n1pdm_ha_3y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_ha_6y.json" "flu_seasonal_h1n1pdm_ha_6y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_ha_12y.json" "flu_seasonal_h1n1pdm_ha_12y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_ha_pandemic_meta.json" "flu_seasonal_h1n1pdm_ha_pandemic_tree.json" "flu_seasonal_h1n1pdm_ha_pandemic_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_na_2y.json" "flu_seasonal_h1n1pdm_na_2y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_na_3y.json" "flu_seasonal_h1n1pdm_na_3y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_na_6y.json" "flu_seasonal_h1n1pdm_na_6y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_na_12y.json" "flu_seasonal_h1n1pdm_na_12y_tip-frequencies.json" \
"flu_seasonal_h1n1pdm_na_pandemic_tree.json" "flu_seasonal_h1n1pdm_na_pandemic_meta.json" "flu_seasonal_h1n1pdm_na_pandemic_tip-frequencies.json" \
"flu_seasonal_vic_ha_2y.json" "flu_seasonal_vic_ha_2y_tip-frequencies.json" "flu_seasonal_vic_ha_2y_root-sequence.json" \
"flu_seasonal_vic_ha_3y.json" "flu_seasonal_vic_ha_3y_tip-frequencies.json" "flu_seasonal_vic_ha_3y_root-sequence.json" \
"flu_seasonal_vic_ha_6y.json" "flu_seasonal_vic_ha_6y_tip-frequencies.json" "flu_seasonal_vic_ha_6y_root-sequence.json" \
"flu_seasonal_vic_ha_12y.json" "flu_seasonal_vic_ha_12y_tip-frequencies.json" "flu_seasonal_vic_ha_12y_root-sequence.json" \
"flu_seasonal_vic_na_2y.json" "flu_seasonal_vic_na_2y_tip-frequencies.json" "flu_seasonal_vic_na_2y_root-sequence.json" \
"flu_seasonal_vic_na_3y.json" "flu_seasonal_vic_na_3y_tip-frequencies.json" "flu_seasonal_vic_na_3y_root-sequence.json" \
"flu_seasonal_vic_na_6y.json" "flu_seasonal_vic_na_6y_tip-frequencies.json" "flu_seasonal_vic_na_6y_root-sequence.json" \
"flu_seasonal_vic_na_12y.json" "flu_seasonal_vic_na_12y_tip-frequencies.json" "flu_seasonal_vic_na_12y_root-sequence.json" \
"flu_seasonal_yam_ha_2y.json" "flu_seasonal_yam_ha_2y_tip-frequencies.json" "flu_seasonal_yam_ha_2y_root-sequence.json" \
"flu_seasonal_yam_ha_3y.json" "flu_seasonal_yam_ha_3y_tip-frequencies.json" "flu_seasonal_yam_ha_3y_root-sequence.json" \
"flu_seasonal_yam_ha_6y.json" "flu_seasonal_yam_ha_6y_tip-frequencies.json" "flu_seasonal_yam_ha_6y_root-sequence.json" \
"flu_seasonal_yam_ha_12y.json" "flu_seasonal_yam_ha_12y_tip-frequencies.json" "flu_seasonal_yam_ha_12y_root-sequence.json" \
"flu_seasonal_yam_na_2y.json" "flu_seasonal_yam_na_2y_tip-frequencies.json" "flu_seasonal_yam_na_2y_root-sequence.json" \
"flu_seasonal_yam_na_3y.json" "flu_seasonal_yam_na_3y_tip-frequencies.json" "flu_seasonal_yam_na_3y_root-sequence.json" \
"flu_seasonal_yam_na_6y.json" "flu_seasonal_yam_na_6y_tip-frequencies.json" "flu_seasonal_yam_na_6y_root-sequence.json" \
"flu_seasonal_yam_na_12y.json" "flu_seasonal_yam_na_12y_tip-frequencies.json" "flu_seasonal_yam_na_12y_root-sequence.json" \
############## LATEST CORE SARS-CoV-2 (COVID-19) BUILDS ##############
"ncov_gisaid_global.json" "ncov_gisaid_global_tip-frequencies.json" \
"ncov_gisaid_africa.json" "ncov_gisaid_africa_tip-frequencies.json" \
"ncov_gisaid_asia.json" "ncov_gisaid_asia_tip-frequencies.json" \
"ncov_gisaid_europe.json" "ncov_gisaid_europe_tip-frequencies.json" \
"ncov_gisaid_north-america.json" "ncov_gisaid_north-america_tip-frequencies.json" \
"ncov_gisaid_oceania.json" "ncov_gisaid_oceania_tip-frequencies.json" \
"ncov_gisaid_south-america.json" "ncov_gisaid_south-america_tip-frequencies.json" \
############## TIMESTAMPED SARS-CoV-2 BUILDS USED IN NARRATIVES #############
"ncov_2020-01-23.json" "ncov_2020-01-25.json" "ncov_2020-01-26.json" "ncov_2020-01-30.json" \
"ncov_2020-03-04.json" "ncov_2020-03-05.json" "ncov_2020-03-11.json" "ncov_2020-03-13.json" \
"ncov_2020-03-20.json" "ncov_2020-03-27.json" "ncov_2020-04-03.json" \
"ncov_global_2020-04-09.json" "ncov_north-america_2020-04-17.json" \
)

rm -rf data/
mkdir -p data/
for i in "${data_files[@]}"
do
curl http://staging.nextstrain.org/"${i}" --compressed -o data/"${i}"
curl http://data.nextstrain.org/"${i}" --compressed -o data/"${i}"
done

echo "Copying the test datasets from test/data to data"
Expand Down
19 changes: 11 additions & 8 deletions src/actions/entropy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debounce } from 'lodash';
import { debounce, isEqual } from 'lodash';
import { calcEntropyInView } from "../util/entropy";
import { nucleotide_gene, equalArrays } from "../util/globals";
import { nucleotide_gene } from "../util/globals";
import * as types from "./types";
import { isColorByGenotype, decodeColorByGenotype, getCdsFromGenotype} from "../util/getGenotype";

Expand All @@ -18,18 +18,18 @@ export const updateEntropyVisibility = debounce((dispatch, getState) => {
}, 500, { leading: true, trailing: true });

/**
* Returns a thunk which makes zero or one dispatches to update the entropy reducer
* Returns a thunk which makes zero or one dispatches to update the entropy reducer
* if the selected CDS and/or positions need updating.
*
*
* The argument may vary:
* - It may be a colorBy string, which may or may not be a genotype coloring
* - It may be a CDS (Object)
* - It may be the constant `nucleotide_gene`
*
*
* The expected state updates to (selectedCds, selectedPositions) are as follows:
* (nuc = nucleotide_gene, x,y,z are positions, [*] means any (or no) positions selected,
* no-op means that no dispatches are made and thus the state is unchanged):
*
*
* -----------------------------------------------------------------------------------
* PREVIOUS STATE | EXAMPLE ARGUMENT | NEW STATE ($ = entropy bar recalc needed)
* -----------------------------------------------------------------------------------
Expand All @@ -49,13 +49,16 @@ export const updateEntropyVisibility = debounce((dispatch, getState) => {
* CdsA, [*] | CdsB | CdsB, [] $
* CdsA, [*] | nucleotide_gene | nuc, [] $
* -----------------------------------------------------------------------------------
*
*
* @returns {ReduxThunk}
*/
export const changeEntropyCdsSelection = (arg) => (dispatch, getState) => {
const action = {type: types.CHANGE_ENTROPY_CDS_SELECTION}
const entropy = getState().entropy;

// no-op if the entropy data isn't present
if (!entropy.loaded) return;

if (arg === nucleotide_gene) {
if (entropy.selectedCds === nucleotide_gene) {
return
Expand Down Expand Up @@ -91,7 +94,7 @@ export const changeEntropyCdsSelection = (arg) => (dispatch, getState) => {
const [data, maxYVal] = calcEntropyInView(state.tree.nodes, state.tree.visibility, action.selectedCds, entropy.showCounts);
action.bars = data;
action.maxYVal = maxYVal;
} else if (equalArrays(action.selectedPositions, entropy.selectedPositions)) {
} else if (isEqual(action.selectedPositions, entropy.selectedPositions)) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/entropy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { select } from "d3-selection";
import { withTranslation } from "react-i18next";
import 'd3-transition';
import { FaInfoCircle } from "react-icons/fa";
import { isEqual } from 'lodash';
import Card from "../framework/card";
import { changeColorBy } from "../../actions/colors";
import { tabGroup, tabGroupMember, tabGroupMemberSelected } from "../../globalStyles";
Expand All @@ -13,7 +14,7 @@ import InfoPanel from "./infoPanel";
import { changeEntropyCdsSelection, showCountsNotEntropy } from "../../actions/entropy";
import { timerStart, timerEnd } from "../../util/perf";
import { encodeColorByGenotype } from "../../util/getGenotype";
import { nucleotide_gene, equalArrays } from "../../util/globals";
import { nucleotide_gene } from "../../util/globals";
import { getCdsByName } from "../../util/entropy";
import { StyledTooltip } from "../controls/styles";
import "../../css/entropy.css";
Expand Down Expand Up @@ -228,7 +229,7 @@ class Entropy extends React.Component {
if (this.props.showCounts !== nextProps.showCounts) {
updateParams.showCounts = nextProps.showCounts;
}
if (!equalArrays(this.props.selectedPositions, nextProps.selectedPositions)) {
if (!isEqual(this.props.selectedPositions, nextProps.selectedPositions)) {
updateParams.selectedPositions = nextProps.selectedPositions
}
if (Object.keys(updateParams).length) {
Expand Down
2 changes: 0 additions & 2 deletions src/util/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,3 @@ const aminoAcids = {
};

export const getAminoAcidName = (x) => aminoAcids[x.toUpperCase()] || "Unknown";

export const equalArrays = (a,b) => a.length===b.length && a.every((el, idx) => b[idx]===el);
Loading