-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add sequence sorting prototype
- Loading branch information
1 parent
db37dd3
commit e8cc7a3
Showing
23 changed files
with
518 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages_rs/nextclade-web/src/components/Autodetect/AutodetectPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from 'react' | ||
import { Col as ColBase, Row as RowBase } from 'reactstrap' | ||
import { useRecoilValue } from 'recoil' | ||
import { TableSlimWithBorders } from 'src/components/Common/TableSlim' | ||
import { Layout } from 'src/components/Layout/Layout' | ||
import { useTranslationSafe } from 'src/helpers/useTranslationSafe' | ||
import { autodetectResultsAtom } from 'src/state/autodetect.state' | ||
import styled from 'styled-components' | ||
|
||
const Container = styled.div` | ||
margin-top: 1rem; | ||
height: 100%; | ||
overflow: hidden; | ||
` | ||
|
||
const Row = styled(RowBase)` | ||
overflow: hidden; | ||
height: 100%; | ||
` | ||
|
||
const Col = styled(ColBase)` | ||
overflow: hidden; | ||
height: 100%; | ||
` | ||
|
||
const Table = styled(TableSlimWithBorders)` | ||
padding-top: 50px; | ||
& thead { | ||
height: 51px; | ||
position: sticky; | ||
top: -2px; | ||
background-color: ${(props) => props.theme.gray700}; | ||
color: ${(props) => props.theme.gray100}; | ||
} | ||
& thead th { | ||
margin: auto; | ||
text-align: center; | ||
vertical-align: middle; | ||
} | ||
` | ||
|
||
const TableWrapper = styled.div` | ||
height: 100%; | ||
overflow-y: auto; | ||
` | ||
|
||
export function AutodetectPage() { | ||
const { t } = useTranslationSafe() | ||
// const minimizerIndex = useRecoilValue(minimizerIndexAtom) | ||
const autodetectResults = useRecoilValue(autodetectResultsAtom) | ||
|
||
return ( | ||
<Layout> | ||
<Container> | ||
<Row noGutters> | ||
<Col> | ||
<TableWrapper> | ||
<Table striped> | ||
<thead> | ||
<tr> | ||
<th>{'#'}</th> | ||
<th>{t('Seq. name')}</th> | ||
<th>{t('dataset')}</th> | ||
<th>{t('total hits')}</th> | ||
<th>{t('max hit')}</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{autodetectResults.map((res) => ( | ||
<tr key={res.fastaRecord.index}> | ||
<td>{res.fastaRecord.index}</td> | ||
<td>{res.fastaRecord.seqName}</td> | ||
<td>{res.result.dataset ?? ''}</td> | ||
<td>{res.result.totalHits}</td> | ||
<td>{res.result.maxNormalizedHit.toFixed(3)}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
</TableWrapper> | ||
</Col> | ||
</Row> | ||
</Container> | ||
</Layout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages_rs/nextclade-web/src/hooks/useRunSeqAutodetect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useRouter } from 'next/router' | ||
import { NextcladeSeqAutodetectWasm } from 'src/gen/nextclade-wasm' | ||
import { useRecoilCallback } from 'recoil' | ||
import { ErrorInternal } from 'src/helpers/ErrorInternal' | ||
import { axiosFetch } from 'src/io/axiosFetch' | ||
import { autodetectResultAtom, autodetectResultsAtom, minimizerIndexAtom } from 'src/state/autodetect.state' | ||
import { minimizerIndexVersionAtom } from 'src/state/dataset.state' | ||
import { MinimizerIndexJson, MinimizerSearchRecord } from 'src/types' | ||
import { qrySeqInputsStorageAtom } from 'src/state/inputs.state' | ||
import { getQueryFasta } from 'src/workers/launchAnalysis' | ||
|
||
export function useRunSeqAutodetect() { | ||
const router = useRouter() | ||
|
||
return useRecoilCallback( | ||
({ set, reset, snapshot: { getPromise } }) => | ||
() => { | ||
reset(minimizerIndexAtom) | ||
reset(autodetectResultsAtom) | ||
|
||
void router.push('/autodetect', '/autodetect') // eslint-disable-line no-void | ||
|
||
function onResult(res: MinimizerSearchRecord) { | ||
set(autodetectResultAtom(res.fastaRecord.index), res) | ||
} | ||
|
||
Promise.all([getPromise(qrySeqInputsStorageAtom), getPromise(minimizerIndexVersionAtom)]) | ||
.then(async ([qrySeqInputs, minimizerIndexVersion]) => { | ||
if (!minimizerIndexVersion) { | ||
throw new ErrorInternal('Tried to run minimizer search without minimizer index available') | ||
} | ||
const fasta = await getQueryFasta(qrySeqInputs) | ||
const minimizerIndex: MinimizerIndexJson = await axiosFetch(minimizerIndexVersion.path) | ||
set(minimizerIndexAtom, minimizerIndex) | ||
return runAutodetect(fasta, minimizerIndex, onResult) | ||
}) | ||
.catch((error) => { | ||
throw error | ||
}) | ||
}, | ||
[router], | ||
) | ||
} | ||
|
||
function runAutodetect( | ||
fasta: string, | ||
minimizerIndex: MinimizerIndexJson, | ||
onResult: (res: MinimizerSearchRecord) => void, | ||
) { | ||
const nextcladeAutodetect = NextcladeSeqAutodetectWasm.new(JSON.stringify(minimizerIndex)) | ||
|
||
function onResultParsed(resStr: string) { | ||
const result = JSON.parse(resStr) as MinimizerSearchRecord | ||
onResult(result) | ||
} | ||
|
||
nextcladeAutodetect.autodetect(fasta, onResultParsed) | ||
} |
Oops, something went wrong.