@sjcrh/proteinpaint-types 2.78.0-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 (62) hide show
  1. package/package.json +29 -0
  2. package/src/Mclass.ts +8 -0
  3. package/src/dataset.ts +1416 -0
  4. package/src/docs.json +16417 -0
  5. package/src/fileOrUrl.ts +15 -0
  6. package/src/filter.ts +125 -0
  7. package/src/genome.ts +123 -0
  8. package/src/index.ts +56 -0
  9. package/src/routes/brainImaging.ts +21 -0
  10. package/src/routes/burden.ts +67 -0
  11. package/src/routes/dzimages.ts +9 -0
  12. package/src/routes/errorResponse.ts +6 -0
  13. package/src/routes/filter.gdc.ts +15 -0
  14. package/src/routes/gdc.maf.ts +41 -0
  15. package/src/routes/gdc.mafBuild.ts +13 -0
  16. package/src/routes/gdc.topMutatedGenes.ts +25 -0
  17. package/src/routes/genelookup.ts +10 -0
  18. package/src/routes/genesetEnrichment.ts +46 -0
  19. package/src/routes/genesetOverrepresentation.ts +32 -0
  20. package/src/routes/healthcheck.ts +57 -0
  21. package/src/routes/hicdata.ts +37 -0
  22. package/src/routes/hicgenome.ts +22 -0
  23. package/src/routes/hicstat.ts +45 -0
  24. package/src/routes/sampledzimages.ts +1 -0
  25. package/src/routes/samplewsimages.ts +15 -0
  26. package/src/routes/termdb.DE.ts +25 -0
  27. package/src/routes/termdb.categories.ts +26 -0
  28. package/src/routes/termdb.cluster.ts +75 -0
  29. package/src/routes/termdb.getSampleImages.ts +14 -0
  30. package/src/routes/termdb.getTopTermsByType.ts +21 -0
  31. package/src/routes/termdb.getdescrstats.ts +31 -0
  32. package/src/routes/termdb.getnumericcategories.ts +21 -0
  33. package/src/routes/termdb.getpercentile.ts +17 -0
  34. package/src/routes/termdb.getrootterm.ts +22 -0
  35. package/src/routes/termdb.gettermchildren.ts +21 -0
  36. package/src/routes/termdb.singleSampleMutation.ts +18 -0
  37. package/src/routes/termdb.singlecellDEgenes.ts +30 -0
  38. package/src/routes/termdb.singlecellData.ts +55 -0
  39. package/src/routes/termdb.singlecellSamples.ts +35 -0
  40. package/src/routes/termdb.termsbyids.ts +15 -0
  41. package/src/routes/termdb.topVariablyExpressedGenes.ts +45 -0
  42. package/src/routes/termdb.violin.ts +74 -0
  43. package/src/routes/wsimages.ts +12 -0
  44. package/src/terms/categorical.ts +106 -0
  45. package/src/terms/condition.ts +55 -0
  46. package/src/terms/geneExpression.ts +32 -0
  47. package/src/terms/geneVariant.ts +51 -0
  48. package/src/terms/metaboliteIntensity.ts +31 -0
  49. package/src/terms/numeric.ts +245 -0
  50. package/src/terms/q.ts +38 -0
  51. package/src/terms/samplelst.ts +41 -0
  52. package/src/terms/singleCellCellType.ts +22 -0
  53. package/src/terms/singleCellGeneExpression.ts +28 -0
  54. package/src/terms/snp.ts +28 -0
  55. package/src/terms/snps.ts +110 -0
  56. package/src/terms/term.ts +184 -0
  57. package/src/terms/tw.ts +38 -0
  58. package/src/terms/updated-types.ts +9 -0
  59. package/src/termsetting.ts +193 -0
  60. package/src/test/numeric.type.spec.ts +275 -0
  61. package/src/typedoc.js +30 -0
  62. package/src/vocab.ts +37 -0
