Browse Source

column map

David Sehnal 7 years ago
parent
commit
1aa995dfff

+ 4 - 0
src/mol-base/collections/_spec/table.spec.ts

@@ -43,6 +43,10 @@ describe('column', () => {
     it('permutation', () => {
         expect(Column.permutation(arr, [1, 0, 3, 2]).toArray()).toEqual([2, 1, 4, 3]);
     });
+
+    it('map to array', () => {
+        expect(Column.mapToArray(arrWindow, x => x + 1)).toEqual([3, 4]);
+    });
 })
 
 describe('table', () => {

+ 10 - 0
src/mol-base/collections/column.ts

@@ -94,6 +94,10 @@ namespace Column {
         return createFirstIndexMapOfColumn(column);
     }
 
+    export function mapToArray<T, S>(column: Column<T>, f: (v: T) => S, ctor?: { new(size: number): ArrayLike<number> }): ArrayLike<S> {
+        return mapToArrayImpl(column, f, ctor || Array);
+    }
+
     /** Makes the column backned by an array. Useful for columns that accessed often. */
     export function asArrayColumn<T>(c: Column<T>, array?: ToArrayParams['array']): Column<T> {
         if (c['@array']) return c;
@@ -257,6 +261,12 @@ function permutationFull<T>(c: Column<T>, map: ArrayLike<number>): Column<T> {
     };
 }
 
+function mapToArrayImpl<T, S>(c: Column<T>, f: (v: T) => S, ctor: { new(size: number): ArrayLike<number> }): ArrayLike<S> {
+    const ret = new ctor(c.rowCount) as any;
+    for (let i = 0, _i = c.rowCount; i < _i; i++) ret[i] = f(c.value(i));
+    return ret;
+}
+
 export namespace ColumnHelpers {
     export function getArrayBounds(rowCount: number, params?: Column.ToArrayParams) {
         const start = params && typeof params.start !== 'undefined' ? Math.max(Math.min(params.start, rowCount - 1), 0) : 0;

+ 1 - 4
src/mol-data/model/properties/macromolecule-tree.ts

@@ -21,10 +21,7 @@ export const AtomsSchema = {
     label_alt_id: mmCIF.atom_site.label_alt_id,
     pdbx_formal_charge: mmCIF.atom_site.pdbx_formal_charge,
     occupancy: mmCIF.atom_site.occupancy,
-    B_iso_or_equiv: mmCIF.atom_site.B_iso_or_equiv,
-
-    key: Column.Type.int,
-    source_row: Column.Type.int,
+    B_iso_or_equiv: mmCIF.atom_site.B_iso_or_equiv
 };
 
 export interface Atoms extends Table<typeof AtomsSchema> { }