@sjcrh/proteinpaint-shared 2.129.2 → 2.129.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.
- package/package.json +1 -1
- package/src/common.js +97 -0
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1232,3 +1232,100 @@ export const colorScaleMap = {
|
|
|
1232
1232
|
// when hierCluster z-score transformation is not performed, should use two-color scale
|
|
1233
1233
|
whiteRed: { domain: [0, 1], range: ['white', 'red'] }
|
|
1234
1234
|
}
|
|
1235
|
+
|
|
1236
|
+
export function invalidcoord(thisgenome, chrom, start, stop) {
|
|
1237
|
+
if (!thisgenome) return 'no genome'
|
|
1238
|
+
if (!chrom) return 'no chr name'
|
|
1239
|
+
const chr = thisgenome.chrlookup[chrom.toUpperCase()]
|
|
1240
|
+
if (!chr) return 'Invalid chromosome name: ' + chr
|
|
1241
|
+
if (!Number.isInteger(start)) return 'Non-numerical position: ' + start
|
|
1242
|
+
if (start < 0 || start >= chr.len) return 'Position out of range: ' + start
|
|
1243
|
+
if (!Number.isInteger(stop)) return 'Non-numerical position: ' + stop
|
|
1244
|
+
if (stop < 0 || stop > chr.len) return 'Position out of range: ' + stop
|
|
1245
|
+
if (start > stop) return 'Start position is greater than stop'
|
|
1246
|
+
return false
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
export function string2pos(s, genome, donotextend) {
|
|
1250
|
+
s = s.replace(/,/g, '')
|
|
1251
|
+
const chr = genome.chrlookup[s.toUpperCase()]
|
|
1252
|
+
if (chr) {
|
|
1253
|
+
// chr name only, to middle
|
|
1254
|
+
return {
|
|
1255
|
+
chr: chr.name,
|
|
1256
|
+
chrlen: chr.len,
|
|
1257
|
+
start: Math.max(0, Math.ceil(chr.len / 2) - 10000),
|
|
1258
|
+
stop: Math.min(chr.len, Math.ceil(chr.len / 2) + 10000)
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
{
|
|
1262
|
+
// special handling for snv4
|
|
1263
|
+
const tmp = s.split('.')
|
|
1264
|
+
if (tmp.length >= 2) {
|
|
1265
|
+
const chr = genome.chrlookup[tmp[0].toUpperCase()]
|
|
1266
|
+
const pos = Number.parseInt(tmp[1])
|
|
1267
|
+
const e = invalidcoord(genome, tmp[0], pos, pos + 1)
|
|
1268
|
+
if (!e) {
|
|
1269
|
+
// valid snv4
|
|
1270
|
+
const bpspan = 400
|
|
1271
|
+
return {
|
|
1272
|
+
chr: chr.name,
|
|
1273
|
+
chrlen: chr.len,
|
|
1274
|
+
start: Math.max(0, pos - Math.ceil(bpspan / 2)),
|
|
1275
|
+
stop: Math.min(chr.len, pos + Math.ceil(bpspan / 2)),
|
|
1276
|
+
actualposition: { position: pos, len: 1 }
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
const tmp = s.split(/[-:\s]+/)
|
|
1282
|
+
if (tmp.length == 2) {
|
|
1283
|
+
// must be chr - pos
|
|
1284
|
+
const pos = Number.parseInt(tmp[1])
|
|
1285
|
+
const e = invalidcoord(genome, tmp[0], pos, pos + 1)
|
|
1286
|
+
if (e) {
|
|
1287
|
+
return null
|
|
1288
|
+
}
|
|
1289
|
+
const chr = genome.chrlookup[tmp[0].toUpperCase()]
|
|
1290
|
+
const bpspan = 400
|
|
1291
|
+
return {
|
|
1292
|
+
chr: chr.name,
|
|
1293
|
+
chrlen: chr.len,
|
|
1294
|
+
start: Math.max(0, pos - Math.ceil(bpspan / 2)),
|
|
1295
|
+
stop: Math.min(chr.len, pos + Math.ceil(bpspan / 2)),
|
|
1296
|
+
actualposition: { position: pos, len: 1 }
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (tmp.length == 3) {
|
|
1300
|
+
// must be chr - start - stop
|
|
1301
|
+
let start = Number.parseInt(tmp[1]),
|
|
1302
|
+
stop = Number.parseInt(tmp[2])
|
|
1303
|
+
const e = invalidcoord(genome, tmp[0], start, stop)
|
|
1304
|
+
if (e) {
|
|
1305
|
+
return null
|
|
1306
|
+
}
|
|
1307
|
+
const actualposition = { position: start, len: stop - start }
|
|
1308
|
+
const chr = genome.chrlookup[tmp[0].toUpperCase()]
|
|
1309
|
+
|
|
1310
|
+
if (!donotextend) {
|
|
1311
|
+
const minspan = 400
|
|
1312
|
+
if (stop - start < minspan) {
|
|
1313
|
+
let center = Math.ceil((start + stop) / 2)
|
|
1314
|
+
if (center + minspan / 2 >= chr.len) {
|
|
1315
|
+
center = chr.len - Math.ceil(minspan / 2)
|
|
1316
|
+
}
|
|
1317
|
+
start = Math.max(0, center - Math.ceil(minspan / 2))
|
|
1318
|
+
stop = start + minspan
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
return {
|
|
1323
|
+
chr: chr.name,
|
|
1324
|
+
chrlen: chr.len,
|
|
1325
|
+
start,
|
|
1326
|
+
stop,
|
|
1327
|
+
actualposition
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return null
|
|
1331
|
+
}
|