Skip to content

Commit

Permalink
Colors from csv
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 24, 2025
1 parent 83d1196 commit 4682143
Show file tree
Hide file tree
Showing 21 changed files with 1,496 additions and 287 deletions.
2 changes: 1 addition & 1 deletion plugins/data-management/src/UCSCTrackHub/ucscTrackHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { generateUnknownTrackConf } from '@jbrowse/core/util/tracks'

import { makeLoc2, makeLoc, makeLocAlt } from './util'

import type { RaStanza, TrackDbFile } from '@gmod/ucsc-hub'
import type { RaStanza, TrackDbFile } from '@gmod/ucsc-hub'
import type { FileLocation } from '@jbrowse/core/util'

export function generateTracks({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const MultiLinearVariantDisplayComponent = observer(function (props: {
)
.filter(([key]) => key !== 'color')
.map(([key, value]) => `${key}:${value}`)
.join('\n')}
.join('<br/>')}
/>
</BaseTooltip>
</div>
Expand Down
18 changes: 5 additions & 13 deletions plugins/variants/src/MultiLinearVariantDisplay/model.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { lazy } from 'react'

import { set1 } from '@jbrowse/core/ui/colors'
import { getSession } from '@jbrowse/core/util'
import { stopStopToken } from '@jbrowse/core/util/stopToken'
import { linearBareDisplayStateModelFactory } from '@jbrowse/plugin-linear-genome-view'
import deepEqual from 'fast-deep-equal'
import { isAlive, types } from 'mobx-state-tree'

import { randomColor } from '../util'

import type { Source } from '../types'
import type PluginManager from '@jbrowse/core/PluginManager'
import type { AnyConfigurationSchemaType } from '@jbrowse/core/configuration'
Expand All @@ -24,7 +21,7 @@ const ClusterDialog = lazy(() => import('../shared/ClusterDialog'))
/**
* #stateModel MultiLinearVariantDisplay
* extends
* - [SharedVariantMixin](../sharedvariantmixin)
* - [LinearBareDisplay](../linearbaredisplay)
*/
export function stateModelFactory(
pluginManager: PluginManager,
Expand Down Expand Up @@ -160,15 +157,10 @@ export function stateModelFactory(
self.sourcesVolatile?.map(s => [s.name, s]) || [],
)
const iter = self.layout.length ? self.layout : self.sourcesVolatile
return iter
?.map(s => ({
...sources[s.name],
...s,
}))
.map((s, i) => ({
...s,
color: s.color || set1[i] || randomColor(s.name),
}))
return iter?.map(s => ({
...sources[s.name],
...s,
}))
},
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const MultiLinearVariantMatrixDisplayComponent = observer(function (props: {
)
.filter(([key]) => key !== 'color')
.map(([key, value]) => `${key}:${value}`)
.join('\n')}
.join('<br/>')}
/>
</BaseTooltip>
</>
Expand Down
18 changes: 5 additions & 13 deletions plugins/variants/src/MultiLinearVariantMatrixDisplay/model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { lazy } from 'react'

import { ConfigurationReference } from '@jbrowse/core/configuration'
import { set1 } from '@jbrowse/core/ui/colors'
import { getSession } from '@jbrowse/core/util'
import { stopStopToken } from '@jbrowse/core/util/stopToken'
import { linearBareDisplayStateModelFactory } from '@jbrowse/plugin-linear-genome-view'
import deepEqual from 'fast-deep-equal'
import { isAlive, types } from 'mobx-state-tree'

import { randomColor } from '../util'

import type { Source } from '../types'
import type { AnyConfigurationSchemaType } from '@jbrowse/core/configuration'
import type { Feature } from '@jbrowse/core/util'
Expand All @@ -24,7 +21,7 @@ const ClusterDialog = lazy(() => import('../shared/ClusterDialog'))
/**
* #stateModel LinearVariantMatrixDisplay
* extends
* - [LinearBasicDisplay](../linearbasicdisplay)
* - [LinearBareDisplay](../linearbaredisplay)
*/
export default function stateModelFactory(
configSchema: AnyConfigurationSchemaType,
Expand Down Expand Up @@ -142,15 +139,10 @@ export default function stateModelFactory(
const sources = Object.fromEntries(
self.sourcesVolatile?.map(s => [s.name, s]) || [],
)
return this.preSources
?.map(s => ({
...sources[s.name],
...s,
}))
.map((s, i) => ({
...s,
color: s.color || set1[i] || randomColor(s.name),
}))
return this.preSources?.map(s => ({
...sources[s.name],
...s,
}))
},
}))
.views(self => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { readConfObject } from '@jbrowse/core/configuration'
import { getStrokeProps, polarToCartesian } from '@jbrowse/core/util'
import { observer } from 'mobx-react'

import type { AnyRegion, Block } from './types'
import type { AnyConfigurationModel } from '@jbrowse/core/configuration'
import type { Feature } from '@jbrowse/core/util'
import type { AnyRegion, Block } from './types'

function bpToRadians(block: Block, pos: number) {
const blockStart = block.region.elided ? 0 : block.region.start
Expand Down
31 changes: 26 additions & 5 deletions plugins/variants/src/VcfAdapter/VcfAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import IntervalTree from '@flatten-js/interval-tree'
import VCF from '@gmod/vcf'
import VcfParser from '@gmod/vcf'
import { BaseFeatureDataAdapter } from '@jbrowse/core/data_adapters/BaseAdapter'
import { fetchAndMaybeUnzip } from '@jbrowse/core/util'
import { openLocation } from '@jbrowse/core/util/io'
import { ObservableCreate } from '@jbrowse/core/util/rxjs'

// local
import VcfFeature from '../VcfFeature'

import type { BaseOptions } from '@jbrowse/core/data_adapters/BaseAdapter'
Expand All @@ -18,6 +17,7 @@ export default class VcfAdapter extends BaseFeatureDataAdapter {

vcfFeatures?: Promise<{
header: string
parser: VcfParser
intervalTreeMap: Record<string, (sc?: StatusCallback) => IntervalTree>
}>

Expand All @@ -29,8 +29,7 @@ export default class VcfAdapter extends BaseFeatureDataAdapter {
}

async getMetadata() {
const { header } = await this.setup()
const parser = new VCF({ header })
const { parser } = await this.setup()
return parser.getMetadata()
}

Expand Down Expand Up @@ -72,7 +71,7 @@ export default class VcfAdapter extends BaseFeatureDataAdapter {
}

const header = headerLines.join('\n')
const parser = new VCF({ header })
const parser = new VcfParser({ header })

const intervalTreeMap = Object.fromEntries(
Object.entries(featureMap).map(([refName, lines]) => [
Expand All @@ -99,6 +98,7 @@ export default class VcfAdapter extends BaseFeatureDataAdapter {

return {
header,
parser,
intervalTreeMap,
}
}
Expand Down Expand Up @@ -135,5 +135,26 @@ export default class VcfAdapter extends BaseFeatureDataAdapter {
}, opts.stopToken)
}

async getSources() {
const conf = this.getConf('samplesTsvLocation')
if (conf.uri === '' || conf.uri === '/path/to/samples.tsv') {
const { parser } = await this.setup()
return parser.samples.map(name => ({
name,
}))
} else {
const txt = await openLocation(conf).readFile('utf8')
const lines = txt.split(/\n|\r\n|\r/)
const header = lines[0]!.split('\t')
return lines.slice(1).map(line =>
Object.fromEntries(
line
.split('\t')
// force col 0 to be called name
.map((c, idx) => [idx === 0 ? 'name' : header[idx], c]),
),
)
}
}
public freeResources(): void {}
}
11 changes: 8 additions & 3 deletions plugins/variants/src/VcfAdapter/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ const VcfAdapter = ConfigurationSchema(
/**
* #slot
*/
samples: {
type: 'frozen',
defaultValue: [],
samplesTsvLocation: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/samples.tsv',
description:
'tsv with header like name\tpopulation\tetc. where the first column is required, and is the sample names',
locationType: 'UriLocation',
},
},
},
{ explicitlyTyped: true },
Expand Down
24 changes: 19 additions & 5 deletions plugins/variants/src/VcfTabixAdapter/VcfTabixAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,26 @@ export default class VcfTabixAdapter extends BaseFeatureDataAdapter {
observer.complete()
}, opts.stopToken)
}