@@ -0,0 +1,275 @@
1
+ import { StartUnboundedBin, StopUnboundedBin, FullyBoundedBin, NumericTerm } from '../terms/numeric'
2
+
3
+ /*
4
+ Non-asserted type definition tests
5
+
6
+ For training only
7
+ - these tests are not meant to be written for all declared types
8
+
9
+ - meant for simple "sanity check", that a declaration makes sense and CATCHES ERRORS
10
+
11
+ - quick tests on lines commented with @ts-expect-error
12
+ - remove a // @ts-expect-error comment to see error message as emitted by the tsc compiler
13
+ - fix the variable declaration value to match the expected type, tsc should emit "Unused '@ts-expect-error' directive"
14
+ */
15
+
16
+ /*****************
17
+ * Simple tests
18
+ ******************/
19
+
20
+ {
21
+ // in unit and integration spec files, use the numeric type definitions
22
+ // to make sure that test data matches expectations, otherwise incorrect
23
+ // test data can lead to false passing or failing tests.
24
+ const valid: NumericTerm = {
25
+ type: 'float',
26
+ id: 'someid',
27
+ name: 'Some Dosage',
28
+ bins: {
29
+ default: {
30
+ type: 'regular-bin',
31
+ bin_size: 1,
32
+ first_bin: {
33
+ startunbounded: true,
34
+ stop: 1
35
+ }
36
+ },
37
+ less: {
38
+ type: 'custom-bin',
39
+ lst: [{ start: 0, stop: 1 }]
40
+ }
41
+ }
42
+ }
43
+
44
+ // @ts-expect-error, wrong term.type
45
+ const A: NumericTerm = { name: 'test', type: 'categorical' }
46
+ // @ts-expect-error, missing other required properties
47
+ const B: NumericTerm = { type: 'integer' }
48
+ const C: NumericTerm = {
49
+ // @ts-expect-error, should be string
50
+ name: 7,
51
+ type: 'integer',
52
+ bins: {
53
+ default: {
54
+ type: 'regular-bin',
55
+ bin_size: 1,
56
+ // tsc can detect type errors for deeply nested property values
57
+ // @ts-expect-error, does not match either StartUnboundedBin | FullyBoundedBin
58
+ first_bin: {
59
+ stop: 1
60
+ }
61
+ },
62
+ less: {
63
+ type: 'custom-bin',
64
+ // @ts-expect-error, empty lst array
65
+ lst: []
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ /*************************
72
+ * !!! How NOT to type !!!
73
+ **************************/
74
+
75
+ // Example of a bad type declaration, where everything is optional.
76
+ // Avoid declaring types with lots of optional properties, unless that's really expected.
77
+ // In the PP codebase, a union of types is more likely to be the correct way to declare
78
+ // a type with mutually exlusive properties based on, for example, term.type or gene variant value dt number.
79
+ type UselessBinType = {
80
+ startunbounded?: boolean
81
+ startinclusive?: boolean
82
+ start?: number
83
+ stop?: number
84
+ stopinclusive?: boolean
85
+ stopunbounded?: boolean
86
+ }
87
+
88
+ {
89
+ // The UselesBinType matches objects with conflicting property values, which does not make sense.
90
+ // We want tsc to emit an error when unallowed, non-sensical combination of properties exist.
91
+ //
92
+ // For example, it does not make sense for a bin to have these combinations of property-values:
93
+ // - startunbounded: true and startinclusive: true // cannot "contain" infinity
94
+ // - startunbounded: true and start: 0 // conflict, start is supposed to be unbounded and yet is assigned a finite value
95
+ // - startunbounded: true and stopunbounded: true // an infinite bin
96
+ //
97
+ // Many other pairing of the property-values below do not make sense.
98
+ // Note that running the tsc on this file does not emit an error, but it should for values that do not make sense.
99
+ // To get tsc to emit errors, we should use the bin types from server/shared/types/terms/numeric.ts,
100
+ // or from the 'better' bin type examples farther down below (which will require more code changes).
101
+ const A: UselessBinType = {
102
+ startunbounded: true,
103
+ startinclusive: true,
104
+ start: 0,
105
+ stop: 1,
106
+ stopinclusive: true,
107
+ stopunbounded: true
108
+ }
109
+
110
+ // no error is thrown by an empty object because all properties are optional,
111
+ // but we want tsc to emit an error in this scenario
112
+ const B: UselessBinType = {}
113
+ // @ts-expect-error, not fully useless since an error is thrown because 'extraProp' is not defined as an optional property
114
+ B.extraProp = 'test'
115
+ }
116
+
117
+ /********************************************
118
+ * Testing types that are able to catch errors
119
+ *********************************************/
120
+
121
+ // Start unbounded Bin
122
+ {
123
+ // valid example
124
+ const A: StartUnboundedBin = {
125
+ startunbounded: true,
126
+ stop: 1
127
+ }
128
+
129
+ // invalid examples
130
+ // @ts-expect-error, conflict between startunbounded and start values
131
+ const B: StartUnboundedBin = { startunbounded: true, start: 0, stop: 1 }
132
+ // @ts-expect-error, missing start value
133
+ const C: StartUnboundedBin = { startunbounded: true }
134
+ // @ts-expect-error, conflict between unbounded flags and assigned finite values for start, stop
135
+ const D: StartUnboundedBin = { startunbounded: true, start: 0, stop: 1, stopunbounded: true }
136
+ // @ts-expect-error, missing properties
137
+ const E: StartUnboundedBin = {}
138
+ // @ts-expect-error, adding a property that was not defined for this type
139
+ E.extraProp = 'test'
140
+ }
141
+
142
+ // Stop unbounded bin
143
+ {
144
+ // valid example
145
+ const A: StopUnboundedBin = {
146
+ stopunbounded: true,
147
+ start: 0
148
+ }
149
+
150
+ // invalid examples
151
+ // @ts-expect-error, conflict between stopunbounded and stop values
152
+ const B: StopUnboundedBin = { stopunbounded: true, start: 0, stop: 1 }
153
+ // @ts-expect-error, missing stop value
154
+ const C: StopUnboundedBin = { stopunbounded: true }
155
+ // @ts-expect-error, conflict between unbounded flags and assigned finite values for start, stop
156
+ const D: StopUnboundedBin = { startunbounded: true, start: 0, stop: 1, stopunbounded: true }
157
+ }
158
+
159
+ // Fully bounded bin
160
+ {
161
+ // valid example
162
+ const A: FullyBoundedBin = {
163
+ startinclusive: true,
164
+ start: 0,
165
+ stop: 1
166
+ }
167
+
168
+ // invalid examples
169
+ // @ts-expect-error, missing start value
170
+ const B: FullyBoundedBin = { stop: 1 }
171
+ // @ts-expect-error, missing stop value
172
+ const C: FullyBoundedBin = { start: 0 }
173
+ }
174
+
175
+ /*** test of union type being fed into a subtype-specific "handler" function ***/
176
+ // to be used as a 'generic' argument
177
+ type NumericBin = StartUnboundedBin | StopUnboundedBin | FullyBoundedBin
178
+
179
+ const handlers = {
180
+ startUnbounded(bin: StartUnboundedBin) {
181
+ console.log(bin)
182
+ },
183
+ fullyBounded(bin: FullyBoundedBin) {
184
+ console.log(bin)
185
+ },
186
+ stopUnbounded(bin: StopUnboundedBin) {
187
+ console.log(bin)
188
+ }
189
+ }
190
+
191
+ /**********************************************************************
192
+ * Test that tsc can infer that a type can be derived from
193
+ * a union of types. This is important for the general approach
194
+ * in the PP codebase to route arguments to specific handler functions.
195
+ ***********************************************************************/
196
+
197
+ // these functions routes the bin argument to the correct handler function
198
+ function correctlyTypedProcessBin(bin: NumericBin) {
199
+ if (bin.startunbounded) handlers.startUnbounded(bin as StartUnboundedBin)
200
+ else if (bin.stopunbounded) handlers.stopUnbounded(bin as StopUnboundedBin)
201
+ else handlers.fullyBounded(bin as FullyBoundedBin)
202
+ }
203
+
204
+ // not declared as part of the NumericBin type
205
+ type NonNumericBin = { fake: true }
206
+ // even though has an extra property compared to FullyBoundedBin,
207
+ // the tsc compiler would consider this equivalent
208
+ type LikeFullyBoundedBin = {
209
+ start: number
210
+ stop: number
211
+ test: boolean
212
+ }
213
+
214
+ function incorrectProcessBin(bin: FullyBoundedBin) {
215
+ // @ts-expect-error, the argument type is not StartUnboundedBin
216
+ if (bin.startunbounded) handlers.startUnbounded(bin as StartUnboundedBin)
217
+ // @ts-expect-error, the argument type is not StopUnboundedBin
218
+ else if (bin.stopunbounded) handlers.stopUnbounded(bin as StopUnboundedBin)
219
+ else {
220
+ // @ts-expect-error, expects StartUnbounded as argument type
221
+ handlers.startUnbounded(bin as FullyBoundedBin)
222
+ // @ts-expect-error, expects StopUnbounded as argument type
223
+ handlers.stopUnbounded(bin as FullyBoundedBin)
224
+ // @ts-expect-error, since this function's argument type (NumericBin) does not include NonNumericBin
225
+ handlers.fullyBounded(bin as NonNumericBinType)
226
+ // !!! SHOULD WORK !!!
227
+ handlers.fullyBounded(bin as LikeFullyBoundedBin)
228
+ // !!! SHOULD WORK !!!
229
+ handlers.fullyBounded(bin as FullyBoundedBin)
230
+ }
231
+ }
232
+
233
+ /************************************************************************
234
+ * Examples of better ways to define data structures to proactively avoid
235
+ * any chance of having flag values that may conflict with each other
236
+ *************************************************************************/
237
+
238
+ // Example of better type declarations
239
+ //
240
+ // NOTE: The bin type declarations in server/shared/types/terms/numeric.ts are good for now,
241
+ // the types below are meant to illustrate that there are different ways to write types that work.
242
+ //
243
+ // TODO: Use these better types, which will require code changes
244
+ //
245
+ type BetterStartUnboundedBin = {
246
+ stop: number
247
+ // by not using a flag, the 'inclusive' property completely avoids unintentionally having
248
+ // `startinclusive: true && stopinclusive: true` at the same time
249
+ inclusive: 'stop'
250
+ }
251
+
252
+ // NOTE: This approach also lessens the number of attributes/properties to define.
253
+ // A problem with flags is it's very easy to have too many of them, and each one has to be defined,
254
+ // and if they are mutually exclusive, most of the time that is not readily apparent.
255
+ type BetterStopUnboundedBin = {
256
+ start: number
257
+ inclusive: 'start'
258
+ }
259
+
260
+ type BetterFullyBoundedBin = {
261
+ start: number
262
+ stop: number
263
+ // for numeric bins that are NOT standalone, using `inclusive: 'both'` will lead to conflict,
264
+ // since adjoining bins can both contain the same boundary value
265
+ inclusive: 'start' | 'stop'
266
+ }
267
+
268
+ type StandaloneBin = {
269
+ start: number
270
+ stop: number
271
+ // for standalone bins, the option to include both start and stop values will not lead to conflict
272
+ inclusive: 'start' | 'stop' | 'both'
273
+ }
274
+
275
+ type BetterNumericBin = BetterStartUnboundedBin | BetterStopUnboundedBin | BetterFullyBoundedBin | StandaloneBin
package/src/typedoc.js ADDED
@@ -0,0 +1,30 @@
1
+ const types = require('./index')
2
+ const test = require('../doc').test
3
+
4
+ module.exports = {
5
+ entryPoints: ['./index.ts'],
6
+ out: '../../../public/docs',
7
+ groupOrder: ['Termdb', 'Termdb - TW', 'TW', '*'],
8
+ categoryOrder: ['Termdb', 'Termdb - TW', 'TW', '*'],
9
+ categorizeByGroup: true,
10
+ plugin: ['typedoc-plugin-replace-text'],
11
+ replaceText: {
12
+ inCodeCommentText: true,
13
+ inCodeCommentTags: true,
14
+ replacements: [
15
+ {
16
+ pattern: 'Type alias',
17
+ flags: 'gi',
18
+ replace: 'Type'
19
+ },
20
+ {
21
+ pattern: /^test\:.*\:$/,
22
+ flags: 'gm',
23
+ replace: match => {
24
+ const name = match.slice(5, -1)
25
+ return 'Test:\n```ts\n' + test[name] + '\n```'
26
+ }
27
+ }
28
+ ]
29
+ }
30
+ }
package/src/vocab.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { TermWrapper } from './terms/tw.ts'
2
+ import { Term } from './terms/term.ts'
3
+ import { Filter } from './filter.ts'
4
+ import { UseCase } from './termsetting.ts'
5
+
6
+ /*
7
+ --------EXPORTED--------
8
+ VocabApi
9
+
10
+ */
11
+
12
+ //type QLst = [Partial<{ nextReuseId?: string }>, ...Q[]]
13
+
14
+ export type VocabApi = {
15
+ termdbConfig: any
16
+ //Methods
17
+ cacheTermQ: (term: Term, q: any) => any
18
+ findTerm: (f: string, activeCohort: number, usecase: UseCase, x: string) => { lst: Term[] }
19
+ getCategories: (term: Term, filer: Filter, body?: any) => any
20
+ getCustomTermQLst: (f: Term) => any
21
+ getPercentile: (term_id: string | number, percentile_lst: number[], filter?: Filter) => any
22
+ getterm: (f: any) => Term
23
+ getTerms: (f: any) => any
24
+ getTermdbConfig: () => any
25
+ getViolinPlotData: (args: any, _body?: any) => any
26
+ getAnnotatedSampleData: (args: any) => any
27
+ getDefaultBins: (args: any) => any
28
+ setTermBins(tw: TermWrapper): any
29
+ getTwMinCopy(tw: TermWrapper): any
30
+ uncacheTermQ: (term: Term, q: any) => any
31
+ hasVerifiedToken: () => boolean
32
+ tokenVerificationMessage: string
33
+ tokenVerificationPayload?: {
34
+ error?: string
35
+ linkKey?: string
36
+ }
37
+ }