jbrowse-plugin-protein3d 1.29.0 → 1.30.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.
Files changed (83) hide show
  1. package/dist/ProteinView/components/GenomeTrackColorDialog.js +11 -2
  2. package/dist/ProteinView/exons.js +4 -2
  3. package/dist/ProteinView/featureFields.js +89 -0
  4. package/dist/ProteinView/fieldPredicates.js +111 -0
  5. package/dist/ProteinView/proteinColor.js +12 -5
  6. package/dist/ProteinView/residueFilter.js +9 -107
  7. package/dist/ProteinView/structureModel.js +2 -1
  8. package/dist/ProteinView/structureReport.js +4 -0
  9. package/dist/ProteinView/trackScoresSource.js +12 -33
  10. package/dist/ProteinView/variantEffectSource.js +4 -2
  11. package/dist/chunks/GenomeTrackColorDialog-VD5NKKQZ.js +2 -0
  12. package/dist/chunks/{GenomeTrackColorDialog-JHHQLVBB.js.map → GenomeTrackColorDialog-VD5NKKQZ.js.map} +3 -3
  13. package/dist/chunks/LaunchProteinViewDialog-B4U5V2WV.js +2 -0
  14. package/dist/chunks/{LaunchProteinViewDialog-AJ62LUV4.js.map → LaunchProteinViewDialog-B4U5V2WV.js.map} +1 -1
  15. package/dist/chunks/ProteinView-AEOQCJ35.js +3 -0
  16. package/dist/chunks/{ProteinView-4JJSYAVY.js.map → ProteinView-AEOQCJ35.js.map} +1 -1
  17. package/dist/chunks/{chunk-CZ5TRTSY.js → chunk-22HNUQZG.js} +2 -2
  18. package/dist/chunks/chunk-46MRJY2F.js +2 -0
  19. package/dist/chunks/chunk-46MRJY2F.js.map +7 -0
  20. package/dist/chunks/{chunk-FNAEADDB.js → chunk-5KWZTAUL.js} +2 -2
  21. package/dist/chunks/{chunk-LJWAVF6V.js → chunk-B23VVDVS.js} +2 -2
  22. package/dist/chunks/{chunk-NAEHT35L.js → chunk-BR44SFC2.js} +2 -2
  23. package/dist/chunks/chunk-CQBWGFIR.js +2 -0
  24. package/dist/chunks/chunk-CQBWGFIR.js.map +7 -0
  25. package/dist/chunks/chunk-F65VCIGM.js +2 -0
  26. package/dist/chunks/chunk-F65VCIGM.js.map +7 -0
  27. package/dist/chunks/{chunk-XEZVHJRK.js → chunk-IL53MSBO.js} +2 -2
  28. package/dist/chunks/{chunk-W7K7OD5Z.js → chunk-KIR7LMDB.js} +2 -2
  29. package/dist/chunks/{chunk-W7K7OD5Z.js.map → chunk-KIR7LMDB.js.map} +3 -3
  30. package/dist/chunks/chunk-NY22OOJ6.js +2 -0
  31. package/dist/chunks/chunk-NY22OOJ6.js.map +7 -0
  32. package/dist/chunks/{chunk-R6VPYHUL.js → chunk-OT7KMAGM.js} +2 -2
  33. package/dist/chunks/launchAnnotationView-NENNHQJN.js +2 -0
  34. package/dist/chunks/{launchAnnotationView-JMO2TEQO.js.map → launchAnnotationView-NENNHQJN.js.map} +1 -1
  35. package/dist/chunks/launchProteinView-HJOBR66M.js +2 -0
  36. package/dist/chunks/{launchProteinView-GXIFQKNJ.js.map → launchProteinView-HJOBR66M.js.map} +1 -1
  37. package/dist/chunks/launchViewUtils-NAACT5YD.js +2 -0
  38. package/dist/chunks/model-IWX5PO7C.js +2 -0
  39. package/dist/chunks/model-IWX5PO7C.js.map +7 -0
  40. package/dist/chunks/{molstarExports-I4RSPU2N.js → molstarExports-VWIGD7KO.js} +2 -2
  41. package/dist/jbrowse-plugin-protein3d.esm.js +1 -1
  42. package/dist/jbrowse-plugin-protein3d.esm.js.map +1 -1
  43. package/dist/version.js +1 -1
  44. package/package.json +1 -1
  45. package/src/ProteinView/components/GenomeTrackColorDialog.tsx +11 -2
  46. package/src/ProteinView/exons.test.ts +48 -4
  47. package/src/ProteinView/exons.ts +5 -2
  48. package/src/ProteinView/featureFields.test.ts +86 -0
  49. package/src/ProteinView/featureFields.ts +126 -0
  50. package/src/ProteinView/fieldPredicates.ts +174 -0
  51. package/src/ProteinView/proteinColor.test.ts +75 -0
  52. package/src/ProteinView/proteinColor.ts +31 -9
  53. package/src/ProteinView/residueFilter.ts +13 -145
  54. package/src/ProteinView/structureLocate.test.ts +1 -0
  55. package/src/ProteinView/structureModel.ts +7 -1
  56. package/src/ProteinView/structureReport.ts +5 -0
  57. package/src/ProteinView/trackScoresSource.test.ts +60 -5
  58. package/src/ProteinView/trackScoresSource.ts +22 -39
  59. package/src/ProteinView/variantEffectSource.test.ts +22 -1
  60. package/src/ProteinView/variantEffectSource.ts +7 -1
  61. package/src/version.ts +1 -1
  62. package/dist/chunks/GenomeTrackColorDialog-JHHQLVBB.js +0 -2
  63. package/dist/chunks/LaunchProteinViewDialog-AJ62LUV4.js +0 -2
  64. package/dist/chunks/ProteinView-4JJSYAVY.js +0 -3
  65. package/dist/chunks/chunk-IQBGBMGH.js +0 -2
  66. package/dist/chunks/chunk-IQBGBMGH.js.map +0 -7
  67. package/dist/chunks/chunk-QGDO6K2Y.js +0 -2
  68. package/dist/chunks/chunk-QGDO6K2Y.js.map +0 -7
  69. package/dist/chunks/chunk-Y72I4AXI.js +0 -2
  70. package/dist/chunks/chunk-Y72I4AXI.js.map +0 -7
  71. package/dist/chunks/launchAnnotationView-JMO2TEQO.js +0 -2
  72. package/dist/chunks/launchProteinView-GXIFQKNJ.js +0 -2
  73. package/dist/chunks/launchViewUtils-GGC32OOM.js +0 -2
  74. package/dist/chunks/model-GDYADBRA.js +0 -2
  75. package/dist/chunks/model-GDYADBRA.js.map +0 -7
  76. /package/dist/chunks/{chunk-CZ5TRTSY.js.map → chunk-22HNUQZG.js.map} +0 -0
  77. /package/dist/chunks/{chunk-FNAEADDB.js.map → chunk-5KWZTAUL.js.map} +0 -0
  78. /package/dist/chunks/{chunk-LJWAVF6V.js.map → chunk-B23VVDVS.js.map} +0 -0
  79. /package/dist/chunks/{chunk-NAEHT35L.js.map → chunk-BR44SFC2.js.map} +0 -0
  80. /package/dist/chunks/{chunk-XEZVHJRK.js.map → chunk-IL53MSBO.js.map} +0 -0
  81. /package/dist/chunks/{chunk-R6VPYHUL.js.map → chunk-OT7KMAGM.js.map} +0 -0
  82. /package/dist/chunks/{launchViewUtils-GGC32OOM.js.map → launchViewUtils-NAACT5YD.js.map} +0 -0
  83. /package/dist/chunks/{molstarExports-I4RSPU2N.js.map → molstarExports-VWIGD7KO.js.map} +0 -0
