Skip to content
Snippets Groups Projects
Commit 8eb43a95 authored by Alexander Rose's avatar Alexander Rose
Browse files

added CoarsedElementKeys.findSequenceKey

parent b74cdd2c
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
* Copyright (c) 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 { mmCIF_Database as mmCIF } from 'mol-io/reader/cif/schema/mmcif'
......@@ -17,6 +18,8 @@ export interface CoarsedElementKeys {
// assign a key to each element, index to the CoarseHierarchy.models table
modelKey: ArrayLike<number>,
/** find index of the residue/feature element where seq_id is included */
findSequenceKey(entityId: string, asym_id: string, seq_id: number): number
findChainKey(entityId: string, asym_id: string): number
}
......
......@@ -92,11 +92,5 @@ export function getAtomicKeys(data: AtomicData, entities: Entities, segments: At
const { findChainKey, findResidueKey } = createLookUp(entities, chainMaps, residueMaps);
return {
residueKey: residueKey,
chainKey: chainKey,
entityKey: entityKey,
findChainKey,
findResidueKey
};
return { residueKey, chainKey, entityKey, findChainKey, findResidueKey };
}
\ No newline at end of file
/**
* 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 };
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment