sequence.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { mmCIF_Database as mmCIF } from 'mol-io/reader/cif/schema/mmcif'
  7. import Sequence from '../../properties/sequence'
  8. import { Column } from 'mol-data/db';
  9. import { Hierarchy } from '../../properties/hierarchy';
  10. import { Entities } from '../../properties/common';
  11. export function getSequence(cif: mmCIF, entities: Entities, hierarchy: Hierarchy): Sequence {
  12. if (!cif.entity_poly_seq._rowCount) return Sequence.fromHierarchy(hierarchy);
  13. const { entity_id, num, mon_id } = cif.entity_poly_seq;
  14. const byEntityKey: Sequence['byEntityKey'] = {};
  15. const count = entity_id.rowCount;
  16. let i = 0;
  17. while (i < count) {
  18. const start = i;
  19. while (i < count - 1 && entity_id.areValuesEqual(i, i + 1)) i++;
  20. i++;
  21. const id = entity_id.value(start);
  22. byEntityKey[entities.getEntityIndex(id)] = { entityId: id, compId: Column.window(mon_id, start, i), num: Column.window(num, start, i) }
  23. }
  24. return { byEntityKey };
  25. }