Skip to content

Commit

Permalink
Add ability to use CSI indexes in @jbrowse/img (#4478)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin authored Jul 10, 2024
1 parent 309960c commit f7413b2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 109 deletions.
89 changes: 0 additions & 89 deletions plugins/alignments/src/LinearPileupDisplay/configSchema.test.js

This file was deleted.

1 change: 1 addition & 0 deletions products/jbrowse-img/data/volvox/volvox-sorted.bam.csi
15 changes: 15 additions & 0 deletions products/jbrowse-img/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ test('renders volvox with variety of args', async () => {
expect(result).toBeTruthy()
}, 40000)

test('renders volvox with csi index', async () => {
const result = await renderRegion({
fasta: fp('volvox.fa'),
trackList: [
[
'bam',
[fp('volvox-sorted.bam'), 'index:' + fp('volvox-sorted.bam.csi')],
],
],
loc: 'ctgA:1000-2000',
})
fs.writeFileSync(pa('../test/svg_from_volvox_fasta_and_bam_csi.svg'), result)
expect(result).toBeTruthy()
}, 40000)

test('renders volvox alignments as snpcov', async () => {
const result = await renderRegion({
fasta: fp('volvox.fa'),
Expand Down
34 changes: 14 additions & 20 deletions products/jbrowse-img/src/renderRegion.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import React from 'react'
import { createRoot } from 'react-dom/client'
import { createViewState } from '@jbrowse/react-linear-genome-view'
import {
LinearGenomeViewModel,
renderToSvg,
} from '@jbrowse/plugin-linear-genome-view'
import createCache from '@emotion/cache'
import { CacheProvider } from '@emotion/react'
import path from 'path'
import fs from 'fs'

// local
import { Entry } from './parseArgv'
import { booleanize } from './util'
import { createRoot } from 'react-dom/client'

export interface Opts {
noRasterize?: boolean
Expand Down Expand Up @@ -173,7 +170,8 @@ export function readData({

trackList.forEach(track => {
const [type, opts] = track
const [file] = opts
const [file, ...rest] = opts
const index = rest.find(r => r.startsWith('index:'))?.replace('index:', '')

if (type === 'bam') {
configData.tracks = [
Expand All @@ -186,7 +184,10 @@ export function readData({
adapter: {
type: 'BamAdapter',
bamLocation: makeLocation(file),
index: { location: makeLocation(file + '.bai') },
index: {
location: makeLocation(index || file + '.bai'),
indexType: index?.endsWith('.csi') ? 'CSI' : 'BAI',
},
sequenceAdapter: configData.assembly.sequence.adapter,
},
...(opts.includes('snpcov')
Expand All @@ -213,7 +214,7 @@ export function readData({
adapter: {
type: 'CramAdapter',
cramLocation: makeLocation(file),
craiLocation: makeLocation(file + '.crai'),
craiLocation: makeLocation(index || file + '.crai'),
sequenceAdapter: configData.assembly.sequence.adapter,
},
...(opts.includes('snpcov')
Expand Down Expand Up @@ -257,7 +258,8 @@ export function readData({
type: 'VcfTabixAdapter',
vcfGzLocation: makeLocation(file),
index: {
location: makeLocation(file + '.tbi'),
location: makeLocation(index || file + '.tbi'),
indexType: index?.endsWith('.csi') ? 'CSI' : 'TBI',
},
},
},
Expand All @@ -276,7 +278,8 @@ export function readData({
type: 'Gff3TabixAdapter',
gffGzLocation: makeLocation(file),
index: {
location: makeLocation(file + '.tbi'),
location: makeLocation(index || file + '.tbi'),
indexType: index?.endsWith('.csi') ? 'CSI' : 'TBI',
},
},
},
Expand Down Expand Up @@ -325,7 +328,8 @@ export function readData({
type: 'BedTabixAdapter',
bedGzLocation: makeLocation(file),
index: {
location: makeLocation(file + '.tbi'),
location: makeLocation(index || file + '.tbi'),
indexType: index?.endsWith('.csi') ? 'CSI' : 'TBI',
},
},
},
Expand All @@ -347,13 +351,6 @@ export function readData({
return configData
}

// without this, the styles can become messed up especially in lgv header
// xref https://github.com/garronej/tss-react/issues/25
export const muiCache = createCache({
key: 'mui',
prepend: true,
})

function process(
trackEntry: Entry,
view: LinearGenomeViewModel,
Expand Down Expand Up @@ -474,8 +471,5 @@ export async function renderRegion(opts: Opts) {
return renderToSvg(view, {
rasterizeLayers: !opts.noRasterize,
...opts,
Wrapper: ({ children }) => (
<CacheProvider value={muiCache}>{children}</CacheProvider>
),
})
}
Binary file modified test_data/volvox/volvox-sorted.bam.csi
Binary file not shown.

0 comments on commit f7413b2

Please sign in to comment.