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

Add ability to open refNameAliases+cytobands in "Open sequence" start screen on desktop #3513

Merged
merged 5 commits into from
Feb 15, 2023
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
7 changes: 0 additions & 7 deletions packages/core/.gitignore

This file was deleted.

15 changes: 2 additions & 13 deletions packages/core/CorePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import { configSchema, stateModelFactory } from './BaseFeatureWidget'
import Plugin from './Plugin'
import PluginManager from './PluginManager'
import * as coreRpcMethods from './rpc/coreRpcMethods'
import AdapterType from './pluggableElementTypes/AdapterType'
import WidgetType from './pluggableElementTypes/WidgetType'
import {
configSchema as cytobandConfigSchema,
DataAdapter,
} from './data_adapters/CytobandAdapter'
import CytobandAdapterF from './data_adapters/CytobandAdapter'

// the core plugin, which registers types that ALL JBrowse applications are
// expected to need.
Expand All @@ -21,14 +17,7 @@ export default class CorePlugin extends Plugin {
pluginManager.addRpcMethod(() => new RpcMethod(pluginManager))
})

pluginManager.addAdapterType(
() =>
new AdapterType({
name: 'CytobandAdapter',
configSchema: cytobandConfigSchema,
AdapterClass: DataAdapter,
}),
)
CytobandAdapterF(pluginManager)

pluginManager.addWidgetType(() => {
return new WidgetType({
Expand Down
51 changes: 0 additions & 51 deletions packages/core/data_adapters/CytobandAdapter.ts

This file was deleted.

39 changes: 39 additions & 0 deletions packages/core/data_adapters/CytobandAdapter/CytobandAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { unzip } from '@gmod/bgzf-filehandle'

// locals
import { SimpleFeature } from '../../util'
import { openLocation } from '../../util/io'
import { BaseAdapter } from '../BaseAdapter'

export function isGzip(buf: Buffer) {
return buf[0] === 31 && buf[1] === 139 && buf[2] === 8
}

export default class CytobandAdapter extends BaseAdapter {
async getData() {
const pm = this.pluginManager
const loc = this.getConf('cytobandLocation')
if (loc.uri === '' || loc.uri === '/path/to/cytoband.txt.gz') {
return []
}
const buffer = (await openLocation(loc, pm).readFile()) as Buffer
const buf = isGzip(buffer) ? await unzip(buffer) : buffer
const text = new TextDecoder('utf8', { fatal: true }).decode(buf)
return text
.split(/\n|\r\n|\r/)
.filter(f => !!f.trim())
.map((line, i) => {
const [refName, start, end, name, type] = line.split('\t')
return new SimpleFeature({
uniqueId: `${i}`,
refName,
start: +start,
end: +end,
name,
type,
})
})
}

freeResources(/* { region } */): void {}
}
22 changes: 22 additions & 0 deletions packages/core/data_adapters/CytobandAdapter/configSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ConfigurationSchema } from '../../configuration'

/**
* #config CytobandAdapter
*/
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars

const configSchema = ConfigurationSchema(
'CytobandAdapter',
{
/**
* #slot
*/
cytobandLocation: {
type: 'fileLocation',
defaultValue: { uri: '/path/to/cytoband.txt.gz' },
},
},
{ explicitlyTyped: true },
)

export default configSchema
14 changes: 14 additions & 0 deletions packages/core/data_adapters/CytobandAdapter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AdapterType } from '../../pluggableElementTypes'
import PluginManager from '../../PluginManager'
import configSchema from './configSchema'

export default (pluginManager: PluginManager) => {
pluginManager.addAdapterType(
() =>
new AdapterType({
name: 'CytobandAdapter',
configSchema,
getAdapterClass: () => import('./CytobandAdapter').then(f => f.default),
}),
)
}
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"dependencies": {
"@babel/runtime": "^7.17.9",
"@gmod/bgzf-filehandle": "^1.4.3",
"@mui/icons-material": "^5.0.1",
"@types/clone": "^2.0.0",
"abortable-promise-cache": "^1.5.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/ui/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ function createDefaultProps(theme?: ThemeOptions) {
},
},
},
MuiToggleButtonGroup: {
defaultProps: {
size: 'small' as const,
},
},
},
}
}
Expand Down
7 changes: 3 additions & 4 deletions plugins/config/src/RefNameAliasAdapter/RefNameAliasAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import {
BaseAdapter,
} from '@jbrowse/core/data_adapters/BaseAdapter'
import { openLocation } from '@jbrowse/core/util/io'
import { readConfObject } from '@jbrowse/core/configuration'

