@apollo-annotation/shared 0.3.6 → 0.3.7
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.
- package/dist/Changes/AddAssemblyAliasesChange.d.ts +16 -0
- package/dist/Changes/AddAssemblyAliasesChange.js +50 -0
- package/dist/Changes/AddAssemblyAliasesChange.js.map +1 -0
- package/dist/Changes/AddFeatureChange.d.ts +1 -0
- package/dist/Changes/AddFeatureChange.js +5 -25
- package/dist/Changes/AddFeatureChange.js.map +1 -1
- package/dist/Changes/DeleteFeatureChange.d.ts +9 -8
- package/dist/Changes/DeleteFeatureChange.js +37 -32
- package/dist/Changes/DeleteFeatureChange.js.map +1 -1
- package/dist/Changes/FeatureAttributeChange.d.ts +2 -1
- package/dist/Changes/FeatureAttributeChange.js +14 -6
- package/dist/Changes/FeatureAttributeChange.js.map +1 -1
- package/dist/Changes/ImportJBrowseConfigChange.d.ts +3 -0
- package/dist/Changes/ImportJBrowseConfigChange.js +17 -13
- package/dist/Changes/ImportJBrowseConfigChange.js.map +1 -1
- package/dist/Changes/LocationEndChange.js +40 -37
- package/dist/Changes/LocationEndChange.js.map +1 -1
- package/dist/Changes/LocationStartChange.js +40 -37
- package/dist/Changes/LocationStartChange.js.map +1 -1
- package/dist/Changes/MergeExonsChange.d.ts +30 -0
- package/dist/Changes/MergeExonsChange.js +130 -0
- package/dist/Changes/MergeExonsChange.js.map +1 -0
- package/dist/Changes/MergeTranscriptsChange.d.ts +36 -0
- package/dist/Changes/MergeTranscriptsChange.js +246 -0
- package/dist/Changes/MergeTranscriptsChange.js.map +1 -0
- package/dist/Changes/SplitExonChange.d.ts +33 -0
- package/dist/Changes/SplitExonChange.js +142 -0
- package/dist/Changes/SplitExonChange.js.map +1 -0
- package/dist/Changes/UndoMergeExonsChange.d.ts +27 -0
- package/dist/Changes/UndoMergeExonsChange.js +104 -0
- package/dist/Changes/UndoMergeExonsChange.js.map +1 -0
- package/dist/Changes/UndoMergeTranscriptsChange.d.ts +27 -0
- package/dist/Changes/UndoMergeTranscriptsChange.js +104 -0
- package/dist/Changes/UndoMergeTranscriptsChange.js.map +1 -0
- package/dist/Changes/UndoSplitExonChange.d.ts +32 -0
- package/dist/Changes/UndoSplitExonChange.js +111 -0
- package/dist/Changes/UndoSplitExonChange.js.map +1 -0
- package/dist/Changes/index.d.ts +21 -0
- package/dist/Changes/index.js +21 -0
- package/dist/Changes/index.js.map +1 -1
- package/dist/GFF3/annotationFeatureToGFF3.js +7 -1
- package/dist/GFF3/annotationFeatureToGFF3.js.map +1 -1
- package/dist/Validations/ParentChildValidation.js +3 -1
- package/dist/Validations/ParentChildValidation.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util.d.ts +2 -0
- package/dist/util.js +13 -0
- package/dist/util.js.map +1 -1
- package/package.json +4 -4
- package/src/Changes/AddAssemblyAliasesChange.ts +69 -0
- package/src/Changes/AddFeatureChange.ts +5 -29
- package/src/Changes/DeleteFeatureChange.ts +42 -36
- package/src/Changes/FeatureAttributeChange.ts +16 -7
- package/src/Changes/ImportJBrowseConfigChange.ts +33 -18
- package/src/Changes/LocationEndChange.ts +41 -50
- package/src/Changes/LocationStartChange.ts +41 -50
- package/src/Changes/MergeExonsChange.ts +185 -0
- package/src/Changes/MergeTranscriptsChange.ts +379 -0
- package/src/Changes/SplitExonChange.ts +249 -0
- package/src/Changes/UndoMergeExonsChange.ts +149 -0
- package/src/Changes/UndoMergeTranscriptsChange.ts +153 -0
- package/src/Changes/UndoSplitExonChange.ts +174 -0
- package/src/Changes/index.ts +21 -0
- package/src/GFF3/annotationFeatureToGFF3.ts +7 -1
- package/src/Validations/ParentChildValidation.ts +3 -2
- package/src/util.ts +16 -0
package/dist/util.d.ts
CHANGED
package/dist/util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.splitStringIntoChunks = splitStringIntoChunks;
|
|
4
|
+
exports.getPrintableId = getPrintableId;
|
|
4
5
|
function splitStringIntoChunks(input, chunkSize) {
|
|
5
6
|
const chunks = [];
|
|
6
7
|
for (let i = 0; i < input.length; i += chunkSize) {
|
|
@@ -9,4 +10,16 @@ function splitStringIntoChunks(input, chunkSize) {
|
|
|
9
10
|
}
|
|
10
11
|
return chunks;
|
|
11
12
|
}
|
|
13
|
+
function getPrintableId(feature) {
|
|
14
|
+
const ff = feature;
|
|
15
|
+
const gff_id = ff.attributes.get('gff_id')?.join(',');
|
|
16
|
+
if (gff_id) {
|
|
17
|
+
return `ID=${gff_id} (_id: ${feature._id.toString()})`;
|
|
18
|
+
}
|
|
19
|
+
const gff_name = ff.attributes.get('gff_name')?.join(',');
|
|
20
|
+
if (gff_name) {
|
|
21
|
+
return `Name=${gff_name} (_id: ${feature._id.toString()})`;
|
|
22
|
+
}
|
|
23
|
+
return `_id: ${feature._id.toString()}`;
|
|
24
|
+
}
|
|
12
25
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAGA,sDAUC;AAED,wCAWC;AAvBD,SAAgB,qBAAqB,CACnC,KAAa,EACb,SAAiB;IAEjB,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QACjD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAA;QAC3C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAgB,cAAc,CAAC,OAAgB;IAC7C,MAAM,EAAE,GAAG,OAAuC,CAAA;IAClD,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACrD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,MAAM,UAAU,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAA;IACxD,CAAC;IACD,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACzD,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,QAAQ,UAAU,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAA;IAC5D,CAAC;IACD,OAAO,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAA;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollo-annotation/shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "yarn clean && tsc --build",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"test:ci": "NODE_V8_COVERAGE=./coverage glob -c \"tsx --test --test-reporter spec --experimental-test-coverage \" \"**/*.test.ts\""
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@apollo-annotation/common": "^0.3.
|
|
14
|
-
"@apollo-annotation/mst": "^0.3.
|
|
15
|
-
"@apollo-annotation/schemas": "^0.3.
|
|
13
|
+
"@apollo-annotation/common": "^0.3.7",
|
|
14
|
+
"@apollo-annotation/mst": "^0.3.7",
|
|
15
|
+
"@apollo-annotation/schemas": "^0.3.7",
|
|
16
16
|
"@gmod/gff": "1.2.0",
|
|
17
17
|
"@gmod/indexedfasta": "^2.0.4",
|
|
18
18
|
"@jbrowse/core": "^3.0.1",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssemblySpecificChange,
|
|
3
|
+
type Change,
|
|
4
|
+
type ChangeOptions,
|
|
5
|
+
type ClientDataStore,
|
|
6
|
+
type LocalGFF3DataStore,
|
|
7
|
+
type SerializedAssemblySpecificChange,
|
|
8
|
+
type ServerDataStore,
|
|
9
|
+
} from '@apollo-annotation/common'
|
|
10
|
+
import { getSession } from '@jbrowse/core/util'
|
|
11
|
+
|
|
12
|
+
export interface SerializedAssemblyAliasesChange
|
|
13
|
+
extends SerializedAssemblySpecificChange {
|
|
14
|
+
typeName: 'AddAssemblyAliasesChange'
|
|
15
|
+
aliases: string[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class AddAssemblyAliasesChange extends AssemblySpecificChange {
|
|
19
|
+
typeName = 'AddAssemblyAliasesChange' as const
|
|
20
|
+
aliases: string[]
|
|
21
|
+
|
|
22
|
+
constructor(json: SerializedAssemblyAliasesChange, options?: ChangeOptions) {
|
|
23
|
+
super(json, options)
|
|
24
|
+
this.aliases = json.aliases
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
executeOnClient(clientDataStore: ClientDataStore) {
|
|
28
|
+
const { assemblyManager } = getSession(clientDataStore)
|
|
29
|
+
const assembly = assemblyManager.get(this.assembly)
|
|
30
|
+
if (!assembly) {
|
|
31
|
+
throw new Error(`assembly ${this.assembly} not found`)
|
|
32
|
+
}
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
34
|
+
assembly.configuration.aliases.set(this.aliases)
|
|
35
|
+
return Promise.resolve()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getInverse(): Change {
|
|
39
|
+
throw new Error('Method not implemented.')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
toJSON(): SerializedAssemblyAliasesChange {
|
|
43
|
+
const { assembly, aliases, typeName } = this
|
|
44
|
+
return { assembly, typeName, aliases }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async executeOnServer(backend: ServerDataStore) {
|
|
48
|
+
const { assemblyModel } = backend
|
|
49
|
+
const { assembly, logger, aliases } = this
|
|
50
|
+
logger.debug?.(
|
|
51
|
+
`Updating assembly aliases for assembly: ${assembly}, aliases: ${JSON.stringify(aliases)}`,
|
|
52
|
+
)
|
|
53
|
+
const asm = await assemblyModel.findById(assembly)
|
|
54
|
+
if (!asm) {
|
|
55
|
+
throw new Error(`Assembly with ID ${assembly} not found`)
|
|
56
|
+
}
|
|
57
|
+
asm.aliases = aliases
|
|
58
|
+
await asm.save()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
executeOnLocalGFF3(_backend: LocalGFF3DataStore): Promise<unknown> {
|
|
62
|
+
throw new Error('Method not implemented.')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
|
|
66
|
+
get notification(): string {
|
|
67
|
+
return 'Assembly aliases have been added.'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
2
|
/* eslint-disable @typescript-eslint/require-await */
|
|
4
3
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
5
4
|
import {
|
|
@@ -46,6 +45,10 @@ export class AddFeatureChange extends FeatureChange {
|
|
|
46
45
|
super(json, options)
|
|
47
46
|
this.changes = 'changes' in json ? json.changes : [json]
|
|
48
47
|
}
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
|
|
49
|
+
get notification() {
|
|
50
|
+
return 'Feature added successfully'
|
|
51
|
+
}
|
|
49
52
|
|
|
50
53
|
toJSON(): SerializedAddFeatureChange {
|
|
51
54
|
const { assembly, changedIds, changes, typeName } = this
|
|
@@ -133,34 +136,7 @@ export class AddFeatureChange extends FeatureChange {
|
|
|
133
136
|
`Could not find feature with ID "${parentFeatureId}" in feature "${topLevelFeature._id}"`,
|
|
134
137
|
)
|
|
135
138
|
}
|
|
136
|
-
|
|
137
|
-
parentFeature.children = new Map()
|
|
138
|
-
}
|
|
139
|
-
if (!parentFeature.attributes?._id) {
|
|
140
|
-
let { attributes } = parentFeature
|
|
141
|
-
if (!attributes) {
|
|
142
|
-
attributes = {}
|
|
143
|
-
}
|
|
144
|
-
attributes = {
|
|
145
|
-
_id: [parentFeature._id.toString()],
|
|
146
|
-
// eslint-disable-next-line unicorn/prefer-structured-clone
|
|
147
|
-
...JSON.parse(JSON.stringify(attributes)),
|
|
148
|
-
}
|
|
149
|
-
parentFeature.attributes = attributes
|
|
150
|
-
}
|
|
151
|
-
parentFeature.children.set(_id, {
|
|
152
|
-
allIds: [],
|
|
153
|
-
...addedFeature,
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
155
|
-
// @ts-expect-error
|
|
156
|
-
_id,
|
|
157
|
-
})
|
|
158
|
-
// Child features should be sorted for click and drag of gene glyphs to work properly
|
|
159
|
-
parentFeature.children = new Map(
|
|
160
|
-
[...parentFeature.children.entries()].sort(
|
|
161
|
-
(a, b) => a[1].min - b[1].min,
|
|
162
|
-
),
|
|
163
|
-
)
|
|
139
|
+
this.addChild(parentFeature, addedFeature)
|
|
164
140
|
const childIds = this.getChildFeatureIds(addedFeature)
|
|
165
141
|
topLevelFeature.allIds.push(_id, ...childIds)
|
|
166
142
|
await topLevelFeature.save()
|
|
@@ -44,6 +44,10 @@ export class DeleteFeatureChange extends FeatureChange {
|
|
|
44
44
|
super(json, options)
|
|
45
45
|
this.changes = 'changes' in json ? json.changes : [json]
|
|
46
46
|
}
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
|
|
48
|
+
get notification() {
|
|
49
|
+
return 'Feature deleted successfully'
|
|
50
|
+
}
|
|
47
51
|
|
|
48
52
|
toJSON(): SerializedDeleteFeatureChange {
|
|
49
53
|
const { assembly, changedIds, changes, typeName } = this
|
|
@@ -92,9 +96,10 @@ export class DeleteFeatureChange extends FeatureChange {
|
|
|
92
96
|
continue
|
|
93
97
|
}
|
|
94
98
|
|
|
95
|
-
const deletedIds =
|
|
99
|
+
const deletedIds = findAndDeleteChildFeature(
|
|
96
100
|
featureDoc,
|
|
97
101
|
deletedFeature._id,
|
|
102
|
+
this,
|
|
98
103
|
)
|
|
99
104
|
deletedIds.push(deletedFeature._id)
|
|
100
105
|
featureDoc.allIds = featureDoc.allIds.filter(
|
|
@@ -115,38 +120,6 @@ export class DeleteFeatureChange extends FeatureChange {
|
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
/**
|
|
119
|
-
* Delete feature's subfeatures that match an ID and return the IDs of any
|
|
120
|
-
* sub-subfeatures that were deleted
|
|
121
|
-
* @param feature -
|
|
122
|
-
* @param featureIdToDelete -
|
|
123
|
-
* @returns - list of deleted feature IDs
|
|
124
|
-
*/
|
|
125
|
-
findAndDeleteChildFeature(
|
|
126
|
-
feature: Feature,
|
|
127
|
-
featureIdToDelete: string,
|
|
128
|
-
): string[] {
|
|
129
|
-
if (!feature.children) {
|
|
130
|
-
throw new Error(`Feature ${feature._id} has no children`)
|
|
131
|
-
}
|
|
132
|
-
const { _id, children } = feature
|
|
133
|
-
const child = children.get(featureIdToDelete)
|
|
134
|
-
if (child) {
|
|
135
|
-
const deletedIds = this.getChildFeatureIds(child)
|
|
136
|
-
children.delete(featureIdToDelete)
|
|
137
|
-
return deletedIds
|
|
138
|
-
}
|
|
139
|
-
for (const [, childFeature] of children) {
|
|
140
|
-
try {
|
|
141
|
-
return this.findAndDeleteChildFeature(childFeature, featureIdToDelete)
|
|
142
|
-
} catch {
|
|
143
|
-
// pass
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
throw new Error(`Feature "${featureIdToDelete}" not found in ${_id}`)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
123
|
async executeOnLocalGFF3(_backend: LocalGFF3DataStore) {
|
|
151
124
|
throw new Error('executeOnLocalGFF3 not implemented')
|
|
152
125
|
}
|
|
@@ -176,9 +149,9 @@ export class DeleteFeatureChange extends FeatureChange {
|
|
|
176
149
|
const inverseChangedIds = [...changedIds].reverse()
|
|
177
150
|
const inverseChanges = [...changes]
|
|
178
151
|
.reverse()
|
|
179
|
-
.map((
|
|
180
|
-
addedFeature:
|
|
181
|
-
parentFeatureId:
|
|
152
|
+
.map((deleteFeatureChange) => ({
|
|
153
|
+
addedFeature: deleteFeatureChange.deletedFeature,
|
|
154
|
+
parentFeatureId: deleteFeatureChange.parentFeatureId,
|
|
182
155
|
}))
|
|
183
156
|
logger.debug?.(`INVERSE CHANGE '${JSON.stringify(inverseChanges)}'`)
|
|
184
157
|
return new AddFeatureChange(
|
|
@@ -193,6 +166,39 @@ export class DeleteFeatureChange extends FeatureChange {
|
|
|
193
166
|
}
|
|
194
167
|
}
|
|
195
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Delete feature's subfeatures that match an ID and return the IDs of any
|
|
171
|
+
* sub-subfeatures that were deleted
|
|
172
|
+
* @param feature -
|
|
173
|
+
* @param featureIdToDelete -
|
|
174
|
+
* @returns - list of deleted feature IDs
|
|
175
|
+
*/
|
|
176
|
+
export function findAndDeleteChildFeature(
|
|
177
|
+
feature: Feature,
|
|
178
|
+
featureIdToDelete: string,
|
|
179
|
+
change: FeatureChange,
|
|
180
|
+
): string[] {
|
|
181
|
+
if (!feature.children) {
|
|
182
|
+
throw new Error(`Feature ${feature._id} has no children`)
|
|
183
|
+
}
|
|
184
|
+
const { _id, children } = feature
|
|
185
|
+
const child = children.get(featureIdToDelete)
|
|
186
|
+
if (child) {
|
|
187
|
+
const deletedIds = change.getChildFeatureIds(child)
|
|
188
|
+
children.delete(featureIdToDelete)
|
|
189
|
+
return deletedIds
|
|
190
|
+
}
|
|
191
|
+
for (const [, childFeature] of children) {
|
|
192
|
+
try {
|
|
193
|
+
return findAndDeleteChildFeature(childFeature, featureIdToDelete, change)
|
|
194
|
+
} catch {
|
|
195
|
+
// pass
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
throw new Error(`Feature "${featureIdToDelete}" not found in ${_id}`)
|
|
200
|
+
}
|
|
201
|
+
|
|
196
202
|
export function isDeleteFeatureChange(
|
|
197
203
|
change: unknown,
|
|
198
204
|
): change is DeleteFeatureChange {
|
|
@@ -17,7 +17,8 @@ interface SerializedFeatureAttributeChangeBase extends SerializedFeatureChange {
|
|
|
17
17
|
|
|
18
18
|
export interface FeatureAttributeChangeDetails {
|
|
19
19
|
featureId: string
|
|
20
|
-
|
|
20
|
+
oldAttributes: Record<string, string[]>
|
|
21
|
+
newAttributes: Record<string, string[]>
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
interface SerializedFeatureAttributeChangeSingle
|
|
@@ -45,8 +46,15 @@ export class FeatureAttributeChange extends FeatureChange {
|
|
|
45
46
|
toJSON(): SerializedFeatureAttributeChange {
|
|
46
47
|
const { assembly, changedIds, changes, typeName } = this
|
|
47
48
|
if (changes.length === 1) {
|
|
48
|
-
const [{
|
|
49
|
-
return {
|
|
49
|
+
const [{ oldAttributes, newAttributes, featureId }] = changes
|
|
50
|
+
return {
|
|
51
|
+
typeName,
|
|
52
|
+
changedIds,
|
|
53
|
+
assembly,
|
|
54
|
+
featureId,
|
|
55
|
+
oldAttributes,
|
|
56
|
+
newAttributes,
|
|
57
|
+
}
|
|
50
58
|
}
|
|
51
59
|
return { typeName, changedIds, assembly, changes }
|
|
52
60
|
}
|
|
@@ -94,9 +102,9 @@ export class FeatureAttributeChange extends FeatureChange {
|
|
|
94
102
|
|
|
95
103
|
// Let's update objects
|
|
96
104
|
for (const [idx, change] of changes.entries()) {
|
|
97
|
-
const {
|
|
105
|
+
const { newAttributes } = change
|
|
98
106
|
const { feature, topLevelFeature } = featuresForChanges[idx]
|
|
99
|
-
feature.attributes =
|
|
107
|
+
feature.attributes = newAttributes
|
|
100
108
|
if (topLevelFeature._id.equals(feature._id)) {
|
|
101
109
|
topLevelFeature.markModified('attributes') // Mark as modified. Without this save() -method is not updating data in database
|
|
102
110
|
} else {
|
|
@@ -131,7 +139,7 @@ export class FeatureAttributeChange extends FeatureChange {
|
|
|
131
139
|
throw new Error(`Could not find feature with identifier "${changedId}"`)
|
|
132
140
|
}
|
|
133
141
|
feature.setAttributes(
|
|
134
|
-
new Map(Object.entries(this.changes[idx].
|
|
142
|
+
new Map(Object.entries(this.changes[idx].newAttributes)),
|
|
135
143
|
)
|
|
136
144
|
}
|
|
137
145
|
}
|
|
@@ -141,7 +149,8 @@ export class FeatureAttributeChange extends FeatureChange {
|
|
|
141
149
|
const inverseChangedIds = [...changedIds].reverse()
|
|
142
150
|
const inverseChanges = [...changes].reverse().map((oneChange) => ({
|
|
143
151
|
featureId: oneChange.featureId,
|
|
144
|
-
|
|
152
|
+
oldAttributes: oneChange.newAttributes,
|
|
153
|
+
newAttributes: oneChange.oldAttributes,
|
|
145
154
|
}))
|
|
146
155
|
return new FeatureAttributeChange(
|
|
147
156
|
{
|
|
@@ -26,6 +26,9 @@ interface JBrowseInternetAccount {
|
|
|
26
26
|
|
|
27
27
|
export interface JBrowseConfig {
|
|
28
28
|
assemblies?: JBrowseAssembly[]
|
|
29
|
+
configuration?: {
|
|
30
|
+
ApolloPlugin?: Record<string, unknown>
|
|
31
|
+
}
|
|
29
32
|
tracks?: JBrowseTrack[]
|
|
30
33
|
plugins?: JBrowsePlugin[]
|
|
31
34
|
internetAccounts?: JBrowseInternetAccount[]
|
|
@@ -39,28 +42,40 @@ export interface SerializedImportJBrowseConfigChange {
|
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
export function filterJBrowseConfig(config: JBrowseConfig): JBrowseConfig {
|
|
42
|
-
const {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
const {
|
|
46
|
+
__v,
|
|
47
|
+
_id,
|
|
48
|
+
assemblies,
|
|
49
|
+
configuration,
|
|
50
|
+
internetAccounts,
|
|
51
|
+
plugins,
|
|
52
|
+
tracks,
|
|
53
|
+
...rest
|
|
54
|
+
} = config
|
|
55
|
+
// Need to make sure that configuration.ApolloPlugin.hasRole isn't set
|
|
52
56
|
const filteredConfig = rest as JBrowseConfig
|
|
53
|
-
if (
|
|
54
|
-
filteredConfig.assemblies =
|
|
57
|
+
if (assemblies) {
|
|
58
|
+
filteredConfig.assemblies = assemblies.filter(
|
|
59
|
+
(a) => a.sequence.adapter.type !== 'ApolloSequenceAdapter',
|
|
60
|
+
)
|
|
55
61
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
62
|
+
if (configuration?.ApolloPlugin?.hasRole) {
|
|
63
|
+
const { hasRole, ...apolloPluginRest } = configuration.ApolloPlugin
|
|
64
|
+
filteredConfig.configuration = {
|
|
65
|
+
...configuration,
|
|
66
|
+
ApolloPlugin: apolloPluginRest,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (internetAccounts) {
|
|
70
|
+
filteredConfig.internetAccounts = internetAccounts.filter(
|
|
71
|
+
(i) => i.type !== 'ApolloInternetAccount',
|
|
72
|
+
)
|
|
58
73
|
}
|
|
59
|
-
if (
|
|
60
|
-
filteredConfig.plugins =
|
|
74
|
+
if (plugins) {
|
|
75
|
+
filteredConfig.plugins = plugins.filter((p) => p.name !== 'Apollo')
|
|
61
76
|
}
|
|
62
|
-
if (
|
|
63
|
-
filteredConfig.
|
|
77
|
+
if (tracks) {
|
|
78
|
+
filteredConfig.trackss = tracks.filter((t) => t.type !== 'ApolloTrack')
|
|
64
79
|
}
|
|
65
80
|
return filteredConfig
|
|
66
81
|
}
|
|
@@ -60,19 +60,32 @@ export class LocationEndChange extends FeatureChange {
|
|
|
60
60
|
async executeOnServer(backend: ServerDataStore) {
|
|
61
61
|
const { featureModel, session } = backend
|
|
62
62
|
const { changes, logger } = this
|
|
63
|
-
const featuresForChanges: {
|
|
64
|
-
feature: Feature
|
|
65
|
-
topLevelFeature: FeatureDocument
|
|
66
|
-
}[] = []
|
|
67
63
|
// Let's first check that all features are found and those old values match with expected ones. We do this just to be sure that all changes can be done.
|
|
64
|
+
const topLevelFeatures: FeatureDocument[] = []
|
|
68
65
|
for (const change of changes) {
|
|
69
|
-
const { featureId, oldEnd } = change
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.
|
|
66
|
+
const { featureId, oldEnd, newEnd } = change
|
|
67
|
+
|
|
68
|
+
// See if we already have top-level feature for this feature
|
|
69
|
+
let topLevelFeature: FeatureDocument | undefined | null
|
|
70
|
+
let feature: Feature | undefined | null
|
|
71
|
+
for (const tlv of topLevelFeatures) {
|
|
72
|
+
const childFeature = this.getFeatureFromId(tlv, featureId)
|
|
73
|
+
if (childFeature) {
|
|
74
|
+
topLevelFeature = tlv
|
|
75
|
+
feature = childFeature
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!topLevelFeature) {
|
|
80
|
+
// Don't already have top-level feature, so let's query it
|
|
81
|
+
topLevelFeature = await featureModel
|
|
82
|
+
.findOne({ allIds: featureId })
|
|
83
|
+
.session(session)
|
|
84
|
+
.exec()
|
|
85
|
+
if (topLevelFeature) {
|
|
86
|
+
topLevelFeatures.push(topLevelFeature)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
76
89
|
|
|
77
90
|
if (!topLevelFeature) {
|
|
78
91
|
const errMsg = `*** ERROR: The following featureId was not found in database ='${featureId}'`
|
|
@@ -84,57 +97,34 @@ export class LocationEndChange extends FeatureChange {
|
|
|
84
97
|
`*** TOP level feature found: ${JSON.stringify(topLevelFeature)}`,
|
|
85
98
|
)
|
|
86
99
|
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
if (!feature) {
|
|
101
|
+
feature = this.getFeatureFromId(topLevelFeature, featureId)
|
|
102
|
+
}
|
|
103
|
+
if (!feature) {
|
|
89
104
|
const errMsg = 'ERROR when searching feature by featureId'
|
|
90
105
|
logger.error(errMsg)
|
|
91
106
|
throw new Error(errMsg)
|
|
92
107
|
}
|
|
93
|
-
logger.debug?.(`*** Found feature: ${JSON.stringify(
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
for (const [, childFeature] of foundFeature.children) {
|
|
99
|
-
if (childFeature.max === oldEnd) {
|
|
100
|
-
logger.debug?.(
|
|
101
|
-
`*************** UPDATE CHILD FEATURE ID= ${featureId}, CHILD: ${JSON.stringify(
|
|
102
|
-
childFeature,
|
|
103
|
-
)}`,
|
|
104
|
-
)
|
|
105
|
-
featuresForChanges.push({
|
|
106
|
-
feature: childFeature,
|
|
107
|
-
topLevelFeature,
|
|
108
|
-
})
|
|
109
|
-
break
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
108
|
+
logger.debug?.(`*** Found feature: ${JSON.stringify(feature)}`)
|
|
109
|
+
if (feature.max !== oldEnd) {
|
|
110
|
+
const errMsg = 'Expected previous max does not match'
|
|
111
|
+
logger.error(errMsg)
|
|
112
|
+
throw new Error(errMsg)
|
|
113
113
|
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Let's update objects.
|
|
117
|
-
for (const [idx, change] of changes.entries()) {
|
|
118
|
-
const { newEnd } = change
|
|
119
|
-
const { feature, topLevelFeature } = featuresForChanges[idx]
|
|
120
114
|
feature.max = newEnd
|
|
121
115
|
if (topLevelFeature._id.equals(feature._id)) {
|
|
122
116
|
topLevelFeature.markModified('end') // Mark as modified. Without this save() -method is not updating data in database
|
|
123
117
|
} else {
|
|
124
118
|
topLevelFeature.markModified('children') // Mark as modified. Without this save() -method is not updating data in database
|
|
125
119
|
}
|
|
126
|
-
|
|
120
|
+
}
|
|
121
|
+
for (const tlv of topLevelFeatures) {
|
|
127
122
|
try {
|
|
128
|
-
await
|
|
123
|
+
await tlv.save()
|
|
129
124
|
} catch (error) {
|
|
130
125
|
logger.debug?.(`*** FAILED: ${error}`)
|
|
131
126
|
throw error
|
|
132
127
|
}
|
|
133
|
-
logger.debug?.(
|
|
134
|
-
`*** Object updated in Mongo. New object: ${JSON.stringify(
|
|
135
|
-
topLevelFeature,
|
|
136
|
-
)}`,
|
|
137
|
-
)
|
|
138
128
|
}
|
|
139
129
|
}
|
|
140
130
|
|
|
@@ -146,12 +136,13 @@ export class LocationEndChange extends FeatureChange {
|
|
|
146
136
|
if (!dataStore) {
|
|
147
137
|
throw new Error('No data store')
|
|
148
138
|
}
|
|
149
|
-
for (const
|
|
150
|
-
const
|
|
139
|
+
for (const change of this.changes) {
|
|
140
|
+
const { featureId, newEnd } = change
|
|
141
|
+
const feature = dataStore.getFeature(featureId)
|
|
151
142
|
if (!feature) {
|
|
152
|
-
throw new Error(`Could not find feature with identifier "${
|
|
143
|
+
throw new Error(`Could not find feature with identifier "${featureId}"`)
|
|
153
144
|
}
|
|
154
|
-
feature.setMax(
|
|
145
|
+
feature.setMax(newEnd)
|
|
155
146
|
}
|
|
156
147
|
}
|
|
157
148
|
|