Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add track filetype guesser for BedGraph #4782

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions plugins/alignments/src/CramAdapter/CramAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ const getVolvoxSequenceSubAdapter: getSubAdapterType = async () => {
}
}

test('adapter can fetch features from volvox-sorted.cram', async () => {
const adapter = new Adapter(
function makeAdapter(arg: string) {
return new Adapter(
configSchema.create({
cramLocation: {
localPath: require.resolve('../../test_data/volvox-sorted.cram'),
localPath: require.resolve(arg),
locationType: 'LocalPathLocation',
},
craiLocation: {
localPath: require.resolve('../../test_data/volvox-sorted.cram.crai'),
localPath: require.resolve(arg + '.crai'),
locationType: 'LocalPathLocation',
},
sequenceAdapter: {},
}),
getVolvoxSequenceSubAdapter,
pluginManager,
)
}

test('adapter can fetch features from volvox-sorted.cram', async () => {
const adapter = makeAdapter('../../test_data/volvox-sorted.cram')

const features = adapter.getFeatures({
assemblyName: 'volvox',
Expand All @@ -57,22 +61,7 @@ test('adapter can fetch features from volvox-sorted.cram', async () => {
})

test('test usage of cramSlightlyLazyFeature toJSON (used in the widget)', async () => {
const adapter = new Adapter(
configSchema.create({
cramLocation: {
localPath: require.resolve('../../test_data/volvox-sorted.cram'),
locationType: 'LocalPathLocation',
},
craiLocation: {
localPath: require.resolve('../../test_data/volvox-sorted.cram.crai'),
locationType: 'LocalPathLocation',
},
sequenceAdapter: {},
}),
getVolvoxSequenceSubAdapter,
pluginManager,
)

const adapter = makeAdapter('../../test_data/volvox-sorted.cram')
const features = adapter.getFeatures({
assemblyName: 'volvox',
refName: 'ctgA',
Expand Down
32 changes: 32 additions & 0 deletions plugins/bed/src/BedGraphAdapter/BedGraphAdapter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { firstValueFrom } from 'rxjs'
import { toArray } from 'rxjs/operators'

import BedGraphAdapter from './BedGraphAdapter'
import configSchema from './configSchema'

function makeAdapter() {
return new BedGraphAdapter(
configSchema.create({
bedGraphLocation: {
localPath: require.resolve('./test_data/test.bg'),
locationType: 'LocalPathLocation',
},
}),
)
}
test('basic', async () => {
const adapter = makeAdapter()

const features = await firstValueFrom(
adapter
.getFeatures({
assemblyName: 'volvox',
refName: 'chr1',
start: 0,
end: 10000,
})
.pipe(toArray()),
)

expect(features).toMatchSnapshot()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`basic 1`] = `
[
{
"end": 200,
"refName": "chr1",
"score": 4,
"source": "col0",
"start": 100,
"uniqueId": "test-chr1-0-0",
},
{
"end": 300,
"refName": "chr1",
"score": 5,
"source": "col0",
"start": 200,
"uniqueId": "test-chr1-1-0",
},
{
"end": 400,
"refName": "chr1",
"score": 6,
"source": "col0",
"start": 300,
"uniqueId": "test-chr1-2-0",
},
]
`;
3 changes: 3 additions & 0 deletions plugins/bed/src/BedGraphAdapter/test_data/test.bg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chr1 100 200 4
chr1 200 300 5
chr1 300 400 6
38 changes: 38 additions & 0 deletions plugins/bed/src/BedGraphTabixAdapter/BedGraphTabixAdapter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { firstValueFrom } from 'rxjs'
import { toArray } from 'rxjs/operators'

import BedGraphTabixAdapter from './BedGraphTabixAdapter'
import configSchema from './configSchema'

function makeAdapter() {
return new BedGraphTabixAdapter(
configSchema.create({
bedGraphGzLocation: {
localPath: require.resolve('./test_data/test.bg.gz'),
locationType: 'LocalPathLocation',
},
index: {
location: {
localPath: require.resolve('./test_data/test.bg.gz.tbi'),
locationType: 'LocalPathLocation',
},
},
}),
)
}
test('basic', async () => {
const adapter = makeAdapter()

const features = await firstValueFrom(
adapter
.getFeatures({
assemblyName: 'volvox',
refName: 'chr1',
start: 0,
end: 10000,
})
.pipe(toArray()),
)

expect(features).toMatchSnapshot()
})
6 changes: 6 additions & 0 deletions plugins/bed/src/BedGraphTabixAdapter/BedGraphTabixAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export default class BedGraphAdapter extends BaseFeatureDataAdapter {
const start = +cols[colStart]!
const end = +(same ? start + 1 : cols[colEnd]!)
const rest = cols.slice(colEnd + 1)
if (Number.isNaN(start) || Number.isNaN(end)) {
throw new Error(
`start/end NaN on line "${line}", with colStart:${colStart} and colEnd:${colEnd}. run "tabix -p bed" to ensure bed preset`,
)
}

for (let j = 0; j < rest.length; j++) {
const uniqueId = `${this.id}-${fileOffset}-${j}`
const score = Math.abs(+rest[j]!)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`basic 1`] = `
[
{
"end": 200,
"refName": "chr1",
"score": 4,
"source": "col0",
"start": 100,
"uniqueId": "test-14548-0",
},
{
"end": 300,
"refName": "chr1",
"score": 5,
"source": "col0",
"start": 200,
"uniqueId": "test-14563-0",
},
{
"end": 400,
"refName": "chr1",
"score": 6,
"source": "col0",
"start": 300,
"uniqueId": "test-14578-0",
},
]
`;
Binary file not shown.
Binary file not shown.
82 changes: 14 additions & 68 deletions plugins/bed/src/BedTabixAdapter/BedTabixAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ import { toArray } from 'rxjs/operators'
import BedTabixAdapter from './BedTabixAdapter'
import MyConfigSchema from './configSchema'

test('adapter can fetch features from volvox-bed12.bed.gz', async () => {
const adapter = new BedTabixAdapter(
function makeAdapter(f: string, extra?: Record<string, unknown>) {
return new BedTabixAdapter(
MyConfigSchema.create({
bedGzLocation: {
localPath: require.resolve('./test_data/volvox-bed12.bed.gz'),
localPath: require.resolve(f),
locationType: 'LocalPathLocation',
},
index: {
location: {
localPath: require.resolve('./test_data/volvox-bed12.bed.gz.tbi'),
localPath: require.resolve(`${f}.tbi`),
locationType: 'LocalPathLocation',
},
},
...extra,
}),
)
}

test('adapter can fetch features from volvox-bed12.bed.gz', async () => {
const adapter = makeAdapter('./test_data/volvox-bed12.bed.gz')
const features = adapter.getFeatures({
refName: 'ctgA',
start: 0,
Expand All @@ -35,21 +39,7 @@ test('adapter can fetch features from volvox-bed12.bed.gz', async () => {
})

test('adapter can fetch features from volvox.sort.bed.gz simple bed3', async () => {
const adapter = new BedTabixAdapter(
MyConfigSchema.create({
bedGzLocation: {
localPath: require.resolve('./test_data/volvox.sort.bed.gz'),
locationType: 'LocalPathLocation',
},
index: {
location: {
localPath: require.resolve('./test_data/volvox.sort.bed.gz.tbi'),
locationType: 'LocalPathLocation',
},
},
}),
)

const adapter = makeAdapter('./test_data/volvox.sort.bed.gz')
const features = adapter.getFeatures({
refName: 'contigA',
start: 0,
Expand All @@ -65,19 +55,8 @@ test('adapter can fetch features from volvox.sort.bed.gz simple bed3', async ()
})

test('adapter can fetch features bed with autosql', async () => {
const adapter = new BedTabixAdapter(
MyConfigSchema.create({
bedGzLocation: {
localPath: require.resolve('./test_data/volvox-autosql.bed.gz'),
locationType: 'LocalPathLocation',
},
index: {
location: {
localPath: require.resolve('./test_data/volvox-autosql.bed.gz.tbi'),
locationType: 'LocalPathLocation',
},
},
autoSql: `table gdcCancer
const adapter = makeAdapter('./test_data/volvox-autosql.bed.gz', {
autoSql: `table gdcCancer
"somatic variants converted from MAF files obtained through the NCI GDC"
(
string chrom; "Chromosome (or contig, scaffold, etc.)"
Expand Down Expand Up @@ -118,8 +97,7 @@ test('adapter can fetch features bed with autosql', async () => {
lstring Matched_Norm_Sample_Barcode; "Matcheds normal sample barcode"
lstring case_id; "Case ID number"
)`,
}),
)
})
const features = adapter.getFeatures({
refName: 'ctgA',
start: 0,
Expand All @@ -135,25 +113,7 @@ test('adapter can fetch features bed with autosql', async () => {
})

test('adapter can fetch bed with header', async () => {
const adapter = new BedTabixAdapter(
MyConfigSchema.create({
bedGzLocation: {
localPath: require.resolve(
'./test_data/volvox.sort.with.header.bed.gz',
),
locationType: 'LocalPathLocation',
},
index: {
location: {
localPath: require.resolve(
'./test_data/volvox.sort.with.header.bed.gz.tbi',
),
locationType: 'LocalPathLocation',
},
},
}),
)

const adapter = makeAdapter('./test_data/volvox.sort.with.header.bed.gz')
const features = adapter.getFeatures({
refName: 'contigA',
start: 0,
Expand All @@ -169,21 +129,7 @@ test('adapter can fetch bed with header', async () => {
})

test('adapter can use gwas header', async () => {
const adapter = new BedTabixAdapter(
MyConfigSchema.create({
bedGzLocation: {
localPath: require.resolve('./test_data/gwas.bed.gz'),
locationType: 'LocalPathLocation',
},
index: {
location: {
localPath: require.resolve('./test_data/gwas.bed.gz.tbi'),
locationType: 'LocalPathLocation',
},
},
}),
)

const adapter = makeAdapter('./test_data/gwas.bed.gz')
const features = adapter.getFeatures({
refName: '1',
start: 0,
Expand Down
Loading
Loading