Skip to content

Commit

Permalink
More status updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 20, 2025
1 parent ecef89d commit cc3163e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 42 deletions.
11 changes: 10 additions & 1 deletion plugins/comparative-adapters/src/ChainAdapter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* SOFTWARE.
*/

import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'

function generate_record(
qname: string,
qstart: number,
Expand Down Expand Up @@ -51,7 +53,8 @@ function generate_record(
}
}

export function paf_chain2paf(buffer: Uint8Array) {
export function paf_chain2paf(buffer: Uint8Array, opts?: BaseOptions) {
const { statusCallback = () => {} } = opts || {}
let t_name = ''
let t_start = 0
let t_end = 0
Expand All @@ -64,9 +67,15 @@ export function paf_chain2paf(buffer: Uint8Array) {
let cigar = ''
const records = []

let i = 0
let blockStart = 0
const decoder = new TextDecoder('utf8')
while (blockStart < buffer.length) {
if (i++ % 10_000 === 0) {
statusCallback(
`Loading ${Math.floor(blockStart / 1_000_000).toLocaleString('en-US')}/${Math.floor(buffer.length / 1_000_000).toLocaleString('en-US')} MB`,
)
}
const n = buffer.indexOf(10, blockStart)
if (n === -1) {
break
Expand Down
11 changes: 10 additions & 1 deletion plugins/comparative-adapters/src/DeltaAdapter/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter/BaseOptions'

/* paf2delta from paftools.js in the minimap2 repository, license reproduced below
*
* The MIT License
Expand Down Expand Up @@ -26,7 +28,8 @@
* SOFTWARE.
*/

export function paf_delta2paf(buffer: Uint8Array) {
export function paf_delta2paf(buffer: Uint8Array, opts?: BaseOptions) {
const { statusCallback = () => {} } = opts || {}
let rname = ''
let qname = ''
let qs = 0
Expand All @@ -45,8 +48,14 @@ export function paf_delta2paf(buffer: Uint8Array) {

let blockStart = 0
let i = 0
let j = 0
const decoder = new TextDecoder('utf8')
while (blockStart < buffer.length) {
if (j++ % 10_000 === 0) {
statusCallback(
`Loading ${Math.floor(blockStart / 1_000_000).toLocaleString('en-US')}/${Math.floor(buffer.length / 1_000_000).toLocaleString('en-US')} MB`,
)
}
const n = buffer.indexOf(10, blockStart)
if (n === -1) {
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type PluginManager from '@jbrowse/core/PluginManager'
import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'
import type { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache'

Check failure on line 12 in plugins/comparative-adapters/src/PairwiseIndexedPAFAdapter/PairwiseIndexedPAFAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

There should be at least one empty line between import groups
import type { Feature } from '@jbrowse/core/util'
import { updateStatus, type Feature } from '@jbrowse/core/util'

Check failure on line 13 in plugins/comparative-adapters/src/PairwiseIndexedPAFAdapter/PairwiseIndexedPAFAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

There should be at least one empty line between import groups

Check failure on line 13 in plugins/comparative-adapters/src/PairwiseIndexedPAFAdapter/PairwiseIndexedPAFAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

`@jbrowse/core/util` import should occur before import of `@jbrowse/core/util/io`

Check failure on line 13 in plugins/comparative-adapters/src/PairwiseIndexedPAFAdapter/PairwiseIndexedPAFAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

`Feature` type import should occur before import of `updateStatus`
import type { FileLocation, Region } from '@jbrowse/core/util/types'

interface PAFOptions extends BaseOptions {
Expand Down Expand Up @@ -77,6 +77,7 @@ export default class PAFAdapter extends BaseFeatureDataAdapter {
}

getFeatures(query: Region, opts: PAFOptions = {}) {
const { statusCallback = () => {} } = opts || {}

Check failure on line 80 in plugins/comparative-adapters/src/PairwiseIndexedPAFAdapter/PairwiseIndexedPAFAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

Unnecessary conditional, value is always truthy
return ObservableCreate<Feature>(async observer => {
const { assemblyName } = query

Expand All @@ -85,45 +86,47 @@ export default class PAFAdapter extends BaseFeatureDataAdapter {
const flip = index === 0
const letter = flip ? 'q' : 't'

await this.pif.getLines(letter + query.refName, query.start, query.end, {
lineCallback: (line, fileOffset) => {
const r = parsePAFLine(line)
const refName = r.qname.slice(1)
const start = r.qstart
const end = r.qend
const mateName = r.tname
const mateStart = r.tstart
const mateEnd = r.tend

const { extra, strand } = r
const { numMatches = 0, blockLen = 1, cg, ...rest } = extra

observer.next(
new SyntenyFeature({
uniqueId: fileOffset + assemblyName,
assemblyName,
start,
end,
type: 'match',
refName,
strand,
...rest,
CIGAR: extra.cg,
syntenyId: fileOffset,
identity: numMatches / blockLen,
numMatches,
blockLen,
mate: {
start: mateStart,
end: mateEnd,
refName: mateName,
assemblyName: assemblyNames[+flip],
},
}),
)
},
stopToken: opts.stopToken,
})
await updateStatus('Downloading features', statusCallback, () =>
this.pif.getLines(letter + query.refName, query.start, query.end, {
lineCallback: (line, fileOffset) => {
const r = parsePAFLine(line)
const refName = r.qname.slice(1)
const start = r.qstart
const end = r.qend
const mateName = r.tname
const mateStart = r.tstart
const mateEnd = r.tend

const { extra, strand } = r
const { numMatches = 0, blockLen = 1, cg, ...rest } = extra

observer.next(
new SyntenyFeature({
uniqueId: fileOffset + assemblyName,
assemblyName,
start,
end,
type: 'match',
refName,
strand,
...rest,
CIGAR: extra.cg,
syntenyId: fileOffset,
identity: numMatches / blockLen,
numMatches,
blockLen,
mate: {
start: mateStart,
end: mateEnd,
refName: mateName,
assemblyName: assemblyNames[+flip],
},
}),
)
},
stopToken: opts.stopToken,
}),
)

observer.complete()
})
Expand Down

0 comments on commit cc3163e

Please sign in to comment.