Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 19, 2024
1 parent c79ec18 commit 7eeb46e
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 154 deletions.
8 changes: 6 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import eslintPluginReactHooks from 'eslint-plugin-react-hooks'
import eslintPluginReactRefresh from 'eslint-plugin-react-refresh'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import tseslint from 'typescript-eslint'
import globals from 'globals'

export default tseslint.config(
{
ignores: ['**/dist/**/*'],
ignores: ['**/dist/**/*', 'esbuild.mjs', 'eslint.config.mjs', 'ucsc/*'],
},
{
languageOptions: {
Expand Down Expand Up @@ -63,6 +62,11 @@ export default tseslint.config(
},
],

'unicorn/no-null': 'off',

'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"format": "prettier --write .",
"build": "tsc && NODE_ENV=production node esbuild.mjs",
"prebuild": "npm run clean",
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src/",
"lint": "eslint --report-unused-disable-directives --max-warnings 0",
"prepack": "npm run build",
"postversion": "git push --follow-tags"
},
Expand Down
6 changes: 4 additions & 2 deletions src/AddHighlightModel/MsaToGenomeHighlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const MsaToGenomeHighlight = observer(function MsaToGenomeHighlight2({
}) {
const { classes } = useStyles()
const { assemblyManager, views } = getSession(model)
const p = views.find(f => f.type === 'MsaView') as JBrowsePluginMsaViewModel
const p = views.find(f => f.type === 'MsaView') as
| JBrowsePluginMsaViewModel
| undefined
const assembly = assemblyManager.get(model.assemblyNames[0]!)
return assembly ? (
<>
{p.connectedHighlights.map((r, idx) => {
{p?.connectedHighlights.map((r, idx) => {
const refName = getCanonicalName(assembly, r.refName)
const s = model.bpToPx({ refName, coord: r.start })
const e = model.bpToPx({ refName, coord: r.end })
Expand Down
2 changes: 1 addition & 1 deletion src/AddHighlightModel/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const useStyles = makeStyles()({
background: 'rgba(255,255,0,0.2)',
border: '1px solid rgba(50,50,0,0.2)',
position: 'absolute',
zIndex: 1000,
zIndex: 99,
textAlign: 'center',
pointerEvents: 'none',
overflow: 'hidden',
Expand Down
3 changes: 2 additions & 1 deletion src/LaunchMsaView/components/LaunchMsaViewDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { AbstractTrackModel, Feature } from '@jbrowse/core/util'

// locals

import { CustomTabPanel, a11yProps } from './TabUtils'
import CustomTabPanel from './TabUtils'
import NewNcbiBlastQueryPanel from './NewNCBIBlastQuery'
import PreLoadedMSA from './PreLoadedMSA/PreLoadedMSADataPanel'
import { a11yProps } from './tabUtil'

export default function LaunchProteinViewDialog({
handleClose,
Expand Down
105 changes: 69 additions & 36 deletions src/LaunchMsaView/components/NewNCBIBlastQuery/useFeatureSequence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'

import { Feature, getSession } from '@jbrowse/core/util'
import { AbstractSessionModel, Feature, getSession } from '@jbrowse/core/util'
import { getConf } from '@jbrowse/core/configuration'

export interface SeqState {
Expand All @@ -14,6 +14,40 @@ export interface ErrorState {
}
const BPLIMIT = 500_000

async function fetchSeq({
start,
end,
refName,
session,
assemblyName,
}: {
start: number
end: number
refName: string
assemblyName: string
session: AbstractSessionModel
}) {
const { assemblyManager, rpcManager } = session
const assembly = await assemblyManager.waitForAssembly(assemblyName)
if (!assembly) {
throw new Error('assembly not found')
}
const sessionId = 'getSequence'
const feats = (await rpcManager.call(sessionId, 'CoreGetFeatures', {
adapterConfig: getConf(assembly, ['sequence', 'adapter']),
sessionId,
regions: [
{
start,
end,
refName: assembly.getCanonicalRefName(refName),
assemblyName,
},
],
})) as Feature[]
return (feats[0]?.get('seq') as string | undefined) ?? ''
}

export function useFeatureSequence({
view,
feature,
Expand All @@ -27,61 +61,60 @@ export function useFeatureSequence({
}) {
const [sequence, setSequence] = useState<SeqState | ErrorState>()
const [error, setError] = useState<unknown>()
const assemblyName = view?.assemblyNames?.[0]
useEffect(() => {
if (view) {
const { assemblyManager, rpcManager } = getSession(view)
const assemblyName = view.assemblyNames?.[0]
async function fetchSeq(start: number, end: number, refName: string) {
const assembly = assemblyName
? await assemblyManager.waitForAssembly(assemblyName)
: undefined
if (!assembly) {
throw new Error('assembly not found')
}
const sessionId = 'getSequence'
const feats = await rpcManager.call(sessionId, 'CoreGetFeatures', {
adapterConfig: getConf(assembly, ['sequence', 'adapter']),
sessionId,
regions: [
{
start,
end,
refName: assembly.getCanonicalRefName(refName),
assemblyName,
},
],
})

const [feat] = feats as Feature[]
return (feat?.get('seq') as string | undefined) || ''
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
setError(undefined)
setSequence(undefined)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { start, end, refName } = feature.toJSON() as any

const session = getSession(view)
const { start, end, refName } = feature.toJSON() as {
start: number
end: number
refName: string
}
if (!assemblyName) {
throw new Error('No assembly found')
}
if (!forceLoad && end - start > BPLIMIT) {
setSequence({
error: `Genomic sequence larger than ${BPLIMIT}bp, use "force load" button to display`,
})
} else {
const b = start - upDownBp
const e = end + upDownBp
const seq = await fetchSeq(start, end, refName)
const up = await fetchSeq(Math.max(0, b), start, refName)
const down = await fetchSeq(end, e, refName)
setSequence({ seq, upstream: up, downstream: down })
setSequence({
seq: await fetchSeq({
start,
end,
refName,
assemblyName,
session,
}),
upstream: await fetchSeq({
start: Math.max(0, b),
end: start,
refName,
assemblyName,
session,
}),
downstream: await fetchSeq({
start: end,
end: e,
refName,
assemblyName,
session,
}),
})
}
} catch (e) {
console.error(e)
setError(e)
}
})()
}
}, [feature, view, upDownBp, forceLoad])
}, [feature, view, upDownBp, assemblyName, forceLoad])
return { sequence, error }
}
8 changes: 1 addition & 7 deletions src/LaunchMsaView/components/TabUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface TabPanelProps {
value: number
}

export function CustomTabPanel(props: TabPanelProps) {
export default function CustomTabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props

return (
Expand All @@ -22,9 +22,3 @@ export function CustomTabPanel(props: TabPanelProps) {
</div>
)
}
export function a11yProps(index: number) {
return {
id: `gtab-${index}`,
'aria-controls': `gtabpanel-${index}`,
}
}
6 changes: 6 additions & 0 deletions src/LaunchMsaView/components/tabUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function a11yProps(index: number) {
return {
id: `gtab-${index}`,
'aria-controls': `gtabpanel-${index}`,
}
}
67 changes: 36 additions & 31 deletions src/LaunchMsaView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,55 @@ import PluginManager from '@jbrowse/core/PluginManager'
import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType'
import { PluggableElementType } from '@jbrowse/core/pluggableElementTypes'
import { IAnyModelType } from 'mobx-state-tree'
import { getSession, getContainingTrack } from '@jbrowse/core/util'
import { getSession, getContainingTrack, Feature } from '@jbrowse/core/util'

// icons
import AddIcon from '@mui/icons-material/Add'

// locals
import LaunchMsaViewDialog from './components/LaunchMsaViewDialog'
import { MenuItem } from '@jbrowse/core/ui'

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

function extendStateModel(stateModel: IAnyModelType) {
return stateModel.views(self => {
const superContextMenuItems = self.contextMenuItems
return {
contextMenuItems() {
const feature = self.contextMenuFeature
const track = getContainingTrack(self)
return [
...superContextMenuItems(),
...(feature
? [
{
label: 'Launch MSA view',
icon: AddIcon,
onClick: () => {
const session = getSession(track)
session.queueDialog(handleClose => [
LaunchMsaViewDialog,
{
model: track,
handleClose,
feature,
},
])
return stateModel.views(
(self: {
contextMenuItems: () => MenuItem[]
contextMenuFeature?: Feature
}) => {
const superContextMenuItems = self.contextMenuItems
return {
contextMenuItems() {
const feature = self.contextMenuFeature
const track = getContainingTrack(self)
return [
...superContextMenuItems(),
...(feature
? [
{
label: 'Launch MSA view',
icon: AddIcon,
onClick: () => {
getSession(track).queueDialog(handleClose => [
LaunchMsaViewDialog,
{
model: track,
handleClose,
feature,
},
])
},
},
},
]
: []),
]
},
}
})
]
: []),
]
},
}
},
)
}

export default function LaunchMsaViewF(pluginManager: PluginManager) {
Expand Down
4 changes: 2 additions & 2 deletions src/LaunchMsaView/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export function getTranscriptFeatures(feature: Feature) {
f.get('subfeatures')?.some(f => f.get('type') === 'CDS'),
)
}
export function getId(val?: Feature) {
return val === undefined ? '' : val.get('name') || val.get('id')
export function getId(val?: Feature): string {
return val?.get('name') || val?.get('id') || ''
}

export function getTranscriptDisplayName(val?: Feature) {
Expand Down
8 changes: 4 additions & 4 deletions src/MsaViewPanel/msaCoordToGenomeCoord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export function msaCoordToGenomeCoord({
coord: number
}) {
const { transcriptToMsaMap } = model
if (mouseCol === undefined || transcriptToMsaMap === undefined) {
if (transcriptToMsaMap === undefined) {
return
}

const c = mouseCol - 1
const k1 = model.globalCoordToRowSpecificSeqCoord('QUERY', c) || 0
const k2 = model.globalCoordToRowSpecificSeqCoord('QUERY', c + 1) || 0
const c = mouseCol
const k1 = model.seqCoordToRowSpecificGlobalCoord('QUERY', c) || 0
const k2 = model.seqCoordToRowSpecificGlobalCoord('QUERY', c + 1) || 0
const { refName, p2g } = transcriptToMsaMap
const s = p2g[k1]
const e = p2g[k2]
Expand Down
3 changes: 3 additions & 0 deletions src/utils/msa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async function wait({
algorithm: string
onProgress: (arg: string) => void
}) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
for (let i = 0; i < 10; i++) {
await timeout(1000)
Expand All @@ -107,6 +108,8 @@ async function wait({

if (result === 'FINISHED') {
break
} else if (result.includes('FAILURE')) {
throw new Error(`Failed to run: jobId ${jobId}`)
}
}
}
Expand Down
Loading

0 comments on commit 7eeb46e

Please sign in to comment.