Skip to content
Snippets Groups Projects
Commit 164c62e0 authored by David Sehnal's avatar David Sehnal
Browse files

more data model

parent 720b23c1
No related branches found
No related tags found
No related merge requests found
...@@ -20,11 +20,10 @@ describe('segments', () => { ...@@ -20,11 +20,10 @@ describe('segments', () => {
}); });
it('map', () => { it('map', () => {
const segs = Segmentation.create([1, 2, 3]); const segs = Segmentation.create([0, 1, 2]);
expect(segs.segmentMap).toEqual(new Int32Array([0, 1])); expect(segs.segmentMap).toEqual(new Int32Array([0, 1]));
expect(segs.offset).toEqual(1); expect(Segmentation.getSegment(segs, 0)).toBe(0);
expect(Segmentation.getSegment(segs, 1)).toBe(0); expect(Segmentation.getSegment(segs, 1)).toBe(1);
expect(Segmentation.getSegment(segs, 2)).toBe(1);
}) })
it('iteration', () => { it('iteration', () => {
......
...@@ -10,22 +10,22 @@ import Interval from '../interval' ...@@ -10,22 +10,22 @@ import Interval from '../interval'
import SortedArray from '../sorted-array' import SortedArray from '../sorted-array'
import Segs from '../segmentation' import Segs from '../segmentation'
type Segmentation = { segments: SortedArray, segmentMap: ArrayLike<number>, offset: number, count: number } type Segmentation = { segments: SortedArray, segmentMap: ArrayLike<number>, count: number }
export function create(values: ArrayLike<number>): Segmentation { export function create(values: ArrayLike<number>): Segmentation {
const segments = SortedArray.ofSortedArray(values); const segments = SortedArray.ofSortedArray(values);
const min = SortedArray.min(segments), max = SortedArray.max(segments); const max = SortedArray.max(segments);
const segmentMap = new Int32Array(max - min); const segmentMap = new Int32Array(max);
for (let i = 0, _i = values.length - 1; i < _i; i++) { for (let i = 0, _i = values.length - 1; i < _i; i++) {
for (let j = values[i] - min, _j = values[i + 1] - min; j < _j; j++) { for (let j = values[i], _j = values[i + 1]; j < _j; j++) {
segmentMap[j] = i; segmentMap[j] = i;
} }
} }
return { segments, segmentMap, offset: min, count: values.length - 1 }; return { segments, segmentMap, count: values.length - 1 };
} }
export function count({ count }: Segmentation) { return count; } export function count({ count }: Segmentation) { return count; }
export function getSegment({ segmentMap, offset }: Segmentation, value: number) { return segmentMap[value - offset]; } export function getSegment({ segmentMap }: Segmentation, value: number) { return segmentMap[value]; }
export function projectValue({ segments }: Segmentation, set: OrderedSet, value: number): Interval { export function projectValue({ segments }: Segmentation, set: OrderedSet, value: number): Interval {
const last = OrderedSet.max(segments); const last = OrderedSet.max(segments);
......
...@@ -24,7 +24,6 @@ namespace Segmentation { ...@@ -24,7 +24,6 @@ namespace Segmentation {
interface Segmentation { interface Segmentation {
'@type': 'segmentation', '@type': 'segmentation',
readonly segmentMap: ArrayLike<number>, readonly segmentMap: ArrayLike<number>,
readonly offset: number,
readonly count: number readonly count: number
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import Tuple from '../mol-base/collections/integer/tuple' import Tuple from '../mol-base/collections/integer/tuple'
/** Atom pointer */
interface Atom { '@type': Tuple['@type'] } interface Atom { '@type': Tuple['@type'] }
namespace Atom { namespace Atom {
......
...@@ -5,18 +5,25 @@ ...@@ -5,18 +5,25 @@
*/ */
import * as Formats from './model/formats' import * as Formats from './model/formats'
import CommonInterface from './model/interfaces/common' import CommonInterface from './model/common'
import MacromoleculeInterface from './model/interfaces/common' import MacromoleculeInterface from './model/macromolecule'
import Segmentation from '../mol-base/collections/integer/segmentation' import Segmentation from '../mol-base/collections/integer/segmentation'
/**
* Interface to the "source data" of the molecule.
*
* "Atoms" are integers in the range [0, atomCount).
*/
interface Model { interface Model {
data: Formats.RawData, sourceData: Formats.RawData,
common: CommonInterface, common: CommonInterface,
macromolecule: MacromoleculeInterface macromolecule: MacromoleculeInterface
atomCount: number,
chains: Segmentation, chains: Segmentation,
residues: Segmentation residues: Segmentation,
entities: Segmentation
} }
export default Model export default Model
\ No newline at end of file
...@@ -21,10 +21,11 @@ function findModelBounds(data: mmCIF, startIndex: number) { ...@@ -21,10 +21,11 @@ function findModelBounds(data: mmCIF, startIndex: number) {
function segment(data: mmCIF, bounds: Interval) { function segment(data: mmCIF, bounds: Interval) {
const start = Interval.start(bounds), end = Interval.end(bounds); const start = Interval.start(bounds), end = Interval.end(bounds);
const residues = [start], chains = [start]; const residues = [0], chains = [0], entities = [0];
const { label_entity_id, auth_asym_id, auth_seq_id, pdbx_PDB_ins_code } = data.atom_site; const { label_entity_id, auth_asym_id, auth_seq_id, pdbx_PDB_ins_code } = data.atom_site;
let offset = 1;
for (let i = start + 1; i < end; i++) { for (let i = start + 1; i < end; i++) {
const newEntity = !label_entity_id.areValuesEqual(i - 1, i); const newEntity = !label_entity_id.areValuesEqual(i - 1, i);
const newChain = newEntity || !auth_asym_id.areValuesEqual(i - 1, i); const newChain = newEntity || !auth_asym_id.areValuesEqual(i - 1, i);
...@@ -32,31 +33,43 @@ function segment(data: mmCIF, bounds: Interval) { ...@@ -32,31 +33,43 @@ function segment(data: mmCIF, bounds: Interval) {
|| !auth_seq_id.areValuesEqual(i - 1, i) || !auth_seq_id.areValuesEqual(i - 1, i)
|| !pdbx_PDB_ins_code.areValuesEqual(i - 1, i); || !pdbx_PDB_ins_code.areValuesEqual(i - 1, i);
if (newResidue) residues[residues.length] = i; if (newEntity) entities[entities.length] = offset;
if (newChain) chains[chains.length] = i; if (newResidue) residues[residues.length] = offset;
if (newChain) chains[chains.length] = offset;
offset++;
} }
residues[residues.length] = end; residues[residues.length] = offset;
chains[chains.length] = end; chains[chains.length] = offset;
entities[entities.length] = offset;
return { residues: Segmentation.create(residues), chains: Segmentation.create(chains) }; return {
residues: Segmentation.create(residues),
chains: Segmentation.create(chains),
entities: Segmentation.create(entities)
};
} }
function createModel(raw: RawData, data: mmCIF, bounds: Interval): Model { function createModel(raw: RawData, data: mmCIF, bounds: Interval): Model {
const segments = segment(data, bounds); const segments = segment(data, bounds);
return { return {
data: raw, sourceData: raw,
common: 0 as any, common: 0 as any,
macromolecule: 0 as any, macromolecule: 0 as any,
atomCount: Interval.size(bounds),
residues: segments.residues, residues: segments.residues,
chains: segments.chains chains: segments.chains,
entities: segments.entities
}; };
} }
function getModels(data: mmCIF): ArrayLike<Model> { function buildModels(data: mmCIF): ArrayLike<Model> {
const raw: RawData = { source: 'mmCIF', data }; const raw: RawData = { source: 'mmCIF', data };
const models: Model[] = []; const models: Model[] = [];
const atomCount = data.atom_site._rowCount; const atomCount = data.atom_site._rowCount;
if (atomCount === 0) return models;
let modelStart = 0; let modelStart = 0;
while (modelStart < atomCount) { while (modelStart < atomCount) {
const bounds = findModelBounds(data, modelStart); const bounds = findModelBounds(data, modelStart);
...@@ -67,9 +80,4 @@ function getModels(data: mmCIF): ArrayLike<Model> { ...@@ -67,9 +80,4 @@ function getModels(data: mmCIF): ArrayLike<Model> {
return models; return models;
} }
export default getModels; export default buildModels;
\ No newline at end of file
// function createStructure() {
// }
/**
* Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
/**
* Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import Model from '../model'
import Structure from '../structure'
//export const Empty { }
export function ofModel(model: Model): Structure {
// TODO: create a unit for each chain in the model
return 0 as any;
}
\ No newline at end of file
...@@ -17,7 +17,7 @@ import CIF from './mol-io/reader/cif' ...@@ -17,7 +17,7 @@ import CIF from './mol-io/reader/cif'
import Computation from './mol-base/computation' import Computation from './mol-base/computation'
import createModels from './mol-data/model/formats/mmcif' import buildModels from './mol-data/model/builders/mmcif'
// import { toTypedFrame as applySchema } from './reader/cif/schema' // import { toTypedFrame as applySchema } from './reader/cif/schema'
import { generateSchema } from './mol-io/reader/cif/schema/utils' import { generateSchema } from './mol-io/reader/cif/schema/utils'
...@@ -115,7 +115,7 @@ async function runCIF(input: string | Uint8Array) { ...@@ -115,7 +115,7 @@ async function runCIF(input: string | Uint8Array) {
console.log(mmcif.pdbx_struct_oper_list.matrix.value(0)); console.log(mmcif.pdbx_struct_oper_list.matrix.value(0));
console.time('createModels'); console.time('createModels');
const models = createModels(mmcif); const models = buildModels(mmcif);
console.timeEnd('createModels'); console.timeEnd('createModels');
console.log(models[0].common); console.log(models[0].common);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment