UNPKG

gpml2pvjson

Version:
55 lines 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GraphIdManager = void 0; require("source-map-support/register"); // TODO should I get rid of the lib above for production browser build? /* pvjson: "id" is a required property. * GPML2013a: GraphId is sometimes optional, e.g., for Groups or Anchors. * GPML2017: supposed to make GraphId required. * * When converting GPML2013a, we fill in any missing GraphIds so that any * element that MAY have a GraphId DOES have one. * If the GraphId is already specified, we don't change it. * If it is not specified, we want to generate one with these properties: * 1) Stability/Purity: you can convert the same GPML file any number of times * and always get the same pvjson output. * 2) Uniqueness: don't clobber an existing GraphId in the pathway. * * The PathVisio algorithm for GraphId generation is basically: * * GraphId = RandomValue + IncrementingValue * * where IncrementingValue is generated by starting with a hex value of * "0xa00" for the first GraphId and incrementing that value for each * subsequent GraphId: * https://github.com/PathVisio/pathvisio/blob/3cb194f120de550ef2e102877965bed3c54a6a75/modules/org.pathvisio.core/src/org/pathvisio/core/biopax/BiopaxElement.java#L245 * * We want a stable output, so instead of using a random value, we use the * namespace "pvjsgeneratedid", and since that's a string, we must append * the IncrementingValue instead of adding it: * * GraphId = "pvjsgeneratedid" + IncrementingValue */ var GraphIdManager = /** @class */ (function () { function GraphIdManager() { this.namespace = "pvjsgeneratedid"; this.incrementingValueAsInt = parseInt("0xa00", 16); } GraphIdManager.prototype.generateAndRecord = function () { this.incrementingValueAsInt += 1; // NOTE: the namespace is not part of incrementingValueAsInt return this.namespace + this.incrementingValueAsInt.toString(16); }; GraphIdManager.prototype.recordExisting = function (graphIdAsHex) { var incrementingValueAsInt = this.incrementingValueAsInt; var graphIdAsInt = parseInt(graphIdAsHex, 16); // NOTE: this graphIdAsInt does not refer to exactly the same thing as PathVisio's // IncrementingValue, because it's the sum of RandomValue and IncrementingValue. if (graphIdAsInt > incrementingValueAsInt) { this.incrementingValueAsInt = graphIdAsInt; } }; return GraphIdManager; }()); exports.GraphIdManager = GraphIdManager; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW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