Skip to content

Commit a8ded30

Browse files
committed
Misc
1 parent 7d19426 commit a8ded30

16 files changed

+163
-127
lines changed

eslint.config.mjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import eslintPluginReactHooks from 'eslint-plugin-react-hooks'
44
import eslintPluginReactRefresh from 'eslint-plugin-react-refresh'
55
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
66
import tseslint from 'typescript-eslint'
7-
import globals from 'globals'
87

98
export default tseslint.config(
109
{
11-
ignores: ['**/dist/**/*'],
10+
ignores: [
11+
'**/dist/**/*',
12+
'jest.config.js',
13+
'eslint.config.mjs',
14+
'esbuild.mjs',
15+
],
1216
},
1317
{
1418
languageOptions: {
@@ -63,8 +67,17 @@ export default tseslint.config(
6367
},
6468
],
6569

70+
'@typescript-eslint/no-unsafe-argument': 'off',
71+
'@typescript-eslint/no-unsafe-return': 'off',
72+
'@typescript-eslint/no-unsafe-call': 'off',
6673
'@typescript-eslint/no-non-null-assertion': 'off',
6774
'@typescript-eslint/ban-ts-comment': 'off',
75+
'@typescript-eslint/no-unsafe-assignment': 'off',
76+
'@typescript-eslint/restrict-template-expressions': 'off',
77+
'@typescript-eslint/no-empty-function': 'off',
78+
79+
'unicorn/no-null': 'off',
80+
'unicorn/prefer-spread': 'off',
6881
'unicorn/no-useless-undefined': 'off',
6982
'unicorn/catch-error-name': 'off',
7083
'unicorn/filename-case': 'off',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"prebuild": "npm run clean",
1818
"start": "node esbuild.mjs",
1919
"build": "tsc && NODE_ENV=production node esbuild.mjs",
20-
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src/",
20+
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
2121
"prepack": "npm run build",
2222
"postversion": "git push --follow-tags"
2323
},

src/AddHighlightModel/ProteinToGenomeClickHighlight.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ const ProteinToGenomeClickHighlight = observer(function ({
1616
}) {
1717
const { assemblyManager, views } = getSession(model)
1818
const { assemblyNames } = model
19-
const p = views.find(
20-
f => f.type === 'ProteinView',
21-
) as JBrowsePluginProteinViewModel
22-
const assembly = assemblyManager.get(assemblyNames[0])
19+
const p = views.find(f => f.type === 'ProteinView') as
20+
| JBrowsePluginProteinViewModel
21+
| undefined
22+
const assemblyName = assemblyNames[0]!
23+
const assembly = assemblyManager.get(assemblyName)
2324
return assembly ? (
2425
<>
25-
{p.clickGenomeHighlights.map((r, idx) => (
26+
{p?.clickGenomeHighlights.map((r, idx) => (
2627
<Highlight
2728
key={`${JSON.stringify(r)}-${idx}}`}
2829
start={r.start}
2930
end={r.end}
3031
refName={r.refName}
31-
assemblyName={assemblyNames[0]}
32+
assemblyName={assemblyName}
3233
model={model}
3334
/>
3435
))}

src/AddHighlightModel/ProteinToGenomeHoverHighlight.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ const ProteinToGenomeHoverHighlight = observer(function ({
1616
}) {
1717
const { assemblyManager, views } = getSession(model)
1818
const { assemblyNames } = model
19-
const p = views.find(
20-
f => f.type === 'ProteinView',
21-
) as JBrowsePluginProteinViewModel
22-
const assembly = assemblyManager.get(assemblyNames[0])
19+
const p = views.find(f => f.type === 'ProteinView') as
20+
| JBrowsePluginProteinViewModel
21+
| undefined
22+
const assemblyName = assemblyNames[0]!
23+
const assembly = assemblyManager.get(assemblyName)
2324
return assembly ? (
2425
<>
25-
{p.hoverGenomeHighlights.map((r, idx) => (
26+
{p?.hoverGenomeHighlights.map((r, idx) => (
2627
<Highlight
2728
key={`${JSON.stringify(r)}-${idx}`}
2829
start={r.start}
2930
end={r.end}
3031
refName={r.refName}
31-
assemblyName={assemblyNames[0]}
32+
assemblyName={assemblyName}
3233
model={model}
3334
/>
3435
))}

src/AddHighlightModel/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const useStyles = makeStyles()({
66
background: 'rgba(255,255,0,0.2)',
77
border: '1px solid rgba(50,50,0,0.2)',
88
position: 'absolute',
9-
zIndex: 1000,
9+
zIndex: 99,
1010
textAlign: 'center',
1111
pointerEvents: 'none',
1212
overflow: 'hidden',

src/LaunchProteinView/components/UserProvidedStructure.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ const UserProvidedStructure = observer(function ({
102102
const { seq: structureSequence2, error: error4 } =
103103
useRemoteStructureFileSequence({ url: structureURL })
104104
const structureName =
105-
file?.name ??
106-
structureURL.slice(structureURL.lastIndexOf('/') + 1) ??
107-
'structureSequence'
105+
file?.name ?? structureURL.slice(structureURL.lastIndexOf('/') + 1)
108106
const structureSequence = structureSequence1 ?? structureSequence2
109107

110108
useEffect(() => {

src/LaunchProteinView/components/calculateProteinSequence.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function calculateProteinSequence({
3030
let protein = ''
3131
for (let i = 0; i < str.length; i += 3) {
3232
// use & symbol for undefined codon, or partial slice
33-
protein += codonTable[str.slice(i, i + 3)] || '&'
33+
protein += codonTable[str.slice(i, i + 3)] ?? '&'
3434
}
3535
return protein
3636
}

src/LaunchProteinView/index.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,51 @@ import PluginManager from '@jbrowse/core/PluginManager'
22
import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType'
33
import { PluggableElementType } from '@jbrowse/core/pluggableElementTypes'
44
import { IAnyModelType } from 'mobx-state-tree'
5-
import { getSession, getContainingTrack } from '@jbrowse/core/util'
5+
import { getSession, getContainingTrack, Feature } from '@jbrowse/core/util'
66

77
// icons
88
import AddIcon from '@mui/icons-material/Add'
99

1010
// locals
1111
import LaunchProteinViewDialog from './components/LaunchProteinViewDialog'
12+
import { MenuItem } from '@jbrowse/core/ui'
1213

1314
function isDisplay(elt: { name: string }): elt is DisplayType {
1415
return elt.name === 'LinearBasicDisplay'
1516
}
1617

1718
function extendStateModel(stateModel: IAnyModelType) {
18-
return stateModel.views(self => {
19-
const superContextMenuItems = self.contextMenuItems
20-
return {
21-
contextMenuItems() {
22-
const feature = self.contextMenuFeature
23-
const track = getContainingTrack(self)
24-
return [
25-
...superContextMenuItems(),
26-
...(feature
27-
? [
28-
{
29-
label: 'Launch 3-D protein view',
30-
icon: AddIcon,
31-
onClick: () => {
32-
getSession(track).queueDialog(handleClose => [
33-
LaunchProteinViewDialog,
34-
{ model: track, handleClose, feature },
35-
])
19+
return stateModel.views(
20+
(self: {
21+
contextMenuItems: () => MenuItem[]
22+
contextMenuFeature?: Feature
23+
}) => {
24+
const superContextMenuItems = self.contextMenuItems
25+
return {
26+
contextMenuItems() {
27+
const feature = self.contextMenuFeature
28+
const track = getContainingTrack(self)
29+
return [
30+
...superContextMenuItems(),
31+
...(feature
32+
? [
33+
{
34+
label: 'Launch 3-D protein view',
35+
icon: AddIcon,
36+
onClick: () => {
37+
getSession(track).queueDialog(handleClose => [
38+
LaunchProteinViewDialog,
39+
{ model: track, handleClose, feature },
40+
])
41+
},
3642
},
37-
},
38-
]
39-
: []),
40-
]
41-
},
42-
}
43-
})
43+
]
44+
: []),
45+
]
46+
},
47+
}
48+
},
49+
)
4450
}
4551

4652
export default function LaunchProteinViewF(pluginManager: PluginManager) {

src/ProteinView/components/ProteinAlignment.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ const ProteinAlignment = observer(function ({
2323
alignmentToStructurePosition,
2424
showHighlight,
2525
} = model
26-
const a0 = alignment!.alns[0].seq as string
27-
const a1 = alignment!.alns[1].seq as string
28-
const con = alignment!.consensus
26+
if (!alignment) {
27+
return <div>No alignment</div>
28+
}
29+
const a0 = alignment.alns[0]!.seq as string
30+
const a1 = alignment.alns[1]!.seq as string
31+
const con = alignment.consensus
2932
const set = new Set<number>()
3033
// eslint-disable-next-line unicorn/no-for-loop
3134
for (let i = 0; i < con.length; i++) {
@@ -47,7 +50,7 @@ const ProteinAlignment = observer(function ({
4750
}
4851
function onClick(alignmentPos: number) {
4952
const structureSeqPos = alignmentToStructurePosition[alignmentPos]
50-
clickProteinToGenome({ model, structureSeqPos }).catch(e => {
53+
clickProteinToGenome({ model, structureSeqPos }).catch((e: unknown) => {
5154
console.error(e)
5255
})
5356
}

src/ProteinView/components/ProteinView.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ import clearSelection from '../clearSelection'
2020
// css
2121
import css from '../css/molstar'
2222

23-
if (document.head) {
24-
const style = document.createElement('style')
25-
style.append(css)
26-
document.head.append(style)
27-
}
23+
const style = document.createElement('style')
24+
style.append(css)
25+
document.head.append(style)
2826

2927
const ProteinView = observer(function ({
3028
model,
@@ -98,9 +96,10 @@ const ProteinViewContainer = observer(function ({
9896
}, [plugin, structure, showHighlight, structureSeqToTranscriptSeqPosition])
9997

10098
useEffect(() => {
101-
if (!plugin || !structure || structureSeqHoverPos === undefined) {
99+
if (!plugin || !structure) {
102100
return
103101
}
102+
104103
if (structureSeqHoverPos === undefined) {
105104
console.warn('not found')
106105
} else {

0 commit comments

Comments
 (0)