UNPKG

gpml2pvjson

Version:
50 lines 3.28 kB
import "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 */ export class GraphIdManager { constructor() { this.namespace = "pvjsgeneratedid"; this.incrementingValueAsInt = parseInt("0xa00", 16); } generateAndRecord() { this.incrementingValueAsInt += 1; // NOTE: the namespace is not part of incrementingValueAsInt return this.namespace + this.incrementingValueAsInt.toString(16); } recordExisting(graphIdAsHex) { const { incrementingValueAsInt } = this; const 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; } } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiR3JhcGhJZE1hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvR3JhcGhJZE1hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyw2QkFBNkIsQ0FBQztBQUNyQyx1RUFBdUU7QUFFdkU7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBMEJHO0FBQ0gsTUFBTSxPQUFPLGNBQWM7SUFHekI7UUFEQSxjQUFTLEdBQVcsaUJBQWlCLENBQUM7UUFFcEMsSUFBSSxDQUFDLHNCQUFzQixHQUFHLFFBQVEsQ0FBQyxPQUFPLEVBQUUsRUFBRSxDQUFDLENBQUM7SUFDdEQsQ0FBQztJQUVELGlCQUFpQjtRQUNmLElBQUksQ0FBQyxzQkFBc0IsSUFBSSxDQUFDLENBQUM7UUFDakMsNERBQTREO1FBQzVELE9BQU8sSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLENBQUMsc0JBQXNCLENBQUMsUUFBUSxDQUFDLEVBQUUsQ0FBQyxDQUFDO0lBQ25FLENBQUM7SUFFRCxjQUFjLENBQUMsWUFBWTtRQUN6QixNQUFNLEVBQUUsc0JBQXNCLEVBQUUsR0FBRyxJQUFJLENBQUM7UUFDeEMsTUFBTSxZQUFZLEdBQUcsUUFBUSxDQUFDLFlBQVksRUFBRSxFQUFFLENBQUMsQ0FBQztRQUNoRCxrRkFBa0Y7UUFDbEYsZ0ZBQWdGO1FBQ2hGLElBQUksWUFBWSxHQUFHLHNCQUFzQixFQUFFO1lBQ3pDLElBQUksQ0FBQyxzQkFBc0IsR0FBRyxZQUFZLENBQUM7U0FDNUM7SUFDSCxDQUFDO0NBQ0YifQ==