Skip to content

Commit

Permalink
Merge pull request #1329 from nextstrain/feat/default-cds
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov authored Dec 8, 2023
2 parents c4eee8c + 89a5eaa commit 699d44f
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 54 deletions.
4 changes: 2 additions & 2 deletions packages_rs/nextclade-cli/src/dataset/dataset_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ pub fn dataset_individual_files_load(
rest_files: BTreeMap::default(),
other: serde_json::Value::default(),
},
default_gene: None,
gene_order_preference: vec![],
default_cds: None,
cds_order_preference: vec![],
mut_labels: LabelledMutationsConfig::default(),
primers: vec![],
qc: None,
Expand Down
6 changes: 3 additions & 3 deletions packages_rs/nextclade-web/src/components/GeneMap/GeneMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { ReactResizeDetectorDimensions, withResizeDetector } from 'react-resize-detector'
import { useRecoilValue, useSetRecoilState } from 'recoil'
import { ErrorInternal } from 'src/helpers/ErrorInternal'
import { isInNucleotideViewAtom, viewedGeneAtom } from 'src/state/seqViewSettings.state'
import { isInNucleotideViewAtom, viewedCdsAtom } from 'src/state/seqViewSettings.state'
import styled from 'styled-components'
import { BASE_MIN_WIDTH_PX } from 'src/constants'
import type { Cds, CdsSegment } from 'src/types'
Expand Down Expand Up @@ -88,7 +88,7 @@ export function CdsSegmentView({
const { t } = useTranslationSafe()
const [showTooltip, setShowTooltip] = useState(false)

const setViewedGene = useSetRecoilState(viewedGeneAtom)
const setViewedGene = useSetRecoilState(viewedCdsAtom)

const [hovered, setHovered] = useState(false)
const [timeoutId, setTimeoutId] = useState<number | undefined>(undefined)
Expand Down Expand Up @@ -224,7 +224,7 @@ export type GeneMapProps = ReactResizeDetectorDimensions
export function GeneMapUnsized({ width = 0, height = 0 }: GeneMapProps) {
const cdsesAll = useRecoilValue(cdsesAtom)
const genomeSize = useRecoilValue(genomeSizeAtom)
const viewedGene = useRecoilValue(viewedGeneAtom)
const viewedGene = useRecoilValue(viewedCdsAtom)
const isInNucView = useRecoilValue(isInNucleotideViewAtom)

const { viewBox, cdsSegViews, geneMapHeight } = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { range } from 'lodash'
import { XAxis, ComposedChart, ResponsiveContainer } from 'recharts'
import { useRecoilValue } from 'recoil'
import { cdsesAtom, genomeSizeAtom } from 'src/state/results.state'
import { viewedGeneAtom } from 'src/state/seqViewSettings.state'
import { viewedCdsAtom } from 'src/state/seqViewSettings.state'
import { getAxisLength } from './getAxisLength'

const MARGIN = {}
Expand All @@ -26,7 +26,7 @@ export function getTickSize(axisLength: number) {
export function GeneMapAxis() {
const genomeSize = useRecoilValue(genomeSizeAtom)
const cdses = useRecoilValue(cdsesAtom)
const viewedGene = useRecoilValue(viewedGeneAtom)
const viewedGene = useRecoilValue(viewedCdsAtom)

const { ticks, domain } = useMemo(() => {
const length = getAxisLength(genomeSize, viewedGene, cdses)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Cds } from 'src/types'
import { GENE_OPTION_NUC_SEQUENCE } from 'src/constants'
import { CDS_OPTION_NUC_SEQUENCE } from 'src/constants'
import { cdsCodonLength } from 'src/types'

/** Retrieves length of the axis to draw: Genome size in case of nuc sequence, or gene length on case of gene */
export function getAxisLength(genomeSize: number, viewedGene: string, cdses: Cds[]) {
let length = genomeSize
if (viewedGene !== GENE_OPTION_NUC_SEQUENCE) {
if (viewedGene !== CDS_OPTION_NUC_SEQUENCE) {
const cds = cdses?.find((cds) => cds.name === viewedGene)
if (cds) {
length = Math.round(cdsCodonLength(cds))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslationSafe as useTranslation } from 'src/helpers/useTranslation
import { FixedSizeList as FixedSizeListBase, FixedSizeListProps } from 'react-window'
import AutoSizerBase from 'react-virtualized-auto-sizer'
import { useRecoilCallback, useRecoilValue } from 'recoil'
import { viewedGeneAtom } from 'src/state/seqViewSettings.state'
import { viewedCdsAtom } from 'src/state/seqViewSettings.state'
import styled from 'styled-components'

import { SortCategory, SortDirection } from 'src/helpers/sortResults'
Expand Down Expand Up @@ -78,7 +78,7 @@ export function ResultsTable() {
const aaMotifsDescs = useRecoilValue(aaMotifsDescsAtom)

const isResultsFilterPanelCollapsed = useRecoilValue(isResultsFilterPanelCollapsedAtom)
const viewedGene = useRecoilValue(viewedGeneAtom)
const viewedGene = useRecoilValue(viewedCdsAtom)

const rowData: TableRowDatum[] = useMemo(() => {
return seqIndices.map((seqIndex) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from 'src/components/Results/ResultsTableStyle'
import { PeptideView } from 'src/components/SequenceView/PeptideView'
import { SequenceView } from 'src/components/SequenceView/SequenceView'
import { GENE_OPTION_NUC_SEQUENCE } from 'src/constants'
import { CDS_OPTION_NUC_SEQUENCE } from 'src/constants'
import { analysisResultAtom } from 'src/state/results.state'
import { ColumnCoverage } from 'src/components/Results/ColumnCoverage'
import { ColumnAaMotifs } from 'src/components/Results/ColumnAaMotifs'
Expand Down Expand Up @@ -185,7 +185,7 @@ export function ResultsTableRowResult({

<TableCell basis={columnWidthsPx.sequenceView} grow={1} shrink={0}>
<Suspense fallback={null}>
{viewedGene === GENE_OPTION_NUC_SEQUENCE ? (
{viewedGene === CDS_OPTION_NUC_SEQUENCE ? (
<SequenceView key={seqName} sequence={analysisResult} />
) : (
<PeptideView key={seqName} sequence={analysisResult} viewedGene={viewedGene} warnings={warnings} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
import { splitToRows } from 'src/components/Results/splitToRows'
import { TableSlim } from 'src/components/Common/TableSlim'
import { AminoacidMutationBadge } from 'src/components/Common/MutationBadge'
import { geneOrderPreferenceAtom } from 'src/state/dataset.state'
import { cdsOrderPreferenceAtom } from 'src/state/dataset.state'
import { sortByCdsName } from './sortByCdsName'

export interface ListOfAminoacidDeletionsProps {
Expand All @@ -18,7 +18,7 @@ export interface ListOfAminoacidDeletionsProps {
export function ListOfAminoacidDeletions({ aminoacidDeletions }: ListOfAminoacidDeletionsProps) {
const { t } = useTranslationSafe()

const geneOrderPreference = useRecoilValue(geneOrderPreferenceAtom)
const geneOrderPreference = useRecoilValue(cdsOrderPreferenceAtom)

const totalDeletions = aminoacidDeletions.length
const maxRows = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRecoilValue } from 'recoil'
import copy from 'fast-copy'

import type { AaSub } from 'src/types'
import { geneOrderPreferenceAtom } from 'src/state/dataset.state'
import { cdsOrderPreferenceAtom } from 'src/state/dataset.state'
import { formatAAMutation } from 'src/helpers/formatMutation'
import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
import { splitToRows } from 'src/components/Results/splitToRows'
Expand All @@ -18,7 +18,7 @@ export interface ListOfAminoacidMutationsProps {
export function ListOfAminoacidSubstitutions({ aminoacidSubstitutions }: ListOfAminoacidMutationsProps) {
const { t } = useTranslationSafe()

const geneOrderPreference = useRecoilValue(geneOrderPreferenceAtom)
const geneOrderPreference = useRecoilValue(cdsOrderPreferenceAtom)

const totalMutations = aminoacidSubstitutions.length
const maxRows = Math.min(8, totalMutations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { Badge as BadgeBase } from 'reactstrap'
import { ButtonFilter } from 'src/components/Results/ButtonFilter'
import { notUndefinedOrNull } from 'src/helpers/notUndefined'
import styled from 'styled-components'
import { viewedGeneAtom } from 'src/state/seqViewSettings.state'
import { viewedCdsAtom } from 'src/state/seqViewSettings.state'
import { useRecoilState, useRecoilValue } from 'recoil'
import { GENE_OPTION_NUC_SEQUENCE } from 'src/constants'
import { CDS_OPTION_NUC_SEQUENCE } from 'src/constants'
import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
import { genesAtom } from 'src/state/results.state'
import { ensureNumber } from 'src/helpers/number'
Expand All @@ -30,23 +30,23 @@ export interface Option {

export function SequenceSelector() {
const genes = useRecoilValue(genesAtom)
const [viewedGene, setViewedGene] = useRecoilState(viewedGeneAtom)
const [viewedGene, setViewedGene] = useRecoilState(viewedCdsAtom)

const { options, defaultOption } = useMemo(() => {
return prepareOptions(genes)
}, [genes])

const option = useMemo((): Option => {
if (viewedGene === GENE_OPTION_NUC_SEQUENCE) {
return { value: GENE_OPTION_NUC_SEQUENCE }
if (viewedGene === CDS_OPTION_NUC_SEQUENCE) {
return { value: CDS_OPTION_NUC_SEQUENCE }
}
return options.find((option) => option.cds?.name === viewedGene) ?? defaultOption
}, [defaultOption, options, viewedGene])

const onChange = useCallback(
(option: Option | null) => {
if (option?.value === GENE_OPTION_NUC_SEQUENCE) {
setViewedGene(GENE_OPTION_NUC_SEQUENCE)
if (option?.value === CDS_OPTION_NUC_SEQUENCE) {
setViewedGene(CDS_OPTION_NUC_SEQUENCE)
}

if (option?.cds?.name) {
Expand Down Expand Up @@ -135,7 +135,7 @@ function OptionLabel(option: Option, meta: FormatOptionLabelMeta<Option>) {
return <OptionLabelProtein protein={option.protein} isMenu={meta.context === 'menu'} />
}

if (option.value === GENE_OPTION_NUC_SEQUENCE) {
if (option.value === CDS_OPTION_NUC_SEQUENCE) {
return <OptionLabelFullGenome isMenu={meta.context === 'menu'} />
}

Expand Down Expand Up @@ -224,7 +224,7 @@ const Indent = styled.div<{ indent?: number | boolean }>`
`

function prepareOptions(genes: Gene[]) {
const options: Option[] = [{ value: GENE_OPTION_NUC_SEQUENCE }]
const options: Option[] = [{ value: CDS_OPTION_NUC_SEQUENCE }]

if (isEmpty(genes)) {
return { options, defaultOption: options[0] }
Expand Down Expand Up @@ -276,7 +276,7 @@ function prepareOptions(genes: Gene[]) {
}

const checkSearchCandidateEntry = (candidate: FilterOptionOption<Option>, searchTerm: string): boolean => {
if (candidate.value === GENE_OPTION_NUC_SEQUENCE) {
if (candidate.value === CDS_OPTION_NUC_SEQUENCE) {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion packages_rs/nextclade-web/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ export const ANY = '.' as const
export const AMINOACID_UNKNOWN = 'X' as const as Aminoacid
export const AMINOACID_GAP = '-' as const as Aminoacid

export const GENE_OPTION_NUC_SEQUENCE = 'Sequence' // Show nucleotide sequence in sequence view (as opposed to a gene)
export const CDS_OPTION_NUC_SEQUENCE = 'Sequence' // Show nucleotide sequence in sequence view (as opposed to a gene)
20 changes: 10 additions & 10 deletions packages_rs/nextclade-web/src/hooks/useRunAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { changeColorBy } from 'auspice/src/actions/colors'
import { useRouter } from 'next/router'
import { useDispatch } from 'react-redux'
import { useRecoilCallback } from 'recoil'
import { viewedGeneAtom } from 'src/state/seqViewSettings.state'
import { viewedCdsAtom } from 'src/state/seqViewSettings.state'
import { AlgorithmGlobalStatus } from 'src/types'
import { sanitizeError } from 'src/helpers/sanitizeError'
import { auspiceStartClean, treeFilterByNodeType } from 'src/state/auspice/auspice.actions'
import { createAuspiceState } from 'src/state/auspice/createAuspiceState'
import { datasetCurrentAtom, geneOrderPreferenceAtom } from 'src/state/dataset.state'
import { datasetCurrentAtom, cdsOrderPreferenceAtom } from 'src/state/dataset.state'
import { globalErrorAtom } from 'src/state/error.state'
import {
geneMapInputAtom,
Expand Down Expand Up @@ -48,8 +48,8 @@ export function useRunAnalysis() {
set(showNewRunPopupAtom, false)

reset(analysisResultsAtom)
reset(viewedGeneAtom)
reset(geneOrderPreferenceAtom)
reset(viewedCdsAtom)
reset(cdsOrderPreferenceAtom)

const numThreads = getPromise(numThreadsAtom)
const datasetCurrent = getPromise(datasetCurrentAtom)
Expand All @@ -71,8 +71,8 @@ export function useRunAnalysis() {
onInitialData({
geneMap,
genomeSize,
defaultGene,
geneOrderPreference,
defaultCds,
cdsOrderPreference,
cladeNodeAttrKeyDescs,
phenotypeAttrDescs,
aaMotifsDescs,
Expand All @@ -85,12 +85,12 @@ export function useRunAnalysis() {
set(cdsesAtom, cdses)
set(genomeSizeAtom, genomeSize)

if (defaultGene) {
set(viewedGeneAtom, defaultGene)
if (defaultCds) {
set(viewedCdsAtom, defaultCds)
}

if (geneOrderPreference) {
set(geneOrderPreferenceAtom, geneOrderPreference)
if (cdsOrderPreference) {
set(cdsOrderPreferenceAtom, cdsOrderPreference)
}

// FIXME: This type is duplicated. One comes from handwritten Auspice typings,
Expand Down
6 changes: 2 additions & 4 deletions packages_rs/nextclade-web/src/state/dataset.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { isNil } from 'lodash'
import { atom, DefaultValue, selector } from 'recoil'

import type { Dataset, MinimizerIndexVersion } from 'src/types'
// import { GENE_OPTION_NUC_SEQUENCE } from 'src/constants'
import { persistAtom } from 'src/state/persist/localStorage'
// import { viewedGeneAtom } from 'src/state/seqViewSettings.state'
import { isDefaultValue } from 'src/state/utils/isDefaultValue'
import { areDatasetsEqual } from 'src/types'

Expand Down Expand Up @@ -46,8 +44,8 @@ export const datasetUpdatedAtom = atom<Dataset | undefined>({
default: undefined,
})

export const geneOrderPreferenceAtom = atom<string[]>({
key: 'geneOrderPreference',
export const cdsOrderPreferenceAtom = atom<string[]>({
key: 'cdsOrderPreferenceAtom',
default: [],
})

Expand Down
12 changes: 6 additions & 6 deletions packages_rs/nextclade-web/src/state/seqViewSettings.state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { atom, selector } from 'recoil'
import { GENE_OPTION_NUC_SEQUENCE } from 'src/constants'
import { CDS_OPTION_NUC_SEQUENCE } from 'src/constants'
import { ErrorInternal } from 'src/helpers/ErrorInternal'

import { persistAtom } from 'src/state/persist/localStorage'
Expand Down Expand Up @@ -93,18 +93,18 @@ export const maxNucMarkersAtom = atom<number>({
effects: [persistAtom],
})

export const viewedGeneAtom = atom<string>({
key: 'viewedGene',
default: GENE_OPTION_NUC_SEQUENCE,
export const viewedCdsAtom = atom<string>({
key: 'viewedCdsAtom',
default: CDS_OPTION_NUC_SEQUENCE,
})

export const isInNucleotideViewAtom = selector<boolean>({
key: 'isInNucleotideView',
get: ({ get }) => get(viewedGeneAtom) === GENE_OPTION_NUC_SEQUENCE,
get: ({ get }) => get(viewedCdsAtom) === CDS_OPTION_NUC_SEQUENCE,
})

export const switchToNucleotideViewAtom = selector({
key: 'switchToNucleotideView',
get: () => undefined,
set: ({ set }) => set(viewedGeneAtom, GENE_OPTION_NUC_SEQUENCE),
set: ({ set }) => set(viewedCdsAtom, CDS_OPTION_NUC_SEQUENCE),
})
4 changes: 2 additions & 2 deletions packages_rs/nextclade/src/analyze/virus_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ pub struct VirusProperties {

pub files: DatasetFiles,

pub default_gene: Option<String>,
pub default_cds: Option<String>,

#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub gene_order_preference: Vec<String>,
pub cds_order_preference: Vec<String>,

#[serde(default)]
pub mut_labels: LabelledMutationsConfig,
Expand Down
8 changes: 4 additions & 4 deletions packages_rs/nextclade/src/run/nextclade_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ pub struct AnalysisInitialData<'a> {
pub genome_size: usize,
pub gene_map: GeneMap,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub default_gene: Option<String>,
pub default_cds: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub gene_order_preference: Vec<String>,
pub cds_order_preference: Vec<String>,
pub clade_node_attr_key_descs: &'a [CladeNodeAttrKeyDesc],
pub phenotype_attr_descs: &'a [PhenotypeAttrDesc],
pub aa_motifs_descs: &'a [AaMotifsDesc],
Expand Down Expand Up @@ -241,8 +241,8 @@ impl Nextclade {
AnalysisInitialData {
gene_map: self.gene_map.clone(),
genome_size: self.ref_seq.len(),
default_gene: self.virus_properties.default_gene.clone(),
gene_order_preference: self.virus_properties.gene_order_preference.clone(),
default_cds: self.virus_properties.default_cds.clone(),
cds_order_preference: self.virus_properties.cds_order_preference.clone(),
clade_node_attr_key_descs: &self.clade_attr_descs,
phenotype_attr_descs: &self.phenotype_attr_descs,
aa_motifs_descs: &self.aa_motifs_descs,
Expand Down

1 comment on commit 699d44f

@vercel
Copy link

@vercel vercel bot commented on 699d44f Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nextclade – ./

nextclade-nextstrain.vercel.app
nextclade.vercel.app
nextclade-git-master-nextstrain.vercel.app

Please sign in to comment.