Skip to content

Commit

Permalink
Auto-select stringify callback
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 17, 2023
1 parent 4eec230 commit c1c051a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import GetAppIcon from '@mui/icons-material/GetApp'

// locals
import { stringifyGFF3 } from './gff3'
import { stringifyGenbank } from './genbank'
import { stringifyGBK } from './genbank'
import { stringifyBED } from './bed'

const useStyles = makeStyles()({
Expand Down Expand Up @@ -71,9 +71,9 @@ const SaveTrackDataDialog = observer(function ({
const [type, setType] = useState('gff3')
const [str, setStr] = useState('')
const options = {
gff3: { name: 'GFF3', extension: 'gff3' },
genbank: { name: 'GenBank', extension: 'gbk' },
bed: { name: 'BED', extension: 'bed' },
gff3: { name: 'GFF3', extension: 'gff3', callback: stringifyGFF3 },
genbank: { name: 'GenBank', extension: 'gbk', callback: stringifyGBK },
bed: { name: 'BED', extension: 'bed', callback: stringifyBED },
}

useEffect(() => {
Expand All @@ -99,27 +99,21 @@ const SaveTrackDataDialog = observer(function ({
if (!features) {
return
}

if (type === 'gff3') {
setStr(stringifyGFF3({ features }))
} else if (type === 'bed') {
setStr(stringifyBED({ features }))
} else if (type === 'gb') {
setStr(
await stringifyGenbank({
features,
session,
assemblyName: view.visibleRegions[0].assemblyName,
}),
)
} else {
setStr('Unknown file type')
const generator = options[type as keyof typeof options] || {
callback: () => 'Unknown',
}
setStr(
await generator.callback({
features,
session,
assemblyName: view.visibleRegions[0].assemblyName,
}),
)
} catch (e) {
setError(e)
}
})()
}, [type, features, model])
}, [type, features, options, model])

return (
<Dialog maxWidth="xl" open onClose={handleClose} title="Save track data">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function formatFeatWithSubfeatures(
].join('\n')
}

export async function stringifyGenbank({
export async function stringifyGBK({
features,
assemblyName,
session,
Expand Down

0 comments on commit c1c051a

Please sign in to comment.