-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
160 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import { Button, DialogContent, Typography } from '@mui/material' | ||
import { | ||
readConfObject, | ||
AnyConfigurationModel, | ||
} from '@jbrowse/core/configuration' | ||
import { Dialog, LoadingEllipses } from '@jbrowse/core/ui' | ||
import { getSession } from '@jbrowse/core/util' | ||
import { observer } from 'mobx-react' | ||
import { makeStyles } from 'tss-react/mui' | ||
import copy from 'copy-to-clipboard' | ||
|
||
const MAX_REF_NAMES = 10_000 | ||
|
||
const useStyles = makeStyles()(theme => ({ | ||
container: { | ||
minWidth: 800, | ||
}, | ||
refNames: { | ||
maxHeight: 300, | ||
width: '100%', | ||
overflow: 'auto', | ||
flexGrow: 1, | ||
background: theme.palette.background.default, | ||
}, | ||
})) | ||
|
||
const RefNameInfoDialog = observer(function ({ | ||
config, | ||
onClose, | ||
}: { | ||
config: AnyConfigurationModel | ||
onClose: () => void | ||
}) { | ||
const [error, setError] = useState<unknown>() | ||
const [refNames, setRefNames] = useState<Record<string, string[]>>() | ||
const [copied, setCopied] = useState(false) | ||
const { classes } = useStyles() | ||
const session = getSession(config) | ||
const { rpcManager } = session | ||
|
||
useEffect(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
;(async () => { | ||
try { | ||
const assemblyNames = [ | ||
...new Set(readConfObject(config, 'assemblyNames') as string[]), | ||
] | ||
const map = await Promise.all( | ||
assemblyNames.map(async assemblyName => { | ||
const adapterConfig = readConfObject(config, 'adapter') | ||
return [ | ||
assemblyName, | ||
(await rpcManager.call(config.trackId, 'CoreGetRefNames', { | ||
adapterConfig, | ||
// hack for synteny adapters | ||
regions: [{ assemblyName }], | ||
})) as string[], | ||
] as const | ||
}), | ||
) | ||
setRefNames(Object.fromEntries(map)) | ||
} catch (e) { | ||
console.error(e) | ||
setError(e) | ||
} | ||
})() | ||
}, [config, rpcManager]) | ||
|
||
const names = refNames ? Object.entries(refNames) : [] | ||
const result = names | ||
.flatMap(([assemblyName, refNames]) => { | ||
return [ | ||
`--- ${assemblyName} ---`, | ||
...refNames.slice(0, MAX_REF_NAMES), | ||
`${ | ||
refNames.length > MAX_REF_NAMES | ||
? `\nToo many refNames to show in browser for ${assemblyName}, use "Copy ref names" button to copy to clipboard` | ||
: '' | ||
}`, | ||
] | ||
}) | ||
.filter(f => !!f) | ||
.join('\n') | ||
|
||
return ( | ||
<Dialog | ||
open | ||
title="Reference sequence names used in track" | ||
onClose={onClose} | ||
> | ||
<DialogContent className={classes.container}> | ||
{error ? ( | ||
<Typography color="error">{`${error}`}</Typography> | ||
) : refNames === undefined ? ( | ||
<LoadingEllipses message="Loading refNames" /> | ||
) : ( | ||
<> | ||
<Button | ||
variant="contained" | ||
onClick={() => { | ||
copy( | ||
names | ||
.flatMap(([assemblyName, refNames]) => [ | ||
`--- ${assemblyName} ---`, | ||
...refNames, | ||
]) | ||
.filter(f => !!f) | ||
.join('\n'), | ||
) | ||
setCopied(true) | ||
setTimeout(() => setCopied(false), 1000) | ||
}} | ||
> | ||
{copied ? 'Copied to clipboard!' : 'Copy ref names'} | ||
</Button> | ||
|
||
<pre className={classes.refNames}>{result}</pre> | ||
</> | ||
)} | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
}) | ||
|
||
export default RefNameInfoDialog |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters