Skip to content

Commit

Permalink
More status
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 4, 2025
1 parent 2b057d3 commit 6f53fbd
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 52 deletions.
52 changes: 32 additions & 20 deletions plugins/alignments/src/BamAdapter/BamAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,40 @@ export default class BamAdapter extends BaseFeatureDataAdapter {
private async setupPre(opts?: BaseOptions) {
const { statusCallback = () => {} } = opts || {}
const { bam } = await this.configure()
console.log('wow')

Check warning on line 86 in plugins/alignments/src/BamAdapter/BamAdapter.ts

View workflow job for this annotation

GitHub Actions / Lint, typecheck, test

Unexpected console statement. Only these console methods are allowed: error, warn
this.samHeader = await updateStatus(
'Downloading index',
statusCallback,
async () => {
const samHeader = await bam.getHeader()

// use the @SQ lines in the header to figure out the
// mapping between ref ref ID numbers and names
const idToName: string[] = []
const nameToId: Record<string, number> = {}
samHeader
?.filter(l => l.tag === 'SQ')
.forEach((sqLine, refId) => {
const SN = sqLine.data.find(item => item.tag === 'SN')
if (SN) {
// this is the ref name
const refName = SN.value
nameToId[refName] = refId
idToName[refId] = refName
}
})

return { idToName, nameToId }
return new Promise(res =>
setTimeout(async () => {
const samHeader = await bam.getHeader()

// use the @SQ lines in the header to figure out the
// mapping between ref ref ID numbers and names
const idToName: string[] = []
const nameToId: Record<string, number> = {}
samHeader
?.filter(l => l.tag === 'SQ')
.forEach((sqLine, refId) => {
const SN = sqLine.data.find(item => item.tag === 'SN')
if (SN) {
// this is the ref name
const refName = SN.value
nameToId[refName] = refId
idToName[refId] = refName
}
})

res({ idToName, nameToId })
}, 4000),
)
},
)
return this.samHeader
}

async setup(opts?: BaseOptions) {
async setupPre2(opts?: BaseOptions) {
if (!this.setupP) {
this.setupP = this.setupPre(opts).catch((e: unknown) => {
this.setupP = undefined
Expand All @@ -121,6 +126,13 @@ export default class BamAdapter extends BaseFeatureDataAdapter {
return this.setupP
}

async setup(opts?: BaseOptions) {
const { statusCallback = () => {} } = opts || {}
return updateStatus('Downloading index', statusCallback, () =>
this.setupPre2(opts),
)
}

async getRefNames(opts?: BaseOptions) {
const { idToName } = await this.setup(opts)
return idToName
Expand Down
68 changes: 36 additions & 32 deletions plugins/alignments/src/CramAdapter/CramAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,42 +148,39 @@ export default class CramAdapter extends BaseFeatureDataAdapter {
return sequence
}

private async setupPre(opts?: BaseOptions) {
const { statusCallback = () => {} } = opts || {}
return updateStatus('Downloading index', statusCallback, async () => {
const conf = await this.configure()
const { cram } = conf
const samHeader = await cram.cram.getSamHeader()

// use the @SQ lines in the header to figure out the mapping between ref
// ID numbers and names
const idToName: string[] = []
const nameToId: Record<string, number> = {}
samHeader
.filter(l => l.tag === 'SQ')
.forEach((sqLine, refId) => {
const SN = sqLine.data.find(item => item.tag === 'SN')
if (SN) {
const refName = SN.value
nameToId[refName] = refId
idToName[refId] = refName
}
})
private async setupPre(_opts?: BaseOptions) {
const conf = await this.configure()
const { cram } = conf
const samHeader = await cram.cram.getSamHeader()

// use the @SQ lines in the header to figure out the mapping between ref
// ID numbers and names
const idToName: string[] = []
const nameToId: Record<string, number> = {}
samHeader
.filter(l => l.tag === 'SQ')
.forEach((sqLine, refId) => {
const SN = sqLine.data.find(item => item.tag === 'SN')
if (SN) {
const refName = SN.value
nameToId[refName] = refId
idToName[refId] = refName
}
})

const readGroups = samHeader
.filter(l => l.tag === 'RG')
.map(rgLine => rgLine.data.find(item => item.tag === 'ID')?.value)
const readGroups = samHeader
.filter(l => l.tag === 'RG')
.map(rgLine => rgLine.data.find(item => item.tag === 'ID')?.value)

const data = { idToName, nameToId, readGroups }
this.samHeader = data
return {
samHeader: data,
...conf,
}
})
const data = { idToName, nameToId, readGroups }
this.samHeader = data
return {
samHeader: data,
...conf,
}
}

private async setup(opts?: BaseOptions) {
private async setupPre2(opts?: BaseOptions) {
if (!this.setupP) {
this.setupP = this.setupPre(opts).catch((e: unknown) => {
this.setupP = undefined
Expand All @@ -193,6 +190,13 @@ export default class CramAdapter extends BaseFeatureDataAdapter {
return this.setupP
}

async setup(opts?: BaseOptions) {
const { statusCallback = () => {} } = opts || {}
return updateStatus('Downloading index', statusCallback, () =>
this.setupPre2(opts),
)
}

async getRefNames(opts?: BaseOptions) {
const { samHeader } = await this.setup(opts)
if (!samHeader.idToName) {
Expand Down

0 comments on commit 6f53fbd

Please sign in to comment.