@jbrowse/plugin-bed 2.16.0 → 2.17.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.
package/esm/util.js CHANGED
@@ -1,173 +1,147 @@
1
- import { SimpleFeature } from '@jbrowse/core/util';
2
- export function ucscProcessedTranscript(feature) {
3
- const { subfeatures: oldSubfeatures, thickStart, thickEnd, blockCount, blockSizes, chromStarts, refName, strand = 0, ...rest } = feature;
4
- if (!thickStart || !thickEnd || !strand) {
5
- return feature;
1
+ import { generateBedMethylFeature, isBedMethylFeature, } from './generateBedMethylFeature';
2
+ import { generateUcscTranscript, isUcscTranscript, } from './generateUcscTranscript';
3
+ import { generateRepeatMaskerFeature, isRepeatMaskerDescriptionField, } from './generateRepeatMaskerFeature';
4
+ function stringToStrand(f) {
5
+ if (f === '-1') {
6
+ return -1;
7
+ }
8
+ else if (f === '+') {
9
+ return 1;
10
+ }
11
+ else {
12
+ return 0;
6
13
  }
7
- const subfeatures = [];
8
- oldSubfeatures
9
- .filter(child => child.type === 'block')
10
- .sort((a, b) => a.start - b.start)
11
- .forEach(block => {
12
- const start = block.start;
13
- const end = block.end;
14
- if (thickStart >= end) {
15
- // left-side UTR
16
- const prime = strand > 0 ? 'five' : 'three';
17
- subfeatures.push({
18
- type: `${prime}_prime_UTR`,
19
- start,
20
- end,
21
- refName,
22
- });
23
- }
24
- else if (thickStart > start && thickStart < end && thickEnd >= end) {
25
- // UTR | CDS
26
- const prime = strand > 0 ? 'five' : 'three';
27
- subfeatures.push({
28
- type: `${prime}_prime_UTR`,
29
- start,
30
- end: thickStart,
31
- refName,
32
- }, {
33
- type: 'CDS',
34
- start: thickStart,
35
- end,
36
- refName,
37
- });
38
- }
39
- else if (thickStart <= start && thickEnd >= end) {
40
- // CDS
41
- subfeatures.push({
42
- type: 'CDS',
43
- start,
44
- end,
45
- refName,
46
- });
47
- }
48
- else if (thickStart > start && thickStart < end && thickEnd < end) {
49
- // UTR | CDS | UTR
50
- const leftPrime = strand > 0 ? 'five' : 'three';
51
- const rightPrime = strand > 0 ? 'three' : 'five';
52
- subfeatures.push({
53
- type: `${leftPrime}_prime_UTR`,
54
- start,
55
- end: thickStart,
56
- refName,
57
- }, {
58
- type: 'CDS',
59
- start: thickStart,
60
- end: thickEnd,
61
- refName,
62
- }, {
63
- type: `${rightPrime}_prime_UTR`,
64
- start: thickEnd,
65
- end,
66
- refName,
67
- });
68
- }
69
- else if (thickStart <= start && thickEnd > start && thickEnd < end) {
70
- // CDS | UTR
71
- const prime = strand > 0 ? 'three' : 'five';
72
- subfeatures.push({
73
- type: 'CDS',
74
- start,
75
- end: thickEnd,
76
- refName,
77
- }, {
78
- type: `${prime}_prime_UTR`,
79
- start: thickEnd,
80
- end,
81
- refName,
82
- });
83
- }
84
- else if (thickEnd <= start) {
85
- // right-side UTR
86
- const prime = strand > 0 ? 'three' : 'five';
87
- subfeatures.push({
88
- type: `${prime}_prime_UTR`,
89
- start,
90
- end,
91
- refName,
92
- });
93
- }
94
- });
95
- return { ...rest, strand, type: 'mRNA', refName, subfeatures };
96
14
  }
97
15
  function defaultParser(fields, line) {
98
16
  const obj = Object.fromEntries(line.split('\t').map((f, i) => [fields[i], f]));
99
17
  const { blockStarts, blockCount, chromStarts, thickEnd, thickStart, blockSizes, ...rest } = obj;
100
18
  return {
101
19
  ...rest,
102
- blockStarts: blockStarts === null || blockStarts === void 0 ? void 0 : blockStarts.split(',').map(r => +r),
103
- chromStarts: chromStarts === null || chromStarts === void 0 ? void 0 : chromStarts.split(',').map(r => +r),
104
- blockSizes: blockSizes === null || blockSizes === void 0 ? void 0 : blockSizes.split(',').map(r => +r),
20
+ blockStarts: arrayify(blockStarts),
21
+ chromStarts: arrayify(chromStarts),
22
+ blockSizes: arrayify(blockSizes),
105
23
  thickStart: thickStart ? +thickStart : undefined,
106
24
  thickEnd: thickEnd ? +thickEnd : undefined,
107
25
  blockCount: blockCount ? +blockCount : undefined,
108
26
  };
109
27
  }
110
28
  export function makeBlocks({ start, uniqueId, refName, chromStarts, blockCount, blockSizes, blockStarts, }) {
111
- const subfeatures = [];
112
- const starts = chromStarts || blockStarts || [];
113
- for (let b = 0; b < blockCount; b++) {
114
- const bmin = (starts[b] || 0) + start;
115
- const bmax = bmin + (blockSizes[b] || 0);
116
- subfeatures.push({
117
- uniqueId: `${uniqueId}-${b}`,
118
- start: bmin,
119
- end: bmax,
120
- refName,
121
- type: 'block',
122
- });
29
+ if (blockCount) {
30
+ const subfeatures = [];
31
+ const starts = chromStarts || blockStarts || [];
32
+ for (let b = 0; b < blockCount; b++) {
33
+ const bmin = (starts[b] || 0) + start;
34
+ const bsize = blockSizes === null || blockSizes === void 0 ? void 0 : blockSizes[b];
35
+ if (bsize && bsize > 0) {
36
+ const bmax = bmin + bsize;
37
+ subfeatures.push({
38
+ uniqueId: `${uniqueId}-${b}`,
39
+ start: bmin,
40
+ end: bmax,
41
+ refName,
42
+ type: 'block',
43
+ });
44
+ }
45
+ }
46
+ return subfeatures;
123
47
  }
124
- return subfeatures;
48
+ return [];
125
49
  }
126
- export function featureData(line, colRef, colStart, colEnd, scoreColumn, parser, uniqueId, names) {
127
- const l = line.split('\t');
128
- const refName = l[colRef];
129
- const start = +l[colStart];
130
- const colSame = colStart === colEnd ? 1 : 0;
131
- const end = +l[colEnd] + colSame;
50
+ export function featureData({ line, colRef, colStart, colEnd, scoreColumn, parser, uniqueId, names, }) {
51
+ const splitLine = line.split('\t');
52
+ const refName = splitLine[colRef];
53
+ const start = +splitLine[colStart];
54
+ const end = +splitLine[colEnd] + (colStart === colEnd ? 1 : 0);
55
+ return featureData2({
56
+ line,
57
+ refName,
58
+ start,
59
+ end,
60
+ parser,
61
+ uniqueId,
62
+ scoreColumn,
63
+ names,
64
+ });
65
+ }
66
+ export function featureData2({ line, refName, start, end, parser, uniqueId, scoreColumn, names, }) {
67
+ const splitLine = line.split('\t');
132
68
  const data = names
133
69
  ? defaultParser(names, line)
134
70
  : parser.parseLine(line, { uniqueId });
135
- const { blockCount, blockSizes, blockStarts, chromStarts, thickStart, thickEnd, type, score, chrom: _1, chromStart: _2, chromEnd: _3, ...rest } = data;
136
- const subfeatures = blockCount
137
- ? makeBlocks({
71
+ const { strand: strand2, score: score2, chrom: _1, chromStart: _2, chromEnd: _3, ...rest } = data;
72
+ const { chromStarts, blockSizes, blockStarts, type, blockCount, thickStart, thickEnd, description, ...rest2 } = rest;
73
+ const score = scoreColumn ? +data[scoreColumn] : score2 ? +score2 : undefined;
74
+ const strand = typeof strand2 === 'string' ? stringToStrand(strand2) : strand2;
75
+ const subfeatures = makeBlocks({
76
+ start,
77
+ uniqueId,
78
+ refName,
79
+ chromStarts,
80
+ blockCount,
81
+ blockSizes,
82
+ blockStarts,
83
+ });
84
+ if (isBedMethylFeature({ splitLine, start, end })) {
85
+ return generateBedMethylFeature({
86
+ line,
87
+ uniqueId,
88
+ refName,
138
89
  start,
90
+ end,
91
+ });
92
+ }
93
+ else if (isRepeatMaskerDescriptionField(description)) {
94
+ return generateRepeatMaskerFeature({
95
+ ...rest2,
139
96
  uniqueId,
97
+ description,
98
+ type,
99
+ score,
100
+ start,
101
+ end,
102
+ strand,
140
103
  refName,
104
+ subfeatures,
105
+ });
106
+ }
107
+ else if (isUcscTranscript({ strand, blockCount, thickStart })) {
108
+ return generateUcscTranscript({
109
+ ...rest,
110
+ description,
141
111
  chromStarts,
142
- blockCount,
112
+ thickStart,
113
+ thickEnd,
143
114
  blockSizes,
144
- blockStarts,
145
- })
146
- : [];
147
- const f = {
148
- ...rest,
149
- type,
150
- score: scoreColumn ? +data[scoreColumn] : score,
151
- start,
152
- end,
153
- refName,
154
- uniqueId,
155
- subfeatures,
156
- };
157
- return new SimpleFeature({
158
- id: uniqueId,
159
- data: isUcscProcessedTranscript(data)
160
- ? ucscProcessedTranscript({
161
- thickStart: thickStart,
162
- thickEnd: thickEnd,
163
- blockCount: blockCount,
164
- blockSizes: blockSizes,
165
- chromStarts: chromStarts,
166
- ...f,
167
- })
168
- : f,
169
- });
115
+ blockCount,
116
+ type,
117
+ score,
118
+ start,
119
+ end,
120
+ strand,
121
+ refName,
122
+ uniqueId,
123
+ subfeatures,
124
+ });
125
+ }
126
+ else {
127
+ return {
128
+ ...rest,
129
+ uniqueId,
130
+ description,
131
+ type,
132
+ score,
133
+ start,
134
+ end,
135
+ strand,
136
+ refName,
137
+ subfeatures,
138
+ };
139
+ }
170
140
  }
171
- export function isUcscProcessedTranscript(f) {
172
- return f.thickStart && f.blockCount && f.strand !== 0;
141
+ export function arrayify(f) {
142
+ return f !== undefined
143
+ ? typeof f === 'string'
144
+ ? f.split(',').map(f => +f)
145
+ : f
146
+ : undefined;
173
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-bed",
3
- "version": "2.16.0",
3
+ "version": "2.17.0",
4
4
  "description": "JBrowse 2 bed adapters, tracks, etc.",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -55,5 +55,5 @@
55
55
  "distModule": "esm/index.js",
56
56
  "srcModule": "src/index.ts",
57
57
  "module": "esm/index.js",
58
- "gitHead": "1e6d4fbc27ce684eed19e3c217f34bd2da24ab75"
58
+ "gitHead": "eed30b5e671f8f7823652d7cecc51aa89226de46"
59
59
  }