sequence.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 StructureSequence from '../../properties/sequence'
  8. import { Column } from 'mol-data/db';
  9. import { AtomicHierarchy } from '../../properties/atomic';
  10. import { Entities } from '../../properties/common';
  11. import { Sequence } from '../../../../sequence';
  12. // TODO how to handle microheterogeneity
  13. // see http://mmcif.wwpdb.org/dictionaries/mmcif_pdbx_v50.dic/Categories/entity_poly_seq.html
  14. //
  15. // Data items in the ENTITY_POLY_SEQ category specify the sequence
  16. // of monomers in a polymer. Allowance is made for the possibility
  17. // of microheterogeneity in a sample by allowing a given sequence
  18. // number to be correlated with more than one monomer ID. The
  19. // corresponding ATOM_SITE entries should reflect this
  20. // heterogeneity.
  21. export function getSequence(cif: mmCIF, entities: Entities, hierarchy: AtomicHierarchy): StructureSequence {
  22. if (!cif.entity_poly_seq._rowCount) return StructureSequence.fromAtomicHierarchy(entities, hierarchy);
  23. const { entity_id, num, mon_id } = cif.entity_poly_seq;
  24. const byEntityKey: StructureSequence['byEntityKey'] = {};
  25. const count = entity_id.rowCount;
  26. let i = 0;
  27. while (i < count) {
  28. const start = i;
  29. while (i < count - 1 && entity_id.areValuesEqual(i, i + 1)) i++;
  30. i++;
  31. const id = entity_id.value(start);
  32. const _compId = Column.window(mon_id, start, i);
  33. const _num = Column.window(num, start, i);
  34. byEntityKey[entities.getEntityIndex(id)] = {
  35. entityId: id,
  36. compId: _compId,
  37. num: _num,
  38. sequence: Sequence.ofResidueNames(_compId, _num)
  39. };
  40. }
  41. return { byEntityKey };
  42. }