1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.GraphIdManager = void 0;
|
4 | require("source-map-support/register");
|
5 | // TODO should I get rid of the lib above for production browser build?
|
6 | /* pvjson: "id" is a required property.
|
7 | * GPML2013a: GraphId is sometimes optional, e.g., for Groups or Anchors.
|
8 | * GPML2017: supposed to make GraphId required.
|
9 | *
|
10 | * When converting GPML2013a, we fill in any missing GraphIds so that any
|
11 | * element that MAY have a GraphId DOES have one.
|
12 | * If the GraphId is already specified, we don't change it.
|
13 | * If it is not specified, we want to generate one with these properties:
|
14 | * 1) Stability/Purity: you can convert the same GPML file any number of times
|
15 | * and always get the same pvjson output.
|
16 | * 2) Uniqueness: don't clobber an existing GraphId in the pathway.
|
17 | *
|
18 | * The PathVisio algorithm for GraphId generation is basically:
|
19 | *
|
20 | * GraphId = RandomValue + IncrementingValue
|
21 | *
|
22 | * where IncrementingValue is generated by starting with a hex value of
|
23 | * "0xa00" for the first GraphId and incrementing that value for each
|
24 | * subsequent GraphId:
|
25 | * https://github.com/PathVisio/pathvisio/blob/3cb194f120de550ef2e102877965bed3c54a6a75/modules/org.pathvisio.core/src/org/pathvisio/core/biopax/BiopaxElement.java#L245
|
26 | *
|
27 | * We want a stable output, so instead of using a random value, we use the
|
28 | * namespace "pvjsgeneratedid", and since that's a string, we must append
|
29 | * the IncrementingValue instead of adding it:
|
30 | *
|
31 | * GraphId = "pvjsgeneratedid" + IncrementingValue
|
32 | */
|
33 | var GraphIdManager = /** @class */ (function () {
|
34 | function GraphIdManager() {
|
35 | this.namespace = "pvjsgeneratedid";
|
36 | this.incrementingValueAsInt = parseInt("0xa00", 16);
|
37 | }
|
38 | GraphIdManager.prototype.generateAndRecord = function () {
|
39 | this.incrementingValueAsInt += 1;
|
40 | // NOTE: the namespace is not part of incrementingValueAsInt
|
41 | return this.namespace + this.incrementingValueAsInt.toString(16);
|
42 | };
|
43 | GraphIdManager.prototype.recordExisting = function (graphIdAsHex) {
|
44 | var incrementingValueAsInt = this.incrementingValueAsInt;
|
45 | var graphIdAsInt = parseInt(graphIdAsHex, 16);
|
46 | // NOTE: this graphIdAsInt does not refer to exactly the same thing as PathVisio's
|
47 | // IncrementingValue, because it's the sum of RandomValue and IncrementingValue.
|
48 | if (graphIdAsInt > incrementingValueAsInt) {
|
49 | this.incrementingValueAsInt = graphIdAsInt;
|
50 | }
|
51 | };
|
52 | return GraphIdManager;
|
53 | }());
|
54 | exports.GraphIdManager = GraphIdManager;
|
55 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiR3JhcGhJZE1hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvR3JhcGhJZE1hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsdUNBQXFDO0FBQ3JDLHVFQUF1RTtBQUV2RTs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0EwQkc7QUFDSDtJQUdFO1FBREEsY0FBUyxHQUFXLGlCQUFpQixDQUFDO1FBRXBDLElBQUksQ0FBQyxzQkFBc0IsR0FBRyxRQUFRLENBQUMsT0FBTyxFQUFFLEVBQUUsQ0FBQyxDQUFDO0lBQ3RELENBQUM7SUFFRCwwQ0FBaUIsR0FBakI7UUFDRSxJQUFJLENBQUMsc0JBQXNCLElBQUksQ0FBQyxDQUFDO1FBQ2pDLDREQUE0RDtRQUM1RCxPQUFPLElBQUksQ0FBQyxTQUFTLEdBQUcsSUFBSSxDQUFDLHNCQUFzQixDQUFDLFFBQVEsQ0FBQyxFQUFFLENBQUMsQ0FBQztJQUNuRSxDQUFDO0lBRUQsdUNBQWMsR0FBZCxVQUFlLFlBQVk7UUFDakIsSUFBQSxzQkFBc0IsR0FBSyxJQUFJLHVCQUFULENBQVU7UUFDeEMsSUFBTSxZQUFZLEdBQUcsUUFBUSxDQUFDLFlBQVksRUFBRSxFQUFFLENBQUMsQ0FBQztRQUNoRCxrRkFBa0Y7UUFDbEYsZ0ZBQWdGO1FBQ2hGLElBQUksWUFBWSxHQUFHLHNCQUFzQixFQUFFO1lBQ3pDLElBQUksQ0FBQyxzQkFBc0IsR0FBRyxZQUFZLENBQUM7U0FDNUM7SUFDSCxDQUFDO0lBQ0gscUJBQUM7QUFBRCxDQUFDLEFBdEJELElBc0JDO0FBdEJZLHdDQUFjIn0= |
\ | No newline at end of file |