Skip to content

Commit 520ae0b

Browse files
committed
Bugfix to JBrowse
1 parent f188499 commit 520ae0b

File tree

4 files changed

+21
-39
lines changed

4 files changed

+21
-39
lines changed

jbrowse/src/client/JBrowse/Browser/plugins/ExtendedVariantPlugin/ExtendedVariantAdapter/ExtendedVcfFeature.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
import { VcfFeature } from '@jbrowse/plugin-variants'
2-
import VcfParser from '@gmod/vcf'
2+
import VcfParser, { Variant } from '@gmod/vcf';
33

44
export default class ExtendedVcfFeature extends VcfFeature {
5-
private readonly vcfParser: VcfParser
6-
7-
constructor(args: { variant: any; parser: VcfParser; id: string }) {
5+
constructor(args: { variant: Variant; parser: VcfParser; id: string }) {
86
args.variant = ExtendedVcfFeature.extractImpact(args.variant)
9-
//args.variant = ExtendedVcfFeature.calculateVariableSamples(args.variant)
107

118
super(args)
12-
13-
this.vcfParser = args.parser
14-
}
15-
16-
public getInfoFieldMeta(propKey: string): VcfParser {
17-
const map = this.vcfParser.getMetadata("INFO")
18-
19-
return map ? map[propKey] : null
209
}
2110

22-
static extractImpact(variant: {
23-
REF: string
24-
POS: number
25-
ALT: string[]
26-
CHROM: string
27-
INFO: any
28-
ID: string[]
29-
}) {
11+
static extractImpact(variant: Variant) {
3012
// Only append if not present:
3113
if (variant.INFO["IMPACT"]) {
3214
return(variant);

jbrowse/src/client/JBrowse/Browser/plugins/ExtendedVariantPlugin/ExtendedVariantRenderer/components/ExtendedVariantRendering.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import jexl from 'jexl';
21
import { SvgFeatureRendererReactComponent } from '@jbrowse/plugin-svg';
32
import { observer } from 'mobx-react';
43
import React from 'react';
54
import { deserializeFilters } from '../../InfoFilterWidget/filterUtil';
65
import Diamond from './Diamond';
76
import { passesInfoFilters, passesSampleFilters } from '../../../../../utils';
7+
import { VcfFeature } from '@jbrowse/plugin-variants';
88

99
export function ExtendedVariantRendering(props) {
1010
const { features, rendererConfig } = props
@@ -17,11 +17,11 @@ export function ExtendedVariantRendering(props) {
1717

1818
const sampleFilters = activeSamples.value ? activeSamples.value.split(',') : null
1919

20-
function diamondValidator(feature) {
20+
function diamondValidator(feature: VcfFeature) {
2121
return feature.get('type') === "SNV";
2222
}
2323

24-
function isFeatureDisplayed(feature) {
24+
function isFeatureDisplayed(feature: VcfFeature) {
2525
return passesInfoFilters(feature, expandedFilters) && passesSampleFilters(feature, sampleFilters)
2626
}
2727

jbrowse/src/client/JBrowse/VariantTable/components/VariantTableWidget.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ const VariantTableWidget = observer(props => {
101101

102102
// Maintain a cached list of all non-WT samples at this position:
103103
filteredFeatures.forEach(variant => {
104-
if (!variant.get('INFO')['variableSamples'] && variant.get('SAMPLES')) {
104+
if (!variant.get('INFO')['variableSamples']) {
105105
variant.get('INFO')['variableSamples'] = []
106-
Object.keys(variant.get('SAMPLES')).forEach(function(sampleId) {
107-
const gt = variant.get('SAMPLES')[sampleId]["GT"] ? variant.get('SAMPLES')[sampleId]["GT"][0] : null
106+
const genotypes = variant.get('GENOTYPES')()
107+
Object.keys(genotypes).forEach(function(sampleId) {
108+
const gt = genotypes[sampleId] ? genotypes[sampleId] : null
108109
if (isVariant(gt)) {
109110
variant.get('INFO')['variableSamples'].push(sampleId)
110111
}

jbrowse/src/client/JBrowse/utils.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { createViewState, loadPlugins } from '@jbrowse/react-linear-genome-view2
44
import { ActionURL, Ajax } from '@labkey/api';
55
import {
66
getGridNumericOperators,
7-
GridCellParams,
87
GridColDef,
98
GridColType,
109
GridComparatorFn,
1110
GridFilterItem,
1211
GridFilterOperator
1312
} from '@mui/x-data-grid';
1413
import { ParsedLocString, parseLocString } from '@jbrowse/core/util';
14+
import { VcfFeature } from '@jbrowse/plugin-variants';
1515

1616
export function arrayMax(array) {
1717
return Array.isArray(array) ? Math.max(...array) : array
@@ -43,31 +43,30 @@ export function passesInfoFilters(feature, filters) {
4343
return true
4444
}
4545

46-
export function passesSampleFilters(feature, sampleIDs){
46+
export function passesSampleFilters(variant : VcfFeature, sampleIDs){
4747
if (!sampleIDs || sampleIDs.length === 0) {
4848
return true
4949
}
5050

51-
const featureVariant = feature.variant ?? feature.data
52-
const samples = featureVariant.SAMPLES || featureVariant.samples
53-
if (!samples || isEmptyObject(samples)) {
54-
return false
55-
}
56-
5751
// Preferentially use pre-computed values:
58-
if (featureVariant.INFO._variableSamples) {
52+
if (variant.get('INFO')['_variableSamples']) {
5953
for (const sampleId of sampleIDs) {
60-
if (featureVariant.INFO._variableSamples.indexOf(sampleId) > -1) {
54+
if (variant.get('INFO')._variableSamples.indexOf(sampleId) > -1) {
6155
return true
6256
}
6357
}
6458

6559
return false
6660
}
6761

62+
const genotypes = variant.get('GENOTYPES')()
63+
if (!genotypes || isEmptyObject(genotypes)) {
64+
return false
65+
}
66+
6867
for (const sampleId of sampleIDs) {
69-
if (samples[sampleId]) {
70-
const gt = samples[sampleId]["GT"][0]
68+
if (genotypes[sampleId]) {
69+
const gt = genotypes[sampleId]
7170

7271
// If any sample in the whitelist is non-WT, show this site. Otherwise filter.
7372
if (isVariant(gt)) {

0 commit comments

Comments
 (0)