@jbrowse/plugin-bed 5.0.0-beta.3 → 5.0.0-beta.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.
@@ -1,7 +1,9 @@
1
- import { ConfigurationSchema } from '@jbrowse/core/configuration';
1
+ import { ConfigurationSchema, fillLocations } from '@jbrowse/core/configuration';
2
2
  export function normalizeSnapshot(snap) {
3
3
  return snap.uri
4
- ? { ...snap, bedLocation: { uri: snap.uri, baseUri: snap.baseUri } }
4
+ ? fillLocations(snap, {
5
+ bedLocation: { uri: snap.uri, baseUri: snap.baseUri },
6
+ })
5
7
  : snap;
6
8
  }
7
9
  /**
@@ -1,13 +1,12 @@
1
- import { ConfigurationSchema } from '@jbrowse/core/configuration';
1
+ import { ConfigurationSchema, fillLocations } from '@jbrowse/core/configuration';
2
2
  export function normalizeSnapshot(snap) {
3
3
  return snap.uri
4
- ? {
5
- ...snap,
4
+ ? fillLocations(snap, {
6
5
  bedGraphLocation: {
7
6
  uri: snap.uri,
8
7
  baseUri: snap.baseUri,
9
8
  },
10
- }
9
+ })
11
10
  : snap;
12
11
  }
13
12
  /**
@@ -1,14 +1,13 @@
1
- import { ConfigurationSchema } from '@jbrowse/core/configuration';
1
+ import { ConfigurationSchema, fillLocations } from '@jbrowse/core/configuration';
2
2
  export function normalizeSnapshot(snap) {
3
3
  return snap.uri
4
- ? {
5
- ...snap,
4
+ ? fillLocations(snap, {
6
5
  bedpeLocation: {
7
6
  uri: snap.uri,
8
7
  baseUri: snap.baseUri,
9
8
  locationType: 'UriLocation',
10
9
  },
11
- }
10
+ })
12
11
  : snap;
13
12
  }
14
13
  /**
@@ -1,14 +1,13 @@
1
- import { ConfigurationSchema } from '@jbrowse/core/configuration';
1
+ import { ConfigurationSchema, fillLocations } from '@jbrowse/core/configuration';
2
2
  import { densityAdapterConfigSchemaFields } from '@jbrowse/core/data_adapters/BaseAdapter';
3
3
  export function normalizeSnapshot(snap) {
4
4
  return snap.uri
5
- ? {
6
- ...snap,
5
+ ? fillLocations(snap, {
7
6
  bigBedLocation: {
8
7
  uri: snap.uri,
9
8
  baseUri: snap.baseUri,
10
9
  },
11
- }
10
+ })
12
11
  : snap;
13
12
  }
14
13
  /**
@@ -2,42 +2,9 @@ import { BaseFeatureDataAdapter, cachedSetup, } from '@jbrowse/core/data_adapter
2
2
  import { SimpleFeature, fetchAndMaybeUnzip } from '@jbrowse/core/util';
3
3
  import { openLocation } from '@jbrowse/core/util/io';
4
4
  import { parseLineByLine } from '@jbrowse/core/util/parseLineByLine';
5
+ import { parseStarFusionBreakpoint, starFusionColumns, } from '@jbrowse/core/util/starFusion';
5
6
  import { buildPairedIntervalTree, intervalTreeFeatures, } from '../adapterUtil.js';
6
- /**
7
- * A STAR-Fusion `refName:pos:strand` breakpoint, read from the RIGHT: a refName
8
- * may contain colons. GRCh38's full analysis set names its HLA contigs
9
- * `HLA-A*01:01:01:01`, so a breakpoint on one arrives as
10
- * `HLA-A*01:01:01:01:5000:+` and splitting at the first colon read the contig as
11
- * `HLA-A*01`, the position as 1 and the strand as absent. Same rule
12
- * `parseSvAlt` applies to a BND mate locstring, one field further along.
13
- *
14
- * A string with fewer than three fields keeps what it always parsed to, so a
15
- * truncated or strandless row is no worse off than before.
16
- */
17
- function parseBreakpoint(str) {
18
- const parts = str.split(':');
19
- const strandStr = parts.length >= 3 ? parts.pop() : undefined;
20
- const pos = parts.length >= 2 ? +parts.pop() : Number.NaN;
21
- return {
22
- refName: parts.join(':'),
23
- start: pos,
24
- end: pos + 1,
25
- strand: strandStr === '+' ? 1 : strandStr === '-' ? -1 : undefined,
26
- };
27
- }
28
- /**
29
- * Which way the sequence a breakpoint keeps runs from it, as the paired-arc
30
- * display's mate-direction tick (1 = right, -1 = left, 0 = unknown). A
31
- * breakpoint's strand in STAR-Fusion is its gene's transcription strand, and the
32
- * fusion transcript keeps the donor's sequence 5' of the junction and the
33
- * acceptor's 3' of it: so on a + strand donor the retained side is at lower
34
- * coordinates and on a + strand acceptor it is at higher ones.
35
- */
36
- function tickDirection(strand, isDonor) {
37
- return strand === undefined ? 0 : isDonor ? -strand : strand;
38
- }
39
7
  export default class StarFusionAdapter extends BaseFeatureDataAdapter {
40
- // No `label`: `fetchAndMaybeUnzip` narrates the download from inside.
41
8
  loadData = cachedSetup({ setup: opts => this.loadDataP(opts) });
42
9
  intervalTrees = {};
43
10
  static capabilities = ['getFeatures', 'getRefNames'];
@@ -48,23 +15,19 @@ export default class StarFusionAdapter extends BaseFeatureDataAdapter {
48
15
  let rightIdx = -1;
49
16
  const feats1 = {};
50
17
  const feats2 = {};
51
- parseLineByLine(buffer, line => {
52
- if (line.startsWith('#')) {
53
- columnNames = line.slice(1).split('\t');
18
+ parseLineByLine(buffer, (line, lineIndex) => {
19
+ if (lineIndex === 0) {
20
+ columnNames = starFusionColumns(line);
54
21
  leftIdx = columnNames.indexOf('LeftBreakpoint');
55
22
  rightIdx = columnNames.indexOf('RightBreakpoint');
56
23
  }
57
- else if (leftIdx >= 0 && rightIdx >= 0) {
24
+ else if (!line.startsWith('#')) {
58
25
  const cols = line.split('\t');
59
26
  const left = cols[leftIdx];
60
27
  const right = cols[rightIdx];
61
- // through parseBreakpoint, so the bucket a row is filed under is the
62
- // refName its feature will report -- a colon-bearing contig split two
63
- // ways puts the row in a bucket no query can reach
64
- const leftRef = left ? parseBreakpoint(left).refName : undefined;
65
- const rightRef = right ? parseBreakpoint(right).refName : undefined;
66
- if (leftRef && rightRef) {
67
- ;
28
+ if (left && right) {
29
+ const leftRef = parseStarFusionBreakpoint(left, true).refName;
30
+ const rightRef = parseStarFusionBreakpoint(right, false).refName;
68
31
  (feats1[leftRef] ??= []).push(line);
69
32
  (feats2[rightRef] ??= []).push(line);
70
33
  }
@@ -80,27 +43,16 @@ export default class StarFusionAdapter extends BaseFeatureDataAdapter {
80
43
  featureFromLine(line, columnNames, uniqueId, flip) {
81
44
  const cols = line.split('\t');
82
45
  const row = Object.fromEntries(columnNames.map((name, i) => [name, cols[i]]));
83
- const primaryBp = parseBreakpoint((flip ? row.RightBreakpoint : row.LeftBreakpoint));
84
- const mateBp = parseBreakpoint((flip ? row.LeftBreakpoint : row.RightBreakpoint));
85
- // the LeftBreakpoint is the donor, so this feature is the donor end of the
86
- // junction whenever it is not flipped, and the mate is the other end
46
+ const donor = parseStarFusionBreakpoint(row.LeftBreakpoint, true);
47
+ const acceptor = parseStarFusionBreakpoint(row.RightBreakpoint, false);
48
+ const [primary, mate] = flip ? [acceptor, donor] : [donor, acceptor];
87
49
  return new SimpleFeature({
88
50
  uniqueId,
89
- refName: primaryBp.refName,
90
- start: primaryBp.start,
91
- end: primaryBp.end,
92
- strand: primaryBp.strand,
93
- mateDirection: tickDirection(primaryBp.strand, !flip),
51
+ ...primary,
94
52
  name: row.FusionName,
95
53
  score: row.JunctionReadCount ? +row.JunctionReadCount : undefined,
96
54
  type: 'fusion',
97
- mate: {
98
- refName: mateBp.refName,
99
- start: mateBp.start,
100
- end: mateBp.end,
101
- strand: mateBp.strand,
102
- mateDirection: tickDirection(mateBp.strand, flip),
103
- },
55
+ mate,
104
56
  ...row,
105
57
  });
106
58
  }
@@ -1,14 +1,13 @@
1
- import { ConfigurationSchema } from '@jbrowse/core/configuration';
1
+ import { ConfigurationSchema, fillLocations } from '@jbrowse/core/configuration';
2
2
  export function normalizeSnapshot(snap) {
3
3
  return snap.uri
4
- ? {
5
- ...snap,
4
+ ? fillLocations(snap, {
6
5
  starFusionLocation: {
7
6
  uri: snap.uri,
8
7
  baseUri: snap.baseUri,
9
8
  locationType: 'UriLocation',
10
9
  },
11
- }
10
+ })
12
11
  : snap;
13
12
  }
14
13
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-bed",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.7",
4
4
  "type": "module",
5
5
  "description": "JBrowse 2 bed adapters, tracks, etc.",
6
6
  "keywords": [
@@ -27,7 +27,7 @@
27
27
  "@jbrowse/mobx-state-tree": "^6.5.1",
28
28
  "mobx": "^7.0.3",
29
29
  "rxjs": "^7.8.2",
30
- "@jbrowse/core": "^5.0.0-beta.3"
30
+ "@jbrowse/core": "^5.0.0-beta.7"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"