Skip to content

Commit

Permalink
Non-streaming parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 4, 2024
1 parent 0523cac commit dd5b27c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 71 deletions.
2 changes: 1 addition & 1 deletion plugins/gff3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@flatten-js/interval-tree": "^1.0.15",
"@gmod/bgzf-filehandle": "^1.4.3",
"@gmod/gff": "^1.3.0",
"gff-nostream": "^1.3.3",
"@gmod/tabix": "^1.5.6"
},
"peerDependencies": {
Expand Down
17 changes: 8 additions & 9 deletions plugins/gff3/src/Gff3Adapter/Gff3Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ObservableCreate } from '@jbrowse/core/util/rxjs'
import IntervalTree from '@flatten-js/interval-tree'
import SimpleFeature, { Feature } from '@jbrowse/core/util/simpleFeature'
import { unzip } from '@gmod/bgzf-filehandle'
import gff from '@gmod/gff'
import { parseStringSync } from 'gff-nostream'
import { isGzip, updateStatus } from '@jbrowse/core/util'

import { featureData } from '../featureData'
Expand Down Expand Up @@ -76,14 +76,13 @@ export default class Gff3Adapter extends BaseFeatureDataAdapter {
if (!this.calculatedIntervalTreeMap[refName]) {
sc?.('Parsing GFF data')
const intervalTree = new IntervalTree()
gff
.parseStringSync(lines, {
parseFeatures: true,
parseComments: false,
parseDirectives: false,
parseSequences: false,
disableDerivesFromReferences: true,
})
parseStringSync(lines, {

Check failure on line 79 in plugins/gff3/src/Gff3Adapter/Gff3Adapter.ts

View workflow job for this annotation

GitHub Actions / Test and typecheck

Expected 1 arguments, but got 2.
parseFeatures: true,
parseComments: false,
parseDirectives: false,
parseSequences: false,
disableDerivesFromReferences: true,
})
.flat()
.map(
(f, i) =>
Expand Down
57 changes: 24 additions & 33 deletions plugins/gff3/src/Gff3TabixAdapter/Gff3TabixAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { openLocation } from '@jbrowse/core/util/io'
import { ObservableCreate } from '@jbrowse/core/util/rxjs'
import SimpleFeature, { Feature } from '@jbrowse/core/util/simpleFeature'
import { TabixIndexedFile } from '@gmod/tabix'
import gff, { GFF3Feature } from '@gmod/gff'
import { parseStringSync, GFF3Feature } from 'gff-nostream'

Check warning on line 11 in plugins/gff3/src/Gff3TabixAdapter/Gff3TabixAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint

'GFF3Feature' is defined but never used
import { Observer } from 'rxjs'
import {
readConfObject,
Expand Down Expand Up @@ -124,7 +124,7 @@ export default class Gff3TabixAdapter extends BaseFeatureDataAdapter {
}

const gff3 = lines
.map((lineRecord: LineFeature) => {
.map(lineRecord => {
if (lineRecord.fields[8] && lineRecord.fields[8] !== '.') {
if (!lineRecord.fields[8].includes('_lineHash')) {
lineRecord.fields[8] += `;_lineHash=${lineRecord.lineHash}`
Expand All @@ -136,27 +136,28 @@ export default class Gff3TabixAdapter extends BaseFeatureDataAdapter {
})
.join('\n')

const features = gff.parseStringSync(gff3, {
parseFeatures: true,
parseComments: false,
parseDirectives: false,
parseSequences: false,
disableDerivesFromReferences: true,
})

features.forEach(featureLocs => {
this.formatFeatures(featureLocs).forEach(f => {
if (
doesIntersect2(
f.get('start'),
f.get('end'),
originalQuery.start,
originalQuery.end,
)
) {
observer.next(f)
}
})
parseStringSync(gff3).forEach(featureLocs => {
console.log({ featureLocs })

Check warning on line 140 in plugins/gff3/src/Gff3TabixAdapter/Gff3TabixAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
featureLocs
.map(
featureLoc =>
new SimpleFeature({
data: featureData(featureLoc),
id: `${this.id}-offset-${featureLoc.attributes?._lineHash?.[0]}`,
}),
)
.forEach(f => {
if (
doesIntersect2(
f.get('start'),
f.get('end'),
originalQuery.start,
originalQuery.end,
)
) {
observer.next(f)
}
})
})
observer.complete()
} catch (e) {
Expand All @@ -180,15 +181,5 @@ export default class Gff3TabixAdapter extends BaseFeatureDataAdapter {
}
}

private formatFeatures(featureLocs: GFF3Feature) {
return featureLocs.map(
featureLoc =>
new SimpleFeature({
data: featureData(featureLoc),
id: `${this.id}-offset-${featureLoc.attributes?._lineHash?.[0]}`,
}),
)
}

public freeResources(/* { region } */) {}
}
2 changes: 1 addition & 1 deletion plugins/gff3/src/featureData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GFF3FeatureLineWithRefs } from '@gmod/gff'
import { GFF3FeatureLineWithRefs } from 'gff-nostream'

export function featureData(data: GFF3FeatureLineWithRefs) {
const f: Record<string, unknown> = { ...data }
Expand Down
2 changes: 1 addition & 1 deletion plugins/gtf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@flatten-js/interval-tree": "^1.0.15",
"@gmod/bgzf-filehandle": "^1.4.3",
"@gmod/gtf": "^0.0.9"
"gtf-nostream": "^1.0.0"
},
"peerDependencies": {
"@jbrowse/core": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions plugins/gtf/src/GtfAdapter/GtfAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isGzip,
} from '@jbrowse/core/util'
import { unzip } from '@gmod/bgzf-filehandle'
import gtf from '@gmod/gtf'
import { parseStringSync } from 'gtf-nostream'

// locals
import { FeatureLoc, featureData } from '../util'
Expand Down Expand Up @@ -83,7 +83,7 @@ export default class GtfAdapter extends BaseFeatureDataAdapter {
sc?.('Parsing GTF data')
const intervalTree = new IntervalTree()
;(
gtf.parseStringSync(lines, {
parseStringSync(lines, {
parseFeatures: true,
parseComments: false,
parseDirectives: false,
Expand Down
36 changes: 12 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2333,20 +2333,6 @@
pump "^3.0.0"
split2 "^4.2.0"

"@gmod/gff@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@gmod/gff/-/gff-1.3.0.tgz#d231a6f807cfb8f191c26c6410021c17155e4093"
integrity sha512-OjEnQLR6iIcrau603blFfUkmnWGDVfOu/LQoJNa7TsvKnjWlHYPlvqb5h2IV7wI+zElDY648mQ9zrElt2uR80A==
dependencies:
stream-browserify "^3.0.0"

"@gmod/gtf@^0.0.9":
version "0.0.9"
resolved "https://registry.yarnpkg.com/@gmod/gtf/-/gtf-0.0.9.tgz#87ef1e753ab2e9903affdd97454e6f948da38cd4"
integrity sha512-IPqKOg8e9nUvxI+8mJznKXdWMrErseJx/w+HnrU+ePTWzr2uCa8iHcbVzfSlPgqxWKkQ15/lK4BnUJSnQHfVow==
dependencies:
stream-browserify "^3.0.0"

"@gmod/http-range-fetcher@^3.0.4":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@gmod/http-range-fetcher/-/http-range-fetcher-3.0.4.tgz#7ab2fdc96703b9f977d9c517e8028fb68765e118"
Expand Down Expand Up @@ -9439,6 +9425,11 @@ get-value@^3.0.1:
dependencies:
isobject "^3.0.1"

gff-nostream@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/gff-nostream/-/gff-nostream-1.3.3.tgz#bd1ed4436a3826051dd91eec6a9034349b263ab0"
integrity sha512-SwwpN+2jxaeherEC4PZPnsL2rsD3kUev+NT9jJJj+pg7kiYQDu7W4B4QzFcJUf7dUvuqWSNie2Nx8xb7u7s//Q==

giget@^1.0.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/giget/-/giget-1.2.3.tgz#ef6845d1140e89adad595f7f3bb60aa31c672cb6"
Expand Down Expand Up @@ -9705,6 +9696,11 @@ graphemer@^1.4.0:
resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6"
integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==

gtf-nostream@^1.0.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/gtf-nostream/-/gtf-nostream-1.3.2.tgz#6cc9d13de26f7615ffaa5263462b3b195bbe7b0b"
integrity sha512-o8bqFWoZ7JjkKfpVOCyhFsW3dAr4gR15khm39Z9PXuymesoDaMDn6AW4m+L69nBWd3JAL5xFxr7mSslFsCu6sg==

gzip-size@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-6.0.0.tgz#065367fd50c239c0671cbcbad5be3e2eeb10e462"
Expand Down Expand Up @@ -10177,7 +10173,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@2, inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3, inherits@~2.0.4:
inherits@2, inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
Expand Down Expand Up @@ -14135,7 +14131,7 @@ readable-stream@^2.0.1, readable-stream@^2.3.0, readable-stream@^2.3.5, readable
string_decoder "~1.1.1"
util-deprecate "~1.0.1"

readable-stream@^3.0.0, readable-stream@^3.0.2, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.4.0, readable-stream@^3.5.0, readable-stream@^3.6.0:
readable-stream@^3.0.0, readable-stream@^3.0.2, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.4.0, readable-stream@^3.6.0:
version "3.6.2"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967"
integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==
Expand Down Expand Up @@ -15158,14 +15154,6 @@ storybook@^8.0.0:
tiny-invariant "^1.3.1"
ts-dedent "^2.0.0"

stream-browserify@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f"
integrity sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==
dependencies:
inherits "~2.0.4"
readable-stream "^3.5.0"

string-length@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/string-length/-/string-length-4.0.2.tgz#a8a8dc7bd5c1a82b9b3c8b87e125f66871b6e57a"
Expand Down

0 comments on commit dd5b27c

Please sign in to comment.