From 9b8d9e0672f62849decfbf2d2e05d749cc621ce8 Mon Sep 17 00:00:00 2001 From: Songchen Tan Date: Fri, 28 Jun 2024 14:47:00 -0400 Subject: [PATCH] Add analyze --- src/pages/[id]/statistics.tsx | 226 ++++++++++++++++++++++++---------- 1 file changed, 163 insertions(+), 63 deletions(-) diff --git a/src/pages/[id]/statistics.tsx b/src/pages/[id]/statistics.tsx index af21bd8..2046b66 100644 --- a/src/pages/[id]/statistics.tsx +++ b/src/pages/[id]/statistics.tsx @@ -1,8 +1,10 @@ -import { Flex, Table } from "antd"; +import { Flex, Select, Table } from "antd"; import { alphabetAtom, displayAtom, frequencyAtom, + repertoireAtom, + sequenceAtom, useChaifenTitle, } from "~/atoms"; import { @@ -14,11 +16,9 @@ import { } from "@ant-design/pro-components"; import { Form, Space, Typography } from "antd"; import { useAtomValue } from "jotai"; -import type { Frequency } from "~/atoms"; import { maxLengthAtom } from "~/atoms"; -import type { AnalyzerForm, AssemblyResult } from "~/lib"; +import type { AnalyzerForm, AssemblyResult, Frequency } from "~/lib"; import { renderIndexed } from "~/lib"; -import { Select } from "~/components/Utils"; import { useState } from "react"; import { assemblyResultAtom } from "~/atoms/cache"; import type { ColumnsType } from "antd/es/table"; @@ -45,6 +45,7 @@ const analyzePrimitiveDuplication = ( result: AssemblyResult, display: (d: string) => string, maxLength: number, + replacer: (d: string) => string = (d) => d, ) => { const reverseMap = new Map(); let relevant = result; @@ -59,11 +60,11 @@ const analyzePrimitiveDuplication = ( relevant = relevant.slice(0, analyzer.top); } for (const assembly of relevant) { - const { name, sequence: elements } = assembly; + const { name, sequence } = assembly; const sliced = range(maxLength).map((i) => - analyzer.position.includes(i) ? elements[i] : "*", + analyzer.position.includes(i) ? sequence[i] : "*", ); - const summary = `(${sliced.map((x) => renderIndexed(x, display)).join(", ")})`; + const summary = `(${sliced.map((x) => replacer(renderIndexed(x, display))).join(", ")})`; reverseMap.set(summary, (reverseMap.get(summary) || []).concat(name)); } @@ -75,11 +76,76 @@ interface Density { items: string[]; } +const AnalyzerConfig = ({ + analyzer, + setAnalyzer, +}: { + analyzer: AnalyzerForm; + setAnalyzer: (a: AnalyzerForm) => void; +}) => { + const [form] = Form.useForm(); + const maxLength = useAtomValue(maxLengthAtom); + return ( + + form={form} + layout="horizontal" + submitter={false} + initialValues={analyzer} + onValuesChange={(_, values) => setAnalyzer(values)} + autoFocusFirstInput={false} + > + + ({ + label: `第 ${d + 1} 码`, + value: d, + }))} + allowClear={false} + /> + + + {({ top }) => ( + + + { - const top = value === 0 ? 0 : 500; - form.setFieldValue("top", top); - setAnalyzer({ ...form.getFieldsValue(), top }); - }} - style={{ width: 96 }} - /> - - - - )} - - - + { ); }; +const MarginalFirstOrderDuplication = () => { + const assemblyResult = useAtomValue(assemblyResultAtom); + const frequency = useAtomValue(frequencyAtom); + const maxLength = useAtomValue(maxLengthAtom); + const display = useAtomValue(displayAtom); + const sequenceMap = useAtomValue(sequenceAtom); + const repertoire = useAtomValue(repertoireAtom); + const hashedElements = new Set(); + for (const { sequence } of assemblyResult) { + sequence.forEach((x) => { + hashedElements.add(renderIndexed(x, display)); + }); + } + const allElements = [...hashedElements].sort(); + + const [elements, setElements] = useState(allElements.slice(0, 2)); + const [analyzer, setAnalyzer] = useState({ + type: "single", + position: range(0, maxLength), + top: 0, + }); + + const rmBefore = analyzePrimitiveDuplication( + analyzer, + frequency, + assemblyResult, + display, + maxLength, + ); + const szBefore = new Set(); + rmBefore.forEach((items) => { + if (items.length > 1) items.forEach((x) => szBefore.add(x)); + }); + const rmAfter = analyzePrimitiveDuplication( + analyzer, + frequency, + assemblyResult, + display, + maxLength, + (d) => (elements.includes(d) ? "^" : d), + ); + const szAfter = new Set(); + rmAfter.forEach((items) => { + if (items.length > 1) items.forEach((x) => szAfter.add(x)); + }); + return ( + <> + 边际一阶重码计算 + + + +