/
baseTrackConfig.ts
204 lines (197 loc) · 5.72 KB
/
baseTrackConfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import { types, Instance } from 'mobx-state-tree'
import { ConfigurationSchema } from '../../configuration'
import PluginManager from '../../PluginManager'
/**
* #config BaseTrack
*/
export function createBaseTrackConfig(pluginManager: PluginManager) {
return ConfigurationSchema(
'BaseTrack',
{
/**
* #slot
*/
name: {
description: 'descriptive name of the track',
type: 'string',
defaultValue: 'Track',
},
/**
* #slot
*/
assemblyNames: {
description: 'name of the assembly (or assemblies) track belongs to',
type: 'stringArray',
defaultValue: ['assemblyName'],
},
/**
* #slot
*/
description: {
description: 'a description of the track',
type: 'string',
defaultValue: '',
},
/**
* #slot
*/
category: {
description: 'the category and sub-categories of a track',
type: 'stringArray',
defaultValue: [],
},
/**
* #slot
*/
metadata: {
type: 'frozen',
description: 'anything to add about this track',
defaultValue: {},
},
/**
* #slot
*/
adapter: pluginManager.pluggableConfigSchemaType('adapter'),
textSearching: ConfigurationSchema('textSearching', {
/**
* #slot textSearching.indexedAttributes
*/
indexingAttributes: {
type: 'stringArray',
description:
'list of which feature attributes to index for text searching',
defaultValue: ['Name', 'ID'],
},
/**
* #slot textSearching.indexingFeatureTypesToExclude
*/
indexingFeatureTypesToExclude: {
type: 'stringArray',
description: 'list of feature types to exclude in text search index',
defaultValue: ['CDS', 'exon'],
},
/**
* #slot textSearching.textSearchAdapter
*/
textSearchAdapter: pluginManager.pluggableConfigSchemaType(
'text search adapter',
),
}),
/**
* #slot
*/
displays: types.array(pluginManager.pluggableConfigSchemaType('display')),
formatDetails: ConfigurationSchema('FormatDetails', {
/**
* #slot formatDetails.feature
*/
feature: {
type: 'frozen',
description: 'adds extra fields to the feature details',
defaultValue: {},
contextVariable: ['feature'],
},
/**
* #slot formatDetails.subfeatures
*/
subfeatures: {
type: 'frozen',
description: 'adds extra fields to the subfeatures of a feature',
defaultValue: {},
contextVariable: ['feature'],
},
/**
* #slot formatDetails.depth
*/
depth: {
type: 'number',
defaultValue: 2,
description:
'depth of subfeatures to iterate the formatter on formatDetails.subfeatures (e.g. you may not want to format the exon/cds subfeatures, so limited to 2',
},
/**
* #slot formatDetails.maxDepth
*/
maxDepth: {
type: 'number',
defaultValue: 99999,
description: 'Maximum depth to render subfeatures',
},
}),
formatAbout: ConfigurationSchema('FormatAbout', {
/**
* #slot formatAbout.config
*/
config: {
type: 'frozen',
description: 'formats configuration object in about dialog',
defaultValue: {},
contextVariable: ['config'],
},
/**
* #slot formatAbout.hideUris
*/
hideUris: {
type: 'boolean',
defaultValue: false,
},
}),
},
{
preProcessSnapshot: s2 => {
const snap = pluginManager.evaluateExtensionPoint(
'Core-preProcessTrackConfig',
JSON.parse(JSON.stringify(s2)),
) as {
trackId: string
name: string
type: string
displays: { type: string; displayId: string }[]
}
const { displays = [] } = snap
if (snap.trackId !== 'placeholderId') {
// Gets the displays on the track snapshot and the possible displays
// from the track type and adds any missing possible displays to the
// snapshot
const configDisplayTypes = new Set(
displays.filter(d => !!d).map(d => d.type),
)
pluginManager.getTrackType(snap.type).displayTypes.forEach(d => {
if (!configDisplayTypes.has(d.name)) {
displays.push({
displayId: `${snap.trackId}-${d.name}`,
type: d.name,
})
}
})
}
return { ...snap, displays }
},
/**
* #identifier
*/
explicitIdentifier: 'trackId',
explicitlyTyped: true,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
actions: (self: any) => ({
addDisplayConf(conf: { type: string; displayId: string }) {
const { type } = conf
if (!type) {
throw new Error(`unknown display type ${type}`)
}
const display = self.displays.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(d: any) => d?.displayId === conf.displayId,
)
if (display) {
return display
}
const length = self.displays.push(conf)
return self.displays[length - 1]
},
}),
},
)
}
export type BaseTrackConfigSchema = ReturnType<typeof createBaseTrackConfig>
export type BaseTrackConfig = Instance<BaseTrackConfigSchema>