jbrowse-plugin-protein3d 1.24.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LaunchProteinViewExtensionPoint/normalizeLaunch.js +7 -0
- package/dist/ProteinView/loadStructureData.js +2 -1
- package/dist/ProteinView/markEncoding.js +5 -0
- package/dist/ProteinView/markProblems.js +138 -0
- package/dist/ProteinView/measurements.js +4 -6
- package/dist/ProteinView/model.js +7 -3
- package/dist/ProteinView/residueFilter.js +184 -0
- package/dist/ProteinView/residueMarks.js +14 -10
- package/dist/ProteinView/residueSpec.js +18 -7
- package/dist/ProteinView/sessionHighlights.js +11 -13
- package/dist/ProteinView/structureModel.js +8 -0
- package/dist/ProteinView/structurePipeline.js +25 -16
- package/dist/chunks/{LaunchProteinViewDialog-GDEANZ6O.js → LaunchProteinViewDialog-PC5HYIE3.js} +2 -2
- package/dist/chunks/{ProteinView-QALYTNTX.js → ProteinView-56FHBQSV.js} +2 -2
- package/dist/chunks/chunk-6B7WZJO7.js +2 -0
- package/dist/chunks/chunk-6B7WZJO7.js.map +7 -0
- package/dist/chunks/chunk-6OAZLCO5.js +2 -0
- package/dist/chunks/chunk-6OAZLCO5.js.map +7 -0
- package/dist/chunks/chunk-DFLRALX5.js +2 -0
- package/dist/chunks/chunk-DFLRALX5.js.map +7 -0
- package/dist/chunks/{chunk-VT5BCVCX.js → chunk-FRK6X72I.js} +2 -2
- package/dist/chunks/chunk-NUJCOEJ3.js +2 -0
- package/dist/chunks/chunk-NUJCOEJ3.js.map +7 -0
- package/dist/chunks/{chunk-KZ76WUQW.js → chunk-WHJFF2WE.js} +2 -2
- package/dist/chunks/chunk-WHJFF2WE.js.map +7 -0
- package/dist/chunks/{launchAnnotationView-UFCA3T3G.js → launchAnnotationView-XEUIILD5.js} +2 -2
- package/dist/chunks/{launchProteinView-S7VBHQK7.js → launchProteinView-XUNPJWEY.js} +2 -2
- package/dist/chunks/{launchViewUtils-7XTBTFAV.js → launchViewUtils-JLW2J4TI.js} +2 -2
- package/dist/chunks/model-QDSVZCTN.js +2 -0
- package/dist/chunks/model-QDSVZCTN.js.map +7 -0
- package/dist/jbrowse-plugin-protein3d.esm.js +1 -1
- package/dist/jbrowse-plugin-protein3d.esm.js.map +1 -1
- package/dist/test_data/molstarPlugin.js +2 -0
- package/dist/test_data/molstarStructure.js +23 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.test.ts +14 -0
- package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.ts +13 -0
- package/src/ProteinView/loadStructureData.ts +4 -3
- package/src/ProteinView/markEncoding.ts +18 -0
- package/src/ProteinView/markProblems.test.ts +95 -0
- package/src/ProteinView/markProblems.ts +161 -0
- package/src/ProteinView/measurements.test.ts +15 -3
- package/src/ProteinView/measurements.ts +6 -7
- package/src/ProteinView/model.test.ts +48 -0
- package/src/ProteinView/model.ts +10 -3
- package/src/ProteinView/proteinViewSpec.ts +6 -0
- package/src/ProteinView/residueFilter.test.ts +97 -0
- package/src/ProteinView/residueFilter.ts +250 -0
- package/src/ProteinView/residueMarks.test.ts +47 -0
- package/src/ProteinView/residueMarks.ts +26 -15
- package/src/ProteinView/residueSpec.ts +24 -8
- package/src/ProteinView/sessionHighlights.test.ts +41 -0
- package/src/ProteinView/sessionHighlights.ts +16 -13
- package/src/ProteinView/structureModel.ts +9 -0
- package/src/ProteinView/structurePipeline.test.ts +100 -1
- package/src/ProteinView/structurePipeline.ts +36 -18
- package/src/test_data/molstarPlugin.ts +11 -1
- package/src/test_data/molstarStructure.ts +28 -1
- package/src/version.ts +1 -1
- package/dist/chunks/chunk-AYS6MD64.js +0 -2
- package/dist/chunks/chunk-AYS6MD64.js.map +0 -7
- package/dist/chunks/chunk-IW33ITI5.js +0 -2
- package/dist/chunks/chunk-IW33ITI5.js.map +0 -7
- package/dist/chunks/chunk-KZ76WUQW.js.map +0 -7
- package/dist/chunks/chunk-SR54J2GA.js +0 -2
- package/dist/chunks/chunk-SR54J2GA.js.map +0 -7
- package/dist/chunks/chunk-UEHBHBLB.js +0 -2
- package/dist/chunks/chunk-UEHBHBLB.js.map +0 -7
- package/dist/chunks/model-66TJN3RN.js +0 -2
- package/dist/chunks/model-66TJN3RN.js.map +0 -7
- /package/dist/chunks/{LaunchProteinViewDialog-GDEANZ6O.js.map → LaunchProteinViewDialog-PC5HYIE3.js.map} +0 -0
- /package/dist/chunks/{ProteinView-QALYTNTX.js.map → ProteinView-56FHBQSV.js.map} +0 -0
- /package/dist/chunks/{chunk-VT5BCVCX.js.map → chunk-FRK6X72I.js.map} +0 -0
- /package/dist/chunks/{launchAnnotationView-UFCA3T3G.js.map → launchAnnotationView-XEUIILD5.js.map} +0 -0
- /package/dist/chunks/{launchProteinView-S7VBHQK7.js.map → launchProteinView-XUNPJWEY.js.map} +0 -0
- /package/dist/chunks/{launchViewUtils-7XTBTFAV.js.map → launchViewUtils-JLW2J4TI.js.map} +0 -0
|
@@ -13,6 +13,7 @@ const STRUCTURE_KEY_ROLES = {
|
|
|
13
13
|
hidden: 'setting',
|
|
14
14
|
assembly: 'setting',
|
|
15
15
|
chains: 'setting',
|
|
16
|
+
filter: 'setting',
|
|
16
17
|
feature: 'launchWide',
|
|
17
18
|
userProvidedTranscriptSequence: 'launchWide',
|
|
18
19
|
connectedViewId: 'launchWide',
|
|
@@ -44,6 +45,11 @@ function isNumber(value) {
|
|
|
44
45
|
function isFeature(value) {
|
|
45
46
|
return isRecord(value);
|
|
46
47
|
}
|
|
48
|
+
// the shape only: the view model refuses a predicate that does not read, with
|
|
49
|
+
// the reason, as it does a color
|
|
50
|
+
function isPredicateList(value) {
|
|
51
|
+
return Array.isArray(value) && value.every(isRecord);
|
|
52
|
+
}
|
|
47
53
|
function isResidueRange(value) {
|
|
48
54
|
return (isRecord(value) &&
|
|
49
55
|
typeof value.start === 'number' &&
|
|
@@ -126,6 +132,7 @@ function readStructure(fields, at, warnings) {
|
|
|
126
132
|
hidden: read('hidden', isBoolean, 'true or false'),
|
|
127
133
|
assembly: read('assembly', isString, 'a string'),
|
|
128
134
|
chains: read('chains', isStringArray, 'a list of chain ids'),
|
|
135
|
+
filter: read('filter', isPredicateList, "a list of predicates such as [{ field: 'residue', lte: 184 }]"),
|
|
129
136
|
feature: read('feature', isFeature, 'a feature object'),
|
|
130
137
|
userProvidedTranscriptSequence: read('userProvidedTranscriptSequence', isString, 'a string'),
|
|
131
138
|
connectedViewId: read('connectedViewId', isString, 'a string'),
|
|
@@ -68,13 +68,14 @@ function structureAssemblies(model, molstar) {
|
|
|
68
68
|
* callers own the decision of whether/where to store the result.
|
|
69
69
|
*/
|
|
70
70
|
export async function loadStructureData({ structure, plugin, }) {
|
|
71
|
-
const { data, url, assembly, chains } = structure;
|
|
71
|
+
const { data, url, assembly, chains, filter } = structure;
|
|
72
72
|
const { model, structures: molstarStructures, modelIds, } = await loadStructure({
|
|
73
73
|
plugin,
|
|
74
74
|
data: data || undefined,
|
|
75
75
|
url,
|
|
76
76
|
assembly,
|
|
77
77
|
chains,
|
|
78
|
+
filter,
|
|
78
79
|
});
|
|
79
80
|
const molstar = await loadMolstar();
|
|
80
81
|
// An experimental entry's B-factors are not confidence: read as pLDDT they
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { narrowsChains } from './residueFilter';
|
|
2
|
+
import { parseSite } from './residueSpec';
|
|
3
|
+
const MARK_TYPES = ['spheres', 'sticks', 'cartoon'];
|
|
4
|
+
const HEX_COLOR = /^#[0-9a-f]{6}$/i;
|
|
5
|
+
function isRecord(x) {
|
|
6
|
+
return typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
7
|
+
}
|
|
8
|
+
function encodingProblems(where, entry) {
|
|
9
|
+
const value = isRecord(entry.encoding)
|
|
10
|
+
? isRecord(entry.encoding.color)
|
|
11
|
+
? entry.encoding.color.value
|
|
12
|
+
: undefined
|
|
13
|
+
: undefined;
|
|
14
|
+
return [
|
|
15
|
+
...('color' in entry
|
|
16
|
+
? [`${where}.color is now encoding: { color: { value: '#rrggbb' } }`]
|
|
17
|
+
: []),
|
|
18
|
+
...(value !== undefined &&
|
|
19
|
+
(typeof value !== 'string' || !HEX_COLOR.test(value))
|
|
20
|
+
? [
|
|
21
|
+
`${where}.encoding.color.value is a #rrggbb color, not ${JSON.stringify(value)}`,
|
|
22
|
+
]
|
|
23
|
+
: []),
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
function siteProblems(where, key, site) {
|
|
27
|
+
return typeof site === 'string' && parseSite(site)
|
|
28
|
+
? []
|
|
29
|
+
: [
|
|
30
|
+
`${where}.${key} is a site such as A:248, A:248@NH2, MOV or G:*, not ${String(site)}`,
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Why `marks` would draw something other than what it says: a site or mark
|
|
35
|
+
* type that does not parse, a color that is not #rrggbb, or a cartoon over a
|
|
36
|
+
* chain the structure already draws whole. `structures` are the view's, whose
|
|
37
|
+
* `chains` and `filter` say what is drawn.
|
|
38
|
+
*/
|
|
39
|
+
export function markProblems(marks, structures = []) {
|
|
40
|
+
if (marks === undefined) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
if (!Array.isArray(marks)) {
|
|
44
|
+
return ['marks is a list'];
|
|
45
|
+
}
|
|
46
|
+
return marks.flatMap((mark, i) => {
|
|
47
|
+
const where = `marks[${i}]`;
|
|
48
|
+
if (!isRecord(mark)) {
|
|
49
|
+
return [`${where} is an object such as { site: 'A:12', mark: 'spheres' }`];
|
|
50
|
+
}
|
|
51
|
+
const site = typeof mark.site === 'string' ? parseSite(mark.site) : undefined;
|
|
52
|
+
const structure = structures[typeof mark.structure === 'number' ? mark.structure : 0];
|
|
53
|
+
const drawn = structure?.chains;
|
|
54
|
+
return [
|
|
55
|
+
...siteProblems(where, 'site', mark.site),
|
|
56
|
+
...(mark.mark !== undefined && !MARK_TYPES.includes(mark.mark)
|
|
57
|
+
? [
|
|
58
|
+
`${where}.mark is one of ${MARK_TYPES.join(', ')}, not ${JSON.stringify(mark.mark)}`,
|
|
59
|
+
]
|
|
60
|
+
: []),
|
|
61
|
+
...encodingProblems(where, mark),
|
|
62
|
+
...(mark.mark === 'cartoon' &&
|
|
63
|
+
site?.kind === 'chain' &&
|
|
64
|
+
!narrowsChains(structure) &&
|
|
65
|
+
(!drawn || drawn.includes(site.chain))
|
|
66
|
+
? [
|
|
67
|
+
`${where} draws chain ${site.chain} as a cartoon over the one the structure draws; list the other chains in chains`,
|
|
68
|
+
]
|
|
69
|
+
: []),
|
|
70
|
+
];
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** The same check for `distances`: two sites and a constant encoding. */
|
|
74
|
+
export function distanceProblems(distances) {
|
|
75
|
+
if (distances === undefined) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
if (!Array.isArray(distances)) {
|
|
79
|
+
return ['distances is a list'];
|
|
80
|
+
}
|
|
81
|
+
return distances.flatMap((d, i) => {
|
|
82
|
+
const where = `distances[${i}]`;
|
|
83
|
+
return isRecord(d)
|
|
84
|
+
? [
|
|
85
|
+
...siteProblems(where, 'a', d.a),
|
|
86
|
+
...siteProblems(where, 'b', d.b),
|
|
87
|
+
...encodingProblems(where, d),
|
|
88
|
+
]
|
|
89
|
+
: [`${where} is an object such as { a: 'A:46@NZ', b: 'A:80@NZ' }`];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A mark or distance written the way 1.23 and 1.24 read it, `style` and a
|
|
94
|
+
* string `color`, in the encoding spelling; any other entry as it is.
|
|
95
|
+
*/
|
|
96
|
+
function migratedLayer(entry) {
|
|
97
|
+
if (!isRecord(entry)) {
|
|
98
|
+
return entry;
|
|
99
|
+
}
|
|
100
|
+
const { style, color, ...rest } = entry;
|
|
101
|
+
return {
|
|
102
|
+
...rest,
|
|
103
|
+
...(rest.mark === undefined && style !== undefined ? { mark: style } : {}),
|
|
104
|
+
...(typeof color === 'string'
|
|
105
|
+
? rest.encoding === undefined
|
|
106
|
+
? { encoding: { color: { value: color } } }
|
|
107
|
+
: {}
|
|
108
|
+
: color === undefined
|
|
109
|
+
? {}
|
|
110
|
+
: { color }),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function migratedList(list) {
|
|
114
|
+
return Array.isArray(list) ? list.map(migratedLayer) : list;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* `marks` and `distances` migrated from the 1.24 spelling, then refused with
|
|
118
|
+
* every problem found in either.
|
|
119
|
+
*/
|
|
120
|
+
export function checkedLayers(snapshot, structures = []) {
|
|
121
|
+
const migrated = {
|
|
122
|
+
...snapshot,
|
|
123
|
+
...(snapshot.marks === undefined
|
|
124
|
+
? {}
|
|
125
|
+
: { marks: migratedList(snapshot.marks) }),
|
|
126
|
+
...(snapshot.distances === undefined
|
|
127
|
+
? {}
|
|
128
|
+
: { distances: migratedList(snapshot.distances) }),
|
|
129
|
+
};
|
|
130
|
+
const problems = [
|
|
131
|
+
...markProblems(migrated.marks, structures),
|
|
132
|
+
...distanceProblems(migrated.distances),
|
|
133
|
+
];
|
|
134
|
+
if (problems.length > 0) {
|
|
135
|
+
throw new Error(problems.join('; '));
|
|
136
|
+
}
|
|
137
|
+
return migrated;
|
|
138
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import loadMolstar from './loadMolstar';
|
|
2
|
+
import { encodedColor } from './markEncoding';
|
|
2
3
|
import { parseSite, siteExpression } from './residueSpec';
|
|
3
4
|
import { serialPerPlugin } from './serialPerPlugin';
|
|
4
5
|
export const MEASUREMENT_TAG = 'jbrowse-measurement';
|
|
5
6
|
const KEY_PREFIX = `${MEASUREMENT_TAG}:`;
|
|
6
7
|
export const DEFAULT_DASH_COLOR = '#ffd60a';
|
|
7
|
-
const HEX_COLOR = /^#[0-9a-f]{6}$/i;
|
|
8
8
|
function atomsOf(molstar, structure, site) {
|
|
9
9
|
const { MolScriptBuilder: MS, OrderedSet, Script, StructureElement, StructureProperties: SP, StructureSelection, Vec3, } = molstar;
|
|
10
10
|
const loci = StructureSelection.toLociWithSourceUnits(Script.getStructureSelection(siteExpression(MS, site), structure));
|
|
@@ -34,7 +34,7 @@ export function closestAtoms(molstar, structure, a, b) {
|
|
|
34
34
|
const siteA = parseSite(a);
|
|
35
35
|
const siteB = parseSite(b);
|
|
36
36
|
if (!siteA || !siteB) {
|
|
37
|
-
return { error: `${siteA ? b : a} is not a
|
|
37
|
+
return { error: `${siteA ? b : a} is not a site such as A:248 or G:*` };
|
|
38
38
|
}
|
|
39
39
|
const atomsA = atomsOf(molstar, structure, siteA);
|
|
40
40
|
const atomsB = atomsOf(molstar, structure, siteB);
|
|
@@ -63,7 +63,7 @@ function atomLoci(molstar, structure, atom) {
|
|
|
63
63
|
]);
|
|
64
64
|
}
|
|
65
65
|
function keyOf(structure, m) {
|
|
66
|
-
return `${KEY_PREFIX}${structure.model.id}|${m.a}|${m.b}|${m.color ?? ''}`;
|
|
66
|
+
return `${KEY_PREFIX}${structure.model.id}|${m.a}|${m.b}|${m.encoding?.color?.value ?? ''}`;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Make the distances drawn in Mol* match `measurements`: the ones no longer
|
|
@@ -97,9 +97,7 @@ export function syncMeasurements({ plugin, structures, measurements, labels = tr
|
|
|
97
97
|
wanted.set(keyOf(structure, measurement), {
|
|
98
98
|
structure,
|
|
99
99
|
pair,
|
|
100
|
-
color:
|
|
101
|
-
? measurement.color
|
|
102
|
-
: DEFAULT_DASH_COLOR,
|
|
100
|
+
color: encodedColor(measurement.encoding, DEFAULT_DASH_COLOR),
|
|
103
101
|
});
|
|
104
102
|
return {
|
|
105
103
|
measurement,
|
|
@@ -13,11 +13,13 @@ import { applyFigureStyle } from './figureStyle';
|
|
|
13
13
|
import { makeSelectionFramer, structuresSettled } from './frameSelection';
|
|
14
14
|
import loadMolstar from './loadMolstar';
|
|
15
15
|
import { makeLociChannel } from './lociChannel';
|
|
16
|
+
import { checkedLayers } from './markProblems';
|
|
16
17
|
import { syncMeasurements } from './measurements';
|
|
17
18
|
import { checkedColor, colorOfScheme, resolvedColor } from './proteinColor';
|
|
18
19
|
import { defaultDisplayName } from './proteinViewSpec';
|
|
19
20
|
import { removeMolstarStructure } from './removeStructure';
|
|
20
21
|
import { reportPluginFailure } from './reportPluginFailure';
|
|
22
|
+
import { checkedStructureFilters } from './residueFilter';
|
|
21
23
|
import { syncResidueMarks } from './residueMarks';
|
|
22
24
|
import { applySavedCamera } from './savedCamera';
|
|
23
25
|
import { highlightCameraSnapshot, syncSessionHighlightMarks, } from './sessionHighlights';
|
|
@@ -167,8 +169,9 @@ function stateModelFactory() {
|
|
|
167
169
|
distances: types.frozen(),
|
|
168
170
|
/**
|
|
169
171
|
* #property
|
|
170
|
-
* sites drawn on their own as spheres or
|
|
171
|
-
* ResidueMark): a partner's residue, a ligand, a pocket
|
|
172
|
+
* sites drawn on their own as spheres, sticks or a cartoon, on any
|
|
173
|
+
* chain (see ResidueMark): a partner's residue, a ligand, a pocket, a
|
|
174
|
+
* partner protein
|
|
172
175
|
*/
|
|
173
176
|
marks: types.frozen(),
|
|
174
177
|
/**
|
|
@@ -219,7 +222,7 @@ function stateModelFactory() {
|
|
|
219
222
|
alignmentAlgorithm: types.optional(types.enumeration('AlignmentAlgorithm', ALIGNMENT_ALGORITHM_VALUES), DEFAULT_ALIGNMENT_ALGORITHM),
|
|
220
223
|
}))
|
|
221
224
|
.preProcessSnapshot(({ colorScheme, ...snapshot }) => withStoredSettings({
|
|
222
|
-
...snapshot,
|
|
225
|
+
...checkedLayers(snapshot, checkedStructureFilters(snapshot.structures)),
|
|
223
226
|
displayName: snapshot.displayName ??
|
|
224
227
|
defaultDisplayName(snapshot.structures ?? []),
|
|
225
228
|
color: checkedColor(snapshot.color ??
|
|
@@ -485,6 +488,7 @@ function stateModelFactory() {
|
|
|
485
488
|
molstarStructure,
|
|
486
489
|
marks: s.sessionHighlightMarks,
|
|
487
490
|
chains: s.chains,
|
|
491
|
+
filter: s.filter,
|
|
488
492
|
}))
|
|
489
493
|
: []);
|
|
490
494
|
const seeded = self.structures.some(s => s.seededSelection);
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fields a predicate tests, each with the Mol* property it reads and the
|
|
3
|
+
* level Mol* tests it at. `residue` is the author residue number
|
|
4
|
+
* (`auth_seq_id`), the numbering a paper cites and `marks` address; `chain`
|
|
5
|
+
* the author chain id (`auth_asym_id`), the one `chains` lists.
|
|
6
|
+
*/
|
|
7
|
+
const FIELDS = {
|
|
8
|
+
residue: {
|
|
9
|
+
property: 'auth_seq_id',
|
|
10
|
+
numeric: true,
|
|
11
|
+
level: 'residue',
|
|
12
|
+
kind: 'a number',
|
|
13
|
+
},
|
|
14
|
+
chain: {
|
|
15
|
+
property: 'auth_asym_id',
|
|
16
|
+
numeric: false,
|
|
17
|
+
level: 'chain',
|
|
18
|
+
kind: 'a string',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const BOUNDS = ['lt', 'lte', 'gt', 'gte', 'range'];
|
|
22
|
+
const OPERATORS = ['equal', ...BOUNDS, 'oneOf'];
|
|
23
|
+
const EXAMPLE = "{ field: 'residue', lte: 184 }";
|
|
24
|
+
const TAKES = `a predicate takes field and one of ${OPERATORS.join(', ')}`;
|
|
25
|
+
function isRecord(x) {
|
|
26
|
+
return typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
27
|
+
}
|
|
28
|
+
function isField(field) {
|
|
29
|
+
return typeof field === 'string' && Object.hasOwn(FIELDS, field);
|
|
30
|
+
}
|
|
31
|
+
function isNumber(value) {
|
|
32
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
33
|
+
}
|
|
34
|
+
function isValue(value, field) {
|
|
35
|
+
return FIELDS[field].numeric ? isNumber(value) : typeof value === 'string';
|
|
36
|
+
}
|
|
37
|
+
function rangeProblems(where, range) {
|
|
38
|
+
if (!Array.isArray(range) || range.length !== 2 || !range.every(isNumber)) {
|
|
39
|
+
return [
|
|
40
|
+
`${where}.range is two numbers, the low and high ends, not ${JSON.stringify(range)}`,
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
const [low, high] = range;
|
|
44
|
+
return low <= high
|
|
45
|
+
? []
|
|
46
|
+
: [`${where}.range runs low to high; ${low} is above ${high}`];
|
|
47
|
+
}
|
|
48
|
+
function operatorProblems(where, field, key, value) {
|
|
49
|
+
if (key === 'range') {
|
|
50
|
+
return rangeProblems(where, value);
|
|
51
|
+
}
|
|
52
|
+
if (key === 'oneOf') {
|
|
53
|
+
return Array.isArray(value) &&
|
|
54
|
+
value.length > 0 &&
|
|
55
|
+
value.every(v => isValue(v, field))
|
|
56
|
+
? []
|
|
57
|
+
: [
|
|
58
|
+
`${where}.oneOf is a list of ${field === 'residue' ? 'numbers' : 'strings'}, not ${JSON.stringify(value)}`,
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
const expected = key === 'equal' ? FIELDS[field].kind : 'a number';
|
|
62
|
+
return (key === 'equal' ? isValue(value, field) : isNumber(value))
|
|
63
|
+
? []
|
|
64
|
+
: [`${where}.${key} is ${expected}, not ${JSON.stringify(value)}`];
|
|
65
|
+
}
|
|
66
|
+
/** The lowest and highest number a predicate's bounds admit; an end no bound
|
|
67
|
+
* names is open. */
|
|
68
|
+
function bounds(predicate) {
|
|
69
|
+
const at = (key) => {
|
|
70
|
+
const value = predicate[key];
|
|
71
|
+
return isNumber(value) ? value : undefined;
|
|
72
|
+
};
|
|
73
|
+
const range = Array.isArray(predicate.range) ? predicate.range : [];
|
|
74
|
+
return {
|
|
75
|
+
low: Math.max(at('gt') ?? -Infinity, at('gte') ?? -Infinity, isNumber(range[0]) ? range[0] : -Infinity),
|
|
76
|
+
high: Math.min(at('lt') ?? Infinity, at('lte') ?? Infinity, isNumber(range[1]) ? range[1] : Infinity),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function predicateProblems(where, predicate) {
|
|
80
|
+
if (!isRecord(predicate)) {
|
|
81
|
+
return [`${where} is an object such as ${EXAMPLE}`];
|
|
82
|
+
}
|
|
83
|
+
const { field, ...tests } = predicate;
|
|
84
|
+
if (!isField(field)) {
|
|
85
|
+
return [
|
|
86
|
+
`${where}.field is ${Object.keys(FIELDS).join(' or ')}, not ${JSON.stringify(field)}`,
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
const named = Object.keys(tests);
|
|
90
|
+
if (named.length === 0) {
|
|
91
|
+
return [`${where} tests nothing: ${TAKES}`];
|
|
92
|
+
}
|
|
93
|
+
const problems = named.flatMap(key => {
|
|
94
|
+
if (!OPERATORS.some(op => op === key)) {
|
|
95
|
+
return [`${where}.${key} is not an operator: ${TAKES}`];
|
|
96
|
+
}
|
|
97
|
+
if (!FIELDS[field].numeric && BOUNDS.some(op => op === key)) {
|
|
98
|
+
return [
|
|
99
|
+
`${where}.${key} is refused: ${field} is ${FIELDS[field].kind}, so it takes equal or oneOf`,
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
return operatorProblems(where, field, key, tests[key]);
|
|
103
|
+
});
|
|
104
|
+
if (problems.length > 0) {
|
|
105
|
+
return problems;
|
|
106
|
+
}
|
|
107
|
+
const { low, high } = bounds(tests);
|
|
108
|
+
return low > high
|
|
109
|
+
? [`${where} selects nothing: its bounds run from ${low} to ${high}`]
|
|
110
|
+
: [];
|
|
111
|
+
}
|
|
112
|
+
/** What is wrong with a `filter`, one line each; empty when nothing is. */
|
|
113
|
+
export function filterProblems(filter, where = 'filter') {
|
|
114
|
+
if (filter === undefined) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
if (!Array.isArray(filter)) {
|
|
118
|
+
return [`${where} is a list of predicates such as [${EXAMPLE}]`];
|
|
119
|
+
}
|
|
120
|
+
return filter.flatMap((predicate, i) => predicateProblems(`${where}[${i}]`, predicate));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The view's structures, refused with every problem their filters have. A
|
|
124
|
+
* filter that does not read would otherwise draw a structure the session did
|
|
125
|
+
* not ask for — or all of it.
|
|
126
|
+
*/
|
|
127
|
+
export function checkedStructureFilters(structures) {
|
|
128
|
+
const given = structures ?? [];
|
|
129
|
+
const problems = given.flatMap((structure, i) => filterProblems(structure.filter, `structures[${i}].filter`));
|
|
130
|
+
if (problems.length > 0) {
|
|
131
|
+
throw new Error(problems.join('; '));
|
|
132
|
+
}
|
|
133
|
+
return given;
|
|
134
|
+
}
|
|
135
|
+
function predicateTests(MS, predicate) {
|
|
136
|
+
const { equal, lt, lte, gt, gte, range, oneOf } = predicate;
|
|
137
|
+
const value = MS.ammp(FIELDS[predicate.field].property);
|
|
138
|
+
return [
|
|
139
|
+
...(equal === undefined ? [] : [MS.core.rel.eq([value, equal])]),
|
|
140
|
+
...(lt === undefined ? [] : [MS.core.rel.lt([value, lt])]),
|
|
141
|
+
...(lte === undefined ? [] : [MS.core.rel.lte([value, lte])]),
|
|
142
|
+
...(gt === undefined ? [] : [MS.core.rel.gr([value, gt])]),
|
|
143
|
+
...(gte === undefined ? [] : [MS.core.rel.gre([value, gte])]),
|
|
144
|
+
...(range === undefined
|
|
145
|
+
? []
|
|
146
|
+
: [MS.core.rel.inRange([value, range[0], range[1]])]),
|
|
147
|
+
...(oneOf === undefined
|
|
148
|
+
? []
|
|
149
|
+
: [MS.core.set.has([MS.set(...oneOf), value])]),
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
function allOf(MS, tests) {
|
|
153
|
+
return tests.length === 0
|
|
154
|
+
? undefined
|
|
155
|
+
: tests.length === 1
|
|
156
|
+
? tests[0]
|
|
157
|
+
: MS.core.logic.and(tests);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* What a structure draws, as the two MolScript tests an atom selection takes:
|
|
161
|
+
* the chains `chains` lists and every predicate of `filter`, all of them. A
|
|
162
|
+
* field is tested at its own level — a residue number per residue, a chain id
|
|
163
|
+
* per chain — so the two compose into one selection rather than nesting.
|
|
164
|
+
*/
|
|
165
|
+
export function drawnTests(MS, drawn) {
|
|
166
|
+
const { chains, filter = [] } = drawn;
|
|
167
|
+
const at = (level) => filter
|
|
168
|
+
.filter(predicate => FIELDS[predicate.field].level === level)
|
|
169
|
+
.flatMap(predicate => predicateTests(MS, predicate));
|
|
170
|
+
return {
|
|
171
|
+
chainTest: allOf(MS, [
|
|
172
|
+
...(chains?.length
|
|
173
|
+
? [MS.core.set.has([MS.set(...chains), MS.ammp('auth_asym_id')])]
|
|
174
|
+
: []),
|
|
175
|
+
...at('chain'),
|
|
176
|
+
]),
|
|
177
|
+
residueTest: allOf(MS, at('residue')),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/** Whether a structure leaves out part of what it draws, so a mark over the
|
|
181
|
+
* rest of a chain adds to the picture rather than covering it. */
|
|
182
|
+
export function narrowsChains(structure) {
|
|
183
|
+
return Array.isArray(structure?.filter) && structure.filter.length > 0;
|
|
184
|
+
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import loadMolstar from './loadMolstar';
|
|
2
|
+
import { encodedColor } from './markEncoding';
|
|
2
3
|
import { parseSite, siteExpression } from './residueSpec';
|
|
3
4
|
import { serialPerPlugin } from './serialPerPlugin';
|
|
4
5
|
import { structureRootCell } from './structureCells';
|
|
5
6
|
export const RESIDUE_MARKS_TAG = 'jbrowse-residue-marks';
|
|
6
|
-
|
|
7
|
+
function markRepresentation(mark) {
|
|
8
|
+
return mark === 'sticks'
|
|
9
|
+
? {
|
|
10
|
+
type: 'ball-and-stick',
|
|
11
|
+
typeParams: { sizeFactor: 0.35, sizeAspectRatio: 0.7 },
|
|
12
|
+
}
|
|
13
|
+
: // as thick as the cartoon drawOnlyChains gives the chains beside it
|
|
14
|
+
mark === 'cartoon'
|
|
15
|
+
? { type: 'cartoon', typeParams: { sizeFactor: 0.45 } }
|
|
16
|
+
: { type: 'spacefill', typeParams: { sizeFactor: 1 } };
|
|
17
|
+
}
|
|
7
18
|
export const DEFAULT_MARK_COLOR = '#f28e2b';
|
|
8
19
|
export function syncResidueMarks({ plugin, structures, marks, }) {
|
|
9
20
|
return serialPerPlugin(plugin, RESIDUE_MARKS_TAG, async () => {
|
|
@@ -22,9 +33,7 @@ export function syncResidueMarks({ plugin, structures, marks, }) {
|
|
|
22
33
|
if (!structure || !site || !root) {
|
|
23
34
|
continue;
|
|
24
35
|
}
|
|
25
|
-
const color =
|
|
26
|
-
? mark.color
|
|
27
|
-
: DEFAULT_MARK_COLOR;
|
|
36
|
+
const color = encodedColor(mark.encoding, DEFAULT_MARK_COLOR);
|
|
28
37
|
update
|
|
29
38
|
.to(root)
|
|
30
39
|
.apply(StateTransforms.Model.StructureComponent, {
|
|
@@ -33,12 +42,7 @@ export function syncResidueMarks({ plugin, structures, marks, }) {
|
|
|
33
42
|
label: mark.site,
|
|
34
43
|
}, { tags: [RESIDUE_MARKS_TAG] })
|
|
35
44
|
.apply(StateTransforms.Representation.StructureRepresentation3D, createStructureRepresentationParams(plugin, structure, {
|
|
36
|
-
...(mark.
|
|
37
|
-
? {
|
|
38
|
-
type: 'ball-and-stick',
|
|
39
|
-
typeParams: { sizeFactor: 0.35, sizeAspectRatio: 0.7 },
|
|
40
|
-
}
|
|
41
|
-
: { type: 'spacefill', typeParams: { sizeFactor: 1 } }),
|
|
45
|
+
...markRepresentation(mark.mark),
|
|
42
46
|
color: 'uniform',
|
|
43
47
|
colorParams: { value: Color.fromHexStyle(color) },
|
|
44
48
|
}), { tags: [RESIDUE_MARKS_TAG] });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const RESIDUE = /^([^:@\s]+):(-?\d+)([A-Za-z]?)(?:@([A-Za-z0-9'"*]+))?$/;
|
|
2
2
|
const COMPONENT = /^[A-Za-z0-9]{1,5}$/;
|
|
3
|
+
const CHAIN = /^([^:@\s]+):\*$/;
|
|
3
4
|
/**
|
|
4
5
|
* `<auth_asym_id>:<auth_seq_id>`, an insertion code after the number
|
|
5
6
|
* (`A:52B`) and an atom after `@` (`A:248@NH2`): the numbering a paper cites.
|
|
@@ -17,21 +18,26 @@ export function parseResidue(text) {
|
|
|
17
18
|
: undefined;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
|
-
* A residue as above,
|
|
21
|
-
*
|
|
21
|
+
* A residue as above, a bare component id (`MOV`, `HEM`) naming every residue
|
|
22
|
+
* of that component, or a whole chain (`G:*`).
|
|
22
23
|
*/
|
|
23
24
|
export function parseSite(text) {
|
|
24
25
|
const residue = parseResidue(text);
|
|
25
|
-
const
|
|
26
|
+
const trimmed = text.trim();
|
|
27
|
+
const chain = CHAIN.exec(trimmed);
|
|
26
28
|
return (residue ??
|
|
27
|
-
(
|
|
28
|
-
? { kind: '
|
|
29
|
-
:
|
|
29
|
+
(chain
|
|
30
|
+
? { kind: 'chain', chain: chain[1] }
|
|
31
|
+
: COMPONENT.test(trimmed)
|
|
32
|
+
? { kind: 'component', compId: trimmed.toUpperCase() }
|
|
33
|
+
: undefined));
|
|
30
34
|
}
|
|
31
35
|
export function formatSite(site) {
|
|
32
36
|
return site.kind === 'component'
|
|
33
37
|
? site.compId
|
|
34
|
-
:
|
|
38
|
+
: site.kind === 'chain'
|
|
39
|
+
? `${site.chain}:*`
|
|
40
|
+
: `${site.chain}:${site.seq}${site.insertion}${site.atom ? `@${site.atom}` : ''}`;
|
|
35
41
|
}
|
|
36
42
|
/** The atoms `site` names, whole residues unless the site names an atom. */
|
|
37
43
|
export function siteExpression(MS, site) {
|
|
@@ -41,6 +47,11 @@ export function siteExpression(MS, site) {
|
|
|
41
47
|
'group-by': MS.struct.atomProperty.macromolecular.residueKey(),
|
|
42
48
|
});
|
|
43
49
|
}
|
|
50
|
+
if (site.kind === 'chain') {
|
|
51
|
+
return MS.struct.generator.atomGroups({
|
|
52
|
+
'chain-test': MS.core.rel.eq([MS.ammp('auth_asym_id'), site.chain]),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
44
55
|
return MS.struct.generator.atomGroups({
|
|
45
56
|
'chain-test': MS.core.rel.eq([MS.ammp('auth_asym_id'), site.chain]),
|
|
46
57
|
'residue-test': MS.core.logic.and([
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { colord } from '@jbrowse/core/util/colord';
|
|
16
16
|
import { SITES_TAG } from './alignmentSites';
|
|
17
17
|
import loadMolstar from './loadMolstar';
|
|
18
|
+
import { drawnTests } from './residueFilter';
|
|
18
19
|
import { structureRootCell } from './structureCells';
|
|
19
20
|
export const SESSION_HIGHLIGHTS_TAG = 'jbrowse-session-highlights';
|
|
20
21
|
// core's default highlight color, which the genome view's band draws in
|
|
@@ -164,27 +165,24 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
|
|
|
164
165
|
anchors.delete(cell.transform.ref);
|
|
165
166
|
update.delete(cell.transform.ref);
|
|
166
167
|
}
|
|
167
|
-
for (const { molstarStructure, marks, chains } of structures) {
|
|
168
|
+
for (const { molstarStructure, marks, chains, filter } of structures) {
|
|
168
169
|
const root = structureRootCell(plugin, molstar, molstarStructure);
|
|
169
170
|
if (!root) {
|
|
170
171
|
continue;
|
|
171
172
|
}
|
|
173
|
+
const { chainTest, residueTest } = drawnTests(MS, { chains, filter });
|
|
172
174
|
const labelled = [];
|
|
173
175
|
for (const { entityId, labelSeqIds, label, color } of marks) {
|
|
176
|
+
const marked = MS.core.set.has([
|
|
177
|
+
MS.set(...labelSeqIds),
|
|
178
|
+
MS.ammp('label_seq_id'),
|
|
179
|
+
]);
|
|
174
180
|
const expression = MS.struct.generator.atomGroups({
|
|
175
181
|
'entity-test': MS.core.rel.eq([MS.ammp('label_entity_id'), entityId]),
|
|
176
|
-
'residue-test':
|
|
177
|
-
MS.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
...(chains?.length
|
|
181
|
-
? {
|
|
182
|
-
'chain-test': MS.core.set.has([
|
|
183
|
-
MS.set(...chains),
|
|
184
|
-
MS.ammp('auth_asym_id'),
|
|
185
|
-
]),
|
|
186
|
-
}
|
|
187
|
-
: {}),
|
|
182
|
+
'residue-test': residueTest
|
|
183
|
+
? MS.core.logic.and([marked, residueTest])
|
|
184
|
+
: marked,
|
|
185
|
+
...(chainTest ? { 'chain-test': chainTest } : {}),
|
|
188
186
|
});
|
|
189
187
|
update
|
|
190
188
|
.to(root)
|
|
@@ -137,6 +137,14 @@ const Structure = types
|
|
|
137
137
|
* highlighted but are not drawn. Absent draws every chain.
|
|
138
138
|
*/
|
|
139
139
|
chains: types.frozen(),
|
|
140
|
+
/**
|
|
141
|
+
* #property
|
|
142
|
+
* Which residues of those chains are drawn, as field predicates on
|
|
143
|
+
* `residue` (`auth_seq_id`) and `chain` (`auth_asym_id`): CCR5's Δ32
|
|
144
|
+
* allele is `[{ field: 'residue', lte: 184 }]`. The rest stay loaded,
|
|
145
|
+
* mapped and highlighted but are not drawn. Absent draws every residue.
|
|
146
|
+
*/
|
|
147
|
+
filter: types.frozen(),
|
|
140
148
|
})
|
|
141
149
|
.volatile(() => ({
|
|
142
150
|
/**
|