Skip to content

Commit

Permalink
Merge pull request #1924 from GMOD/fix_bed_spreadsheet
Browse files Browse the repository at this point in the history
Fix import of BED and navToLocString from spreadsheet views
  • Loading branch information
rbuels authored Apr 28, 2021
2 parents 418c7df + 05dcb4c commit 2bcdfe2
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"tslib": "^2.0.1",
"typescript": "^3.7.2",
"wait-on": "^5.0.0",
"web-encoding": "^1.1.5",
"webpack-cli": "^3.3.11",
"worker-loader": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/ui/FileSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const FileLocationEditor = observer(
</ToggleButton>
) : null}
<ToggleButton value="url" aria-label="url">
Url
URL
</ToggleButton>
</ToggleButtonGroup>
</Grid>
Expand Down
1 change: 1 addition & 0 deletions packages/core/util/jexl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function (/* config?: any*/): JexlNonBuildable {
j.addFunction('floor', Math.floor)
j.addFunction('round', Math.round)
j.addFunction('abs', Math.abs)
j.addFunction('parseInt', Number.parseInt)

// string
j.addFunction('split', (str: string, char: string) => str.split(char))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ exports[`ConfigurationEditor widget renders all the different types of built-in
<span
class="MuiToggleButton-label"
>
Url
URL
</span>
<span
class="MuiTouchRipple-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ exports[`<AddTrackWidget /> renders 1`] = `
<span
class="MuiToggleButton-label"
>
Url
URL
</span>
<span
class="MuiTouchRipple-root"
Expand Down Expand Up @@ -156,7 +156,7 @@ exports[`<AddTrackWidget /> renders 1`] = `
<span
class="MuiToggleButton-label"
>
Url
URL
</span>
<span
class="MuiTouchRipple-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const ImportForm = observer(({ model }) => {
<Button
disabled={!model.isReadyToOpen}
variant="contained"
data-testid="open_spreadsheet"
color="primary"
onClick={model.import}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export async function parseBedBuffer(buffer: Buffer, options: ParseOptions) {
name: 'Location',
dataType: { type: 'LocString' },
isDerived: true,
derivationFunctionText: `jexl:{text:row.cells.ref.text+':'+row.cells.start.text+'..'+row.cells.end.text,\n
extendedData: {refName: row.cells.ref.text, start: +row.cells.start.text, end: +row.cells.end.text}}`,
derivationFunctionText: `jexl:{text:row.cells[0].text+':'+row.cells[1].text+'..'+row.cells[2].text,\n
extendedData: {refName: row.cells.ref.text, start: parseInt(row.cells.start.text,10), end: parseInt(row.cells.end.text,10)}}`,
})
return data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ export default pluginManager => {
displayName: assemblyName,
id: newViewId,
})
await when(() => view.initialized)

// note that we have to clone this because otherwise it adds "same object
// twice to the mst tree"
view.setDisplayedRegions([
JSON.parse(JSON.stringify(newDisplayedRegion)),
])
await when(() => view.initialized)
}
view.navToLocString(cell.text)
} catch (e) {
Expand Down
82 changes: 82 additions & 0 deletions products/jbrowse-web/src/tests/1.Spreadsheet.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// library
import '@testing-library/jest-dom/extend-expect'

import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import React from 'react'
import { LocalFile } from 'generic-filehandle'

// locals
import { clearCache } from '@jbrowse/core/util/io/rangeFetcher'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { TextEncoder, TextDecoder } from 'web-encoding'
import JBrowse from '../JBrowse'
import { setup, getPluginManager, generateReadBuffer } from './util'

window.TextEncoder = TextEncoder
window.TextDecoder = TextDecoder

expect.extend({ toMatchImageSnapshot })

setup()

afterEach(cleanup)

beforeEach(() => {
clearCache()
clearAdapterCache()
fetch.resetMocks()
fetch.mockResponse(
generateReadBuffer(url => {
return new LocalFile(require.resolve(`../../test_data/volvox/${url}`))
}),
)
})

test('opens a vcf.gz file in the spreadsheet view', async () => {
const pluginManager = getPluginManager()
const { findByTestId, getByTestId, findByText } = render(
<JBrowse pluginManager={pluginManager} />,
)
fireEvent.click(await findByText('File'))
fireEvent.click(await findByText('Add'))
fireEvent.click(await findByText('Spreadsheet view'))

await findByTestId('spreadsheet_view_open')
fireEvent.click(await findByText('URL'))
fireEvent.change(await findByTestId('urlInput'), {
target: { value: 'volvox.filtered.vcf.gz' },
})
await waitFor(() =>
expect(
getByTestId('open_spreadsheet').closest('button'),
).not.toBeDisabled(),
)
fireEvent.click(await findByTestId('open_spreadsheet'))
// fireEvent.click(await findByText('ctgA:276..277'))
expect(pluginManager.rootModel.session.views.length).toBe(2)
}, 15000)

test('opens a bed.gz file in the spreadsheet view', async () => {
const pluginManager = getPluginManager()
const { findByTestId, getByTestId, findByText } = render(
<JBrowse pluginManager={pluginManager} />,
)
fireEvent.click(await findByText('File'))
fireEvent.click(await findByText('Add'))
fireEvent.click(await findByText('Spreadsheet view'))

await findByTestId('spreadsheet_view_open')
fireEvent.click(await findByText('URL'))
fireEvent.change(await findByTestId('urlInput'), {
target: { value: 'volvox-bed12.bed.gz' },
})
await waitFor(() =>
expect(
getByTestId('open_spreadsheet').closest('button'),
).not.toBeDisabled(),
)
fireEvent.click(await findByTestId('open_spreadsheet'))
// fireEvent.click(await findByText('ctgA:1299..9000'))
expect(pluginManager.rootModel.session.views.length).toBe(2)
}, 15000)
31 changes: 31 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7493,6 +7493,11 @@
mkdirp-promise "^5.0.1"
mz "^2.5.0"

"@zxing/[email protected]":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@zxing/text-encoding/-/text-encoding-0.9.0.tgz#fb50ffabc6c7c66a0c96b4c03e3d9be74864b70b"
integrity sha512-U/4aVJ2mxI0aDNI8Uq0wEhMgY+u4CNtEb0om3+y3+niDAsoTCOB33UF0sxpzqzdqXLqmvc+vZyAt4O8pPdfkwA==

JSONStream@^1.0.4, JSONStream@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -15314,6 +15319,11 @@ is-generator-fn@^2.0.0:
resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-2.1.0.tgz#7d140adc389aaf3011a8f2a2a4cfa6faadffb118"
integrity sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==

is-generator-function@^1.0.7:
version "1.0.8"
resolved "https://registry.yarnpkg.com/is-generator-function/-/is-generator-function-1.0.8.tgz#dfb5c2b120e02b0a8d9d2c6806cd5621aa922f7b"
integrity sha512-2Omr/twNtufVZFr1GhxjOMFPAj2sjc/dKaIqBhvo4qciXfJmITGH6ZGd8eZYNHza8t1y0e01AuqRhJwfWp26WQ==

is-glob@^2.0.0, is-glob@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863"
Expand Down Expand Up @@ -24770,6 +24780,18 @@ util@^0.11.0:
dependencies:
inherits "2.0.3"

util@^0.12.3:
version "0.12.3"
resolved "https://registry.yarnpkg.com/util/-/util-0.12.3.tgz#971bb0292d2cc0c892dab7c6a5d37c2bec707888"
integrity sha512-I8XkoQwE+fPQEhy9v012V+TSdH2kp9ts29i20TaaDUXsg7x/onePbhFJUExBfv/2ay1ZOp/Vsm3nDlmnFGSAog==
dependencies:
inherits "^2.0.3"
is-arguments "^1.0.4"
is-generator-function "^1.0.7"
is-typed-array "^1.1.3"
safe-buffer "^5.1.2"
which-typed-array "^1.1.2"

utila@^0.4.0, utila@~0.4:
version "0.4.0"
resolved "https://registry.yarnpkg.com/utila/-/utila-0.4.0.tgz#8a16a05d445657a3aea5eecc5b12a4fa5379772c"
Expand Down Expand Up @@ -24961,6 +24983,15 @@ wcwidth@^1.0.0, wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"

web-encoding@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/web-encoding/-/web-encoding-1.1.5.tgz#fc810cf7667364a6335c939913f5051d3e0c4864"
integrity sha512-HYLeVCdJ0+lBYV2FvNZmv3HJ2Nt0QYXqZojk3d9FJOLkwnuhzM9tmamh8d7HPM8QqjKH8DeHkFTx+CFlWpZZDA==
dependencies:
util "^0.12.3"
optionalDependencies:
"@zxing/text-encoding" "0.9.0"

web-namespaces@^1.0.0:
version "1.1.4"
resolved "https://registry.yarnpkg.com/web-namespaces/-/web-namespaces-1.1.4.tgz#bc98a3de60dadd7faefc403d1076d529f5e030ec"
Expand Down

0 comments on commit 2bcdfe2

Please sign in to comment.