Skip to content

Commit

Permalink
Replace 'show all regions' with 'show all regions in assembly' (#1599)
Browse files Browse the repository at this point in the history
* Update maxBpPerPx to be based on self.width also
  • Loading branch information
cmdcolin authored Jan 6, 2021
1 parent fbdbc9f commit 17175e3
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ exports[`<LinearGenomeView /> renders one track, one region 1`] = `
/>
<input
type="hidden"
value="332.1928094887362"
value="284.799690655495"
/>
<span
aria-orientation="horizontal"
aria-valuemax="564.3856189774724"
aria-valuemin="332.1928094887362"
aria-valuenow="332.1928094887362"
aria-valuemin="284.799690655495"
aria-valuenow="284.799690655495"
class="MuiSlider-thumb MuiSlider-thumbColorPrimary"
data-index="0"
role="slider"
Expand Down Expand Up @@ -961,7 +961,7 @@ exports[`<LinearGenomeView /> renders two tracks, two regions 1`] = `
/>
<span
class="MuiSlider-track"
style="left: 0%; width: 2.3783941938133566%;"
style="left: 0%; width: 9.774680693120512%;"
/>
<input
type="hidden"
Expand All @@ -970,12 +970,12 @@ exports[`<LinearGenomeView /> renders two tracks, two regions 1`] = `
<span
aria-orientation="horizontal"
aria-valuemax="564.3856189774724"
aria-valuemin="-13.750352374993502"
aria-valuemin="-61.143471208234715"
aria-valuenow="0"
class="MuiSlider-thumb MuiSlider-thumbColorPrimary"
data-index="0"
role="slider"
style="left: 2.3783941938133566%;"
style="left: 9.774680693120512%;"
tabindex="0"
/>
</span>
Expand Down
108 changes: 64 additions & 44 deletions plugins/linear-genome-view/src/LinearGenomeView/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConfigurationSchema } from '@jbrowse/core/configuration'
import DisplayType from '@jbrowse/core/pluggableElementTypes/DisplayType'
import { Region } from '@jbrowse/core/util/types/mst'
import {
createBaseTrackConfig,
createBaseTrackModel,
Expand Down Expand Up @@ -49,6 +50,18 @@ stubManager.createPluggableElements()
stubManager.configure()
const LinearGenomeModel = stateModelFactory(stubManager)

const Assembly = types
.model({
regions: types.array(Region),
})
.views(() => ({
getCanonicalRefName(refName: string) {
if (refName === 'contigA') {
return 'ctgA'
}
return refName
},
}))
const Session = types
.model({
name: 'testSession',
Expand All @@ -66,32 +79,24 @@ const Session = types
assemblyManager: new Map([
[
'volvox',
{
getCanonicalRefName(refName: string) {
if (refName === 'contigA') {
return 'ctgA'
}
return refName
},
get regions() {
return [
{
assemblyName: 'volvox',
start: 0,
end: 50001,
refName: 'ctgA',
reversed: false,
},
{
assemblyName: 'volvox',
start: 0,
end: 6079,
refName: 'ctgB',
reversed: false,
},
]
},
},
Assembly.create({
regions: [
{
assemblyName: 'volvox',
start: 0,
end: 50001,
refName: 'ctgA',
reversed: false,
},
{
assemblyName: 'volvox',
start: 0,
end: 6079,
refName: 'ctgB',
reversed: false,
},
],
}),
],
]),
}))
Expand Down Expand Up @@ -121,11 +126,11 @@ test('can instantiate a model that lets you navigate', () => {
tracks: [{ name: 'foo track', type: 'FeatureTrack' }],
}),
)
model.setWidth(800)
model.setDisplayedRegions([
{ assemblyName: 'volvox', start: 0, end: 10000, refName: 'ctgA' },
])
model.setWidth(800)
expect(model.maxBpPerPx).toEqual(10)
expect(model.maxBpPerPx).toBeCloseTo(13.888)
model.setNewView(0.02, 0)

expect(model.scaleBarHeight).toEqual(20)
Expand Down Expand Up @@ -167,12 +172,12 @@ test('can instantiate a model that has multiple displayed regions', () => {
tracks: [{ name: 'foo track', type: 'FeatureTrack' }],
}),
)
model.setWidth(800)
model.setDisplayedRegions([
{ assemblyName: 'volvox', start: 0, end: 10000, refName: 'ctgA' },
{ assemblyName: 'volvox', start: 0, end: 10000, refName: 'ctgB' },
])
model.setWidth(800)
expect(model.maxBpPerPx).toEqual(20)
expect(model.maxBpPerPx).toBeCloseTo(27.777)
model.setNewView(0.02, 0)

expect(model.offsetPx).toEqual(0)
Expand All @@ -199,7 +204,7 @@ test('can instantiate a model that tests navTo/moveTo', async () => {
{ assemblyName: 'volvox', start: 0, end: 10000, refName: 'ctgA' },
{ assemblyName: 'volvox', start: 0, end: 10000, refName: 'ctgB' },
])
expect(model.maxBpPerPx).toEqual(20)
expect(model.maxBpPerPx).toBeCloseTo(27.7777)

model.navTo({ refName: 'ctgA', start: 0, end: 100 })
expect(model.offsetPx).toBe(0)
Expand Down Expand Up @@ -357,16 +362,10 @@ describe('Zoom to selected displayed regions', () => {
refName: 'ctgB',
},
)
// 15000 + 10000 + 1 = 25001 / 800 - 8 = 28
// this is the newBpPerPx ~ 28
// minBpPerPx = 0.2 & max is 28
// extrabp = 0
// bpToStart 464 / 28
// expect(model.scrollTo(16.58)).toEqual(0)
// This should be 28

largestBpPerPx = model.bpPerPx
expect(model.offsetPx).toEqual(0)
expect(model.bpPerPx).toEqual(28)
expect(model.bpPerPx).toBeCloseTo(31.408)
})

it('can select if start and end object are swapped', () => {
Expand All @@ -390,7 +389,7 @@ describe('Zoom to selected displayed regions', () => {
},
)
expect(model.offsetPx).toEqual(0)
expect(model.bpPerPx).toEqual(28)
expect(model.bpPerPx).toBeCloseTo(31.408)
})

it('can select over one refSeq', () => {
Expand Down Expand Up @@ -447,7 +446,7 @@ describe('Zoom to selected displayed regions', () => {
it('can select over two regions in the same reference sequence', () => {
model.setWidth(800)
model.showAllRegions()
expect(model.bpPerPx).toBe(28)
expect(model.bpPerPx).toBeCloseTo(38.8888)
// totalBp = 28000 / 1000 = 28 as maxBpPerPx
model.zoomToDisplayedRegions(
{
Expand Down Expand Up @@ -480,8 +479,9 @@ describe('Zoom to selected displayed regions', () => {
])
model.setWidth(800)
model.showAllRegions()
// totalBo 15000 + 3000 + 35000 = 53000 / 800 = 66.25 but maxBp is 53000/ 1000 thus 53
expect(model.bpPerPx).toBe(53)
// totalBp 15000 + 3000 + 35000 = 53000
// then 53000 / (width*0.9) = 73.6111
expect(model.bpPerPx).toBeCloseTo(73.61111)
model.zoomToDisplayedRegions(
{
start: 5000,
Expand Down Expand Up @@ -549,7 +549,7 @@ test('can instantiate a model that >2 regions', () => {
expect(model.offsetPx).toEqual(10000 / model.bpPerPx + 2)
expect(model.displayedRegionsTotalPx).toEqual(30000 / model.bpPerPx)
model.showAllRegions()
expect(model.offsetPx).toEqual(100)
expect(model.offsetPx).toEqual(-40)

expect(model.bpToPx({ refName: 'ctgA', coord: 100 })).toEqual({
index: 0,
Expand Down Expand Up @@ -677,3 +677,23 @@ test('can perform pxToBp on human genome things with ellided blocks (zoomed out)
expect(model.pxToBp(1500).refName).toBe('Y_KI270740v1_random')
expect(model.pxToBp(1500).oob).toBeTruthy()
})

test('can showAllRegionsInAssembly', async () => {
const session = Session.create({
configuration: {},
})
const width = 800
const model = session.setView(
LinearGenomeModel.create({
id: 'test4',
type: 'LinearGenomeView',
tracks: [{ name: 'foo track', type: 'FeatureTrack' }],
}),
)
model.setWidth(width)
model.showAllRegionsInAssembly('volvox')
expect(model.displayedRegions.map(reg => reg.refName)).toEqual([
'ctgA',
'ctgB',
])
})
35 changes: 32 additions & 3 deletions plugins/linear-genome-view/src/LinearGenomeView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function stateModelFactory(pluginManager: PluginManager) {
},

get maxBpPerPx() {
return this.totalBp / 1000
return this.totalBp / (self.width * 0.9)
},

get minBpPerPx() {
Expand Down Expand Up @@ -1005,6 +1005,35 @@ export function stateModelFactory(pluginManager: PluginManager) {
this.center()
},

showAllRegionsInAssembly(assemblyName?: string) {
const session = getSession(self)
const { assemblyManager } = session
if (!assemblyName) {
const assemblyNames = [
...new Set(
self.displayedRegions.map(region => region.assemblyName),
),
]
if (assemblyNames.length > 1) {
session.notify(
`Can't perform this with multiple assemblies currently`,
)
return
}

