Bläddra i källkod

model type improvements, readonly maps

Alexander Rose 6 år sedan
förälder
incheckning
cad35f7c0f

+ 2 - 2
src/mol-model/sequence/sequence.ts

@@ -49,7 +49,7 @@ namespace Sequence {
         return { kind: Kind.Generic, code: (v: string) => 'X' };
     }
 
-    function modCode(code: (name: string) => string, map: Map<string, string>): (name: string) => string {
+    function modCode(code: (name: string) => string, map: ReadonlyMap<string, string>): (name: string) => string {
         return n => {
             const ret = code(n);
             if (ret !== 'X' || !map.has(n)) return ret;
@@ -57,7 +57,7 @@ namespace Sequence {
         }
     }
 
-    export function ofResidueNames(residueName: Column<string>, seqId: Column<number>, modifiedMap?: Map<string, string>): Sequence {
+    export function ofResidueNames(residueName: Column<string>, seqId: Column<number>, modifiedMap?: ReadonlyMap<string, string>): Sequence {
         if (seqId.rowCount === 0) throw new Error('cannot be empty');
 
         const { kind, code } = determineKind(residueName);

+ 5 - 5
src/mol-model/structure/model/formats/mmcif.ts

@@ -23,7 +23,7 @@ import { getSecondaryStructureMmCif } from './mmcif/secondary-structure';
 import { getSequence } from './mmcif/sequence';
 import { sortAtomSite } from './mmcif/sort';
 import { StructConn } from './mmcif/bonds/struct_conn';
-import { ChemicalComponent } from '../properties/chemical-component';
+import { ChemicalComponent, ChemicalComponentMap } from '../properties/chemical-component';
 import { ComponentType, getMoleculeType } from '../types';
 
 import mmCIF_Format = Format.mmCIF
@@ -86,7 +86,7 @@ function getModifiedResidueNameMap(format: mmCIF_Format): Model['properties']['m
     return { parentId, details };
 }
 
-function getAsymIdSerialMap(format: mmCIF_Format) {
+function getAsymIdSerialMap(format: mmCIF_Format): ReadonlyMap<string, number> {
     const data = format.data.struct_asym;
     const map = new Map<string, number>();
     let serial = 0
@@ -104,7 +104,7 @@ function getAsymIdSerialMap(format: mmCIF_Format) {
     return map;
 }
 
-function getChemicalComponentMap(format: mmCIF_Format) {
+function getChemicalComponentMap(format: mmCIF_Format): ChemicalComponentMap {
     const map = new Map<string, ChemicalComponent>();
     const { id, type, name, pdbx_synonyms, formula, formula_weight } = format.data.chem_comp
     for (let i = 0, il = id.rowCount; i < il; ++i) {
@@ -126,8 +126,8 @@ function getChemicalComponentMap(format: mmCIF_Format) {
 
 export interface FormatData {
     modifiedResidues: Model['properties']['modifiedResidues']
-    asymIdSerialMap: Map<string, number>
-    chemicalComponentMap: Map<string, ChemicalComponent>
+    asymIdSerialMap: Model['properties']['asymIdSerialMap']
+    chemicalComponentMap: Model['properties']['chemicalComponentMap']
 }
 
 function getFormatData(format: mmCIF_Format): FormatData {

+ 1 - 1
src/mol-model/structure/model/formats/mmcif/sequence.ts

@@ -21,7 +21,7 @@ import { Sequence } from '../../../../sequence';
 // corresponding ATOM_SITE entries should reflect this
 // heterogeneity.
 
-export function getSequence(cif: mmCIF, entities: Entities, hierarchy: AtomicHierarchy, modResMap: Map<string, string>): StructureSequence {
+export function getSequence(cif: mmCIF, entities: Entities, hierarchy: AtomicHierarchy, modResMap: ReadonlyMap<string, string>): StructureSequence {
     if (!cif.entity_poly_seq._rowCount) return StructureSequence.fromAtomicHierarchy(entities, hierarchy, modResMap);
 
     const { entity_id, num, mon_id } = cif.entity_poly_seq;

+ 7 - 7
src/mol-model/structure/model/model.ts

@@ -15,7 +15,7 @@ import { CustomProperties } from './properties/custom';
 import { SecondaryStructure } from './properties/seconday-structure';
 
 import from_mmCIF from './formats/mmcif'
-import { ChemicalComponent } from './properties/chemical-component';
+import { ChemicalComponentMap } from './properties/chemical-component';
 
 /**
  * Interface to the "source data" of the molecule.
@@ -42,14 +42,14 @@ export interface Model extends Readonly<{
         /** secondary structure provided by the input file */
         readonly secondaryStructure: SecondaryStructure,
         /** maps modified residue name to its parent */
-        readonly modifiedResidues: {
-            parentId: Map<string, string>,
-            details: Map<string, string>
-        },
+        readonly modifiedResidues: Readonly<{
+            parentId: ReadonlyMap<string, string>,
+            details: ReadonlyMap<string, string>
+        }>,
         /** maps asym id to unique serial number */
-        readonly asymIdSerialMap: Map<string, number>
+        readonly asymIdSerialMap: ReadonlyMap<string, number>
         /** maps residue name to `ChemicalComponent` data */
-        readonly chemicalComponentMap: Map<string, ChemicalComponent>
+        readonly chemicalComponentMap: ChemicalComponentMap
     },
 
     customProperties: CustomProperties,

+ 2 - 0
src/mol-model/structure/model/properties/chemical-component.ts

@@ -15,3 +15,5 @@ export interface ChemicalComponent {
     formula: string
     formulaWeight: number
 }
+
+export type ChemicalComponentMap = ReadonlyMap<string, ChemicalComponent>

+ 1 - 1
src/mol-model/structure/model/properties/sequence.ts

@@ -24,7 +24,7 @@ namespace StructureSequence {
         readonly sequence: Sequence
     }
 
-    export function fromAtomicHierarchy(entities: Entities, hierarchy: AtomicHierarchy, modResMap?: Map<string, string>): StructureSequence {
+    export function fromAtomicHierarchy(entities: Entities, hierarchy: AtomicHierarchy, modResMap?: ReadonlyMap<string, string>): StructureSequence {
         const { label_comp_id, label_seq_id } = hierarchy.residues
         const { chainAtomSegments, residueAtomSegments } = hierarchy