react-msaview 1.3.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/bundle/index.js +285 -97099
  2. package/dist/StructureModel.d.ts +9 -0
  3. package/dist/StructureModel.js +11 -0
  4. package/dist/StructureModel.js.map +1 -0
  5. package/dist/UniprotTrack.d.ts +27 -0
  6. package/dist/UniprotTrack.js +53 -0
  7. package/dist/UniprotTrack.js.map +1 -0
  8. package/dist/colorSchemes.d.ts +5 -11
  9. package/dist/colorSchemes.js +27 -32
  10. package/dist/colorSchemes.js.map +1 -0
  11. package/dist/components/BoxTrack.d.ts +6 -6
  12. package/dist/components/BoxTrack.js +9 -137
  13. package/dist/components/BoxTrack.js.map +1 -0
  14. package/dist/components/BoxTrackBlock.d.ts +8 -0
  15. package/dist/components/BoxTrackBlock.js +136 -0
  16. package/dist/components/BoxTrackBlock.js.map +1 -0
  17. package/dist/components/Header.d.ts +2 -2
  18. package/dist/components/Header.js +55 -48
  19. package/dist/components/Header.js.map +1 -0
  20. package/dist/components/ImportForm.d.ts +2 -2
  21. package/dist/components/ImportForm.js +59 -71
  22. package/dist/components/ImportForm.js.map +1 -0
  23. package/dist/components/MSABlock.d.ts +8 -0
  24. package/dist/components/MSABlock.js +103 -0
  25. package/dist/components/MSABlock.js.map +1 -0
  26. package/dist/components/MSACanvas.d.ts +2 -2
  27. package/dist/components/MSACanvas.js +32 -133
  28. package/dist/components/MSACanvas.js.map +1 -0
  29. package/dist/components/MSAMouseoverCanvas.d.ts +6 -0
  30. package/dist/components/MSAMouseoverCanvas.js +52 -0
  31. package/dist/components/MSAMouseoverCanvas.js.map +1 -0
  32. package/dist/components/MSAView.d.ts +2 -2
  33. package/dist/components/MSAView.js +17 -62
  34. package/dist/components/MSAView.js.map +1 -0
  35. package/dist/components/MultiAlignmentSelector.d.ts +6 -0
  36. package/dist/components/MultiAlignmentSelector.js +13 -0
  37. package/dist/components/MultiAlignmentSelector.js.map +1 -0
  38. package/dist/components/ResizeHandles.d.ts +5 -5
  39. package/dist/components/ResizeHandles.js +31 -32
  40. package/dist/components/ResizeHandles.js.map +1 -0
  41. package/dist/components/Rubberband.d.ts +3 -2
  42. package/dist/components/Rubberband.js +41 -64
  43. package/dist/components/Rubberband.js.map +1 -0
  44. package/dist/components/Ruler.d.ts +2 -16
  45. package/dist/components/Ruler.js +19 -88
  46. package/dist/components/Ruler.js.map +1 -0
  47. package/dist/components/TextTrack.d.ts +5 -5
  48. package/dist/components/TextTrack.js +23 -24
  49. package/dist/components/TextTrack.js.map +1 -0
  50. package/dist/components/Track.d.ts +5 -5
  51. package/dist/components/Track.js +41 -40
  52. package/dist/components/Track.js.map +1 -0
  53. package/dist/components/TreeBranchMenu.d.ts +14 -0
  54. package/dist/components/TreeBranchMenu.js +26 -0
  55. package/dist/components/TreeBranchMenu.js.map +1 -0
  56. package/dist/components/TreeCanvas.d.ts +2 -2
  57. package/dist/components/TreeCanvas.js +24 -356
  58. package/dist/components/TreeCanvas.js.map +1 -0
  59. package/dist/components/TreeCanvasBlock.d.ts +7 -0
  60. package/dist/components/TreeCanvasBlock.js +252 -0
  61. package/dist/components/TreeCanvasBlock.js.map +1 -0
  62. package/dist/components/TreeMenu.d.ts +12 -0
  63. package/dist/components/TreeMenu.js +56 -0
  64. package/dist/components/TreeMenu.js.map +1 -0
  65. package/dist/components/TreeRuler.d.ts +2 -2
  66. package/dist/components/TreeRuler.js +3 -3
  67. package/dist/components/TreeRuler.js.map +1 -0
  68. package/dist/components/VerticalGuide.d.ts +7 -0
  69. package/dist/components/VerticalGuide.js +30 -0
  70. package/dist/components/VerticalGuide.js.map +1 -0
  71. package/dist/components/ZoomControls.d.ts +6 -0
  72. package/dist/components/ZoomControls.js +58 -0
  73. package/dist/components/ZoomControls.js.map +1 -0
  74. package/dist/components/data/seq2.d.ts +3 -3
  75. package/dist/components/data/seq2.js +33 -3
  76. package/dist/components/data/seq2.js.map +1 -0
  77. package/dist/components/dialogs/AboutDlg.d.ts +4 -0
  78. package/dist/components/dialogs/AboutDlg.js +40 -0
  79. package/dist/components/dialogs/AboutDlg.js.map +1 -0
  80. package/{bundle/components → dist/components/dialogs}/AddTrackDlg.d.ts +3 -3
  81. package/dist/components/dialogs/AddTrackDlg.js +26 -0
  82. package/dist/components/dialogs/AddTrackDlg.js.map +1 -0
  83. package/dist/components/{AnnotationDlg.d.ts → dialogs/AnnotationDlg.d.ts} +3 -3
  84. package/dist/components/dialogs/AnnotationDlg.js +65 -0
  85. package/dist/components/dialogs/AnnotationDlg.js.map +1 -0
  86. package/dist/components/dialogs/DetailsDlg.d.ts +7 -0
  87. package/dist/components/dialogs/DetailsDlg.js +13 -0
  88. package/dist/components/dialogs/DetailsDlg.js.map +1 -0
  89. package/dist/components/dialogs/MoreInfoDlg.d.ts +6 -0
  90. package/dist/components/dialogs/MoreInfoDlg.js +11 -0
  91. package/dist/components/dialogs/MoreInfoDlg.js.map +1 -0
  92. package/dist/components/dialogs/SettingsDlg.d.ts +7 -0
  93. package/dist/components/dialogs/SettingsDlg.js +48 -0
  94. package/dist/components/dialogs/SettingsDlg.js.map +1 -0
  95. package/dist/components/dialogs/TrackInfoDlg.d.ts +9 -0
  96. package/{bundle/components → dist/components/dialogs}/TrackInfoDlg.js +12 -13
  97. package/dist/components/dialogs/TrackInfoDlg.js.map +1 -0
  98. package/dist/components/dialogs/TracklistDlg.d.ts +7 -0
  99. package/dist/components/dialogs/TracklistDlg.js +18 -0
  100. package/dist/components/dialogs/TracklistDlg.js.map +1 -0
  101. package/{bundle/components/Ruler.d.ts → dist/components/util.d.ts} +1 -6
  102. package/dist/components/util.js +68 -0
  103. package/dist/components/util.js.map +1 -0
  104. package/dist/index.d.ts +2 -4
  105. package/dist/index.js +3 -3
  106. package/dist/index.js.map +1 -0
  107. package/dist/layout.js +14 -20
  108. package/dist/layout.js.map +1 -0
  109. package/dist/model.d.ts +114 -97
  110. package/dist/model.js +248 -486
  111. package/dist/model.js.map +1 -0
  112. package/dist/parseNewick.d.ts +1 -5
  113. package/dist/parseNewick.js +11 -8
  114. package/dist/parseNewick.js.map +1 -0
  115. package/dist/parsers/ClustalMSA.d.ts +6 -18
  116. package/dist/parsers/ClustalMSA.js +55 -64
  117. package/dist/parsers/ClustalMSA.js.map +1 -0
  118. package/dist/parsers/FastaMSA.d.ts +5 -12
  119. package/dist/parsers/FastaMSA.js +55 -64
  120. package/dist/parsers/FastaMSA.js.map +1 -0
  121. package/dist/parsers/StockholmMSA.d.ts +10 -17
  122. package/dist/parsers/StockholmMSA.js +81 -110
  123. package/dist/parsers/StockholmMSA.js.map +1 -0
  124. package/dist/util.d.ts +34 -7
  125. package/dist/util.js +76 -24
  126. package/dist/util.js.map +1 -0
  127. package/dist/version.d.ts +1 -0
  128. package/dist/version.js +2 -0
  129. package/dist/version.js.map +1 -0
  130. package/package.json +34 -34
  131. package/src/StructureModel.ts +11 -0
  132. package/src/UniprotTrack.ts +59 -0
  133. package/src/colorSchemes.ts +520 -0
  134. package/src/components/BoxTrack.tsx +33 -0
  135. package/src/components/BoxTrackBlock.tsx +198 -0
  136. package/src/components/Header.tsx +106 -0
  137. package/src/components/ImportForm.tsx +192 -0
  138. package/src/components/MSABlock.tsx +164 -0
  139. package/src/components/MSACanvas.tsx +142 -0
  140. package/src/components/MSAMouseoverCanvas.tsx +87 -0
  141. package/src/components/MSAView.tsx +88 -0
  142. package/src/components/MultiAlignmentSelector.tsx +33 -0
  143. package/src/components/ResizeHandles.tsx +137 -0
  144. package/src/components/Rubberband.tsx +270 -0
  145. package/src/components/Ruler.tsx +123 -0
  146. package/src/components/TextTrack.tsx +120 -0
  147. package/src/components/Track.tsx +153 -0
  148. package/src/components/TreeBranchMenu.tsx +67 -0
  149. package/src/components/TreeCanvas.tsx +128 -0
  150. package/src/components/TreeCanvasBlock.tsx +359 -0
  151. package/src/components/TreeMenu.tsx +105 -0
  152. package/src/components/TreeRuler.tsx +12 -0
  153. package/src/components/VerticalGuide.tsx +50 -0
  154. package/src/components/ZoomControls.tsx +78 -0
  155. package/src/components/data/seq2.ts +35 -0
  156. package/src/components/dialogs/AboutDlg.tsx +58 -0
  157. package/src/components/dialogs/AddTrackDlg.tsx +74 -0
  158. package/src/components/dialogs/AnnotationDlg.tsx +144 -0
  159. package/src/components/dialogs/DetailsDlg.tsx +28 -0
  160. package/src/components/dialogs/MoreInfoDlg.tsx +21 -0
  161. package/src/components/dialogs/SettingsDlg.tsx +154 -0
  162. package/src/components/dialogs/TrackInfoDlg.tsx +59 -0
  163. package/src/components/dialogs/TracklistDlg.tsx +59 -0
  164. package/src/components/util.ts +93 -0
  165. package/src/declare.d.ts +1 -0
  166. package/src/index.ts +2 -0
  167. package/src/layout.ts +83 -0
  168. package/src/model.ts +793 -0
  169. package/{bundle/parseNewick.d.ts → src/parseNewick.ts} +35 -5
  170. package/src/parsers/ClustalMSA.ts +79 -0
  171. package/src/parsers/FastaMSA.ts +82 -0
  172. package/src/parsers/StockholmMSA.ts +137 -0
  173. package/src/util.ts +142 -0
  174. package/src/version.ts +1 -0
  175. package/bundle/colorSchemes.d.ts +0 -16
  176. package/bundle/colorSchemes.js +0 -455
  177. package/bundle/components/AboutDlg.d.ts +0 -5
  178. package/bundle/components/AboutDlg.js +0 -47
  179. package/bundle/components/AddTrackDlg.js +0 -26
  180. package/bundle/components/AnnotationDlg.d.ts +0 -11
  181. package/bundle/components/AnnotationDlg.js +0 -77
  182. package/bundle/components/BoxTrack.d.ts +0 -7
  183. package/bundle/components/BoxTrack.js +0 -143
  184. package/bundle/components/DetailsDlg.d.ts +0 -8
  185. package/bundle/components/DetailsDlg.js +0 -12
  186. package/bundle/components/Header.d.ts +0 -6
  187. package/bundle/components/Header.js +0 -63
  188. package/bundle/components/ImportForm.d.ts +0 -6
  189. package/bundle/components/ImportForm.js +0 -89
  190. package/bundle/components/MSACanvas.d.ts +0 -6
  191. package/bundle/components/MSACanvas.js +0 -210
  192. package/bundle/components/MSAView.d.ts +0 -6
  193. package/bundle/components/MSAView.js +0 -88
  194. package/bundle/components/MoreInfoDlg.d.ts +0 -6
  195. package/bundle/components/MoreInfoDlg.js +0 -11
  196. package/bundle/components/ResizeHandles.d.ts +0 -8
  197. package/bundle/components/ResizeHandles.js +0 -110
  198. package/bundle/components/Rubberband.d.ts +0 -7
  199. package/bundle/components/Rubberband.js +0 -196
  200. package/bundle/components/Ruler.js +0 -121
  201. package/bundle/components/SettingsDlg.d.ts +0 -8
  202. package/bundle/components/SettingsDlg.js +0 -40
  203. package/bundle/components/TextTrack.d.ts +0 -7
  204. package/bundle/components/TextTrack.js +0 -72
  205. package/bundle/components/Track.d.ts +0 -11
  206. package/bundle/components/Track.js +0 -81
  207. package/bundle/components/TrackInfoDlg.d.ts +0 -6
  208. package/bundle/components/TracklistDlg.d.ts +0 -8
  209. package/bundle/components/TracklistDlg.js +0 -18
  210. package/bundle/components/TreeCanvas.d.ts +0 -6
  211. package/bundle/components/TreeCanvas.js +0 -431
  212. package/bundle/components/TreeRuler.d.ts +0 -6
  213. package/bundle/components/TreeRuler.js +0 -8
  214. package/bundle/components/data/seq2.d.ts +0 -3
  215. package/bundle/components/data/seq2.js +0 -3
  216. package/bundle/index.d.ts +0 -4
  217. package/bundle/layout.d.ts +0 -23
  218. package/bundle/layout.js +0 -53
  219. package/bundle/model.d.ts +0 -364
  220. package/bundle/model.js +0 -894
  221. package/bundle/parseNewick.js +0 -94
  222. package/bundle/parsers/ClustalMSA.d.ts +0 -39
  223. package/bundle/parsers/ClustalMSA.js +0 -77
  224. package/bundle/parsers/FastaMSA.d.ts +0 -26
  225. package/bundle/parsers/FastaMSA.js +0 -78
  226. package/bundle/parsers/StockholmMSA.d.ts +0 -75
  227. package/bundle/parsers/StockholmMSA.js +0 -142
  228. package/bundle/util.d.ts +0 -17
  229. package/bundle/util.js +0 -33
  230. package/dist/components/AboutDlg.d.ts +0 -5
  231. package/dist/components/AboutDlg.js +0 -50
  232. package/dist/components/AddTrackDlg.d.ts +0 -8
  233. package/dist/components/AddTrackDlg.js +0 -26
  234. package/dist/components/AnnotationDlg.js +0 -77
  235. package/dist/components/DetailsDlg.d.ts +0 -8
  236. package/dist/components/DetailsDlg.js +0 -12
  237. package/dist/components/MoreInfoDlg.d.ts +0 -6
  238. package/dist/components/MoreInfoDlg.js +0 -11
  239. package/dist/components/SettingsDlg.d.ts +0 -8
  240. package/dist/components/SettingsDlg.js +0 -40
  241. package/dist/components/TrackInfoDlg.d.ts +0 -6
  242. package/dist/components/TrackInfoDlg.js +0 -33
  243. package/dist/components/TracklistDlg.d.ts +0 -8
  244. package/dist/components/TracklistDlg.js +0 -18
  245. package/dist/components/package.json +0 -62
@@ -57,8 +57,38 @@
57
57
  * ]
58
58
  * }
59
59
  */
60
- export default function parse(s: any): {
61
- branchset: {}[];
62
- name: any;
63
- length: number;
64
- };
60
+ export default function parse(s: string) {
61
+ const ancestors = []
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ let tree = {} as Record<string, any>
64
+ const tokens = s.split(/\s*(;|\(|\)|,|:)\s*/)
65
+ for (let i = 0; i < tokens.length; i++) {
66
+ const token = tokens[i]
67
+ const subtree = {}
68
+ switch (token) {
69
+ case '(': // new branchset
70
+ tree.branchset = [subtree]
71
+ ancestors.push(tree)
72
+ tree = subtree
73
+ break
74
+ case ',': // another branch
75
+ ancestors.at(-1)?.branchset.push(subtree)
76
+ tree = subtree
77
+ break
78
+ case ')': // optional name next
79
+ tree = ancestors.pop()!
80
+ break
81
+ case ':': // optional length next
82
+ break
83
+ default: {
84
+ const x = tokens[i - 1]
85
+ if (x === ')' || x === '(' || x === ',') {
86
+ tree.name = token
87
+ } else if (x === ':') {
88
+ tree.length = parseFloat(token)
89
+ }
90
+ }
91
+ }
92
+ }
93
+ return tree
94
+ }
@@ -0,0 +1,79 @@
1
+ import { parse } from 'clustal-js'
2
+ import { NodeWithIds } from '../util'
3
+ export default class ClustalMSA {
4
+ private MSA: ReturnType<typeof parse>
5
+
6
+ constructor(text: string) {
7
+ this.MSA = parse(text)
8
+ }
9
+
10
+ getMSA() {
11
+ return this.MSA
12
+ }
13
+
14
+ getRow(name: string) {
15
+ return this.MSA.alns.find(aln => aln.id === name)?.seq.split('')
16
+ }
17
+
18
+ getWidth() {
19
+ return this.MSA.alns[0].seq.length
20
+ }
21
+
22
+ getRowData() {
23
+ return undefined
24
+ }
25
+
26
+ getHeader() {
27
+ return this.MSA.header
28
+ }
29
+
30
+ getNames() {
31
+ return this.MSA.alns.map(aln => aln.id)
32
+ }
33
+
34
+ getStructures() {
35
+ return {}
36
+ }
37
+
38
+ get alignmentNames() {
39
+ return []
40
+ }
41
+
42
+ getTree(): NodeWithIds {
43
+ return {
44
+ id: 'root',
45
+ name: 'root',
46
+ noTree: true,
47
+ branchset: this.getNames().map(name => ({
48
+ id: name,
49
+ name,
50
+ branchset: [],
51
+ })),
52
+ }
53
+ }
54
+
55
+ get seqConsensus() {
56
+ return this.MSA.consensus
57
+ }
58
+ get secondaryStructureConsensus() {
59
+ return undefined
60
+ }
61
+
62
+ get tracks() {
63
+ return this.seqConsensus?.trim()
64
+ ? [
65
+ {
66
+ id: 'seqConsensus',
67
+ name: 'Sequence consensus',
68
+ data: this.seqConsensus,
69
+ customColorScheme: {
70
+ '*': 'white',
71
+ ':': 'grey',
72
+ '.': 'darkgrey',
73
+ ' ': 'black',
74
+ },
75
+ },
76
+ ]
77
+ : []
78
+ }
79
+ }
@@ -0,0 +1,82 @@
1
+ import { NodeWithIds } from '../util'
2
+
3
+ function parseSmallFasta(text: string) {
4
+ return text
5
+ .split('>')
6
+ .filter(t => /\S/.test(t))
7
+ .map(entryText => {
8
+ const [defLine, ...seqLines] = entryText.split('\n')
9
+ const [id, ...description] = defLine.split(' ')
10
+ const descriptionStr = description.join(' ')
11
+ const seqLinesStr = seqLines.join('')
12
+ const sequence = seqLinesStr.replaceAll(/\s/g, '')
13
+ return { id, description: descriptionStr, sequence }
14
+ })
15
+ }
16
+ export default class FastaMSA {
17
+ private MSA: { seqdata: Record<string, string> }
18
+ constructor(text: string) {
19
+ this.MSA = {
20
+ seqdata: Object.fromEntries(
21
+ parseSmallFasta(text).map(m => [`${m.id}`, m.sequence]),
22
+ ),
23
+ }
24
+ }
25
+
26
+ getMSA() {
27
+ return this.MSA
28
+ }
29
+
30
+ getRowData() {
31
+ return undefined
32
+ }
33
+
34
+ getNames() {
35
+ return Object.keys(this.MSA.seqdata)
36
+ }
37
+
38
+ getRow(name: string) {
39
+ return this.MSA?.seqdata[name]?.split('')
40
+ }
41
+
42
+ getWidth() {
43
+ const name = Object.keys(this.MSA?.seqdata)[0]
44
+ return this.getRow(name).length
45
+ }
46
+
47
+ getStructures() {
48
+ return {}
49
+ }
50
+
51
+ get alignmentNames() {
52
+ return []
53
+ }
54
+
55
+ getHeader() {
56
+ return {}
57
+ }
58
+
59
+ getTree(): NodeWithIds {
60
+ return {
61
+ id: 'root',
62
+ name: 'root',
63
+ noTree: true,
64
+ branchset: this.getNames().map(name => ({
65
+ id: name,
66
+ branchset: [],
67
+ name,
68
+ })),
69
+ }
70
+ }
71
+
72
+ get seqConsensus() {
73
+ return undefined
74
+ }
75
+ get secondaryStructureConsensus() {
76
+ return undefined
77
+ }
78
+
79
+ get tracks() {
80
+ return []
81
+ }
82
+ }
@@ -0,0 +1,137 @@
1
+ import Stockholm from 'stockholm-js'
2
+ import parseNewick from '../parseNewick'
3
+
4
+ import { NodeWithIds, generateNodeIds } from '../util'
5
+ interface StockholmEntry {
6
+ gf: {
7
+ DE?: string[]
8
+ NH?: string[]
9
+ }
10
+ gs: {
11
+ AC: Record<string, string>
12
+ DR: Record<string, string>
13
+ }
14
+ gc?: {
15
+ SS_cons?: string
16
+ seq_cons?: string
17
+ }
18
+ seqdata: Record<string, string>
19
+ }
20
+
21
+ export default class StockholmMSA {
22
+ private data: StockholmEntry[]
23
+ private MSA: StockholmEntry
24
+
25
+ constructor(text: string, currentAlignment: number) {
26
+ const res = Stockholm.parseAll(text)
27
+ this.data = res
28
+ this.MSA = res[currentAlignment]
29
+ }
30
+
31
+ getMSA() {
32
+ return this.MSA
33
+ }
34
+
35
+ getRow(name: string) {
36
+ return this.MSA?.seqdata[name]?.split('')
37
+ }
38
+
39
+ getWidth() {
40
+ const name = Object.keys(this.MSA?.seqdata)[0]
41
+ return this.getRow(name).length
42
+ }
43
+
44
+ get alignmentNames() {
45
+ return this.data.map((aln, idx) => aln.gf.DE?.[0] || `Alignment ${idx + 1}`)
46
+ }
47
+
48
+ getHeader() {
49
+ return {
50
+ General: this.MSA.gf,
51
+ Accessions: this.MSA.gs?.AC,
52
+ Dbxref: this.MSA.gs?.DR,
53
+ }
54
+ }
55
+
56
+ getRowData(rowName: string) {
57
+ return {
58
+ name: rowName,
59
+ accession: this.MSA.gs?.AC?.[rowName],
60
+ dbxref: this.MSA.gs?.DR?.[rowName],
61
+ }
62
+ }
63
+
64
+ getNames() {
65
+ return Object.keys(this.MSA.seqdata)
66
+ }
67
+
68
+ getSeqCoords() {}
69
+
70
+ getStructures() {
71
+ const pdbRegex = /PDB; +(\S+) +(\S); ([0-9]+)-([0-9]+)/
72
+ const ent = this.MSA
73
+ const args = Object.entries(ent.gs?.DR || {})
74
+ .map(([id, dr]) => [id, pdbRegex.exec(dr)] as const)
75
+ .filter((item): item is [string, RegExpExecArray] => !!item[1])
76
+ .map(([id, match]) => {
77
+ const pdb = match[1].toLowerCase()
78
+ const chain = match[2]
79
+ const startPos = +match[3]
80
+ const endPos = +match[4]
81
+ return { id, pdb, chain, startPos, endPos }
82
+ })
83
+
84
+ const ret = {} as Record<string, Omit<(typeof args)[0], 'id'>[]>
85
+ for (const entry of args) {
86
+ const { id, ...rest } = entry
87
+ if (!ret[id]) {
88
+ ret[id] = []
89
+ }
90
+ ret[id].push(rest)
91
+ }
92
+ return ret
93
+ }
94
+
95
+ getTree(): NodeWithIds {
96
+ const tree = this.MSA?.gf?.NH?.[0]
97
+ return tree
98
+ ? generateNodeIds(parseNewick(tree))
99
+ : {
100
+ id: 'root',
101
+ name: 'root',
102
+ noTree: true,
103
+ branchset: this.getNames().map(name => ({
104
+ id: name,
105
+ branchset: [],
106
+ name,
107
+ })),
108
+ }
109
+ }
110
+
111
+ get seqConsensus() {
112
+ return this.MSA.gc?.seq_cons
113
+ }
114
+ get secondaryStructureConsensus() {
115
+ return this.MSA.gc?.SS_cons
116
+ }
117
+
118
+ get tracks() {
119
+ return [
120
+ {
121
+ id: 'seqConsensus',
122
+ name: 'Sequence consensus',
123
+ data: this.seqConsensus,
124
+ customColorScheme: {},
125
+ },
126
+ {
127
+ id: 'secondaryStruct',
128
+ name: 'Secondary-structure',
129
+ data: this.secondaryStructureConsensus,
130
+ customColorScheme: {
131
+ '>': 'pink',
132
+ '<': 'lightblue',
133
+ },
134
+ },
135
+ ]
136
+ }
137
+ }
package/src/util.ts ADDED
@@ -0,0 +1,142 @@
1
+ import Color from 'color'
2
+ import { HierarchyNode } from 'd3-hierarchy'
3
+ import { max } from 'd3-array'
4
+ import { Theme } from '@mui/material'
5
+
6
+ export function transform<T>(
7
+ obj: Record<string, T>,
8
+ cb: (arg0: [string, T]) => [string, T],
9
+ ) {
10
+ return Object.fromEntries(Object.entries(obj).map(cb))
11
+ }
12
+
13
+ interface Node {
14
+ branchset?: Node[]
15
+ name?: string
16
+ [key: string]: unknown
17
+ }
18
+
19
+ export interface NodeWithIds {
20
+ id: string
21
+ name: string
22
+ branchset: NodeWithIds[]
23
+ length?: number
24
+ noTree?: boolean
25
+ }
26
+
27
+ export interface NodeWithIdsAndLength {
28
+ id: string
29
+ name: string
30
+ branchset: NodeWithIdsAndLength[]
31
+ noTree?: boolean
32
+ length: number
33
+ }
34
+
35
+ export function generateNodeIds(
36
+ tree: Node,
37
+ parent = 'node',
38
+ depth = 0,
39
+ ): NodeWithIds {
40
+ const id = `${parent}-${depth}`
41
+
42
+ return {
43
+ ...tree,
44
+ id,
45
+ name: tree.name || id,
46
+ branchset:
47
+ tree.branchset?.map((b, i) =>
48
+ generateNodeIds(b, `${id}-${i}`, depth + 1),
49
+ ) || [],
50
+ }
51
+ }
52
+
53
+ export function colorContrast(
54
+ colorScheme: Record<string, string>,
55
+ theme: Theme,
56
+ ) {
57
+ return transform(colorScheme, ([letter, color]) => [
58
+ letter,
59
+ theme.palette.getContrastText(Color(color).hex()),
60
+ ])
61
+ }
62
+
63
+ export function parseGFF(str?: string) {
64
+ return str
65
+ ?.split('\n')
66
+ .map(f => f.trim())
67
+ .filter(f => !!f && !f.startsWith('#'))
68
+ .map(f => {
69
+ const [seq_id, source, type, start, end, score, strand, phase, col9] =
70
+ f.split('\t')
71
+
72
+ return {
73
+ seq_id,
74
+ source,
75
+ type,
76
+ start: +start,
77
+ end: +end,
78
+ score: +score,
79
+ strand,
80
+ phase,
81
+ ...Object.fromEntries(
82
+ col9
83
+ .split(';')
84
+ .map(f => f.trim())
85
+ .filter(f => !!f)
86
+ .map(f => f.split('='))
87
+ .map(([key, val]) => [
88
+ key.trim(),
89
+ decodeURIComponent(val).trim().split(',').join(' '),
90
+ ]),
91
+ ),
92
+ }
93
+ })
94
+ }
95
+
96
+ export function skipBlanks(blanks: number[], arg: string | string[]) {
97
+ let s = ''
98
+ let b = 0
99
+ for (let j = 0; j < arg.length; j++) {
100
+ if (j === blanks[b]) {
101
+ b++
102
+ } else {
103
+ s += arg[j]
104
+ }
105
+ }
106
+ return s
107
+ }
108
+
109
+ export function setBrLength(
110
+ d: HierarchyNode<NodeWithIds>,
111
+ y0: number,
112
+ k: number,
113
+ ) {
114
+ // @ts-expect-error
115
+ d.len = (y0 += Math.max(d.data.length || 0, 0)) * k
116
+ d.children?.forEach(d => {
117
+ setBrLength(d, y0, k)
118
+ })
119
+ }
120
+
121
+ export function maxLength(d: HierarchyNode<NodeWithIds>): number {
122
+ return (
123
+ (d.data.length || 1) + (d.children ? max(d.children, maxLength) || 0 : 0)
124
+ )
125
+ }
126
+
127
+ // Collapse the node and all it's children, from
128
+ // https://bl.ocks.org/d3noob/43a860bc0024792f8803bba8ca0d5ecd
129
+ export function collapse(d: HierarchyNode<NodeWithIds>) {
130
+ if (d.children) {
131
+ // @ts-expect-error
132
+ d._children = d.children
133
+ // @ts-expect-error
134
+ d._children.forEach(collapse)
135
+ // @ts-expect-error
136
+ d.children = null
137
+ }
138
+ }
139
+
140
+ export function clamp(min: number, num: number, max: number) {
141
+ return Math.min(Math.max(num, min), max)
142
+ }
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const version = '2.1.0'
@@ -1,16 +0,0 @@
1
- declare const _default: {
2
- [k: string]: {
3
- [key: string]: string;
4
- };
5
- };
6
- export default _default;
7
- export declare function getClustalXColor(stats: {
8
- [key: string]: number;
9
- }, model: {
10
- columns: Record<string, string>;
11
- }, row: number, col: number): "rgb(128,179,230)" | "#d88" | "rgb(192, 72, 192)" | "rgb(204, 77, 204)" | "#8f8" | "rgb(26,204,26)" | "rgb(240, 128, 128)" | "rgb(240, 144, 72)" | "rgb(204, 204, 0)" | "rgb(26, 179, 179)" | undefined;
12
- export declare function getPercentIdentityColor(stats: {
13
- [key: string]: number;
14
- }, model: {
15
- columns: Record<string, string>;
16
- }, row: number, col: number): string | undefined;