Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 23, 2024
1 parent 1f21e56 commit d3f5040
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 101 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "next",
"eslint-plugin-react-hooks": "^5.1.0-rc-eb3ad065-20240822",
"eslint-plugin-react-refresh": "^0.4.11",
"eslint-plugin-unicorn": "^55.0.0",
"fp-ts": "^2.16.9",
Expand Down
19 changes: 11 additions & 8 deletions src/ProteinView/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ const ProteinViewHeader = observer(function ({
}: {
model: JBrowsePluginProteinViewModel
}) {
const { showAlignment } = model
const { structures, showAlignment } = model
return (
<div>
<InformativeHeaderArea model={model} />
{showAlignment
? model.structures.map(s => {
const { alignment } = s

return alignment ? (
<ProteinAlignment model={s} />
) : (
<LoadingEllipses message="Loading pairwise alignment" />
? structures.map((structure, idx) => {
const { alignment } = structure
return (
<div key={idx}>
{alignment ? (
<ProteinAlignment key={idx} model={structure} />
) : (
<LoadingEllipses message="Loading pairwise alignment" />
)}
</div>
)
})
: null}
Expand Down
59 changes: 9 additions & 50 deletions src/ProteinView/components/ProteinView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react'
import { observer } from 'mobx-react'
import { ErrorMessage } from '@jbrowse/core/ui'
import { ErrorMessage, ResizeHandle } from '@jbrowse/core/ui'
import { PluginContext } from 'molstar/lib/mol-plugin/context'

// locals
Expand Down Expand Up @@ -54,57 +54,10 @@ const ProteinViewContainer = observer(function ({
plugin?: PluginContext
parentRef?: React.RefObject<HTMLDivElement>
}) {
const {
width,
height,
showHighlight,
// structureSeqToTranscriptSeqPosition,
// structureSeqHoverPos,
// alignment,
} = model
const { width, height, error } = model

// const { error } = useProteinViewClickBehavior({ plugin, model })
// useProteinViewHoverBehavior({ plugin, model })

// const structure =
// plugin?.managers.structure.hierarchy.current.structures[0]?.cell.obj?.data

// useEffect(() => {
// if (!plugin || !structureSeqToTranscriptSeqPosition || !structure) {
// return
// }
// if (showHighlight) {
// for (const coord of Object.keys(structureSeqToTranscriptSeqPosition)) {
// selectResidue({
// structure,
// plugin,
// selectedResidue: +coord + 1,
// })
// }
// } else {
// clearSelection({ plugin })
// }
// }, [plugin, structure, showHighlight, structureSeqToTranscriptSeqPosition])
//
// useEffect(() => {
// if (!plugin || !structure) {
// return
// }
//
// if (structureSeqHoverPos === undefined) {
// console.warn('not found')
// } else {
// highlightResidue({
// structure,
// plugin,
// selectedResidue: structureSeqHoverPos,
// })
// }
// }, [plugin, structure, structureSeqHoverPos])
const error = undefined
const alignment = undefined
return (
<div style={{ background: alignment ? undefined : '#ccc' }}>
<div style={{ background: '#ccc' }}>
{error ? <ErrorMessage error={error} /> : null}
<Header model={model} />
<div
Expand All @@ -115,6 +68,12 @@ const ProteinViewContainer = observer(function ({
height,
}}
/>
<ResizeHandle
style={{ height: 4, background: 'grey' }}
onDrag={delta => {
model.setHeight(model.height + delta)
}}
/>
</div>
)
})
Expand Down
71 changes: 59 additions & 12 deletions src/ProteinView/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { PluginContext } from 'molstar/lib/mol-plugin/context'
import { addStructureFromData } from './addStructureFromData'
import { addStructureFromURL } from './addStructureFromURL'
import Structure from './structureModel'
import highlightResidue from './highlightResidue'
import {
StructureElement,

Check warning on line 13 in src/ProteinView/model.ts

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

'StructureElement' is defined but never used
StructureProperties,

Check warning on line 14 in src/ProteinView/model.ts

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

'StructureProperties' is defined but never used
} from 'molstar/lib/mol-model/structure'
import { clickProteinToGenome } from './proteinToGenomeMapping'

Check warning on line 16 in src/ProteinView/model.ts

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

'clickProteinToGenome' is defined but never used

/**
* #stateModel Protein3dViewPlugin
Expand Down Expand Up @@ -36,7 +42,7 @@ function stateModelFactory() {
/**
* #property
*/
showControls: true,
showControls: false,
/**
* #property
*/
Expand Down Expand Up @@ -72,6 +78,12 @@ function stateModelFactory() {
}))

.actions(self => ({
/**
* #action
*/
setHeight(n: number) {
self.height = n
},
/**
* #action
*/
Expand Down Expand Up @@ -121,17 +133,30 @@ function stateModelFactory() {
if (molstarPluginContext) {
for (const structure of structures) {
try {
if (structure.data) {
await addStructureFromData({
data: structure.data,
plugin: molstarPluginContext,
})
} else if (structure.url) {
await addStructureFromURL({
url: structure.url,
plugin: molstarPluginContext,
})
}
const { model } = structure.data
? await addStructureFromData({
data: structure.data,
plugin: molstarPluginContext,
})
: structure.url
? await addStructureFromURL({
url: structure.url,
plugin: molstarPluginContext,
})
: { model: undefined }

const sequences = model?.obj?.data.sequence.sequences.map(
s => {
let seq = ''
const arr = s.sequence.label.toArray()
// eslint-disable-next-line unicorn/no-for-loop,@typescript-eslint/prefer-for-of
for (let i = 0; i < arr.length; i++) {
seq += arr[i]!
}
return seq
},
)
structure.setSequences(sequences)
} catch (e) {
self.setError(e)
console.error(e)
Expand All @@ -140,6 +165,28 @@ function stateModelFactory() {
}
}),
)

addDisposer(
self,
autorun(() => {
const { structures, molstarPluginContext } = self
if (molstarPluginContext) {
for (const [i, s0] of structures.entries()) {
const structure =
molstarPluginContext.managers.structure.hierarchy.current
.structures[i]?.cell.obj?.data
const pos = s0.structureSeqHoverPos
if (structure && pos !== undefined) {
highlightResidue({
structure,
plugin: molstarPluginContext,
selectedResidue: pos,
})
}
}
}
}),
)
},
}))
}
Expand Down
Loading

0 comments on commit d3f5040

Please sign in to comment.