Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix height of Hi-C track, and add adjust-to-height #4849

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions plugins/hic/src/HicRenderer/HicRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { readConfObject } from '@jbrowse/core/configuration'
import { getAdapter } from '@jbrowse/core/data_adapters/dataAdapterCache'
import ServerSideRendererType from '@jbrowse/core/pluggableElementTypes/renderers/ServerSideRendererType'
import { renderToAbstractCanvas } from '@jbrowse/core/util/offscreenCanvasUtils'
Expand Down Expand Up @@ -37,6 +36,7 @@ export interface RenderArgsDeserialized
highResolutionScaling: number
resolution: number
adapterConfig: AnyConfigurationModel
displayHeight?: number
}

export interface RenderArgsDeserializedWithFeatures
Expand All @@ -53,16 +53,18 @@ export default class HicRenderer extends ServerSideRendererType {
supportsSVG = true

async render(renderProps: RenderArgsDeserialized) {
const { config, regions, bpPerPx } = renderProps
const { displayHeight, regions, bpPerPx } = renderProps
const region = regions[0]!
const width = (region.end - region.start) / bpPerPx
const height = readConfObject(config, 'maxHeight')
const hyp = width / 2
const height = displayHeight ?? hyp
const features = await this.getFeatures(renderProps)

const { makeImageData } = await import('./makeImageData')
const res = await renderToAbstractCanvas(width, height, renderProps, ctx =>
makeImageData(ctx, {
...renderProps,
yScalar: height / Math.max(height, hyp),
features,
pluginManager: this.pluginManager,
}),
Expand Down
9 changes: 8 additions & 1 deletion plugins/hic/src/HicRenderer/makeImageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export interface RenderArgs extends ServerSideRenderArgs {

export async function makeImageData(
ctx: CanvasRenderingContext2D,
props: RenderArgsDeserializedWithFeatures & { pluginManager: PluginManager },
props: RenderArgsDeserializedWithFeatures & {
yScalar: number
pluginManager: PluginManager
},
) {
const {
features,
Expand All @@ -40,6 +43,7 @@ export async function makeImageData(
colorScheme,
regions,
pluginManager,
yScalar,
} = props

const { statusCallback = () => {} } = props
Expand Down Expand Up @@ -93,6 +97,9 @@ export async function makeImageData(
const scale = useLogScale
? scaleSequentialLog(x1).domain([1, m])
: scaleSequential(x1).domain([0, m])
if (yScalar) {
ctx.scale(1, yScalar)
}
ctx.save()

if (region.reversed === true) {
Expand Down
48 changes: 45 additions & 3 deletions plugins/hic/src/LinearHicDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default function stateModelFactory(
* #property
*/
activeNormalization: 'KR',
/**
* #property
*/
mode: 'triangular',
}),
)
.volatile(() => ({
Expand Down Expand Up @@ -87,6 +91,7 @@ export default function stateModelFactory(
return {
...superRenderProps(),
config,
displayHeight: self.mode === 'adjust' ? self.height : undefined,
normalization: self.activeNormalization,
rpcDriverName: self.rpcDriverName,
displayModel: self,
Expand Down Expand Up @@ -128,12 +133,18 @@ export default function stateModelFactory(
setAvailableNormalizations(f: string[]) {
self.availableNormalizations = f
},
/**
* #action
*/
setMode(arg: string) {
self.mode = arg
},
}))
.views(self => {
const { trackMenuItems: superTrackMenuItems } = self
return {
/**
* #getter
* #method
*/
trackMenuItems() {
return [
Expand All @@ -146,36 +157,67 @@ export default function stateModelFactory(
self.setUseLogScale(!self.useLogScale)
},
},
{
label: 'Rendering mode',
type: 'subMenu',
subMenu: [
{
label: 'Triangular',
type: 'radio',
checked: self.mode === 'triangular',
onClick: () => {
self.setMode('triangular')
},
},
{
label: 'Adjust to height of display',
type: 'radio',
checked: self.mode === 'adjust',
onClick: () => {
self.setMode('adjust')
},
},
],
},
{
label: 'Color scheme',
type: 'subMenu',
subMenu: [
{
label: 'Fall',
type: 'radio',
checked: self.colorScheme === 'fall',
onClick: () => {
self.setColorScheme('fall')
},
},
{
label: 'Viridis',
type: 'radio',
checked: self.colorScheme === 'viridis',
onClick: () => {
self.setColorScheme('viridis')
},
},
{
label: 'Juicebox',
type: 'radio',
checked: self.colorScheme === 'juicebox',
onClick: () => {
self.setColorScheme('juicebox')
},
},
{
label: 'Clear',
label: 'Default',
type: 'radio',
checked: self.colorScheme === undefined,
onClick: () => {
self.setColorScheme(undefined)
},
},
],
},

{
label: 'Resolution',
subMenu: [
Expand All @@ -199,7 +241,7 @@ export default function stateModelFactory(
label: 'Normalization scheme',
subMenu: self.availableNormalizations.map(norm => ({
label: norm,
type: 'checkbox',
type: 'radio',
checked: norm === self.activeNormalization,
onClick: () => {
self.setActiveNormalization(norm)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading