structure-quality-report.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 { StructureQualityReport, StructureQualityReportProvider } from '../../../mol-model-props/pdbe/structure-quality-report';
  7. import { Location } from '../../../mol-model/location';
  8. import { StructureElement } from '../../../mol-model/structure';
  9. import { ColorTheme, LocationColor } from '../../../mol-theme/color';
  10. import { ThemeDataContext } from '../../../mol-theme/theme';
  11. import { Color } from '../../../mol-util/color';
  12. import { TableLegend } from '../../../mol-util/legend';
  13. import { ParamDefinition as PD } from '../../../mol-util/param-definition';
  14. import { CustomProperty } from '../../common/custom-property';
  15. const ValidationColors = [
  16. Color.fromRgb(170, 170, 170), // not applicable
  17. Color.fromRgb(0, 255, 0), // 0 issues
  18. Color.fromRgb(255, 255, 0), // 1
  19. Color.fromRgb(255, 128, 0), // 2
  20. Color.fromRgb(255, 0, 0), // 3 or more
  21. ]
  22. const ValidationColorTable: [string, Color][] = [
  23. ['No Issues', ValidationColors[1]],
  24. ['One Issue', ValidationColors[2]],
  25. ['Two Issues', ValidationColors[3]],
  26. ['Three Or More Issues', ValidationColors[4]],
  27. ['Not Applicable', ValidationColors[9]]
  28. ]
  29. export const StructureQualityReportColorThemeParams = {
  30. type: PD.MappedStatic('issue-count', {
  31. 'issue-count': PD.Group({}),
  32. 'specific-issue': PD.Group({
  33. kind: PD.Text()
  34. })
  35. })
  36. };
  37. type Params = typeof StructureQualityReportColorThemeParams
  38. export function StructureQualityReportColorTheme(ctx: ThemeDataContext, props: PD.Values<Params>): ColorTheme<Params> {
  39. let color: LocationColor
  40. if (ctx.structure && !ctx.structure.isEmpty && ctx.structure.models[0].customProperties.has(StructureQualityReportProvider.descriptor)) {
  41. const getIssues = StructureQualityReport.getIssues;
  42. if (props.type.name === 'issue-count') {
  43. color = (location: Location) => {
  44. if (StructureElement.Location.is(location)) {
  45. return ValidationColors[Math.min(3, getIssues(location).length) + 1];
  46. }
  47. return ValidationColors[0];
  48. }
  49. } else {
  50. const issue = props.type.params.kind;
  51. color = (location: Location) => {
  52. if (StructureElement.Location.is(location) && getIssues(location).indexOf(issue) >= 0) {
  53. return ValidationColors[4];
  54. }
  55. return ValidationColors[0];
  56. }
  57. }
  58. } else {
  59. color = () => ValidationColors[0];
  60. }
  61. return {
  62. factory: StructureQualityReportColorTheme,
  63. granularity: 'group',
  64. color: color,
  65. props: props,
  66. description: 'Assigns residue colors according to the number of quality issues or a specific quality issue. Data from wwPDB Validation Report, obtained via PDBe.',
  67. legend: TableLegend(ValidationColorTable)
  68. }
  69. }
  70. export const StructureQualityReportColorThemeProvider: ColorTheme.Provider<Params, 'pdbe-structure-quality-report'> = {
  71. name: 'pdbe-structure-quality-report',
  72. label: 'Structure Quality Report',
  73. category: ColorTheme.Category.Validation,
  74. factory: StructureQualityReportColorTheme,
  75. getParams: ctx => {
  76. const issueTypes = StructureQualityReport.getIssueTypes(ctx.structure);
  77. if (issueTypes.length === 0) {
  78. return {
  79. type: PD.MappedStatic('issue-count', {
  80. 'issue-count': PD.Group({})
  81. })
  82. };
  83. }
  84. return {
  85. type: PD.MappedStatic('issue-count', {
  86. 'issue-count': PD.Group({}),
  87. 'specific-issue': PD.Group({
  88. kind: PD.Select(issueTypes[0], PD.arrayToOptions(issueTypes))
  89. }, { isFlat: true })
  90. })
  91. };
  92. },
  93. defaultValues: PD.getDefaultValues(StructureQualityReportColorThemeParams),
  94. isApplicable: (ctx: ThemeDataContext) => StructureQualityReport.isApplicable(ctx.structure?.models[0]),
  95. ensureCustomProperties: {
  96. attach: (ctx: CustomProperty.Context, data: ThemeDataContext) => data.structure ? StructureQualityReportProvider.attach(ctx, data.structure.models[0], void 0, true) : Promise.resolve(),
  97. detach: (data) => data.structure && data.structure.models[0].customProperties.reference(StructureQualityReportProvider.descriptor, false)
  98. }
  99. }