Skip to content

Commit

Permalink
Wow
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 22, 2024
1 parent a756359 commit eb2f164
Show file tree
Hide file tree
Showing 14 changed files with 455 additions and 446 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface LoadStructureOptions {
}

// adapted from https://github.com/molstar/molstar/blob/ab4130d42d0ab2591f62460292ade0203207d4d2/src/apps/viewer/app.ts#L255C1-L259C6
export async function loadStructureFromData({
export async function addStructureFromData({
data,
format = 'pdb',
options,
Expand All @@ -18,8 +18,6 @@ export async function loadStructureFromData({
options?: LoadStructureOptions & { label?: string; dataLabel?: string }
plugin: PluginContext
}) {
await plugin.clear()

const _data = await plugin.builders.data.rawData({
data,
label: options?.dataLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface LoadStructureOptions {
}

// adapted from https://github.com/molstar/molstar/blob/ab4130d42d0ab2591f62460292ade0203207d4d2/src/apps/viewer/app.ts#L230
export async function loadStructureFromURL({
export async function addStructureFromURL({
url,
format = 'mmcif',
isBinary,
Expand All @@ -20,11 +20,16 @@ export async function loadStructureFromURL({
options?: LoadStructureOptions & { label?: string }
plugin: PluginContext
}) {
await plugin.clear()

const data = await plugin.builders.data.download(
{ url, isBinary },
{ state: { isGhost: true } },
{
url,
isBinary,
},
{
state: {
isGhost: true,
},
},
)

const trajectory = await plugin.builders.structure.parseTrajectory(
Expand Down
8 changes: 4 additions & 4 deletions src/ProteinView/components/ProteinAlignment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { observer } from 'mobx-react'
import { Tooltip, Typography } from '@mui/material'

// locals
import { JBrowsePluginProteinViewModel } from '../model'
import { JBrowsePluginProteinStructureModel } from '../model'
import ProteinAlignmentHelpButton from './ProteinAlignmentHelpButton'
import {
clickProteinToGenome,
Expand All @@ -14,7 +14,7 @@ import SplitString from './SplitString'
const ProteinAlignment = observer(function ({
model,
}: {
model: JBrowsePluginProteinViewModel
model: JBrowsePluginProteinStructureModel
}) {
const {
structureSeqHoverPos,
Expand All @@ -26,8 +26,8 @@ const ProteinAlignment = observer(function ({
if (!alignment) {
return <div>No alignment</div>
}
const a0 = alignment.alns[0]!.seq as string
const a1 = alignment.alns[1]!.seq as string
const a0 = alignment.alns[0].seq
const a1 = alignment.alns[1].seq
const con = alignment.consensus
const set = new Set<number>()
// eslint-disable-next-line unicorn/no-for-loop
Expand Down
101 changes: 44 additions & 57 deletions src/ProteinView/components/ProteinView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,88 +29,75 @@ const ProteinView = observer(function ({
}: {
model: JBrowsePluginProteinViewModel
}) {
const { url, data, showControls } = model
const { plugin, seq, parentRef, error } = useProteinView({
url,
data,
const { showControls } = model
const { plugin, parentRef, error } = useProteinView({
showControls,
})
return error ? (
<ErrorMessage error={error} />
) : (
<ProteinViewContainer
model={model}
plugin={plugin}
seq={seq}
parentRef={parentRef}
/>
<ProteinViewContainer model={model} plugin={plugin} parentRef={parentRef} />
)
})

const ProteinViewContainer = observer(function ({
model,
plugin,
seq,
parentRef,
}: {
model: JBrowsePluginProteinViewModel
plugin?: PluginContext
seq?: string
parentRef?: React.RefObject<HTMLDivElement>
}) {
const {
width,
height,
structureSeqToTranscriptSeqPosition,
seq2,
structureSeqHoverPos,
showHighlight,
alignment,
// structureSeqToTranscriptSeqPosition,
// structureSeqHoverPos,
// alignment,
} = model

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

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

useEffect(() => {
model.setSeqs(seq, seq2)
}, [seq, model, seq2])

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 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' }}>
{error ? <ErrorMessage error={error} /> : null}
Expand Down
14 changes: 5 additions & 9 deletions src/ProteinView/genomeToProtein.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { getSession } from '@jbrowse/core/util'
import { checkHovered } from './util'
import { JBrowsePluginProteinViewModel } from './model'
import { JBrowsePluginProteinStructureModel } from './model'

export function genomeToProtein({
model,
}: {
model: JBrowsePluginProteinViewModel
model: JBrowsePluginProteinStructureModel
}): number | undefined {
const { hovered } = getSession(model)
const { genomeToTranscriptSeqMapping, connectedView } = model
if (
!connectedView?.initialized ||
return !connectedView?.initialized ||
!genomeToTranscriptSeqMapping ||
!checkHovered(hovered)
) {
return undefined
}

return genomeToTranscriptSeqMapping.g2p[hovered.hoverPosition.coord]
? undefined
: genomeToTranscriptSeqMapping.g2p[hovered.hoverPosition.coord]
}
Loading

0 comments on commit eb2f164

Please sign in to comment.