Browse Source

Added stringEquals to column

David Sehnal 7 years ago
parent
commit
8b1552d344

+ 0 - 0
src/reader/cif/binary-field.ts → src/reader/cif/binary/field.ts


+ 0 - 0
src/reader/cif/binary-parser.ts → src/reader/cif/binary/parser.ts


+ 5 - 2
src/reader/cif/index.ts

@@ -4,12 +4,15 @@
  * @author David Sehnal <david.sehnal@gmail.com>
  */
 
-import parseText from './text-parser'
+import parseText from './text/parser'
+import { Block } from './data-model'
 import { apply as applySchema } from './schema'
 import mmCIF from './schema/mmcif'
 
 export default {
     parseText,
     applySchema,
-    schema: { mmCIF }
+    schema: {
+        mmCIF: (block: Block) => applySchema(mmCIF, block)
+    }
 }

+ 1 - 0
src/reader/cif/schema.ts

@@ -71,6 +71,7 @@ export namespace Field {
             rowCount: field.rowCount,
             value,
             isValueDefined: row => presence(row) === Data.ValuePresence.Present,
+            stringEquals: field.stringEquals,
             areValuesEqual: field.areValuesEqual,
             toArray
         };

+ 5 - 5
src/reader/cif/text-field.ts → src/reader/cif/text/field.ts

@@ -4,11 +4,11 @@
  * @author David Sehnal <david.sehnal@gmail.com>
  */
 
-import * as Column from '../common/column'
-import * as TokenColumn from '../common/text/column/token'
-import { Tokens } from '../common/text/tokenizer'
-import * as Data from './data-model'
-import { parseInt as fastParseInt, parseFloat as fastParseFloat } from '../common/text/number-parser'
+import * as Column from '../../common/column'
+import * as TokenColumn from '../../common/text/column/token'
+import { Tokens } from '../../common/text/tokenizer'
+import * as Data from '../data-model'
+import { parseInt as fastParseInt, parseFloat as fastParseFloat } from '../../common/text/number-parser'
 
 export default function CifTextField(tokens: Tokens, rowCount: number): Data.Field {
     const { data, indices } = tokens;

+ 4 - 4
src/reader/cif/text-parser.ts → src/reader/cif/text/parser.ts

@@ -22,10 +22,10 @@
  *
  */
 
-import * as Data from './data-model'
-import Field from './text-field'
-import { Tokens, TokenBuilder } from '../common/text/tokenizer'
-import Result from '../result'
+import * as Data from '../data-model'
+import Field from './field'
+import { Tokens, TokenBuilder } from '../../common/text/tokenizer'
+import Result from '../../result'
 
 /**
  * Types of supported mmCIF tokens.

+ 3 - 1
src/reader/common/column.ts

@@ -27,6 +27,7 @@ export interface Column<T> {
     value(row: number): T,
     isValueDefined(row: number): boolean,
     toArray(params?: ToArrayParams): ReadonlyArray<T>,
+    stringEquals(row: number, value: string): boolean,
     areValuesEqual(rowA: number, rowB: number): boolean
 }
 
@@ -42,7 +43,8 @@ export function UndefinedColumn<T extends ColumnType>(rowCount: number, type: T)
             for (let i = 0, _i = array.length; i < _i; i++) array[i] = value(0)
             return array;
         },
-        areValuesEqual() { return true; }
+        stringEquals(row, value) { return !value; },
+        areValuesEqual(rowA, rowB) { return true; }
     }
 }
 

+ 1 - 0
src/reader/common/text/column/fixed.ts

@@ -47,6 +47,7 @@ export function FixedColumn<T extends ColumnType>(lines: Tokens, offset: number,
         value,
         isValueDefined(row) { return true; },
         toArray(params) { return createAndFillArray(rowCount, value, params); },
+        stringEquals(row, v) { return value(row) === v; },
         areValuesEqual(rowA, rowB) {
             return value(rowA) === value(rowB);
         }

+ 10 - 0
src/reader/common/text/column/token.ts

@@ -35,6 +35,16 @@ export function TokenColumn<T extends ColumnType>(tokens: Tokens, type: T): Colu
         value,
         isValueDefined(row) { return true; },
         toArray(params) { return createAndFillArray(rowCount, value, params); },
+        stringEquals(row, v) {
+            const s = indices[2 * row];
+            const value = v || '';
+            const len = value.length;
+            if (len !== indices[2 * row + 1] - s) return false;
+            for (let i = 0; i < len; i++) {
+                if (data.charCodeAt(i + s) !== value.charCodeAt(i)) return false;
+            }
+            return true;
+        },
         areValuesEqual: areValuesEqualProvider(tokens)
     };
 }

+ 1 - 1
src/reader/spec/cif.spec.ts

@@ -5,7 +5,7 @@
  */
 
 import * as Data from '../cif/data-model'
-import TextField from '../cif/text-field'
+import TextField from '../cif/text/field'
 import * as Schema from '../cif/schema'
 
 const columnData = `123abc`;

+ 1 - 1
src/script.ts

@@ -94,7 +94,7 @@ export function _cif() {
         console.log(atom_site.getField('Cartn_x')!.float(0));
         //console.log(atom_site.getField('label_atom_id')!.toStringArray());
 
-        const mmcif = CIF.applySchema(CIF.schema.mmCIF, data);
+        const mmcif = CIF.schema.mmCIF(data);
         console.log(mmcif.atom_site.Cartn_x.value(0));
         console.log(mmcif.entity.type.toArray());
         console.log(mmcif.pdbx_struct_oper_list.matrix.value(0));