;[assemblyName] = assemblyNames
}
const assembly = assemblyManager.get(assemblyName)
if (assembly) {
const { regions } = getSnapshot(assembly)
if (regions) {
this.setDisplayedRegions(regions)
self.zoomTo(self.maxBpPerPx)
this.center()
}
}
},

setDraggingTrackId(idx?: string) {
self.draggingTrackId = idx
},
Expand Down Expand Up @@ -1076,9 +1105,9 @@ export function stateModelFactory(pluginManager: PluginManager) {
onClick: self.horizontallyFlip,
},
{
label: 'Show all regions',
label: 'Show all regions in assembly',
icon: VisibilityIcon,
onClick: self.showAllRegions,
onClick: self.showAllRegionsInAssembly,
},
{
label: 'Show center line',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ exports[`<JBrowseLinearGenomeView /> renders successfully 1`] = `
/>
<span
class="MuiSlider-track"
style="left: 0%; width: 48.86084055306146%;"
style="left: 0%; width: 56.78411120929245%;"
/>
<input
type="hidden"
Expand All @@ -355,12 +355,12 @@ exports[`<JBrowseLinearGenomeView /> renders successfully 1`] = `
<span
aria-orientation="horizontal"
aria-valuemax="564.3856189774724"
aria-valuemin="305.8893689053569"
aria-valuemin="258.49625007211563"
aria-valuenow="432.19280948873626"
class="MuiSlider-thumb MuiSlider-thumbColorPrimary"
data-index="0"
role="slider"
style="left: 48.86084055306146%;"
style="left: 56.78411120929245%;"
tabindex="0"
/>
</span>
Expand Down

0 comments on commit 17175e3

Please sign in to comment.