@jbrowse/plugin-rdf 2.13.0 → 2.14.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.
|
@@ -2,9 +2,9 @@ import { BaseFeatureDataAdapter, BaseOptions } from '@jbrowse/core/data_adapters
|
|
|
2
2
|
import { NoAssemblyRegion } from '@jbrowse/core/util/types';
|
|
3
3
|
import { Feature } from '@jbrowse/core/util/simpleFeature';
|
|
4
4
|
import { Instance } from 'mobx-state-tree';
|
|
5
|
-
import MyConfigSchema from './configSchema';
|
|
6
5
|
import PluginManager from '@jbrowse/core/PluginManager';
|
|
7
6
|
import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache';
|
|
7
|
+
import type MyConfigSchema from './configSchema';
|
|
8
8
|
export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
9
9
|
private endpoint;
|
|
10
10
|
private queryTemplate;
|
|
@@ -21,17 +21,15 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
21
21
|
if (this.refNames) {
|
|
22
22
|
return this.refNames;
|
|
23
23
|
}
|
|
24
|
-
let refNames = [];
|
|
25
24
|
if (this.refNamesQueryTemplate) {
|
|
26
25
|
const queryTemplate = encodeURIComponent(this.refNamesQueryTemplate);
|
|
27
26
|
const results = await this.querySparql(queryTemplate, opts);
|
|
28
|
-
refNames = this.resultsToRefNames(results);
|
|
27
|
+
this.refNames = this.resultsToRefNames(results);
|
|
29
28
|
}
|
|
30
|
-
else
|
|
31
|
-
refNames = this.configRefNames;
|
|
29
|
+
else {
|
|
30
|
+
this.refNames = this.configRefNames;
|
|
32
31
|
}
|
|
33
|
-
this.refNames
|
|
34
|
-
return refNames;
|
|
32
|
+
return this.refNames;
|
|
35
33
|
}
|
|
36
34
|
getFeatures(query, opts = {}) {
|
|
37
35
|
return (0, rxjs_1.ObservableCreate)(async (observer) => {
|
|
@@ -44,7 +42,6 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
44
42
|
observer.complete();
|
|
45
43
|
}, opts.signal);
|
|
46
44
|
}
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
45
|
async querySparql(query, opts) {
|
|
49
46
|
let additionalQueryParams = '';
|
|
50
47
|
if (this.additionalQueryParams.length) {
|
|
@@ -58,11 +55,7 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
58
55
|
return response.json();
|
|
59
56
|
}
|
|
60
57
|
resultsToRefNames(response) {
|
|
61
|
-
|
|
62
|
-
const rows = ((_a = response === null || response === void 0 ? void 0 : response.results) === null || _a === void 0 ? void 0 : _a.bindings) || [];
|
|
63
|
-
if (!rows.length) {
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
58
|
+
const rows = response.results.bindings || [];
|
|
66
59
|
const fields = response.head.vars;
|
|
67
60
|
if (!fields.includes('refName')) {
|
|
68
61
|
throw new Error('"refName" not found in refNamesQueryTemplate response');
|
|
@@ -70,11 +63,7 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
70
63
|
return rows.map(row => row.refName.value);
|
|
71
64
|
}
|
|
72
65
|
resultsToFeatures(results, refName) {
|
|
73
|
-
|
|
74
|
-
const rows = ((_a = results === null || results === void 0 ? void 0 : results.results) === null || _a === void 0 ? void 0 : _a.bindings) || [];
|
|
75
|
-
if (!rows.length) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
66
|
+
const rows = results.results.bindings || [];
|
|
78
67
|
const fields = results.head.vars;
|
|
79
68
|
const requiredFields = ['start', 'end', 'uniqueId'];
|
|
80
69
|
requiredFields.forEach(requiredField => {
|
|
@@ -100,18 +89,18 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
100
89
|
}
|
|
101
90
|
});
|
|
102
91
|
rawData.forEach((rd, idx) => {
|
|
103
|
-
const { uniqueId } = rd;
|
|
92
|
+
const { uniqueId, start, end, strand } = rd;
|
|
104
93
|
if (idx < rawData.length - 1) {
|
|
105
94
|
rawData[idx + 1].parentUniqueId = uniqueId;
|
|
106
95
|
}
|
|
107
96
|
seenFeatures[uniqueId] = {
|
|
108
97
|
data: {
|
|
109
98
|
...rd,
|
|
110
|
-
uniqueId,
|
|
99
|
+
uniqueId: uniqueId,
|
|
111
100
|
refName,
|
|
112
|
-
start: parseInt(
|
|
113
|
-
end: parseInt(
|
|
114
|
-
strand: parseInt(
|
|
101
|
+
start: Number.parseInt(start, 10),
|
|
102
|
+
end: Number.parseInt(end, 10),
|
|
103
|
+
strand: Number.parseInt(strand, 10) || 0,
|
|
115
104
|
},
|
|
116
105
|
};
|
|
117
106
|
});
|
|
@@ -119,7 +108,7 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
119
108
|
// resolve subfeatures, keeping only top-level features in seenFeatures
|
|
120
109
|
for (const [uniqueId, f] of Object.entries(seenFeatures)) {
|
|
121
110
|
const pid = f.data.parentUniqueId;
|
|
122
|
-
|
|
111
|
+
f.data.parentUniqueId = undefined;
|
|
123
112
|
if (pid) {
|
|
124
113
|
const p = seenFeatures[pid];
|
|
125
114
|
if (p) {
|
|
@@ -139,7 +128,7 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
139
128
|
.flat();
|
|
140
129
|
let found = false;
|
|
141
130
|
for (const subfeature of subfeatures) {
|
|
142
|
-
if (subfeature
|
|
131
|
+
if (subfeature.uniqueId === pid) {
|
|
143
132
|
if (!subfeature.subfeatures) {
|
|
144
133
|
subfeature.subfeatures = [];
|
|
145
134
|
}
|
|
@@ -151,7 +140,7 @@ class SPARQLAdapter extends BaseAdapter_1.BaseFeatureDataAdapter {
|
|
|
151
140
|
found = true;
|
|
152
141
|
break;
|
|
153
142
|
}
|
|
154
|
-
|
|
143
|
+
if (subfeature.subfeatures) {
|
|
155
144
|
subfeatures.push(...subfeature.subfeatures);
|
|
156
145
|
}
|
|
157
146
|
}
|
|
@@ -2,9 +2,9 @@ import { BaseFeatureDataAdapter, BaseOptions } from '@jbrowse/core/data_adapters
|
|
|
2
2
|
import { NoAssemblyRegion } from '@jbrowse/core/util/types';
|
|
3
3
|
import { Feature } from '@jbrowse/core/util/simpleFeature';
|
|
4
4
|
import { Instance } from 'mobx-state-tree';
|
|
5
|
-
import MyConfigSchema from './configSchema';
|
|
6
5
|
import PluginManager from '@jbrowse/core/PluginManager';
|
|
7
6
|
import { getSubAdapterType } from '@jbrowse/core/data_adapters/dataAdapterCache';
|
|
7
|
+
import type MyConfigSchema from './configSchema';
|
|
8
8
|
export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
9
9
|
private endpoint;
|
|
10
10
|
private queryTemplate;
|
|
@@ -16,17 +16,15 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
16
16
|
if (this.refNames) {
|
|
17
17
|
return this.refNames;
|
|
18
18
|
}
|
|
19
|
-
let refNames = [];
|
|
20
19
|
if (this.refNamesQueryTemplate) {
|
|
21
20
|
const queryTemplate = encodeURIComponent(this.refNamesQueryTemplate);
|
|
22
21
|
const results = await this.querySparql(queryTemplate, opts);
|
|
23
|
-
refNames = this.resultsToRefNames(results);
|
|
22
|
+
this.refNames = this.resultsToRefNames(results);
|
|
24
23
|
}
|
|
25
|
-
else
|
|
26
|
-
refNames = this.configRefNames;
|
|
24
|
+
else {
|
|
25
|
+
this.refNames = this.configRefNames;
|
|
27
26
|
}
|
|
28
|
-
this.refNames
|
|
29
|
-
return refNames;
|
|
27
|
+
return this.refNames;
|
|
30
28
|
}
|
|
31
29
|
getFeatures(query, opts = {}) {
|
|
32
30
|
return ObservableCreate(async (observer) => {
|
|
@@ -39,7 +37,6 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
39
37
|
observer.complete();
|
|
40
38
|
}, opts.signal);
|
|
41
39
|
}
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
40
|
async querySparql(query, opts) {
|
|
44
41
|
let additionalQueryParams = '';
|
|
45
42
|
if (this.additionalQueryParams.length) {
|
|
@@ -53,11 +50,7 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
53
50
|
return response.json();
|
|
54
51
|
}
|
|
55
52
|
resultsToRefNames(response) {
|
|
56
|
-
|
|
57
|
-
const rows = ((_a = response === null || response === void 0 ? void 0 : response.results) === null || _a === void 0 ? void 0 : _a.bindings) || [];
|
|
58
|
-
if (!rows.length) {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
53
|
+
const rows = response.results.bindings || [];
|
|
61
54
|
const fields = response.head.vars;
|
|
62
55
|
if (!fields.includes('refName')) {
|
|
63
56
|
throw new Error('"refName" not found in refNamesQueryTemplate response');
|
|
@@ -65,11 +58,7 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
65
58
|
return rows.map(row => row.refName.value);
|
|
66
59
|
}
|
|
67
60
|
resultsToFeatures(results, refName) {
|
|
68
|
-
|
|
69
|
-
const rows = ((_a = results === null || results === void 0 ? void 0 : results.results) === null || _a === void 0 ? void 0 : _a.bindings) || [];
|
|
70
|
-
if (!rows.length) {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
61
|
+
const rows = results.results.bindings || [];
|
|
73
62
|
const fields = results.head.vars;
|
|
74
63
|
const requiredFields = ['start', 'end', 'uniqueId'];
|
|
75
64
|
requiredFields.forEach(requiredField => {
|
|
@@ -95,18 +84,18 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
95
84
|
}
|
|
96
85
|
});
|
|
97
86
|
rawData.forEach((rd, idx) => {
|
|
98
|
-
const { uniqueId } = rd;
|
|
87
|
+
const { uniqueId, start, end, strand } = rd;
|
|
99
88
|
if (idx < rawData.length - 1) {
|
|
100
89
|
rawData[idx + 1].parentUniqueId = uniqueId;
|
|
101
90
|
}
|
|
102
91
|
seenFeatures[uniqueId] = {
|
|
103
92
|
data: {
|
|
104
93
|
...rd,
|
|
105
|
-
uniqueId,
|
|
94
|
+
uniqueId: uniqueId,
|
|
106
95
|
refName,
|
|
107
|
-
start: parseInt(
|
|
108
|
-
end: parseInt(
|
|
109
|
-
strand: parseInt(
|
|
96
|
+
start: Number.parseInt(start, 10),
|
|
97
|
+
end: Number.parseInt(end, 10),
|
|
98
|
+
strand: Number.parseInt(strand, 10) || 0,
|
|
110
99
|
},
|
|
111
100
|
};
|
|
112
101
|
});
|
|
@@ -114,7 +103,7 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
114
103
|
// resolve subfeatures, keeping only top-level features in seenFeatures
|
|
115
104
|
for (const [uniqueId, f] of Object.entries(seenFeatures)) {
|
|
116
105
|
const pid = f.data.parentUniqueId;
|
|
117
|
-
|
|
106
|
+
f.data.parentUniqueId = undefined;
|
|
118
107
|
if (pid) {
|
|
119
108
|
const p = seenFeatures[pid];
|
|
120
109
|
if (p) {
|
|
@@ -134,7 +123,7 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
134
123
|
.flat();
|
|
135
124
|
let found = false;
|
|
136
125
|
for (const subfeature of subfeatures) {
|
|
137
|
-
if (subfeature
|
|
126
|
+
if (subfeature.uniqueId === pid) {
|
|
138
127
|
if (!subfeature.subfeatures) {
|
|
139
128
|
subfeature.subfeatures = [];
|
|
140
129
|
}
|
|
@@ -146,7 +135,7 @@ export default class SPARQLAdapter extends BaseFeatureDataAdapter {
|
|
|
146
135
|
found = true;
|
|
147
136
|
break;
|
|
148
137
|
}
|
|
149
|
-
|
|
138
|
+
if (subfeature.subfeatures) {
|
|
150
139
|
subfeatures.push(...subfeature.subfeatures);
|
|
151
140
|
}
|
|
152
141
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jbrowse/plugin-rdf",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "JBrowse 2 RDF resources",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jbrowse",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "npm-run-all build:*",
|
|
27
|
-
"test": "cd ../..; jest plugins/rdf",
|
|
27
|
+
"test": "cd ../..; jest --passWithNoTests plugins/rdf",
|
|
28
28
|
"prepublishOnly": "yarn test",
|
|
29
29
|
"prepack": "yarn build && yarn useDist",
|
|
30
30
|
"postpack": "yarn useSrc",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "9fb8231d932db40adf0a283081765431756c66ff"
|
|
55
55
|
}
|