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 90503cf
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 118 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useFeatureSequence({
throw new Error('assembly not found')
}
const sessionId = 'getSequence'
const feats = await rpcManager.call(sessionId, 'CoreGetFeatures', {
const feats = (await rpcManager.call(sessionId, 'CoreGetFeatures', {
adapterConfig: getConf(assembly, ['sequence', 'adapter']),
sessionId,
regions: [
Expand All @@ -50,19 +50,25 @@ export function useFeatureSequence({
assemblyName,
},
],
})
})) as Feature[]

const [feat] = feats as Feature[]
return (feat?.get('seq') as string | undefined) || ''
const res = (feats[0]?.get('seq') as string | undefined) ?? ''
if (!res) {
throw new Error('no sequence')
}
return res
}

// 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 { start, end, refName } = feature.toJSON() as {
start: number
end: number
refName: string
}

if (!forceLoad && end - start > BPLIMIT) {
setSequence({
Expand Down
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
2 changes: 1 addition & 1 deletion src/MsaViewPanel/msaCoordToGenomeCoord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function msaCoordToGenomeCoord({
coord: number
}) {
const { transcriptToMsaMap } = model
if (mouseCol === undefined || transcriptToMsaMap === undefined) {
if (transcriptToMsaMap === undefined) {
return
}

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
28 changes: 20 additions & 8 deletions src/utils/ncbiBlast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@ export async function queryBlast({
})
onRid(rid)
await waitForRid({ rid, onProgress })
const ret = await jsonfetch(
const ret = (await jsonfetch(
`${BLAST_URL}?CMD=Get&RID=${rid}&FORMAT_TYPE=JSON2_S&FORMAT_OBJECT=Alignment`,
)
const hits = ret.BlastOutput2[0].report.results.search.hits as {
description: { accession: string; id: string; sciname: string }[]
hsps: { hseq: string }[]
}[]

return { rid, hits }
)) as {
BlastOutput2: {
report: {
results: {
search: {
hits: {
description: { accession: string; id: string; sciname: string }[]
hsps: { hseq: string }[]
}[]
}
}
}
}[]
}
return {
rid,
hits: ret.BlastOutput2[0]?.report.results.search.hits ?? [],
}
}

async function initialQuery({
Expand Down Expand Up @@ -78,6 +89,7 @@ async function waitForRid({
rid: string
onProgress: (arg: string) => void
}) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
const iter = 20
for (let i = 0; i < iter; i++) {
Expand Down
Loading

0 comments on commit 90503cf

Please sign in to comment.