export default class RefNameAliasAdapter
extends BaseAdapter
implements BaseRefNameAliasAdapter
{
async getRefNameAliases() {
const loc = readConfObject(this.config, 'location')
const loc = this.getConf('location')
if (loc.uri === '' || loc.uri === '/path/to/my/aliases.txt') {
return []
}
const results = await openLocation(loc).readFile('utf8')
const refColumn = readConfObject(this.config, 'refNameColumn')
const results = await openLocation(loc, this.pluginManager).readFile('utf8')
const refColumn = this.getConf('refNameColumn')
return results
.trim()
.split(/\n|\r\n|\r/)
Expand Down
115 changes: 115 additions & 0 deletions products/jbrowse-desktop/src/AdapterInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import React from 'react'
import { Grid } from '@mui/material'
import { FileSelector } from '@jbrowse/core/ui'
import { FileLocation } from '@jbrowse/core/util/types'

export default function AdapterInput({
adapterSelection,
fastaLocation,
setFastaLocation,
faiLocation,
setFaiLocation,
chromSizesLocation,
gziLocation,
setGziLocation,
twoBitLocation,
setTwoBitLocation,
setChromSizesLocation,
}: {
adapterSelection: string
fastaLocation: FileLocation
setFastaLocation: Function
faiLocation: FileLocation
setFaiLocation: Function
gziLocation: FileLocation
chromSizesLocation: FileLocation
setGziLocation: Function
twoBitLocation: FileLocation
setTwoBitLocation: Function
setChromSizesLocation: Function
}) {
if (adapterSelection === 'IndexedFastaAdapter') {
return (
<Grid container spacing={2}>
<Grid item>
<FileSelector
name="fastaLocation"
location={fastaLocation}
setLocation={loc => setFastaLocation(loc)}
/>
</Grid>
<Grid item>
<FileSelector
name="faiLocation"
location={faiLocation}
setLocation={loc => setFaiLocation(loc)}
/>
</Grid>
</Grid>
)
}
if (adapterSelection === 'BgzipFastaAdapter') {
return (
<Grid container spacing={2}>
<Grid item>
<FileSelector
name="fastaLocation"
location={fastaLocation}
setLocation={loc => setFastaLocation(loc)}
/>
</Grid>
<Grid item>
<FileSelector
name="faiLocation"
location={faiLocation}
setLocation={loc => setFaiLocation(loc)}
/>
</Grid>
<Grid item>
<FileSelector
name="gziLocation"
location={gziLocation}
setLocation={loc => setGziLocation(loc)}
/>
</Grid>
</Grid>
)
}

if (adapterSelection === 'TwoBitAdapter') {
return (
<Grid container spacing={2}>
<Grid item>
<FileSelector
name="twoBitLocation"
location={twoBitLocation}
setLocation={loc => setTwoBitLocation(loc)}
/>
</Grid>
<Grid item>
<FileSelector
name="chromSizesLocation (optional, can be added to speed up loading 2bit files with many contigs)"
location={chromSizesLocation}
setLocation={loc => setChromSizesLocation(loc)}
/>
</Grid>
</Grid>
)
}

if (adapterSelection === 'FastaAdapter') {
return (
<Grid container spacing={2}>
<Grid item>
<FileSelector
name="fastaLocation"
location={fastaLocation}
setLocation={loc => setFastaLocation(loc)}
/>
</Grid>
</Grid>
)
}

return null
}
Loading