@sjcrh/proteinpaint-shared 2.116.1-1 → 2.118.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/package.json +1 -1
- package/src/common.js +0 -75
- package/src/terms.js +16 -0
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1216,81 +1216,6 @@ for (const _dtTerm of _dtTerms) {
|
|
|
1216
1216
|
}
|
|
1217
1217
|
}
|
|
1218
1218
|
|
|
1219
|
-
const dtFilter = {
|
|
1220
|
-
opts: { joinWith: ['and', 'or'] },
|
|
1221
|
-
terms: dtTerms
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
const groupsetLst = []
|
|
1225
|
-
for (const term of dtTerms) {
|
|
1226
|
-
// wildtype filter
|
|
1227
|
-
const WTfilter = structuredClone(dtFilter)
|
|
1228
|
-
WTfilter.group = 2
|
|
1229
|
-
const WT = 'WT'
|
|
1230
|
-
const WTvalue = { key: WT, label: term.values[WT].label, value: WT }
|
|
1231
|
-
const WTtvs = { type: 'tvs', tvs: { term, values: [WTvalue] } }
|
|
1232
|
-
WTfilter.active = getWrappedTvslst([WTtvs])
|
|
1233
|
-
let WTname = 'Wildtype'
|
|
1234
|
-
// mutated filter
|
|
1235
|
-
const MUTfilter = structuredClone(dtFilter)
|
|
1236
|
-
MUTfilter.group = 1
|
|
1237
|
-
const classes = Object.keys(term.values)
|
|
1238
|
-
if (classes.length < 2) throw 'should have at least 2 classes'
|
|
1239
|
-
let MUTtvs, MUTname
|
|
1240
|
-
if (classes.length == 2) {
|
|
1241
|
-
// only 2 classes
|
|
1242
|
-
// mutant filter will filter for the mutant class
|
|
1243
|
-
const MUT = classes.find(c => c != WT)
|
|
1244
|
-
const MUTvalue = { key: MUT, label: term.values[MUT].label, value: MUT }
|
|
1245
|
-
MUTtvs = { type: 'tvs', tvs: { term, values: [MUTvalue] } }
|
|
1246
|
-
MUTname = term.values[MUT].label
|
|
1247
|
-
} else {
|
|
1248
|
-
// more than 2 classes
|
|
1249
|
-
// mutant filter will filter for all non-wildtype classes
|
|
1250
|
-
MUTtvs = { type: 'tvs', tvs: { term, values: [WTvalue], isnot: true } }
|
|
1251
|
-
MUTname = term.name_noOrigin
|
|
1252
|
-
}
|
|
1253
|
-
MUTfilter.active = getWrappedTvslst([MUTtvs])
|
|
1254
|
-
// excluded filter
|
|
1255
|
-
const EXCLUDEfilter = structuredClone(dtFilter)
|
|
1256
|
-
EXCLUDEfilter.group = 0
|
|
1257
|
-
EXCLUDEfilter.active = getWrappedTvslst()
|
|
1258
|
-
// assign filters to groups
|
|
1259
|
-
let GRPSETname = `${MUTname} vs. Wildtype`
|
|
1260
|
-
if (term.origin) GRPSETname += ` (${term.origin})`
|
|
1261
|
-
const WTgroup = {
|
|
1262
|
-
name: WTname,
|
|
1263
|
-
type: 'filter',
|
|
1264
|
-
uncomputable: false,
|
|
1265
|
-
filter: WTfilter
|
|
1266
|
-
}
|
|
1267
|
-
const MUTgroup = {
|
|
1268
|
-
name: MUTname,
|
|
1269
|
-
type: 'filter',
|
|
1270
|
-
uncomputable: false,
|
|
1271
|
-
filter: MUTfilter
|
|
1272
|
-
}
|
|
1273
|
-
const EXCLUDEgroup = {
|
|
1274
|
-
name: 'Excluded categories',
|
|
1275
|
-
type: 'filter',
|
|
1276
|
-
uncomputable: true,
|
|
1277
|
-
filter: EXCLUDEfilter
|
|
1278
|
-
}
|
|
1279
|
-
// assign groups to groupset
|
|
1280
|
-
const groupset = {
|
|
1281
|
-
name: GRPSETname,
|
|
1282
|
-
groups: [EXCLUDEgroup, MUTgroup, WTgroup],
|
|
1283
|
-
id: term.id
|
|
1284
|
-
}
|
|
1285
|
-
groupsetLst.push(groupset)
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
export const geneVariantTermGroupsetting = {
|
|
1289
|
-
disabled: false, // as const, // TODO: may need to add is when converting common.js to .ts
|
|
1290
|
-
type: 'custom',
|
|
1291
|
-
lst: groupsetLst
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
1219
|
export const colorScaleMap = {
|
|
1295
1220
|
blueWhiteRed: { domain: [0, 0.5, 1], range: ['blue', 'white', 'red'] },
|
|
1296
1221
|
greenWhiteRed: { domain: [0, 0.5, 1], range: ['green', 'white', 'red'] },
|
package/src/terms.js
CHANGED
|
@@ -210,6 +210,13 @@ export function termType2label(type) {
|
|
|
210
210
|
return typeMap[type] || 'Unknown term type'
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
export function getDateFromNumber(value) {
|
|
214
|
+
const year = Math.floor(value)
|
|
215
|
+
const time = (value - year) * 365 * 24 * 60 * 60 * 1000 // convert to milliseconds
|
|
216
|
+
const january1st = new Date(year, 0, 0)
|
|
217
|
+
const date = new Date(january1st.getTime() + time)
|
|
218
|
+
return date
|
|
219
|
+
}
|
|
213
220
|
/*
|
|
214
221
|
Value is a decimal year.
|
|
215
222
|
A decimal year is a way of expressing a date or time period as a year with a decimal part, where the decimal portion
|
|
@@ -243,3 +250,12 @@ export function getNumberFromDateStr(str) {
|
|
|
243
250
|
const decimal = roundValueAuto(diffDays / 365)
|
|
244
251
|
return year + decimal
|
|
245
252
|
}
|
|
253
|
+
|
|
254
|
+
export function getNumberFromDate(date) {
|
|
255
|
+
const year = date.getFullYear()
|
|
256
|
+
const january1st = new Date(year, 0, 0)
|
|
257
|
+
const diffTime = date - january1st
|
|
258
|
+
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))
|
|
259
|
+
const decimal = roundValueAuto(diffDays / 365)
|
|
260
|
+
return year + decimal
|
|
261
|
+
}
|