Skip to content

Commit 358156b

Browse files
committed
Updates
1 parent d06f85a commit 358156b

9 files changed

Lines changed: 629 additions & 105 deletions

File tree

lib/src/components/SequenceTextArea.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ export default function SequenceTextArea({ str }: { str: [string, string][] }) {
2424
const [showGaps, setShowGaps] = useState(false)
2525
const [showEmpty, setShowEmpty] = useState(false)
2626

27+
const removeGaps = (s: string) => s.replaceAll('-', '').replaceAll('.', '')
2728
const disp = str
28-
.map(([s1, s2]) => [s1, showGaps ? s2 : s2.replaceAll('-', '')] as const)
29+
.map(([s1, s2]) => [s1, showGaps ? s2 : removeGaps(s2)] as const)
2930
.filter(f => (showEmpty ? true : !!f[1]))
30-
.map(([s1, s2]) => `>${s1}\n${showGaps ? s2 : s2.replaceAll('-', '')}`)
31+
.map(([s1, s2]) => `>${s1}\n${showGaps ? s2 : removeGaps(s2)}`)
3132
.join('\n')
3233
return (
3334
<>

lib/src/components/header/GappynessSlider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const GappynessSlider = observer(function GappynessSlider({
2525
max={100}
2626
value={allowedGappyness}
2727
onChange={(_, val) => {
28-
model.setAllowedGappyness(val as number)
28+
model.setAllowedGappyness(val)
2929
}}
3030
/>
3131
</div>

lib/src/components/header/HeaderMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React, { lazy } from 'react'
22

33
import CascadingMenuButton from '@jbrowse/core/ui/CascadingMenuButton'
4+
import AccountTree from '@mui/icons-material/AccountTree'
45
import Assignment from '@mui/icons-material/Assignment'
56
import FilterAlt from '@mui/icons-material/FilterAlt'
67
import FolderOpen from '@mui/icons-material/FolderOpen'
78
import MoreVert from '@mui/icons-material/Menu'
89
import PhotoCamera from '@mui/icons-material/PhotoCamera'
910
import Search from '@mui/icons-material/Search'
1011
import Sort from '@mui/icons-material/Sort'
11-
import AccountTree from '@mui/icons-material/AccountTree'
1212
import Visibility from '@mui/icons-material/Visibility'
1313
import { observer } from 'mobx-react'
1414

lib/src/components/msa/MSACanvasBlock.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ const MSACanvasBlock = observer(function ({
136136
}}
137137
/>
138138
{hoveredInsertion && mousePosition ? (
139-
<BaseTooltip clientPoint={{ x: mousePosition.x, y: mousePosition.y + 15 }}>
140-
Insertion ({hoveredInsertion.letters.length}bp): {hoveredInsertion.letters}
139+
<BaseTooltip
140+
clientPoint={{ x: mousePosition.x, y: mousePosition.y + 15 }}
141+
>
142+
Insertion ({hoveredInsertion.letters.length}bp):{' '}
143+
{hoveredInsertion.letters.length > 20
144+
? `${hoveredInsertion.letters.slice(0, 20)}...`
145+
: hoveredInsertion.letters}
141146
</BaseTooltip>
142147
) : null}
143148
</>

lib/src/components/msa/renderMSABlock.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export function renderMSABlock({
7575
drawInsertionIndicators({
7676
model,
7777
ctx,
78-
offsetX,
7978
xStart,
8079
xEnd,
8180
visibleLeaves,
@@ -247,13 +246,11 @@ function drawText({
247246
function drawInsertionIndicators({
248247
model,
249248
ctx,
250-
offsetX,
251249
visibleLeaves,
252250
xStart,
253251
xEnd,
254252
}: {
255253
model: MsaViewModel
256-
offsetX: number
257254
ctx: CanvasRenderingContext2D
258255
visibleLeaves: HierarchyNode<NodeWithIdsAndLength>[]
259256
xStart: number
@@ -273,7 +270,7 @@ function drawInsertionIndicators({
273270
const y = node.x!
274271
for (const { pos } of insertions) {
275272
if (pos >= xStart && pos < xEnd) {
276-
const x = pos * colWidth + offsetX - (offsetX % colWidth)
273+
const x = pos * colWidth
277274
const top = y - rowHeight
278275
const bottom = y
279276
ctx.beginPath()

lib/src/model.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ import {
4949
import { flatToTree } from './flatToTree'
5050
import palettes from './ggplotPalettes'
5151
import { measureTextCanvas } from './measureTextCanvas'
52-
import { calculateNeighborJoiningTree } from './neighborJoining'
5352
import { DataModelF } from './model/DataModel'
5453
import { DialogQueueSessionMixin } from './model/DialogQueue'
5554
import { MSAModelF } from './model/msaModel'
5655
import { TreeModelF } from './model/treeModel'
56+
import { calculateNeighborJoiningTree } from './neighborJoining'
5757
import { parseAsn1 } from './parseAsn1'
5858
import parseNewick from './parseNewick'
5959
import A3mMSA from './parsers/A3mMSA'
@@ -847,8 +847,10 @@ function stateModelFactory() {
847847
* Returns a map of row name to array of insertions with display position and letters
848848
*/
849849
get insertionPositions() {
850+
const { hideGapsEffective } = self
850851
const { blanks, rows } = this
851-
if (blanks.length === 0) {
852+
const blanksLen = blanks.length
853+
if (blanksLen === 0 || !hideGapsEffective) {
852854
return new Map<string, { pos: number; letters: string }[]>()
853855
}
854856
const result = new Map<string, { pos: number; letters: string }[]>()
@@ -857,28 +859,36 @@ function stateModelFactory() {
857859
let displayPos = 0
858860
let blankIdx = 0
859861
let currentInsertPos = -1
860-
let currentLetters = ''
861-
for (let i = 0; i < seq.length; i++) {
862-
if (blankIdx < blanks.length && blanks[blankIdx] === i) {
863-
const char = seq[i]!
864-
if (char !== '-' && char !== '.') {
862+
let letterChars: string[] = []
863+
const seqLen = seq.length
864+
for (let i = 0; i < seqLen; i++) {
865+
if (blankIdx < blanksLen && blanks[blankIdx] === i) {
866+
// bit trick: (code - 45) >>> 0 <= 1 checks for '-' (45) or '.' (46)
867+
const code = seq.charCodeAt(i)
868+
if (!((code - 45) >>> 0 <= 1)) {
865869
if (currentInsertPos === displayPos) {
866-
currentLetters += char
870+
letterChars.push(seq[i]!)
867871
} else {
868-
if (currentLetters) {
869-
insertions.push({ pos: currentInsertPos, letters: currentLetters })
872+
if (letterChars.length > 0) {
873+
insertions.push({
874+
pos: currentInsertPos,
875+
letters: letterChars.join(''),
876+
})
870877
}
871878
currentInsertPos = displayPos
872-
currentLetters = char
879+
letterChars = [seq[i]!]
873880
}
874881
}
875882
blankIdx++
876883
} else {
877884
displayPos++
878885
}
879886
}
880-
if (currentLetters) {
881-
insertions.push({ pos: currentInsertPos, letters: currentLetters })
887+
if (letterChars.length > 0) {
888+
insertions.push({
889+
pos: currentInsertPos,
890+
letters: letterChars.join(''),
891+
})
882892
}
883893
if (insertions.length > 0) {
884894
result.set(name, insertions)

0 commit comments

Comments
 (0)