@@ -14,6 +14,18 @@ import InfoFilterWidget from './InfoFilterWidget';
1414import ColorWidget from './ColorWidget' ;
1515import SampleFilterWidget from './SampleFilterWidget' ;
1616import GlyphType from '@jbrowse/core/pluggableElementTypes/GlyphType' ;
17+ import { readConfObject } from '@jbrowse/core/configuration' ;
18+ import { emphasize } from '@jbrowse/core/util/color' ;
19+ import { deserializeFilters } from './InfoFilterWidget/filterUtil' ;
20+ import { passesInfoFilters , passesSampleFilters } from '../../../utils' ;
21+
22+ const utrHeightFraction = 0.65
23+
24+ function isUTR ( feature : any ) {
25+ return / ( \b U T R | _ U T R | u n t r a n s l a t e d [ _ \s ] r e g i o n ) \b / . test (
26+ feature ?. get ?.( 'type' ) || '' ,
27+ )
28+ }
1729
1830export default class ExtendedVariantPlugin extends Plugin {
1931 name = 'ExtendedVariantPlugin'
@@ -64,17 +76,39 @@ export default class ExtendedVariantPlugin extends Plugin {
6476 new GlyphType ( {
6577 name : 'SNVGlyph' ,
6678 displayName : 'SNV Diamond' ,
67- draw : ctx => {
68- const { ctx : context , featureLayout } = ctx
69- const { x, y, width, height } = featureLayout
79+ draw : ( ctx : any ) => {
80+ const { ctx : context , featureLayout, feature, config } = ctx
81+ const selected = ! ! ctx ?. selected
82+ const rendererConfig : any = config
83+ const { x, y, width } = featureLayout
84+
85+ let top = y
86+ let height = featureLayout . height
87+ if ( isUTR ( feature ) ) {
88+ top += ( ( 1 - utrHeightFraction ) / 2 ) * height
89+ height *= utrHeightFraction
90+ }
7091
7192 const centerX = x + width / 2
72- const centerY = y + height / 2
73- const halfWidth = Math . max ( width / 2 , 4 )
93+ const centerY = top + height / 2
94+ const halfWidth = height / 2
7495 const halfHeight = height / 2
7596
76- // Purple diamond fill
77- context . fillStyle = '#800080'
97+ const color = ( readConfObject as any ) (
98+ rendererConfig ,
99+ isUTR ( feature ) ? 'color3' : 'color1' ,
100+ { feature } ,
101+ ) || '#800080'
102+ const color2 = ( readConfObject as any ) ( rendererConfig , 'color2' , { feature } ) || '#4B0082'
103+
104+ let emphasizedColor
105+ try {
106+ emphasizedColor = emphasize ( color , 0.3 )
107+ } catch ( error ) {
108+ emphasizedColor = color
109+ }
110+
111+ context . fillStyle = selected ? emphasizedColor : color
78112 context . beginPath ( )
79113 context . moveTo ( centerX , centerY - halfHeight ) // top
80114 context . lineTo ( centerX + halfWidth , centerY ) // right
@@ -83,10 +117,11 @@ export default class ExtendedVariantPlugin extends Plugin {
83117 context . closePath ( )
84118 context . fill ( )
85119
86- // Indigo stroke
87- context . strokeStyle = '#4B0082'
88- context . lineWidth = 1
89- context . stroke ( )
120+ if ( selected ) {
121+ context . strokeStyle = color2
122+ context . lineWidth = 1
123+ context . stroke ( )
124+ }
90125 } ,
91126 match : feature => feature . get ( 'type' ) === 'SNV' ,
92127 } )
@@ -163,6 +198,31 @@ export default class ExtendedVariantPlugin extends Plugin {
163198 pluginManager . jexl . addFunction ( 'formatWithCommas' , ( val ) => {
164199 return val ? Number ( val ) . toLocaleString ( ) : val
165200 } )
201+
202+ pluginManager . jexl . addFunction ( 'passesInfoFilters' , ( feature , serializedFilters ) => {
203+ try {
204+ const filters = typeof serializedFilters === 'string'
205+ ? JSON . parse ( serializedFilters )
206+ : serializedFilters
207+ const expandedFilters = deserializeFilters ( filters )
208+ return passesInfoFilters ( feature , expandedFilters )
209+ } catch ( e ) {
210+ console . error ( e )
211+ return true
212+ }
213+ } )
214+
215+ pluginManager . jexl . addFunction ( 'passesSampleFilters' , ( feature , serializedSampleFilters ) => {
216+ try {
217+ const sampleFilters = typeof serializedSampleFilters === 'string'
218+ ? JSON . parse ( serializedSampleFilters )
219+ : serializedSampleFilters
220+ return passesSampleFilters ( feature , sampleFilters )
221+ } catch ( e ) {
222+ console . error ( e )
223+ return true
224+ }
225+ } )
166226 }
167227
168228 configure ( pluginManager : PluginManager ) {
0 commit comments