|
@@ -1,7 +1,8 @@
|
|
|
/**
|
|
|
- * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
+ * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* @author David Sehnal <david.sehnal@gmail.com>
|
|
|
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
|
*/
|
|
|
|
|
|
import { Entities } from '../common';
|
|
@@ -21,16 +22,27 @@ function getElementSubstructureKeyMap(map: Map<number, Map<string, number>>, key
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-function createLookUp(entities: Entities, chain: Map<number, Map<string, number>>) {
|
|
|
+function createLookUp(entities: Entities, chain: Map<number, Map<string, number>>, seq: Map<number, Map<number, number>>) {
|
|
|
const getEntKey = entities.getEntityIndex;
|
|
|
const findChainKey: CoarsedElementKeys['findChainKey'] = (e, c) => {
|
|
|
- let eKey = getEntKey(e);
|
|
|
+ const eKey = getEntKey(e);
|
|
|
if (eKey < 0) return -1;
|
|
|
const cm = chain.get(eKey)!;
|
|
|
if (!cm.has(c)) return -1;
|
|
|
return cm.get(c)!;
|
|
|
}
|
|
|
- return { findChainKey };
|
|
|
+ const findSequenceKey: CoarsedElementKeys['findSequenceKey'] = (e, c, s) => {
|
|
|
+ const eKey = getEntKey(e);
|
|
|
+ if (eKey < 0) return -1;
|
|
|
+ const cm = chain.get(eKey);
|
|
|
+ if (cm === undefined) return -1
|
|
|
+ const cKey = cm.get(c)
|
|
|
+ if (cKey === undefined) return -1
|
|
|
+ const sm = seq.get(cKey)!
|
|
|
+ if (!sm.has(s)) return -1;
|
|
|
+ return sm.get(s)!
|
|
|
+ }
|
|
|
+ return { findChainKey, findSequenceKey };
|
|
|
}
|
|
|
|
|
|
function missingEntity(k: string) {
|
|
@@ -42,9 +54,11 @@ function missingModel(k: string) {
|
|
|
}
|
|
|
|
|
|
export function getCoarseKeys(data: CoarseElementData, modelIndex: (id: number) => number, entities: Entities): CoarsedElementKeys {
|
|
|
- const { model_id, entity_id, asym_id, count, chainSegments } = data;
|
|
|
+ const { model_id, entity_id, asym_id, seq_id_begin, seq_id_end, count, chainSegments } = data;
|
|
|
|
|
|
+ const seqMaps = new Map<number, Map<number, number>>();
|
|
|
const chainMaps = new Map<number, Map<string, number>>(), chainCounter = { index: 0 };
|
|
|
+
|
|
|
const chainKey = new Int32Array(count);
|
|
|
const entityKey = new Int32Array(count);
|
|
|
const modelKey = new Int32Array(count);
|
|
@@ -61,14 +75,22 @@ export function getCoarseKeys(data: CoarseElementData, modelIndex: (id: number)
|
|
|
const map = getElementSubstructureKeyMap(chainMaps, entityKey[start]);
|
|
|
const key = getElementKey(map, asym_id.value(start), chainCounter);
|
|
|
for (let i = start; i < end; i++) chainKey[i] = key;
|
|
|
+
|
|
|
+ // create seq_id map for the ranges defined by seq_id_begin and seq_id_end
|
|
|
+ const seqMap: Map<number, number> = new Map()
|
|
|
+ seqMaps.set(key, seqMap)
|
|
|
+ for (let i = start; i < end; i++) {
|
|
|
+ const seqStart = seq_id_begin.value(i)
|
|
|
+ const seqEnd = seq_id_end.value(i)
|
|
|
+ for (let j = seqStart; j <= seqEnd; j++) {
|
|
|
+ seqMap.set(j, i)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- const { findChainKey } = createLookUp(entities, chainMaps);
|
|
|
|
|
|
- return {
|
|
|
- chainKey: chainKey,
|
|
|
- entityKey: entityKey,
|
|
|
- modelKey: modelKey,
|
|
|
- findChainKey
|
|
|
- };
|
|
|
+
|
|
|
+ const { findChainKey, findSequenceKey } = createLookUp(entities, chainMaps, seqMaps);
|
|
|
+
|
|
|
+ return { chainKey, entityKey, modelKey, findSequenceKey, findChainKey };
|
|
|
}
|