Skip to content

Commit

Permalink
Lint error fixes (#420)
Browse files Browse the repository at this point in the history
* fixes

* fixes

* A few type changes

---------

Co-authored-by: Garrett Stevens <stevens.garrett.j@gmail.com>
  • Loading branch information
shashankbrgowda and garrettjstevens authored Aug 13, 2024
1 parent ce52e14 commit 9b6cf97
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 73 deletions.
14 changes: 6 additions & 8 deletions packages/apollo-shared/src/GFF3/gff3ToAnnotationFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ export function gff3ToAnnotationFeature(
if (type !== 'CDS') {
throw new Error('GFF3 features has multiple locations but is not a CDS')
}
const mins = gff3Feature
.map((f) => {
if (f.start === null) {
throw new Error(`feature does not have start: ${JSON.stringify(f)}`)
}
return f.start - 1
})
.filter<number>((m): m is number => m !== null)
const mins = gff3Feature.map((f) => {
if (f.start === null) {
throw new Error(`feature does not have start: ${JSON.stringify(f)}`)
}
return f.start - 1
})
const maxes = gff3Feature
.map((f) => f.end)
.filter<number>((m): m is number => m !== null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AnnotationFeature } from '@apollo-annotation/mst'
import { AnnotationFeature, ApolloRefSeqI } from '@apollo-annotation/mst'
import { AbstractSessionModel, getSession, revcom } from '@jbrowse/core/util'
import { observer } from 'mobx-react'
import { IAnyStateTreeNode, getRoot } from 'mobx-state-tree'
import { getRoot } from 'mobx-state-tree'
import React from 'react'

import { ApolloInternetAccountModel } from '../ApolloInternetAccount/model'
Expand All @@ -10,6 +10,7 @@ import { ApolloRootModel } from '../types'
import { Attributes } from './Attributes'
import { TranscriptBasicInformation } from './TranscriptBasic'
import { TranscriptSequence } from './TranscriptSequence'
import { ApolloTranscriptDetailsWidget as ApolloTranscriptDetailsWidgetState } from './model'

export interface CDSInfo {
id: string
Expand All @@ -29,8 +30,7 @@ export interface ExonInfo {

export const getCDSInfo = (
feature: AnnotationFeature,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
refData: any,
refData: ApolloRefSeqI,
): CDSInfo[] => {
const CDSresult: CDSInfo[] = []
const traverse = (
Expand Down Expand Up @@ -64,8 +64,8 @@ export const getCDSInfo = (
max: (currentFeature.max + 1) as unknown as string,
oldMin: (currentFeature.min + 1) as unknown as string,
oldMax: (currentFeature.max + 1) as unknown as string,
startSeq: startSeq ?? '',
endSeq: endSeq ?? '',
startSeq: startSeq || '',
endSeq: endSeq || '',
}
CDSresult.push(oneCDS)
}
Expand Down Expand Up @@ -104,7 +104,9 @@ export const getCDSInfo = (
}

export const ApolloTranscriptDetailsWidget = observer(
function ApolloTranscriptDetails(props: { model: IAnyStateTreeNode }) {
function ApolloTranscriptDetails(props: {
model: ApolloTranscriptDetailsWidgetState
}) {
const { model } = props
const { assembly, feature, refName } = model
const session = getSession(model) as unknown as AbstractSessionModel
Expand All @@ -126,12 +128,12 @@ export const ApolloTranscriptDetailsWidget = observer(
if (!refSeq) {
return null
}
const { end, start } = feature
const { max, min } = feature

const sequence = refSeq.getSequence(start, end)
const sequence = refSeq.getSequence(min, max)
if (!sequence) {
void apolloSession.apolloDataStore.loadRefSeq([
{ assemblyName: assembly, refName, start, end },
{ assemblyName: assembly, refName, start: min, end: max },
])
}

Expand All @@ -140,21 +142,21 @@ export const ApolloTranscriptDetailsWidget = observer(
<TranscriptBasicInformation
feature={feature}
session={apolloSession}
assembly={currentAssembly ? currentAssembly._id : ''}
assembly={currentAssembly._id || ''}
refName={refName}
/>
<hr />
<Attributes
feature={feature}
session={apolloSession}
assembly={currentAssembly ? currentAssembly._id : ''}
assembly={currentAssembly._id || ''}
editable={editable}
/>
<hr />
<TranscriptSequence
feature={feature}
session={apolloSession}
assembly={currentAssembly ? currentAssembly._id : ''}
assembly={currentAssembly._id || ''}
refName={refName}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ import { NumberTextField } from './NumberTextField'
* @param featureId -
* @returns
*/
function getFeatureFromId(feature: any, featureId: string): any | null {
function getFeatureFromId(
feature: AnnotationFeature,
featureId: string,
): AnnotationFeature | null {
if (feature._id === featureId) {
return feature
}
// Check if there is also childFeatures in parent feature and it's not empty
// Let's get featureId from recursive method
for (const [, childFeature] of feature.children ?? new Map()) {
if (!feature.children) {
return null
}
for (const [, childFeature] of feature.children) {
const subFeature = getFeatureFromId(childFeature, featureId)
if (subFeature) {
return subFeature
Expand Down Expand Up @@ -106,11 +112,12 @@ export const TranscriptBasicInformation = observer(
newStart,
assembly,
})
return changeManager.submit(change)
changeManager.submit(change).catch(() => {
notify('Error updating feature start position')
})
}
}
}
return
}

function handleEndChange(
Expand All @@ -123,7 +130,7 @@ export const TranscriptBasicInformation = observer(
notify('Feature start cannot be greater than parent end', 'error')
return
}
if (subFeature.children) {
if (subFeature?.children) {
// Let's check CDS start and end values. And possibly update those too
for (const child of subFeature.children) {
if (
Expand All @@ -138,11 +145,12 @@ export const TranscriptBasicInformation = observer(
newEnd,
assembly,
})
return changeManager.submit(change)
changeManager.submit(change).catch(() => {
notify('Error updating feature end position')
})
}
}
}
return
}

const featureNew = feature as unknown as AnnotationFeature
Expand Down Expand Up @@ -188,8 +196,8 @@ export const TranscriptBasicInformation = observer(
max: dataPoint.max as unknown as string,
oldMin: (dataPoint.min + 1) as unknown as string,
oldMax: dataPoint.max as unknown as string,
startSeq: startSeq ?? '',
endSeq: endSeq ?? '',
startSeq: startSeq || '',
endSeq: endSeq || '',
}
// CDSresult.push(oneCDS)
// Check if there is already an object with the same start and end
Expand All @@ -206,7 +214,7 @@ export const TranscriptBasicInformation = observer(
}

// Add possible UTRs
const foundExon = findExonInRange(
const foundExon: ExonInfo | null = findExonInRange(
exonsArray,
dataPoint.min + 1,
dataPoint.max,
Expand All @@ -231,9 +239,11 @@ export const TranscriptBasicInformation = observer(
type: 'three_prime_UTR',
strand: Number(feature.strand),
min: (dataPoint.min + 1) as unknown as string,
max: foundExon.min + 1,
max: ((foundExon.min as unknown as number) +
1) as unknown as string,
oldMin: (dataPoint.min + 1) as unknown as string,
oldMax: foundExon.min + 1,
oldMax: ((foundExon.min as unknown as number) +
1) as unknown as string,
startSeq: '',
endSeq: '',
}
Expand Down Expand Up @@ -302,9 +312,10 @@ export const TranscriptBasicInformation = observer(
id: featureNew._id,
type: 'five_prime_UTR',
strand: Number(featureNew.strand),
min: (element.min + 1) as unknown as string,
min: ((element.min as unknown as number) + 1) as unknown as string,
max: element.max,
oldMin: (element.min + 1) as unknown as string,
oldMin: ((element.min as unknown as number) +
1) as unknown as string,
oldMax: element.max,
startSeq: '',
endSeq: '',
Expand All @@ -315,10 +326,12 @@ export const TranscriptBasicInformation = observer(
id: featureNew._id,
type: 'three_prime_UTR',
strand: Number(featureNew.strand),
min: (element.min + 1) as unknown as string,
max: element.max + 1,
oldMin: (element.min + 1) as unknown as string,
oldMax: element.max + 1,
min: ((element.min as unknown as number) + 1) as unknown as string,
max: ((element.max as unknown as number) + 1) as unknown as string,
oldMin: ((element.min as unknown as number) +
1) as unknown as string,
oldMax: ((element.max as unknown as number) +
1) as unknown as string,
startSeq: '',
endSeq: '',
}
Expand Down Expand Up @@ -395,9 +408,9 @@ export const TranscriptBasicInformation = observer(
}}
variant="outlined"
value={item.min}
onChangeCommitted={(newStart: number) =>
onChangeCommitted={(newStart: number) => {
handleStartChange(newStart, item.id, Number(item.oldMin))
}
}}
/>
<span style={{ margin: '0 10px' }}>
{item.strand === -1 ? '-' : item.strand === 1 ? '+' : ''}

Check failure on line 416 in packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/TranscriptBasic.tsx

View workflow job for this annotation

GitHub Actions / Lint

Nest ternary expression should be parenthesized
Expand All @@ -416,9 +429,9 @@ export const TranscriptBasicInformation = observer(
}}
variant="outlined"
value={item.max}
onChangeCommitted={(newEnd: number) =>
onChangeCommitted={(newEnd: number) => {
handleEndChange(newEnd, item.id, Number(item.oldMax))
}
}}
/>
<span style={{ marginLeft: '8px', fontWeight: 'bold' }}>
{item.endSeq}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnnotationFeature } from '@apollo-annotation/mst'
import { AnnotationFeature, ApolloRefSeqI } from '@apollo-annotation/mst'
import { splitStringIntoChunks } from '@apollo-annotation/shared'
import { revcom } from '@jbrowse/core/util'
import {
Expand Down Expand Up @@ -52,11 +52,11 @@ export const TranscriptSequence = observer(function TranscriptSequence({
session: ApolloSessionModel
}) {
const currentAssembly = session.apolloDataStore.assemblies.get(assembly)
const refData = currentAssembly?.getByRefName(refName)
const refData = currentAssembly?.getByRefName(refName) as ApolloRefSeqI
const [showSequence, setShowSequence] = useState(false)
const [selectedOption, setSelectedOption] = useState('Select')

if (!(feature && currentAssembly)) {
if (!currentAssembly) {
return null
}
const refSeq = currentAssembly.getByRefName(refName)
Expand Down Expand Up @@ -95,8 +95,8 @@ export const TranscriptSequence = observer(function TranscriptSequence({
textSegments.push({ text: `>${refName} : CDS\n`, color: 'black' })
for (const item of transcriptItems) {
if (item.type === 'CDS') {
const refSeq: string | undefined = refData?.getSequence(
Number(item.min + 1),
const refSeq: string | undefined = refData.getSequence(
Number((item.min as unknown as number) + 1),
Number(item.max),
)
seqData += item.strand === -1 && refSeq ? revcom(refSeq) : refSeq
Expand All @@ -113,8 +113,8 @@ export const TranscriptSequence = observer(function TranscriptSequence({
item.type === 'three_prime_UTR' ||
item.type === 'five_prime_UTR'
) {
const refSeq: string | undefined = refData?.getSequence(
Number(item.min + 1),
const refSeq: string | undefined = refData.getSequence(
Number((item.min as unknown as number) + 1),
Number(item.max),
)
seqData += item.strand === -1 && refSeq ? revcom(refSeq) : refSeq
Expand Down Expand Up @@ -142,7 +142,7 @@ export const TranscriptSequence = observer(function TranscriptSequence({
count != transcriptItems.length
) {
// Intron etc. between CDS/UTRs. No need to check this on very last item
const refSeq: string | undefined = refData?.getSequence(
const refSeq: string | undefined = refData.getSequence(
lastEnd + 1,
Number(item.min) - 1,
)
Expand All @@ -154,8 +154,8 @@ export const TranscriptSequence = observer(function TranscriptSequence({
item.type === 'three_prime_UTR' ||
item.type === 'five_prime_UTR'
) {
const refSeq: string | undefined = refData?.getSequence(
Number(item.min + 1),
const refSeq: string | undefined = refData.getSequence(
Number((item.min as unknown as number) + 1),
Number(item.max),
)
seqData += item.strand === -1 && refSeq ? revcom(refSeq) : refSeq
Expand Down Expand Up @@ -185,7 +185,7 @@ export const TranscriptSequence = observer(function TranscriptSequence({
}
}

async function handleChangeSeqOption(e: SelectChangeEvent) {
function handleChangeSeqOption(e: SelectChangeEvent) {
const option = e.target.value
setSelectedOption(option)
getSequenceAsTextSegment(option)
Expand All @@ -201,7 +201,7 @@ export const TranscriptSequence = observer(function TranscriptSequence({
.then(() => {
// console.log('Text copied to clipboard!')
})
.catch((error_) => {
.catch((error_: unknown) => {
console.error('Failed to copy text to clipboard', error_)
})
}
Expand Down
11 changes: 10 additions & 1 deletion packages/jbrowse-plugin-apollo/src/FeatureDetailsWidget/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ApolloFeatureDetailsWidget
export interface ApolloFeatureDetailsWidgetSnapshot
extends SnapshotIn<typeof ApolloFeatureDetailsWidgetModel> {}

export const ApolloTranscriptDetails = types
export const ApolloTranscriptDetailsModel = types
.model('ApolloTranscriptDetails', {
id: ElementId,
type: types.literal('ApolloTranscriptDetails'),
Expand Down Expand Up @@ -123,3 +123,12 @@ export const ApolloTranscriptDetails = types
)
},
}))

// eslint disables because of
// https://mobx-state-tree.js.org/tips/typescript#using-a-mst-type-at-design-time
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ApolloTranscriptDetailsWidget
extends Instance<typeof ApolloTranscriptDetailsModel> {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ApolloTranscriptDetailsWidgetSnapshot
extends SnapshotIn<typeof ApolloTranscriptDetailsModel> {}
Loading

0 comments on commit 9b6cf97

Please sign in to comment.