@@ -87,13 +87,14 @@ const GenomeTrackColorDialog = observer(function GenomeTrackColorDialog({ model,
87
87
  React.createElement(Button, { variant: "contained", disabled: !trackId || cutsInvalid, onClick: () => {
88
88
  // the same track on the same scale keeps what a session wrote
89
89
  // beside it: its palette, labels, title and domain, and the same
90
- // track its scoreField, which a count does not read
90
+ // track its filter, and its scoreField, which a count does not read
91
91
  const sameTrack = color.field === 'track' && color.trackId === trackId;
92
92
  const kept = sameTrack &&
93
93
  (color.scale === 'threshold') === (scale === 'threshold')
94
94
  ? color
95
95
  : undefined;
96
96
  const scoreField = sameTrack && stat !== 'count' ? color.scoreField : undefined;
97
+ const filter = sameTrack ? color.filter : undefined;
97
98
  const sameBands = kept?.range?.length === (cuts?.length ?? 0) + 1;
98
99
  model.setColor(scale === 'threshold' && cuts
99
100
  ? {
@@ -102,6 +103,7 @@ const GenomeTrackColorDialog = observer(function GenomeTrackColorDialog({ model,
102
103
  trackId,
103
104
  stat,
104
105
  scoreField,
106
+ filter,
105
107
  scale,
106
108
  domain: cuts,
107
109
  range: sameBands
@@ -109,7 +111,14 @@ const GenomeTrackColorDialog = observer(function GenomeTrackColorDialog({ model,
109
111
  : thresholdRange(cuts.length + 1),
110
112
  labels: sameBands ? kept.labels : undefined,
111
113
  }
112
- : { ...kept, field: 'track', trackId, stat, scoreField });
114
+ : {
115
+ ...kept,
116
+ field: 'track',
117
+ trackId,
118
+ stat,
119
+ scoreField,
120
+ filter,
121
+ });
113
122
  handleClose();
114
123
  } }, "Color"))));
115
124
  });
@@ -5,11 +5,12 @@ export const EMPTY_EXON_COLOR = { ...RESIDUE_COLORS.exon };
5
5
  function isUtr(type) {
6
6
  return type !== undefined && /utr/i.test(type);
7
7
  }
8
+ export const MAX_ALIGNMENT_GAP_BP = 9;
8
9
  function mergedBlocks(rows) {
9
10
  const merged = [];
10
11
  for (const { start, end } of rows.toSorted((a, b) => a.start - b.start)) {
11
12
  const last = merged.at(-1);
12
- if (last && start <= last.end) {
13
+ if (last && start - last.end <= MAX_ALIGNMENT_GAP_BP) {
13
14
  last.end = Math.max(last.end, end);
14
15
  }
15
16
  else {
@@ -21,7 +22,8 @@ function mergedBlocks(rows) {
21
22
  /**
22
23
  * A transcript's exons in transcript order. Its `exon` rows when it has them;
23
24
  * otherwise its CDS and UTR rows, joined where they touch, which rebuilds the
24
- * exons a BED12 or bigBed transcript implies.
25
+ * exons a BED12 or bigBed transcript implies. Blocks a gap too short to be an
26
+ * intron separates are one exon.
25
27
  */
26
28
  export function transcriptExons(feature) {
27
29
  const rows = feature.subfeatures ?? [];
@@ -0,0 +1,89 @@
1
+ import { predicateListProblems } from './fieldPredicates';
2
+ /**
3
+ * A field of a feature by the name jbrowse-components' displays read it by:
4
+ * the whole name first, then a dotted path into a structured field, so
5
+ * `INFO.AF` reads a VCF record's INFO and `INFO.AF.1` its second allele's.
6
+ */
7
+ export function readFeatureField(feature, name) {
8
+ const whole = feature.get(name);
9
+ const path = name.split('.');
10
+ return whole !== undefined || path.length === 1
11
+ ? whole
12
+ : path
13
+ .slice(1)
14
+ .reduce((value, key) => typeof value === 'object' && value !== null
15
+ ? Reflect.get(value, key)
16
+ : undefined, feature.get(path[0]));
17
+ }
18
+ /**
19
+ * A field's value as one number. A list, such as a multi-allelic site's
20
+ * `INFO.AF`, gives its highest entry, as overlapping features give a base
21
+ * their highest score; a string a VCF header left untyped is read as a number.
22
+ */
23
+ export function numberOfField(value) {
24
+ const items = Array.isArray(value) ? value : [value];
25
+ const numbers = items
26
+ .map(v => typeof v === 'string' && v.trim() !== ''
27
+ ? Number(v)
28
+ : typeof v === 'number'
29
+ ? v
30
+ : Number.NaN)
31
+ .filter(Number.isFinite);
32
+ return numbers.length > 0 ? Math.max(...numbers) : Number.NaN;
33
+ }
34
+ export function isFeatureFieldName(field) {
35
+ return typeof field === 'string' && field !== '' && !field.startsWith('jexl:');
36
+ }
37
+ const GRAMMAR = {
38
+ kindOf: field => (isFeatureFieldName(field) ? 'string or number' : undefined),
39
+ fields: 'a feature field name such as FILTER or INFO.AF, not a jexl: expression',
40
+ example: "{ field: 'FILTER', equal: 'PASS' }",
41
+ };
42
+ /** What is wrong with a track color's `filter`, one line each; empty when
43
+ * nothing is. */
44
+ export function featureFilterProblems(filter, where = 'filter') {
45
+ return predicateListProblems(filter, where, GRAMMAR);
46
+ }
47
+ function entryEquals(entry, expected) {
48
+ return typeof expected === 'number'
49
+ ? numberOfField(entry) === expected
50
+ : entry === expected;
51
+ }
52
+ /**
53
+ * Whether a feature passes one predicate. A list, such as the failed filters
54
+ * a VCF record's FILTER names, passes `equal` and `oneOf` when any entry
55
+ * does; the bounds test the field's number as `scoreField` reads it, a list's
56
+ * highest. A field the feature lacks passes no test.
57
+ */
58
+ function passes(feature, predicate) {
59
+ const { field, equal, lt, lte, gt, gte, range, oneOf } = predicate;
60
+ const value = readFeatureField(feature, field);
61
+ const entries = Array.isArray(value) ? value : [value];
62
+ const n = numberOfField(value);
63
+ return ((equal === undefined || entries.some(e => entryEquals(e, equal))) &&
64
+ (oneOf === undefined ||
65
+ entries.some(e => oneOf.some(o => entryEquals(e, o)))) &&
66
+ (lt === undefined || n < lt) &&
67
+ (lte === undefined || n <= lte) &&
68
+ (gt === undefined || n > gt) &&
69
+ (gte === undefined || n >= gte) &&
70
+ (range === undefined || (n >= range[0] && n <= range[1])));
71
+ }
72
+ export function passesFeatureFilter(feature, filter) {
73
+ return filter.every(predicate => passes(feature, predicate));
74
+ }
75
+ function predicateLabel({ field, equal, lt, lte, gt, gte, range, oneOf, }) {
76
+ return [
77
+ ...(equal === undefined ? [] : [`${field} = ${equal}`]),
78
+ ...(oneOf === undefined ? [] : [`${field} = ${oneOf.join(' or ')}`]),
79
+ ...(gt === undefined ? [] : [`${field} > ${gt}`]),
80
+ ...(gte === undefined ? [] : [`${field} ≥ ${gte}`]),
81
+ ...(lt === undefined ? [] : [`${field} < ${lt}`]),
82
+ ...(lte === undefined ? [] : [`${field} ≤ ${lte}`]),
83
+ ...(range === undefined ? [] : [`${field} ${range[0]}–${range[1]}`]),
84
+ ];
85
+ }
86
+ /** A filter as a legend reads it, such as `FILTER = PASS, INFO.AF ≥ 0.01`. */
87
+ export function featureFilterLabel(filter) {
88
+ return filter.flatMap(predicateLabel).join(', ');
89
+ }
@@ -0,0 +1,111 @@
1
+ const KIND_NAMES = {
2
+ number: { one: 'a number', many: 'numbers' },
3
+ string: { one: 'a string', many: 'strings' },
4
+ 'string or number': {
5
+ one: 'a string or a number',
6
+ many: 'strings or numbers',
7
+ },
8
+ };
9
+ const BOUNDS = ['lt', 'lte', 'gt', 'gte', 'range'];
10
+ const OPERATORS = ['equal', ...BOUNDS, 'oneOf'];
11
+ const TAKES = `a predicate takes field and one of ${OPERATORS.join(', ')}`;
12
+ function isRecord(x) {
13
+ return typeof x === 'object' && x !== null && !Array.isArray(x);
14
+ }
15
+ function isNumber(value) {
16
+ return typeof value === 'number' && Number.isFinite(value);
17
+ }
18
+ function isValue(value, kind) {
19
+ return kind === 'number'
20
+ ? isNumber(value)
21
+ : kind === 'string'
22
+ ? typeof value === 'string'
23
+ : typeof value === 'string' || isNumber(value);
24
+ }
25
+ function rangeProblems(where, range) {
26
+ const ends = Array.isArray(range) ? range : [];
27
+ const [low, high] = ends;
28
+ return ends.length === 2 && isNumber(low) && isNumber(high)
29
+ ? low <= high
30
+ ? []
31
+ : [`${where}.range runs low to high; ${low} is above ${high}`]
32
+ : [
33
+ `${where}.range is two numbers, the low and high ends, not ${JSON.stringify(range)}`,
34
+ ];
35
+ }
36
+ function operatorProblems(where, kind, key, value) {
37
+ if (key === 'range') {
38
+ return rangeProblems(where, value);
39
+ }
40
+ if (key === 'oneOf') {
41
+ return Array.isArray(value) &&
42
+ value.length > 0 &&
43
+ value.every(v => isValue(v, kind))
44
+ ? []
45
+ : [
46
+ `${where}.oneOf is a list of ${KIND_NAMES[kind].many}, not ${JSON.stringify(value)}`,
47
+ ];
48
+ }
49
+ const expected = key === 'equal' ? kind : 'number';
50
+ return isValue(value, expected)
51
+ ? []
52
+ : [
53
+ `${where}.${key} is ${KIND_NAMES[expected].one}, not ${JSON.stringify(value)}`,
54
+ ];
55
+ }
56
+ /** The lowest and highest number a predicate's bounds admit; an end no bound
57
+ * names is open. */
58
+ function bounds(predicate) {
59
+ const at = (key) => {
60
+ const value = predicate[key];
61
+ return isNumber(value) ? value : undefined;
62
+ };
63
+ const range = Array.isArray(predicate.range) ? predicate.range : [];
64
+ return {
65
+ low: Math.max(at('gt') ?? -Infinity, at('gte') ?? -Infinity, isNumber(range[0]) ? range[0] : -Infinity),
66
+ high: Math.min(at('lt') ?? Infinity, at('lte') ?? Infinity, isNumber(range[1]) ? range[1] : Infinity),
67
+ };
68
+ }
69
+ function predicateProblems(where, predicate, grammar) {
70
+ if (!isRecord(predicate)) {
71
+ return [`${where} is an object such as ${grammar.example}`];
72
+ }
73
+ const { field, ...tests } = predicate;
74
+ const kind = grammar.kindOf(field);
75
+ if (kind === undefined) {
76
+ return [`${where}.field is ${grammar.fields}, not ${JSON.stringify(field)}`];
77
+ }
78
+ const named = Object.keys(tests);
79
+ if (named.length === 0) {
80
+ return [`${where} tests nothing: ${TAKES}`];
81
+ }
82
+ const problems = named.flatMap(key => {
83
+ if (!OPERATORS.some(op => op === key)) {
84
+ return [`${where}.${key} is not an operator: ${TAKES}`];
85
+ }
86
+ if (kind === 'string' && BOUNDS.some(op => op === key)) {
87
+ return [
88
+ `${where}.${key} is refused: ${String(field)} is ${KIND_NAMES[kind].one}, so it takes equal or oneOf`,
89
+ ];
90
+ }
91
+ return operatorProblems(where, kind, key, tests[key]);
92
+ });
93
+ if (problems.length > 0) {
94
+ return problems;
95
+ }
96
+ const { low, high } = bounds(tests);
97
+ return low > high
98
+ ? [`${where} selects nothing: its bounds run from ${low} to ${high}`]
99
+ : [];
100
+ }
101
+ /** What is wrong with a list of predicates, one line each; empty when
102
+ * nothing is. */
103
+ export function predicateListProblems(predicates, where, grammar) {
104
+ if (predicates === undefined) {
105
+ return [];
106
+ }
107
+ if (!Array.isArray(predicates)) {
108
+ return [`${where} is a list of predicates such as [${grammar.example}]`];
109
+ }
110
+ return predicates.flatMap((predicate, i) => predicateProblems(`${where}[${i}]`, predicate, grammar));
111
+ }
@@ -1,3 +1,4 @@
1
+ import { featureFilterLabel, featureFilterProblems, isFeatureFieldName, } from './featureFields';
1
2
  import { RESIDUE_COLORS } from './residueColors';
2
3
  /**
3
4
  * The fields the view colors its structures by, each with its menu label and
@@ -84,7 +85,7 @@ const SCALE_MEMBERS = {
84
85
  * member must be.
85
86
  */
86
87
  const FIELD_MEMBERS = {
87
- track: ['trackId', 'stat', 'scoreField'],
88
+ track: ['trackId', 'stat', 'scoreField', 'filter'],
88
89
  values: ['values'],
89
90
  };
90
91
  function isDataScaledField(field) {
@@ -140,7 +141,7 @@ const MEMBER_TYPES = {
140
141
  `one of ${TRACK_STATS.join(', ')}`,
141
142
  ],
142
143
  scoreField: [
143
- v => typeof v === 'string' && v !== '' && !v.startsWith('jexl:'),
144
+ isFeatureFieldName,
144
145
  'a field name such as INFO.AF, not a jexl: expression',
145
146
  ],
146
147
  values: [
@@ -209,6 +210,9 @@ export function colorProblems(color) {
209
210
  ? []
210
211
  : [`color.scale of ${field} is ${preset.scale}`];
211
212
  }
213
+ if (key === 'filter') {
214
+ return featureFilterProblems(value, 'color.filter');
215
+ }
212
216
  const [accepts, kind] = MEMBER_TYPES[key];
213
217
  return accepts(value) ? [] : [`color.${key} is ${kind}`];
214
218
  });
@@ -276,18 +280,21 @@ export function checkedColor(color) {
276
280
  * preset; undefined for a field whose colors are Mol*'s or the alignment's.
277
281
  */
278
282
  export function resolvedColor(color) {
279
- const { field, trackId, stat, scoreField, values, ...members } = color;
283
+ const { field, trackId, stat, scoreField, filter, values, ...members } = color;
280
284
  return field && isScaledField(field)
281
285
  ? { ...presetOf(field, members.scale), ...members }
282
286
  : undefined;
283
287
  }
284
288
  /** What a track color's legend says a residue's value is. */
285
- export function trackStatLabel({ stat = 'mean', scoreField }) {
286
- return stat === 'count'
289
+ export function trackStatLabel({ stat = 'mean', scoreField, filter = [], }) {
290
+ const reads = stat === 'count'
287
291
  ? 'features per codon'
288
292
  : scoreField === undefined
289
293
  ? `${stat} per codon`
290
294
  : `${stat} ${scoreField} per codon`;
295
+ return filter.length > 0
296
+ ? `${reads} where ${featureFilterLabel(filter)}`
297
+ : reads;
291
298
  }
292
299
  /** The Mol* theme a color object paints with; undefined is Mol*'s default. */
293
300
  export function molstarThemeOf(color) {
@@ -1,3 +1,4 @@
1
+ import { predicateListProblems } from './fieldPredicates';
1
2
  /**
2
3
  * The fields a predicate tests, each with the Mol* property it reads and the
3
4
  * level Mol* tests it at. `residue` is the author residue number
@@ -5,119 +6,20 @@
5
6
  * the author chain id (`auth_asym_id`), the one `chains` lists.
6
7
  */
7
8
  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
- },
9
+ residue: { property: 'auth_seq_id', kind: 'number', level: 'residue' },
10
+ chain: { property: 'auth_asym_id', kind: 'string', level: 'chain' },
20
11
  };
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
12
  function isField(field) {
29
13
  return typeof field === 'string' && Object.hasOwn(FIELDS, field);
30
14
  }
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
- }
15
+ const GRAMMAR = {
16
+ kindOf: field => (isField(field) ? FIELDS[field].kind : undefined),
17
+ fields: Object.keys(FIELDS).join(' or '),
18
+ example: "{ field: 'residue', lte: 184 }",
19
+ };
112
20
  /** What is wrong with a `filter`, one line each; empty when nothing is. */
113
21
  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));
22
+ return predicateListProblems(filter, where, GRAMMAR);
121
23
  }
122
24
  /**
123
25
  * The view's structures, refused with every problem their filters have. A
@@ -1008,7 +1008,7 @@ const Structure = types
1008
1008
  return alphaMissenseAsk(self.uniProtEntry);
1009
1009
  }
1010
1010
  if (field === 'track') {
1011
- const { trackId, stat = 'mean', scoreField } = self.parentView.color;
1011
+ const { trackId, stat = 'mean', scoreField, filter, } = self.parentView.color;
1012
1012
  const session = getSession(self);
1013
1013
  const conf = trackId ? session.getTrackById(trackId) : undefined;
1014
1014
  return genomeTrackAsk({
@@ -1016,6 +1016,7 @@ const Structure = types
1016
1016
  trackName: conf ? getTrackName(conf, session) : undefined,
1017
1017
  stat,
1018
1018
  scoreField,
1019
+ filter,
1019
1020
  feature: self.feature,
1020
1021
  assemblyName: self.connectedView?.assemblyNames[0],
1021
1022
  });
@@ -49,6 +49,10 @@ export function structureReport(s) {
49
49
  loading: s.loading,
50
50
  error: s.error === undefined ? undefined : errorMessage(s.error),
51
51
  status: s.statusMessage,
52
+ selection: s.clickedStructureRanges.map(({ start, end }) => ({
53
+ start,
54
+ end,
55
+ })),
52
56
  mapping: mappingReport(s),
53
57
  };
54
58
  }
@@ -1,5 +1,6 @@
1
1
  import { readConfObject } from '@jbrowse/core/configuration';
2
2
  import { codingSpans } from 'p2s_mapper';
3
+ import { featureFilterLabel, numberOfField, passesFeatureFilter, readFeatureField, } from './featureFields';
3
4
  import { countByResidue, scoreByBase, scoreByResidue } from './trackScores';
4
5
  import { VariantEffectRefusal } from './variantEffects';
5
6
  import { genomeToTranscriptSeqMapping } from '../mappings';
@@ -8,34 +9,6 @@ export const DEFAULT_SCORE_FIELD = 'score';
8
9
  function number(value) {
9
10
  return typeof value === 'number' ? value : Number.NaN;
10
11
  }
11
- /**
12
- * A field of a feature by the name jbrowse-components' displays read it by:
13
- * the whole name first, then a dotted path into a structured field, so
14
- * `INFO.AF` reads a VCF record's INFO and `INFO.AF.1` its second allele's.
15
- */
16
- export function readFeatureField(feature, name) {
17
- const whole = feature.get(name);
18
- const path = name.split('.');
19
- return whole !== undefined || path.length === 1
20
- ? whole
21
- : path
22
- .slice(1)
23
- .reduce((value, key) => typeof value === 'object' && value !== null
24
- ? Reflect.get(value, key)
25
- : undefined, feature.get(path[0]));
26
- }
27
- /**
28
- * A field's value as one number. A list, such as a multi-allelic site's
29
- * `INFO.AF`, gives its highest entry, as overlapping features give a base
30
- * their highest score; a string a VCF header left untyped is read as a number.
31
- */
32
- export function numberOfField(value) {
33
- const items = Array.isArray(value) ? value : [value];
34
- const numbers = items
35
- .map(v => typeof v === 'string' && v.trim() !== '' ? Number(v) : number(v))
36
- .filter(Number.isFinite);
37
- return numbers.length > 0 ? Math.max(...numbers) : Number.NaN;
38
- }
39
12
  const SEQUENCE_ALLELE = /^[ACGTN]+$/i;
40
13
  /**
41
14
  * Whether a VCF record's first base is the padding base VCF writes before an
@@ -61,20 +34,25 @@ function startsOnPaddingBase(feature) {
61
34
  * codon, because the request searched every codon; the other stats reduce
62
35
  * the number at `scoreField`, and a residue with none has no value. A feature
63
36
  * returned for two coding spans counts once, and a VCF indel reads from the
64
- * base after its padding base.
37
+ * base after its padding base. Only features every predicate of `filter`
38
+ * passes are read.
65
39
  */
66
- export function trackValuesByResidue({ features, p2gCodon, stat, scoreField = DEFAULT_SCORE_FIELD, trackId, }) {
40
+ export function trackValuesByResidue({ features, p2gCodon, stat, scoreField = DEFAULT_SCORE_FIELD, filter = [], trackId, }) {
67
41
  const unique = [...new Map(features.map(f => [f.id(), f])).values()];
68
42
  if (unique.length === 0) {
69
43
  throw new VariantEffectRefusal(`Track "${trackId}" has no features under this transcript's coding bases`);
70
44
  }
71
- const intervals = unique.map(f => ({
45
+ const kept = unique.filter(f => passesFeatureFilter(f, filter));
46
+ if (kept.length === 0) {
47
+ throw new VariantEffectRefusal(`None of track "${trackId}"'s ${unique.length} features under this transcript passes the filter ${featureFilterLabel(filter)}`);
48
+ }
49
+ const intervals = kept.map(f => ({
72
50
  start: number(f.get('start')) + (startsOnPaddingBase(f) ? 1 : 0),
73
51
  end: number(f.get('end')),
74
52
  score: numberOfField(readFeatureField(f, scoreField)),
75
53
  }));
76
54
  if (stat !== 'count' && !intervals.some(i => Number.isFinite(i.score))) {
77
- throw new VariantEffectRefusal(`Track "${trackId}"'s ${unique.length} features under this transcript carry no number in ${scoreField}${scoreField === DEFAULT_SCORE_FIELD
55
+ throw new VariantEffectRefusal(`Track "${trackId}"'s ${kept.length} ${filter.length > 0 ? 'filtered ' : ''}features under this transcript carry no number in ${scoreField}${scoreField === DEFAULT_SCORE_FIELD
78
56
  ? '; name the field to read with scoreField, such as INFO.AF, or count the features with stat "count"'
79
57
  : ''}`);
80
58
  }
@@ -87,7 +65,7 @@ export function trackValuesByResidue({ features, p2gCodon, stat, scoreField = DE
87
65
  * three bases of its codon. Reads only the transcript's coding spans, in one
88
66
  * request, at the track's full resolution.
89
67
  */
90
- export async function fetchTrackScores({ session, trackId, stat, scoreField, feature, assemblyName, signal, }) {
68
+ export async function fetchTrackScores({ session, trackId, stat, scoreField, filter, feature, assemblyName, signal, }) {
91
69
  const entry = session.getTrackById(trackId);
92
70
  const conf = entry ? trackConfigNode(session, entry) : undefined;
93
71
  if (!conf) {
@@ -124,6 +102,7 @@ export async function fetchTrackScores({ session, trackId, stat, scoreField, fea
124
102
  p2gCodon,
125
103
  stat,
126
104
  scoreField,
105
+ filter,
127
106
  trackId,
128
107
  });
129
108
  }
@@ -84,7 +84,7 @@ export function clinVarAsk({ feature, assemblyName, assemblyNames, }) {
84
84
  * view's assembly, so it needs the transcript and that view. `trackName`
85
85
  * labels the request in a message.
86
86
  */
87
- export function genomeTrackAsk({ trackId, trackName, stat, scoreField, feature, assemblyName, }) {
87
+ export function genomeTrackAsk({ trackId, trackName, stat, scoreField, filter, feature, assemblyName, }) {
88
88
  const source = VARIANT_EFFECT_SOURCE_NAMES['genome-track'];
89
89
  if (!trackId) {
90
90
  return { status: 'unavailable', reason: 'No genome track is chosen' };
@@ -106,11 +106,12 @@ export function genomeTrackAsk({ trackId, trackName, stat, scoreField, feature,
106
106
  status: 'ready',
107
107
  request: {
108
108
  scheme: 'genome-track',
109
- key: `genome-track:${assemblyName}:${trackId}:${stat}:${scoreField}:${refName}:${start}-${end}:${uniqueId}`,
109
+ key: `genome-track:${assemblyName}:${trackId}:${stat}:${scoreField}:${JSON.stringify(filter)}:${refName}:${start}-${end}:${uniqueId}`,
110
110
  label: trackName ?? trackId,
111
111
  trackId,
112
112
  stat,
113
113
  scoreField,
114
+ filter,
114
115
  assemblyName,
115
116
  feature,
116
117
  },
@@ -143,6 +144,7 @@ async function load(request, session, signal) {
143
144
  trackId: request.trackId,
144
145
  stat: request.stat,
145
146
  scoreField: request.scoreField,
147
+ filter: request.filter,
146
148
  feature: new SimpleFeature(request.feature),
147
149
  assemblyName: request.assemblyName,
148
150
  signal,
@@ -0,0 +1,2 @@
1
+ import{c as C}from"./chunk-F65VCIGM.js";import{E as b,G as V,a as T,e as N,f as B,g as P,h as W,r as g}from"./chunk-SB4F5EHZ.js";import{a as M}from"./chunk-BWRMG55K.js";import{r as f,s as t,u as O}from"./chunk-INAB36B4.js";import{a as _}from"./chunk-2KHWAKTL.js";import"./chunk-46MRJY2F.js";import{d as E}from"./chunk-THJLCDMW.js";import{f as D,g as A}from"./chunk-CIZQGPKL.js";import{d as F}from"./chunk-LGVXT66Y.js";import"./chunk-XBJKSIMP.js";O();var y=["#d7191c","#fdae61","#abd9e9","#2c7bb6"],q={2:["#d7191c","#2c7bb6"],3:["#d7191c","#fdae61","#abd9e9"],4:y};function L(i){let n=q[i];if(n)return n;let r=E({field:"palette",scale:"linear",domainMin:0,domainMax:1,range:y});return Array.from({length:Math.max(i,1)},(s,l)=>r(i>1?l/(i-1):0)??y[0])}function j(i){let n=i.split(/[\s,;]+/).filter(Boolean).map(Number);return n.length>0&&n.every((r,s)=>Number.isFinite(r)&&(s===0||r>n[s-1]))?n:void 0}var z={mean:"Mean of the three bases",max:"Highest of the three bases",min:"Lowest of the three bases",count:"How many features fall on the codon"},Q=new Set(["QuantitativeTrack","VariantTrack","FeatureTrack"]),X=M(function({model:n,handleClose:r}){let s=D(n),l=n.structures.find(e=>e.connectedView)?.connectedView?.assemblyNames[0],p=l?s.assemblyManager.get(l):void 0,v=new Set([...l?[l]:[],...p?[p.name,...p.aliases]:[]]),x=s.tracks.filter(e=>Q.has(e.type)).filter(e=>{let a=_(s,e);return a!==void 0&&(v.size===0||F(a,"assemblyNames").some(d=>v.has(d)))}).map(e=>({trackId:e.trackId,name:A(e,s)})).toSorted((e,a)=>e.name.localeCompare(a.name)),{color:o}=n,[m,G]=f(o.field==="track"?o.trackId??"":""),[u,H]=f(o.field==="track"?o.stat??"mean":"mean"),[c,J]=f(o.field==="track"&&o.scale==="threshold"?"threshold":"linear"),[S,K]=f(o.field==="track"&&o.domain?o.domain.join(", "):""),h=j(S),k=c==="threshold"&&!h;return t.createElement(N,{open:!0,onClose:r,maxWidth:"sm",fullWidth:!0},t.createElement(W,null,"Color by a genome track"),t.createElement(P,null,t.createElement(V,{variant:"body2",color:"text.secondary",sx:{mb:2}},"Each residue takes the track's scores under its codon on the genome view's assembly",l?` (${l})`:"","."," ",u==="count"?"A residue no feature falls on reads 0.":"Residues with no score are grey."),t.createElement(b,{select:!0,fullWidth:!0,label:"Track",value:m,onChange:e=>{G(e.target.value)},helperText:x.length===0?"This session has no quantitative, variant or feature track on the genome view\u2019s assembly":void 0,sx:{mb:2}},x.map(e=>t.createElement(g,{key:e.trackId,value:e.trackId},e.name))),t.createElement(b,{select:!0,fullWidth:!0,label:"Score per residue",value:u,onChange:e=>{let a=C.find(d=>d===e.target.value);a&&H(a)}},C.map(e=>t.createElement(g,{key:e,value:e},z[e]))),t.createElement(b,{select:!0,fullWidth:!0,label:"Scale",value:c,onChange:e=>{J(e.target.value)},sx:{mt:2}},t.createElement(g,{value:"linear"},"Continuous, light to dark"),t.createElement(g,{value:"threshold"},"Thresholds")),c==="threshold"?t.createElement(b,{fullWidth:!0,label:"Cuts, lowest first",placeholder:"-1.328, -0.748",value:S,error:k,helperText:k?"Numbers, each above the last":"Red below the first cut, blue above the last",onChange:e=>{K(e.target.value)},sx:{mt:2}}):null),t.createElement(B,null,t.createElement(T,{onClick:r},"Cancel"),t.createElement(T,{variant:"contained",disabled:!m||k,onClick:()=>{let e=o.field==="track"&&o.trackId===m,a=e&&o.scale==="threshold"==(c==="threshold")?o:void 0,d=e&&u!=="count"?o.scoreField:void 0,w=e?o.filter:void 0,I=a?.range?.length===(h?.length??0)+1;n.setColor(c==="threshold"&&h?{...a,field:"track",trackId:m,stat:u,scoreField:d,filter:w,scale:c,domain:h,range:I?a.range:L(h.length+1),labels:I?a.labels:void 0}:{...a,field:"track",trackId:m,stat:u,scoreField:d,filter:w}),r()}},"Color")))}),re=X;export{re as default};
2
+ //# sourceMappingURL=GenomeTrackColorDialog-VD5NKKQZ.js.map