Skip to content

Commit

Permalink
feat: assign new nodes to the "Unknown" region
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Aug 4, 2020
1 parent 56e1274 commit a04e0d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/web/src/algorithms/tree/locateInTree.ts
Expand Up @@ -13,6 +13,7 @@ import { formatClades } from 'src/helpers/formatClades'

import auspiceDataRaw from 'src/assets/data/ncov_small.json'
import { formatRange } from 'src/helpers/formatRange'
import { UNKNOWN_VALUE } from 'src/constants'

export type MutationMap = Map<number, Nucleotide>

Expand Down Expand Up @@ -257,6 +258,9 @@ export function attach_to_tree(base_node: AuspiceTreeNodeExtended, seq: Analysis
const new_node = get_node_struct(seq)
set(new_node, 'branch_attrs.mutations', mutations)
set(new_node, 'node_attrs.div', div)
set(new_node, 'node_attrs.region', { value: UNKNOWN_VALUE })
set(new_node, 'node_attrs.country', { value: UNKNOWN_VALUE })
set(new_node, 'node_attrs.division', { value: UNKNOWN_VALUE })
set(new_node, 'mutations', cloneDeep(base_node.mutations))

for (const mut of nucMutations) {
Expand Down
20 changes: 15 additions & 5 deletions packages/web/src/components/Tree/TreeFilter.tsx
Expand Up @@ -21,6 +21,7 @@ import { State } from 'src/state/reducer'
import { setTreeFilterPanelCollapsed } from 'src/state/ui/ui.actions'
import { notUndefined } from 'src/helpers/notUndefined'
import { TreeFilterCheckboxGroup } from 'src/components/Tree/TreeFilterCheckboxGroup'
import { UNKNOWN_VALUE } from 'src/constants'

export const Card = styled(ReactstrapCard)<ReactstrapCardProps>`
box-shadow: 1px 1px 3px 2px rgba(128, 128, 128, 0.5);
Expand All @@ -41,13 +42,22 @@ export const CardBody = styled(ReactstrapCardBody)<ReactstrapCardBodyProps>`
padding: 3px 3px;
`

export function moveToFirst<T>(arr: T[], value: T) {
if (arr.includes(value)) {
const others = arr.filter((x) => x !== value)
return [value, ...others]
}
return arr
}

export function selectKnownTraitValues(state: State, trait: string) {
const nodes = (state?.tree?.nodes ?? []) as AuspiceTreeNode[]
let clades = nodes.map((node) => get(node, `node_attrs.${trait}.value`) as string | undefined)
clades = clades.filter(notUndefinedOrNull)
clades = unique(clades)
clades.sort()
return clades
const valuesRaw = nodes.map((node) => get(node, `node_attrs.${trait}.value`) as string | undefined) || []
let values = valuesRaw.filter(notUndefined)
values = uniq(values)
values.sort()
moveToFirst(values, UNKNOWN_VALUE)
return values ?? []
}

const mapStateToProps = (state: State) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/constants.ts
Expand Up @@ -10,6 +10,7 @@ export const URL_MANIFEST_JSON = `${DOMAIN}/manifest.json`
export const SAFARI_PINNED_TAB_COLOR = '#555555' as const
export const MS_TILE_COLOR = '#2b5797' as const

export const UNKNOWN_VALUE = 'Unknown'
export const BASE_MIN_WIDTH_PX = 4 as const
export const EXPORT_CSV_FILENAME = 'nextclade.csv' as const
export const EXPORT_JSON_FILENAME = 'nextclade.json' as const
Expand Down

0 comments on commit a04e0d5

Please sign in to comment.