sequence.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 { Column } from 'mol-data/db'
  7. import { AtomicHierarchy } from './atomic/hierarchy';
  8. import { Entities } from './common';
  9. import { Sequence } from '../../../sequence';
  10. interface StructureSequence {
  11. readonly byEntityKey: { [key: number]: StructureSequence.Entity }
  12. }
  13. namespace StructureSequence {
  14. export interface Entity {
  15. readonly entityId: string,
  16. readonly num: Column<number>,
  17. // Corresponds to _entity_poly_seq.mon_id
  18. readonly compId: Column<string>,
  19. readonly sequence: Sequence
  20. }
  21. export function fromAtomicHierarchy(entities: Entities, hierarchy: AtomicHierarchy): StructureSequence {
  22. const { label_comp_id, label_seq_id } = hierarchy.residues
  23. const { chainSegments, residueSegments } = hierarchy
  24. const byEntityKey: StructureSequence['byEntityKey'] = { };
  25. for (let cI = 0, _cI = hierarchy.chains._rowCount; cI < _cI; cI++) {
  26. const entityKey = hierarchy.entityKey[cI];
  27. // Only for polymers, trying to mirror _entity_poly_seq
  28. if (byEntityKey[entityKey] !== void 0 || entities.data.type.value(entityKey) !== 'polymer') continue;
  29. let start = cI;
  30. cI++;
  31. while (cI < _cI && entityKey === hierarchy.entityKey[cI] && entities.data.type.value(entityKey) !== 'polymer') {
  32. cI++;
  33. }
  34. cI--;
  35. const rStart = residueSegments.segmentMap[chainSegments.segments[start]];
  36. const rEnd = residueSegments.segmentMap[chainSegments.segments[cI + 1]];
  37. const compId = Column.window(label_comp_id, rStart, rEnd);
  38. const num = Column.window(label_seq_id, rStart, rEnd);
  39. byEntityKey[entityKey] = {
  40. entityId: entities.data.id.value(entityKey),
  41. compId,
  42. num,
  43. sequence: Sequence.ofResidueNames(compId, num)
  44. };
  45. }
  46. return { byEntityKey }
  47. }
  48. }
  49. export default StructureSequence