Skip to content

Commit

Permalink
Revert "Misc"
Browse files Browse the repository at this point in the history
This reverts commit c4e16eb.
  • Loading branch information
cmdcolin committed Dec 4, 2024
1 parent c4e16eb commit 4c09a6a
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 72 deletions.
20 changes: 10 additions & 10 deletions packages/core/pluggableElementTypes/renderers/BoxRendererType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ export default class BoxRendererType extends FeatureRendererType {
args,
) as ResultsSerialized

return {
...serialized,
layout: results.layout.serializeRegion(
this.getExpandedRegion(args.regions[0]!, args),
),
maxHeightReached: serialized.layout.maxHeightReached,
features: serialized.features.filter(
f => !!serialized.layout.rectangles[f.uniqueId],
),
}
const region = args.regions[0]!
serialized.layout = results.layout.serializeRegion(
this.getExpandedRegion(region, args),
)
serialized.features = serialized.features.filter(f => {
return Boolean(serialized.layout.rectangles[f.uniqueId])
})

serialized.maxHeightReached = serialized.layout.maxHeightReached
return serialized
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,34 @@ export default class ServerSideRenderer extends RendererType {
* @param results - the results of the render
* @param args - the arguments passed to render
*/
deserializeResultsInClient(res: ResultsSerialized, args: RenderArgs) {
// if we are rendering svg, we skip hydration and check if rendere support
// SVG (e.g. this.supportsSVG) and then return just the HTML if so
return args.exportSVG
? {
...res,
html: this.supportsSVG
? res.html
: '<text y="12" fill="black">SVG export not supported for this track</text>',
}
: {
...res,
reactElement: (
<ServerSideRenderedContent
{...args}
{...res}
RenderingComponent={this.ReactComponent}
/>
),
}
deserializeResultsInClient(
res: ResultsSerialized,
args: RenderArgs,
): ResultsDeserialized {
// if we are rendering svg, we skip hydration
if (args.exportSVG) {
// only return the res if the renderer explicitly has
// this.supportsSVG support to avoid garbage being rendered in SVG
// document
return {
...res,
html: this.supportsSVG
? res.html
: '<text y="12" fill="black">SVG export not supported for this track</text>',
}
}

// get res using ServerSideRenderedContent
return {
...res,
reactElement: (
<ServerSideRenderedContent
{...args}
{...res}
RenderingComponent={this.ReactComponent}
/>
),
}
}

/**
Expand All @@ -115,17 +123,18 @@ export default class ServerSideRenderer extends RendererType {
*
* @param args - the converted arguments to modify
*/
deserializeArgsInWorker(args: RenderArgsSerialized) {
console.log('deserializeArgsInWorker', { args })
return {
...args,
config: this.configSchema.create(args.config || {}, {
pluginManager: this.pluginManager,
}),
filters: args.filters
? new SerializableFilterChain({ filters: args.filters })
: undefined,
}
deserializeArgsInWorker(args: RenderArgsSerialized): RenderArgsDeserialized {
const deserialized = { ...args } as unknown as RenderArgsDeserialized
deserialized.config = this.configSchema.create(args.config || {}, {
pluginManager: this.pluginManager,
})
deserialized.filters = args.filters
? new SerializableFilterChain({
filters: args.filters,
})
: undefined

return deserialized
}

/**
Expand Down Expand Up @@ -206,4 +215,4 @@ export default class ServerSideRenderer extends RendererType {
}
}

export type { RenderResults } from './RendererType'
export { type RenderResults } from './RendererType'
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import {
} from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail'
import { Paper } from '@mui/material'
import { observer } from 'mobx-react'
import { SimpleFeatureSerialized } from '@jbrowse/core/util'

const BreakpointAlignmentsFeatureDetail = observer(function ({
model,
}: {
model: { featureData: Record<string, unknown> }
model: {
featureData: {
feature1: SimpleFeatureSerialized
feature2: SimpleFeatureSerialized
}
}
}) {
const { feature1, feature2 } = JSON.parse(JSON.stringify(model.featureData))
const { featureData } = model
const { feature1, feature2 } = structuredClone(featureData)
return (
<Paper data-testid="alignment-side-drawer">
<Paper>
<BaseCoreDetails title="Feature 1" feature={feature1} />
<BaseCoreDetails title="Feature 2" feature={feature2} />
<BaseAttributes title="Feature 1 attributes" feature={feature1} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const SyntenyFeatureDetail = observer(function ({
model: SyntenyFeatureDetailModel
}) {
return (
<Paper data-testid="alignment-side-drawer">
<Paper>
<BaseFeatureDetail title="Feature" model={model} />
<BaseCard title="Link to view">
<CustomLinker model={model} />
Expand Down
6 changes: 2 additions & 4 deletions plugins/variants/src/MultiLinearVariantDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import type { Instance } from 'mobx-state-tree'
// lazies
const Tooltip = lazy(() => import('../shared/Tooltip'))
const SetColorDialog = lazy(() => import('../shared/SetColorDialog'))
const HierarchicalClusterDialog = lazy(
() => import('../shared/HierarchicalClusterDialog'),
)
const ClusterDialog = lazy(() => import('../shared/ClusterDialog'))

// using a map because it preserves order
const rendererTypes = new Map([['multivariant', 'MultiVariantRenderer']])
Expand Down Expand Up @@ -263,7 +261,7 @@ export function stateModelFactory(
label: 'Cluster by genotype',
onClick: () => {
getSession(self).queueDialog(handleClose => [
HierarchicalClusterDialog,
ClusterDialog,
{
model: self,
handleClose,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
const useStyles = makeStyles()({
cursor: {
pointerEvents: 'none',
zIndex: 1000,
},
})

Expand Down
21 changes: 17 additions & 4 deletions plugins/variants/src/MultiLinearVariantMatrixDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import type { Instance } from 'mobx-state-tree'
// lazies
const SetColorDialog = lazy(() => import('../shared/SetColorDialog'))
const MAFFilterDialog = lazy(() => import('../shared/MAFFilterDialog'))
const HierarchicalClusterDialog = lazy(
() => import('../shared/HierarchicalClusterDialog'),
)
const ClusterDialog = lazy(() => import('../shared/ClusterDialog'))

/**
* #stateModel LinearVariantMatrixDisplay
Expand Down Expand Up @@ -176,7 +174,7 @@ export default function stateModelFactory(
label: 'Cluster by genotype',
onClick: () => {
getSession(self).queueDialog(handleClose => [
HierarchicalClusterDialog,
ClusterDialog,
{
model: self,
handleClose,
Expand Down Expand Up @@ -252,6 +250,21 @@ export default function stateModelFactory(
}
}
})()

// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
const { getMultiVariantSourcesAutorun } = await import(
'../getMultiVariantSourcesAutorun'
)
getMultiVariantSourcesAutorun(self)
} catch (e) {
if (isAlive(self)) {
console.error(e)
getSession(self).notifyError(`${e}`, e)
}
}
})()
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const LinearVariantMatrixRendering = observer(function (props: {
regions: Region[]
bpPerPx: number
simplifiedFeatures: Feature[]
exportSVG: boolean
onMouseMove?: (event: React.MouseEvent, featureId?: string) => void
}) {
const { exportSVG, simplifiedFeatures, displayModel, width, height } = props
const [renderLines, setRenderLines] = useState(exportSVG)
const { simplifiedFeatures, displayModel, width, height } = props
console.log('Rendering', props.regions)
const [renderLines, setRenderLines] = useState(false)
useEffect(() => {
setRenderLines(true)
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAda
import type { RenderArgs } from '@jbrowse/core/rpc/coreRpcMethods'
import type { Feature, Region } from '@jbrowse/core/util'

export class MultiVariantGetHierarchicalMatrix extends RpcMethodType {
name = 'MultiVariantGetHierarchicalMatrix'
export class MultiVariantGetGenotypeMatrix extends RpcMethodType {
name = 'MultiVariantGetGenotypeMatrix'

async deserializeArguments(args: any, rpcDriverClassName: string) {
const l = await super.deserializeArguments(args, rpcDriverClassName)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { getAdapter } from '@jbrowse/core/data_adapters/dataAdapterCache'
import RpcMethodType from '@jbrowse/core/pluggableElementTypes/RpcMethodType'
import SerializableFilterChain from '@jbrowse/core/pluggableElementTypes/renderers/util/serializableFilterChain'
import { renameRegionsIfNeeded } from '@jbrowse/core/util'

import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
import type { RenderArgs } from '@jbrowse/core/rpc/coreRpcMethods'
import type { Region } from '@jbrowse/core/util'
import { toArray } from 'rxjs'

export class MultiVariantGetSimplifiedFeatures extends RpcMethodType {
name = 'MultiVariantGetSimplifiedFeatures'

async deserializeArguments(args: any, rpcDriverClassName: string) {
const l = await super.deserializeArguments(args, rpcDriverClassName)
return {
...l,
filters: args.filters
? new SerializableFilterChain({
filters: args.filters,
})
: undefined,
}
}

async serializeArguments(
args: RenderArgs & {
stopToken?: string
statusCallback?: (arg: string) => void
},
rpcDriverClassName: string,
) {
const pm = this.pluginManager
const assemblyManager = pm.rootModel?.session?.assemblyManager
if (!assemblyManager) {
return args
}

const renamedArgs = await renameRegionsIfNeeded(assemblyManager, {
...args,
filters: args.filters?.toJSON().filters,
})

return super.serializeArguments(renamedArgs, rpcDriverClassName)
}

async execute(
args: {
adapterConfig: AnyConfigurationModel
stopToken?: string
sessionId: string
headers?: Record<string, string>
regions: Region[]
bpPerPx: number
},
rpcDriverClassName: string,
) {
const pm = this.pluginManager
const deserializedArgs = await this.deserializeArguments(
args,
rpcDriverClassName,
)
const { regions, adapterConfig, sessionId } = deserializedArgs
const { dataAdapter } = await getAdapter(pm, sessionId, adapterConfig)

// @ts-expect-error
const feats = await firstValuFrom(
dataAdapter.getFeatures(regions, deserializedArgs).pipe(toArray()),
)
return feats.map(f => ({
start: f.get('start'),
end: f.get('end'),
refName: f.get('refName'),
}))
}
}
36 changes: 35 additions & 1 deletion plugins/variants/src/getMultiVariantSourcesAutorun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,41 @@ export function getMultiVariantSourcesAutorun(self: {
sessionId,
'MultiVariantGetSources',
{
regions: view.staticBlocks.contentBlocks,
regions: view.dynamicBlocks.contentBlocks,
sessionId,
adapterConfig,
},
)) as Source[]
if (isAlive(self)) {
self.setSources(sources)
}
} catch (e) {
if (!isAbortException(e) && isAlive(self)) {
console.error(e)
getSession(self).notifyError(`${e}`, e)
}
}
}),
)

addDisposer(
self,
autorun(async () => {
try {
const view = getContainingView(self) as LinearGenomeViewModel
if (!view.initialized) {
return
}
const { rpcManager } = getSession(self)
const { adapterConfig } = self
const token = createStopToken()
self.setSourcesLoading(token)
const sessionId = getRpcSessionId(self)
const sources = (await rpcManager.call(
sessionId,
'MultiVariantGetSimplifiedFeatures',
{
regions: view.dynamicBlocks.contentBlocks,
sessionId,
adapterConfig,
},
Expand Down
8 changes: 6 additions & 2 deletions plugins/variants/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import LinearVariantMatrixRendererF from './MultiLinearVariantMatrixRenderer'
import MultiVariantRendererF from './MultiLinearVariantRenderer'
import StructuralVariantChordRendererF from './StructuralVariantChordRenderer'
import VariantFeatureWidgetF from './VariantFeatureWidget'
import { MultiVariantGetHierarchicalMatrix } from './VariantRPC/MultiVariantGetHierarchicalMatrix'
import { MultiVariantGetGenotypeMatrix } from './VariantRPC/MultiVariantGetGenotypeMatrix'
import { MultiVariantGetSources } from './VariantRPC/MultiVariantGetSources'
import { MultiVariantGetSimplifiedFeatures } from './VariantRPC/MultiVariantGetSimplifiedFeatures'
import VariantTrackF from './VariantTrack'
import VcfAdapterF from './VcfAdapter'
import VcfTabixAdapterF from './VcfTabixAdapter'
Expand All @@ -36,7 +37,10 @@ export default class VariantsPlugin extends Plugin {

pluginManager.addRpcMethod(() => new MultiVariantGetSources(pluginManager))
pluginManager.addRpcMethod(
() => new MultiVariantGetHierarchicalMatrix(pluginManager),
() => new MultiVariantGetGenotypeMatrix(pluginManager),
)
pluginManager.addRpcMethod(
() => new MultiVariantGetSimplifiedFeatures(pluginManager),
)
}
}
Expand Down
Loading

0 comments on commit 4c09a6a

Please sign in to comment.