async getSources() {
const { parser } = await this.configure()
return parser.samples.map(name => ({
name,
}))
const conf = this.getConf('samplesTsvLocation')
if (conf.uri === '' || conf.uri === '/path/to/samples.tsv') {
const { parser } = await this.configure()
return parser.samples.map(name => ({
name,
}))
} else {
const txt = await openLocation(conf).readFile('utf8')
const lines = txt.split(/\n|\r\n|\r/)
const header = lines[0]!.split('\t')
return lines.slice(1).map(line =>
Object.fromEntries(
line
.split('\t')
// force col 0 to be called name
.map((c, idx) => [idx === 0 ? 'name' : header[idx], c]),
),
)
}
}

public freeResources(/* { region } */): void {}
Expand Down
11 changes: 8 additions & 3 deletions plugins/variants/src/VcfTabixAdapter/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ const VcfTabixAdapter = ConfigurationSchema(
/**
* #slot
*/
samples: {
type: 'frozen',
defaultValue: [],
samplesTsvLocation: {
type: 'fileLocation',
defaultValue: {
uri: '/path/to/samples.tsv',
description:
'tsv with header like name\tpopulation\tetc. where the first column is required, and is the sample names',
locationType: 'UriLocation',
},
},
},
{ explicitlyTyped: true },
Expand Down
2 changes: 1 addition & 1 deletion plugins/variants/src/getMultiVariantFeaturesAutorun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Source {
name: string
color?: string
group?: string
[key: string]: string | undefined
[key: string]: unknown
}

export function getMultiVariantFeaturesAutorun(self: {
Expand Down
Loading

0 comments on commit 4682143

Please sign in to comment.