From 497fc85f590892011639a552e10401b43dfc660b Mon Sep 17 00:00:00 2001 From: ivan-aksamentov Date: Wed, 18 Jan 2023 14:15:51 +0100 Subject: [PATCH] feat: show position indices in msa viewer --- src/components/Msa/Msa.tsx | 4 +- src/components/Msa/MsaPositionRow.tsx | 62 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/components/Msa/MsaPositionRow.tsx diff --git a/src/components/Msa/Msa.tsx b/src/components/Msa/Msa.tsx index 2342644..dc56b6c 100644 --- a/src/components/Msa/Msa.tsx +++ b/src/components/Msa/Msa.tsx @@ -8,8 +8,8 @@ import styled from 'styled-components' import { Card, CardBody, CardHeader, Col, Container, Row } from 'reactstrap' import { LOADING } from 'src/components/Loading/Loading' import { MSA_CHAR_HEIGHT, MSA_CHAR_WIDTH } from 'src/components/Msa/MsaCharacter' +import { MsaRefSequence } from 'src/components/Msa/MsaPositionRow' import { MsaRow } from 'src/components/Msa/MsaRow' -import { MsaSequence } from 'src/components/Msa/MsaSequence' import { useTranslationSafe } from 'src/helpers/useTranslationSafe' import type { GeneCluster, SpeciesDesc } from 'src/hooks/useDataIndexQuery' import { SequenceType, useGeneClusterData } from 'src/hooks/useDataIndexQuery' @@ -151,7 +151,7 @@ function MsaSized({ species, gene, seqType, width, height }: MsaSizedProps) { {rows} - + diff --git a/src/components/Msa/MsaPositionRow.tsx b/src/components/Msa/MsaPositionRow.tsx new file mode 100644 index 0000000..35c8e0b --- /dev/null +++ b/src/components/Msa/MsaPositionRow.tsx @@ -0,0 +1,62 @@ +/* eslint-disable react/no-array-index-key */ +import React, { ComponentProps, ForwardedRef, forwardRef, useMemo } from 'react' +import Konva from 'konva' +import { Group, Rect, Text } from 'react-konva' +import { MSA_CHAR_HEIGHT, MSA_CHAR_WIDTH, MsaCharacter } from 'src/components/Msa/MsaCharacter' +import type { SequenceType } from 'src/hooks/useDataIndexQuery' + +const MSA_POS_FONT_SIZE = 8 + +export interface MsaRefSequenceProps extends ComponentProps { + seq: string + seqType: SequenceType +} + +export const MsaRefSequence = forwardRef(function MsaRefSequenceWithRef( + { seq, seqType, ...restProps }: MsaRefSequenceProps, + ref: ForwardedRef, +) { + const chars = useMemo( + () => + seq.split('').map((c, pos) => ( + + {(pos + 1) % 2 === 0 && } + + + )), + [seq, seqType], + ) + return ( + + {chars} + + ) +}) + +export interface MsaPositionProps extends ComponentProps { + pos: number +} + +function MsaPosition({ pos, ...restProps }: MsaPositionProps) { + const text = useMemo(() => { + return ( + + ) + }, [pos]) + + return ( + + + {text} + + ) +}