Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
Created February 6, 2024 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmdcolin/08e47c53641b5d2152a08933bbd1e546 to your computer and use it in GitHub Desktop.
Save cmdcolin/08e47c53641b5d2152a08933bbd1e546 to your computer and use it in GitHub Desktop.
Convert JBrowse 1 NCList on disk to GFF
import { LocalFile } from 'generic-filehandle'
import NCList from '@gmod/nclist'
const filter = new Set([
'Start',
'End',
'Strand',
'Source',
'Seq_id',
'Name',
'Score',
'Id',
'Type',
'Subfeatures',
'Parent',
])
;(async () => {
const store = new NCList({
baseUrl: '',
urlTemplate: process.argv[2] + '/{refseq}/trackData.json',
readFile: (url: string) => new LocalFile(url).readFile(),
})
for await (const feature of store.getFeatures({
refName: process.argv[3],
start: 0,
end: 50_000_000,
})) {
const parent = feature.get('parent')
const name = feature.get('name')
const rest = feature
.tags()
.filter((f: string) => !filter.has(f)) as string[]
if (rest.length !== 0) {
console.error(rest.length, rest)
}
console.log(
[
feature.get('seq_id'),
feature.get('source'),
feature.get('type'),
feature.get('start'),
feature.get('end'),
feature.get('score') || '.',
feature.get('strand') === -1 ? '-' : feature === 1 ? '+' : '.',
feature.get('phase') || '.',
[
`ID=${feature.get('ID')}`,
parent ? `Parent=${parent}` : '',
name ? `Name=${name}` : '',
...rest.map(r => `${r}=${feature.get(r)}`),
]
.filter(f => !!f)
.join(';'),
].join('\t'),
)
}
})()
@cmdcolin
Copy link
Author

cmdcolin commented Feb 6, 2024

usage

run it in the data directories "tracks" folder

for j in * ; do touch "$j.gff"; for i in $j/*; do echo $j `basename $i`; node dist/index.js "$j" `basename $i` >> "$j.gff"; done;  done;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment