@genspectrum/dashboard-components 0.5.3 → 0.5.5

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 (40) hide show
  1. package/custom-elements.json +322 -0
  2. package/dist/dashboard-components.js +609 -265
  3. package/dist/dashboard-components.js.map +1 -1
  4. package/dist/genspectrum-components.d.ts +78 -0
  5. package/package.json +1 -1
  6. package/src/lapisApi/ReferenceGenome.ts +2 -0
  7. package/src/preact/aggregatedData/aggregate.tsx +2 -14
  8. package/src/preact/dateRangeSelector/date-range-selector.tsx +2 -14
  9. package/src/preact/locationFilter/location-filter.tsx +2 -7
  10. package/src/preact/mutationComparison/mutation-comparison.tsx +2 -10
  11. package/src/preact/mutationFilter/mutation-filter-info.tsx +117 -0
  12. package/src/preact/mutationFilter/mutation-filter.tsx +2 -2
  13. package/src/preact/mutationFilter/sequenceTypeFromSegment.spec.ts +1 -1
  14. package/src/preact/mutationFilter/sequenceTypeFromSegment.ts +2 -2
  15. package/src/preact/mutations/mutations.tsx +2 -10
  16. package/src/preact/numberSequencesOverTime/__mockData__/oneVariantEG.json +1702 -0
  17. package/src/preact/numberSequencesOverTime/__mockData__/twoVariantsEG.json +1710 -0
  18. package/src/preact/numberSequencesOverTime/__mockData__/twoVariantsJN1.json +1070 -0
  19. package/src/preact/numberSequencesOverTime/__mockData__/twoVariantsXBB.json +506 -0
  20. package/src/preact/numberSequencesOverTime/getNumberOfSequencesOverTimeTableData.spec.ts +75 -0
  21. package/src/preact/numberSequencesOverTime/getNumberOfSequencesOverTimeTableData.ts +39 -0
  22. package/src/preact/numberSequencesOverTime/number-sequences-over-time-bar-chart.tsx +58 -0
  23. package/src/preact/numberSequencesOverTime/number-sequences-over-time-table.tsx +32 -0
  24. package/src/preact/numberSequencesOverTime/number-sequences-over-time.stories.tsx +133 -0
  25. package/src/preact/numberSequencesOverTime/number-sequences-over-time.tsx +105 -0
  26. package/src/preact/prevalenceOverTime/prevalence-over-time-bar-chart.tsx +11 -20
  27. package/src/preact/prevalenceOverTime/prevalence-over-time.tsx +2 -20
  28. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.tsx +2 -14
  29. package/src/preact/textInput/text-input.tsx +2 -2
  30. package/src/query/queryAggregatedDataOverTime.ts +78 -0
  31. package/src/query/queryNumberOfSequencesOverTime.spec.ts +195 -0
  32. package/src/query/queryNumberOfSequencesOverTime.ts +33 -0
  33. package/src/query/queryPrevalenceOverTime.ts +10 -86
  34. package/src/utils/sort.ts +9 -0
  35. package/src/utils/temporalTestHelpers.ts +9 -0
  36. package/src/utils/utils.ts +7 -0
  37. package/src/web-components/input/gs-mutation-filter.stories.ts +57 -1
  38. package/src/web-components/visualization/gs-number-sequences-over-time.stories.ts +232 -0
  39. package/src/web-components/visualization/gs-number-sequences-over-time.tsx +140 -0
  40. package/src/web-components/visualization/index.ts +1 -0
@@ -453,6 +453,77 @@ export declare class MutationsComponent extends PreactLitAdapterWithGridJsStyles
453
453
  render(): JSX_2.Element;
454
454
  }
455
455
 
456
+ /**
457
+ * TODO(#330) write docs
458
+ */
459
+ export declare class NumberSequencesOverTimeComponent extends PreactLitAdapterWithGridJsStyles {
460
+ /**
461
+ * Required.
462
+ * Either a LAPIS filter or an array of LAPIS filters to calculate the prevalence for.
463
+ *
464
+ * The `lapisFilter` will be sent as is to LAPIS to select the data.
465
+ * It must be a valid LAPIS filter object.
466
+ *
467
+ * The `displayName` will be used as the label the prevalence in the views.
468
+ * It should be human-readable.
469
+ *
470
+ */ lapisFilter: {
471
+ lapisFilter: Record<string, string | number | null | boolean>;
472
+ displayName: string;
473
+ } | {
474
+ lapisFilter: Record<string, string | number | null | boolean>;
475
+ displayName: string;
476
+ }[];
477
+ /**
478
+ * Required.
479
+ *
480
+ * The LAPIS field that the data should be aggregated by.
481
+ * The values will be used on the x-axis of the diagram.
482
+ * Must be a field of type `date` in LAPIS.
483
+ */
484
+ lapisDateField: string;
485
+ /**
486
+ * A list of tabs with views that this component should provide.
487
+ */
488
+ views: ('bar' | 'line' | 'table')[];
489
+ /**
490
+ * The headline of the component. Set to an empty string to hide the headline.
491
+ */
492
+ headline: string;
493
+ /**
494
+ * The width of the component.
495
+ *
496
+ * Visit https://genspectrum.github.io/dashboard-components/?path=/docs/components-size-of-components--docs for more information.
497
+ */
498
+ width: string;
499
+ /**
500
+ * The height of the component.
501
+ *
502
+ * Visit https://genspectrum.github.io/dashboard-components/?path=/docs/components-size-of-components--docs for more information.
503
+ */
504
+ height: string;
505
+ /**
506
+ * The granularity of the time axis.
507
+ */
508
+ granularity: 'day' | 'week' | 'month' | 'year';
509
+ /**
510
+ * The number of time steps to use for smoothing the data.
511
+ * `0` means no smoothing.
512
+ * Must be a non-negative integer.
513
+ *
514
+ * For a given time, the shown value is the mean of the neighbouring measured values.
515
+ * The `smoothingWindow` value provides the number of neighbouring values to take into account.
516
+ * The resulting time is computed via `Math.floor(smoothingWindow / 2)`.
517
+ */
518
+ smoothingWindow: number;
519
+ /**
520
+ * The maximum number of rows to display in the table view.
521
+ * Set to `false` to disable pagination. Set to `true` to enable pagination with a default limit (10).
522
+ */
523
+ pageSize: boolean | number;
524
+ render(): JSX_2.Element;
525
+ }
526
+
456
527
  declare abstract class PreactLitAdapter extends ReactiveElement {
457
528
  static styles: CSSResult[];
458
529
  /* Excluded from this release type: lapis */
@@ -824,6 +895,13 @@ declare global {
824
895
  }
825
896
 
826
897
 
898
+ declare global {
899
+ interface HTMLElementTagNameMap {
900
+ 'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
901
+ }
902
+ }
903
+
904
+
827
905
  declare global {
828
906
  interface HTMLElementTagNameMap {
829
907
  'gs-date-range-selector': DateRangeSelectorComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genspectrum/dashboard-components",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "GenSpectrum web components for building dashboards",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -28,3 +28,5 @@ export const getSegmentNames = (referenceGenome: ReferenceGenome, sequenceType:
28
28
  }
29
29
  }
30
30
  };
31
+
32
+ export const isSingleSegmented = (referenceGenome: ReferenceGenome) => referenceGenome.nucleotideSequences.length === 1;
@@ -35,15 +35,10 @@ export interface AggregateInnerProps {
35
35
  }
36
36
 
37
37
  export const Aggregate: FunctionComponent<AggregateProps> = ({
38
- views,
39
38
  width,
40
39
  height,
41
40
  headline = 'Mutations',
42
- filter,
43
- fields,
44
- pageSize,
45
- initialSortField,
46
- initialSortDirection,
41
+ ...innerProps
47
42
  }) => {
48
43
  const size = { height, width };
49
44
 
@@ -51,14 +46,7 @@ export const Aggregate: FunctionComponent<AggregateProps> = ({
51
46
  <ErrorBoundary size={size} headline={headline}>
52
47
  <ResizeContainer size={size}>
53
48
  <Headline heading={headline}>
54
- <AggregateInner
55
- fields={fields}
56
- filter={filter}
57
- views={views}
58
- initialSortField={initialSortField}
59
- initialSortDirection={initialSortDirection}
60
- pageSize={pageSize}
61
- />
49
+ <AggregateInner {...innerProps} />
62
50
  </Headline>
63
51
  </ResizeContainer>
64
52
  </ErrorBoundary>
@@ -28,27 +28,15 @@ export interface DateRangeSelectorPropsInner<CustomLabel extends string> {
28
28
  }
29
29
 
30
30
  export const DateRangeSelector = <CustomLabel extends string>({
31
- customSelectOptions,
32
- earliestDate = '1900-01-01',
33
- initialValue,
34
31
  width,
35
- dateColumn,
36
- initialDateFrom,
37
- initialDateTo,
32
+ ...innerProps
38
33
  }: DateRangeSelectorProps<CustomLabel>) => {
39
34
  const size = { width, height: '3rem' };
40
35
 
41
36
  return (
42
37
  <ErrorBoundary size={size}>
43
38
  <div style={{ width }}>
44
- <DateRangeSelectorInner
45
- customSelectOptions={customSelectOptions}
46
- earliestDate={earliestDate}
47
- initialValue={initialValue}
48
- dateColumn={dateColumn}
49
- initialDateFrom={initialDateFrom}
50
- initialDateTo={initialDateTo}
51
- />
39
+ <DateRangeSelectorInner {...innerProps} />
52
40
  </div>
53
41
  </ErrorBoundary>
54
42
  );
@@ -20,18 +20,13 @@ export interface LocationFilterProps extends LocationFilterInnerProps {
20
20
  width: string;
21
21
  }
22
22
 
23
- export const LocationFilter: FunctionComponent<LocationFilterProps> = ({
24
- width,
25
- initialValue,
26
- fields,
27
- placeholderText,
28
- }) => {
23
+ export const LocationFilter: FunctionComponent<LocationFilterProps> = ({ width, ...innerProps }) => {
29
24
  const size = { width, height: '3rem' };
30
25
 
31
26
  return (
32
27
  <ErrorBoundary size={size}>
33
28
  <ResizeContainer size={size}>
34
- <LocationFilterInner initialValue={initialValue} fields={fields} placeholderText={placeholderText} />
29
+ <LocationFilterInner {...innerProps} />
35
30
  </ResizeContainer>
36
31
  </ErrorBoundary>
37
32
  );
@@ -38,13 +38,10 @@ export interface MutationComparisonInnerProps {
38
38
  }
39
39
 
40
40
  export const MutationComparison: FunctionComponent<MutationComparisonProps> = ({
41
- lapisFilters,
42
- sequenceType,
43
- views,
44
41
  width,
45
42
  height,
46
43
  headline = 'Mutation comparison',
47
- pageSize,
44
+ ...innerProps
48
45
  }) => {
49
46
  const size = { height, width };
50
47
 
@@ -52,12 +49,7 @@ export const MutationComparison: FunctionComponent<MutationComparisonProps> = ({
52
49
  <ErrorBoundary size={size} headline={headline}>
53
50
  <ResizeContainer size={size}>
54
51
  <Headline heading={headline}>
55
- <MutationComparisonInner
56
- lapisFilters={lapisFilters}
57
- sequenceType={sequenceType}
58
- views={views}
59
- pageSize={pageSize}
60
- />
52
+ <MutationComparisonInner {...innerProps} />
61
53
  </Headline>
62
54
  </ResizeContainer>
63
55
  </ErrorBoundary>
@@ -0,0 +1,117 @@
1
+ import { useContext } from 'preact/hooks';
2
+
3
+ import { isSingleSegmented } from '../../lapisApi/ReferenceGenome';
4
+ import { ReferenceGenomeContext } from '../ReferenceGenomeContext';
5
+ import Info, { InfoHeadline1, InfoHeadline2, InfoParagraph } from '../components/info';
6
+
7
+ export const MutationFilterInfo = () => {
8
+ const referenceGenome = useContext(ReferenceGenomeContext);
9
+
10
+ const firstGene = referenceGenome.genes[0].name;
11
+ return (
12
+ <Info height={'80vh'}>
13
+ <InfoHeadline1> Mutation Filter</InfoHeadline1>
14
+ <InfoParagraph>This component allows you to filter for mutations at specific positions.</InfoParagraph>
15
+
16
+ <InfoHeadline2> Nucleotide Mutations and Insertions</InfoHeadline2>
17
+ {isSingleSegmented(referenceGenome) ? (
18
+ <SingleSegmentedNucleotideMutationsInfo />
19
+ ) : (
20
+ <MultiSegmentedNucleotideMutationsInfo />
21
+ )}
22
+
23
+ <InfoHeadline2>Amino Acid Mutations and Insertions</InfoHeadline2>
24
+ <InfoParagraph>
25
+ An amino acid mutation has the format <b>&lt;gene&gt;:&lt;position&gt;&lt;base&gt;</b> or
26
+ <b>&lt;gene&gt;:&lt;base_ref&gt;&lt;position&gt;&lt;base&gt;</b>. A <b>&lt;base&gt;</b> can be one of
27
+ the 20 amino acid codes. It can also be <b>-</b> for deletion and <b>X</b> for unknown. Example:{' '}
28
+ <b>E:57Q</b>.
29
+ </InfoParagraph>
30
+ <InfoParagraph>
31
+ Insertions can be searched for in the same manner, they just need to have <b>ins_</b> appended to the
32
+ start of the mutation. Example: <b>ins_{firstGene}:31:N</b> would filter for sequences with an insertion
33
+ of N between positions 31 and 32 in the gene {firstGene}.
34
+ </InfoParagraph>
35
+ <InfoParagraph>
36
+ This organism has the following genes: {referenceGenome.genes.map((gene) => gene.name).join(', ')}.
37
+ </InfoParagraph>
38
+
39
+ <InfoHeadline2>Insertion Wildcards</InfoHeadline2>
40
+ <InfoParagraph>
41
+ This component supports insertion queries that contain wildcards <b>?</b>. For example{' '}
42
+ <b>ins_{firstGene}:214:?EP?</b> will match all cases where segment <b>{firstGene}</b> has an insertion
43
+ of <b>EP</b> between the positions <b>214</b> and <b>215</b> but also an insertion of other amino acids
44
+ which include the <b>EP</b>, e.g. the insertion <b>EPE</b> will be matched.
45
+ </InfoParagraph>
46
+ <InfoParagraph>
47
+ You can also use wildcards to match any insertion at a given position. For example{' '}
48
+ <b>ins_{firstGene}:214:?</b> match any (but at least one) insertion between the positions 214 and 215.
49
+ </InfoParagraph>
50
+
51
+ <InfoHeadline2>Multiple Mutations</InfoHeadline2>
52
+ <InfoParagraph>
53
+ Multiple mutation filters can be provided by adding one mutation after the other.
54
+ </InfoParagraph>
55
+
56
+ <InfoHeadline2>Any Mutation</InfoHeadline2>
57
+ <InfoParagraph>
58
+ To filter for any mutation at a given position you can omit the <b>&lt;base&gt;</b>. Example:{' '}
59
+ <b>{firstGene}:20</b>.
60
+ </InfoParagraph>
61
+
62
+ <InfoHeadline2>No Mutation</InfoHeadline2>
63
+ <InfoParagraph>
64
+ You can write a <b>.</b> for the <b>&lt;base&gt;</b> to filter for sequences for which it is confirmed
65
+ that no mutation occurred, i.e. has the same base as the reference genome at the specified position.
66
+ </InfoParagraph>
67
+ </Info>
68
+ );
69
+ };
70
+
71
+ const SingleSegmentedNucleotideMutationsInfo = () => {
72
+ return (
73
+ <>
74
+ <InfoParagraph>
75
+ This organism is single-segmented. Thus, nucleotide mutations have the format{' '}
76
+ <b>&lt;position&gt;&lt;base&gt;</b> or <b>&lt;base_ref&gt;&lt;position&gt;&lt;base&gt;</b>. The{' '}
77
+ <b>&lt;base_ref&gt;</b> is the reference base at the position. It is optional. A <b>&lt;base&gt;</b> can
78
+ be one of the four nucleotides <b>A</b>, <b>T</b>, <b>C</b>, and <b>G</b>. It can also be <b>-</b> for
79
+ deletion and <b>N</b> for unknown. For example if the reference sequence is <b>A</b> at position{' '}
80
+ <b>23</b> both: <b>23T</b> and <b>A23T</b> will yield the same results.
81
+ </InfoParagraph>
82
+ <InfoParagraph>
83
+ Insertions can be searched for in the same manner, they just need to have <b>ins_</b> appended to the
84
+ start of the mutation. Example: <b>ins_1046:A</b> would filter for sequences with an insertion of A
85
+ between the positions 1046 and 1047 in the nucleotide sequence.
86
+ </InfoParagraph>
87
+ </>
88
+ );
89
+ };
90
+
91
+ const MultiSegmentedNucleotideMutationsInfo = () => {
92
+ const referenceGenome = useContext(ReferenceGenomeContext);
93
+
94
+ const firstSegment = referenceGenome.nucleotideSequences[0].name;
95
+
96
+ return (
97
+ <>
98
+ <InfoParagraph>
99
+ This organism is multi-segmented. Thus, nucleotide mutations have the format{' '}
100
+ <b>&lt;segment&gt;:&lt;position&gt;&lt;base&gt;</b> or{' '}
101
+ <b>&lt;segment&gt;:&lt;base_ref&gt;&lt;position&gt;&lt;base&gt;</b>. <b>&lt;base_ref&gt;</b> is the
102
+ reference base at the position. It is optional. A <b>&lt;base&gt;</b> can be one of the four nucleotides{' '}
103
+ <b>A</b>, <b>T</b>, <b>C</b>, and <b>G</b>. It can also be <b>-</b> for deletion and <b>N</b> for
104
+ unknown. For example if the reference sequence is <b>A</b> at position <b>23</b> both:{' '}
105
+ <b>{firstSegment}:23T</b> and <b>{firstSegment}:A23T</b> will yield the same results.
106
+ </InfoParagraph>
107
+ <InfoParagraph>
108
+ Insertions can be searched for in the same manner, they just need to have <b>ins_</b> appended to the
109
+ start of the mutation. Example: <b>ins_{firstSegment}:10462:A</b>.
110
+ </InfoParagraph>
111
+ <InfoParagraph>
112
+ This organism has the following segments:{' '}
113
+ {referenceGenome.nucleotideSequences.map((gene) => gene.name).join(', ')}.
114
+ </InfoParagraph>{' '}
115
+ </>
116
+ );
117
+ };
@@ -1,12 +1,12 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext, useRef, useState } from 'preact/hooks';
3
3
 
4
+ import { MutationFilterInfo } from './mutation-filter-info';
4
5
  import { parseAndValidateMutation } from './parseAndValidateMutation';
5
6
  import { type ReferenceGenome } from '../../lapisApi/ReferenceGenome';
6
7
  import { type Deletion, type Insertion, type Mutation, type Substitution } from '../../utils/mutations';
7
8
  import { ReferenceGenomeContext } from '../ReferenceGenomeContext';
8
9
  import { ErrorBoundary } from '../components/error-boundary';
9
- import Info from '../components/info';
10
10
  import { singleGraphColorRGBByName } from '../shared/charts/colors';
11
11
  import { DeleteIcon } from '../shared/icons/DeleteIcon';
12
12
 
@@ -103,7 +103,7 @@ export const MutationFilterInner: FunctionComponent<MutationFilterInnerProps> =
103
103
  return (
104
104
  <form className='w-full border boder-gray-300 rounded-md relative' onSubmit={handleSubmit} ref={formRef}>
105
105
  <div className='absolute -top-3 -right-3'>
106
- <Info height={'100px'}>Info for mutation filter</Info>
106
+ <MutationFilterInfo />
107
107
  </div>
108
108
  <div className='w-full flex p-2 flex-wrap items-center'>
109
109
  <SelectedMutationDisplay
@@ -45,7 +45,7 @@ describe('getSequenceType', () => {
45
45
  ],
46
46
  };
47
47
 
48
- it('should return nucleotide when the segment is undefined for singe segmented genome', () => {
48
+ it('should return nucleotide when the segment is undefined for single segmented genome', () => {
49
49
  expect(sequenceTypeFromSegment('nuc1', singleSegmentedReferenceGenome)).toBe('nucleotide');
50
50
  expect(sequenceTypeFromSegment(undefined, singleSegmentedReferenceGenome)).toBe('nucleotide');
51
51
  });
@@ -1,4 +1,4 @@
1
- import type { ReferenceGenome } from '../../lapisApi/ReferenceGenome';
1
+ import { isSingleSegmented, type ReferenceGenome } from '../../lapisApi/ReferenceGenome';
2
2
  import type { SequenceType } from '../../types';
3
3
 
4
4
  export const sequenceTypeFromSegment = (
@@ -6,7 +6,7 @@ export const sequenceTypeFromSegment = (
6
6
  referenceGenome: ReferenceGenome,
7
7
  ): SequenceType | undefined => {
8
8
  if (possibleSegment === undefined) {
9
- return referenceGenome.nucleotideSequences.length === 1 ? 'nucleotide' : undefined;
9
+ return isSingleSegmented(referenceGenome) ? 'nucleotide' : undefined;
10
10
  }
11
11
 
12
12
  if (referenceGenome.nucleotideSequences.some((sequence) => sequence.name === possibleSegment)) {
@@ -45,13 +45,10 @@ export interface MutationsProps extends MutationsInnerProps {
45
45
  }
46
46
 
47
47
  export const Mutations: FunctionComponent<MutationsProps> = ({
48
- lapisFilter,
49
- sequenceType,
50
- views,
51
48
  width,
52
49
  height,
53
50
  headline = 'Mutations',
54
- pageSize,
51
+ ...innerProps
55
52
  }) => {
56
53
  const size = { height, width };
57
54
 
@@ -59,12 +56,7 @@ export const Mutations: FunctionComponent<MutationsProps> = ({
59
56
  <ErrorBoundary size={size} headline={headline}>
60
57
  <ResizeContainer size={size}>
61
58
  <Headline heading={headline}>
62
- <MutationsInner
63
- lapisFilter={lapisFilter}
64
- sequenceType={sequenceType}
65
- views={views}
66
- pageSize={pageSize}
67
- />
59
+ <MutationsInner {...innerProps} />
68
60
  </Headline>
69
61
  </ResizeContainer>
70
62
  </ErrorBoundary>