@graphty/graph-io 0.3.17 → 0.3.19

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.
Files changed (154) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +64 -3
  3. package/dist/chunks/{escape-scjHxjpr.js → escape-CWExcecC.js} +3 -2
  4. package/dist/chunks/{escape-scjHxjpr.js.map → escape-CWExcecC.js.map} +1 -1
  5. package/dist/chunks/exporter-CbMZyVt-.js +735 -0
  6. package/dist/chunks/exporter-CbMZyVt-.js.map +1 -0
  7. package/dist/chunks/importer-BAP4PrxR.js +2194 -0
  8. package/dist/chunks/importer-BAP4PrxR.js.map +1 -0
  9. package/dist/chunks/{importer-Xg07gk7p.js → importer-BNFuV1-K.js} +5 -3
  10. package/dist/chunks/{importer-Xg07gk7p.js.map → importer-BNFuV1-K.js.map} +1 -1
  11. package/dist/chunks/{importer-BmOl9gLW.js → importer-BVGtU1NA.js} +5 -3
  12. package/dist/chunks/{importer-BmOl9gLW.js.map → importer-BVGtU1NA.js.map} +1 -1
  13. package/dist/chunks/{importer-ruMWWvVs.js → importer-BW-Ft2ps.js} +5 -3
  14. package/dist/chunks/{importer-ruMWWvVs.js.map → importer-BW-Ft2ps.js.map} +1 -1
  15. package/dist/chunks/{importer-B6rKRxzv.js → importer-Bm1_5vPS.js} +781 -104
  16. package/dist/chunks/importer-Bm1_5vPS.js.map +1 -0
  17. package/dist/chunks/importer-ByPGO-09.js +1614 -0
  18. package/dist/chunks/importer-ByPGO-09.js.map +1 -0
  19. package/dist/chunks/importer-DOepkgnG.js +1713 -0
  20. package/dist/chunks/importer-DOepkgnG.js.map +1 -0
  21. package/dist/chunks/json-elements-CZY1wiZh.js +779 -0
  22. package/dist/chunks/json-elements-CZY1wiZh.js.map +1 -0
  23. package/dist/chunks/ontology-BnrJ4I98.js +113 -0
  24. package/dist/chunks/ontology-BnrJ4I98.js.map +1 -0
  25. package/dist/chunks/{records-DSpbTE5s.js → records-BzNicMsf.js} +2 -2
  26. package/dist/chunks/{records-DSpbTE5s.js.map → records-BzNicMsf.js.map} +1 -1
  27. package/dist/chunks/{writer-DHHfHn11.js → report-BcWboivV.js} +106 -928
  28. package/dist/chunks/report-BcWboivV.js.map +1 -0
  29. package/dist/chunks/weights-CwISIpCP.js +176 -0
  30. package/dist/chunks/weights-CwISIpCP.js.map +1 -0
  31. package/dist/chunks/writer-DQiKgQJc.js +656 -0
  32. package/dist/chunks/writer-DQiKgQJc.js.map +1 -0
  33. package/dist/csv.js +5 -3
  34. package/dist/csv.js.map +1 -1
  35. package/dist/cx.d.ts +1 -0
  36. package/dist/cx.js +6 -0
  37. package/dist/cx.js.map +1 -0
  38. package/dist/cx2.d.ts +1 -0
  39. package/dist/cx2.js +10 -0
  40. package/dist/cx2.js.map +1 -0
  41. package/dist/dot.js +1 -1
  42. package/dist/gexf.js +15 -3
  43. package/dist/gexf.js.map +1 -1
  44. package/dist/gml.js +5 -3
  45. package/dist/gml.js.map +1 -1
  46. package/dist/graph-io.js +158 -383
  47. package/dist/graph-io.js.map +1 -1
  48. package/dist/graphml.js +1 -1
  49. package/dist/json.js +1 -1
  50. package/dist/neo4j.js +5 -3
  51. package/dist/neo4j.js.map +1 -1
  52. package/dist/obo.d.ts +1 -0
  53. package/dist/obo.js +6 -0
  54. package/dist/obo.js.map +1 -0
  55. package/dist/pajek.js +1 -1
  56. package/dist/src/common/json-elements.d.ts +286 -0
  57. package/dist/src/common/json-elements.d.ts.map +1 -0
  58. package/dist/src/common/json-elements.js +926 -0
  59. package/dist/src/common/json-elements.js.map +1 -0
  60. package/dist/src/common/ontology.d.ts +59 -0
  61. package/dist/src/common/ontology.d.ts.map +1 -0
  62. package/dist/src/common/ontology.js +147 -0
  63. package/dist/src/common/ontology.js.map +1 -0
  64. package/dist/src/formats/cx/importer.d.ts +133 -0
  65. package/dist/src/formats/cx/importer.d.ts.map +1 -0
  66. package/dist/src/formats/cx/importer.js +2220 -0
  67. package/dist/src/formats/cx/importer.js.map +1 -0
  68. package/dist/src/formats/cx/index.d.ts +7 -0
  69. package/dist/src/formats/cx/index.d.ts.map +1 -0
  70. package/dist/src/formats/cx/index.js +7 -0
  71. package/dist/src/formats/cx/index.js.map +1 -0
  72. package/dist/src/formats/cx2/exporter.d.ts +59 -0
  73. package/dist/src/formats/cx2/exporter.d.ts.map +1 -0
  74. package/dist/src/formats/cx2/exporter.js +864 -0
  75. package/dist/src/formats/cx2/exporter.js.map +1 -0
  76. package/dist/src/formats/cx2/importer.d.ts +169 -0
  77. package/dist/src/formats/cx2/importer.d.ts.map +1 -0
  78. package/dist/src/formats/cx2/importer.js +1652 -0
  79. package/dist/src/formats/cx2/importer.js.map +1 -0
  80. package/dist/src/formats/cx2/index.d.ts +7 -0
  81. package/dist/src/formats/cx2/index.d.ts.map +1 -0
  82. package/dist/src/formats/cx2/index.js +7 -0
  83. package/dist/src/formats/cx2/index.js.map +1 -0
  84. package/dist/src/formats/gexf/exporter.d.ts +2 -0
  85. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  86. package/dist/src/formats/gexf/exporter.js +6 -0
  87. package/dist/src/formats/gexf/exporter.js.map +1 -1
  88. package/dist/src/formats/gexf/importer.d.ts +2 -4
  89. package/dist/src/formats/gexf/importer.d.ts.map +1 -1
  90. package/dist/src/formats/gexf/importer.js +2 -4
  91. package/dist/src/formats/gexf/importer.js.map +1 -1
  92. package/dist/src/formats/gexf/index.d.ts +1 -1
  93. package/dist/src/formats/gexf/index.js +2 -2
  94. package/dist/src/formats/gexf/index.js.map +1 -1
  95. package/dist/src/formats/gml/exporter.js +1 -1
  96. package/dist/src/formats/gml/exporter.js.map +1 -1
  97. package/dist/src/formats/json/dialect.d.ts +8 -6
  98. package/dist/src/formats/json/dialect.d.ts.map +1 -1
  99. package/dist/src/formats/json/dialect.js +26 -3
  100. package/dist/src/formats/json/dialect.js.map +1 -1
  101. package/dist/src/formats/json/importer.d.ts +324 -7
  102. package/dist/src/formats/json/importer.d.ts.map +1 -1
  103. package/dist/src/formats/json/importer.js +159 -126
  104. package/dist/src/formats/json/importer.js.map +1 -1
  105. package/dist/src/formats/json/obographs.d.ts +21 -0
  106. package/dist/src/formats/json/obographs.d.ts.map +1 -0
  107. package/dist/src/formats/json/obographs.js +476 -0
  108. package/dist/src/formats/json/obographs.js.map +1 -0
  109. package/dist/src/formats/obo/importer.d.ts +90 -0
  110. package/dist/src/formats/obo/importer.d.ts.map +1 -0
  111. package/dist/src/formats/obo/importer.js +1248 -0
  112. package/dist/src/formats/obo/importer.js.map +1 -0
  113. package/dist/src/formats/obo/index.d.ts +7 -0
  114. package/dist/src/formats/obo/index.d.ts.map +1 -0
  115. package/dist/src/formats/obo/index.js +7 -0
  116. package/dist/src/formats/obo/index.js.map +1 -0
  117. package/dist/src/formats/obo/syntax.d.ts +121 -0
  118. package/dist/src/formats/obo/syntax.d.ts.map +1 -0
  119. package/dist/src/formats/obo/syntax.js +424 -0
  120. package/dist/src/formats/obo/syntax.js.map +1 -0
  121. package/dist/src/index.d.ts +3 -0
  122. package/dist/src/index.d.ts.map +1 -1
  123. package/dist/src/index.js +3 -0
  124. package/dist/src/index.js.map +1 -1
  125. package/dist/src/registry.d.ts.map +1 -1
  126. package/dist/src/registry.js +8 -1
  127. package/dist/src/registry.js.map +1 -1
  128. package/dist/src/sniff.d.ts +1 -1
  129. package/dist/src/sniff.d.ts.map +1 -1
  130. package/dist/src/sniff.js +25 -3
  131. package/dist/src/sniff.js.map +1 -1
  132. package/package.json +16 -1
  133. package/src/common/json-elements.ts +1147 -0
  134. package/src/common/ontology.ts +169 -0
  135. package/src/formats/cx/importer.ts +2733 -0
  136. package/src/formats/cx/index.ts +7 -0
  137. package/src/formats/cx2/exporter.ts +1036 -0
  138. package/src/formats/cx2/importer.ts +2187 -0
  139. package/src/formats/cx2/index.ts +7 -0
  140. package/src/formats/gexf/exporter.ts +11 -0
  141. package/src/formats/gexf/importer.ts +2 -2
  142. package/src/formats/gexf/index.ts +1 -1
  143. package/src/formats/gml/exporter.ts +1 -1
  144. package/src/formats/json/dialect.ts +37 -7
  145. package/src/formats/json/importer.ts +210 -132
  146. package/src/formats/json/obographs.ts +563 -0
  147. package/src/formats/obo/importer.ts +1695 -0
  148. package/src/formats/obo/index.ts +7 -0
  149. package/src/formats/obo/syntax.ts +466 -0
  150. package/src/index.ts +11 -0
  151. package/src/registry.ts +8 -1
  152. package/src/sniff.ts +48 -5
  153. package/dist/chunks/importer-B6rKRxzv.js.map +0 -1
  154. package/dist/chunks/writer-DHHfHn11.js.map +0 -1
@@ -0,0 +1,169 @@
1
+ /**
2
+ * What the OBO importer and the JSON importer's `obographs` dialect share (design section 1.0, the
3
+ * `ontology.ts` building block): the OBO column vocabulary (names, dtypes, roles), so the `.obo` and
4
+ * the `.json` of one ontology give the same columns, and the OBO 1.4 rule for turning the IRIs
5
+ * OBO Graphs writes back into the identifiers the `.obo` file writes (section 4.6).
6
+ */
7
+
8
+ import { type ColumnDecl } from "@graphty/graph-format";
9
+
10
+ /** The dtypes the OBO vocabulary uses. */
11
+ type OboDtype = "string" | "dict" | "bool" | "list" | "json";
12
+
13
+ /** One column of the OBO vocabulary. */
14
+ interface OboColumnSpec {
15
+ /** The dtype. */
16
+ readonly dtype: OboDtype;
17
+ /** The role, when the column carries one. */
18
+ readonly role?: "label" | "kind" | undefined;
19
+ }
20
+
21
+ /**
22
+ * The node columns of the OBO vocabulary, keyed by column name (design section 4.2). The names are
23
+ * the OBO tag names, so a Gene Ontology user finds `namespace`, `def` and `is_obsolete` under the
24
+ * names the GO documentation uses.
25
+ */
26
+ export const OBO_NODE_COLUMNS: Readonly<Record<string, OboColumnSpec>> = Object.freeze({
27
+ type: { dtype: "dict" },
28
+ name: { dtype: "string", role: "label" },
29
+ namespace: { dtype: "dict" },
30
+ def: { dtype: "string" },
31
+ "def.xrefs": { dtype: "list" },
32
+ comment: { dtype: "string" },
33
+ synonym: { dtype: "json" },
34
+ xref: { dtype: "list" },
35
+ "xref.descriptions": { dtype: "json" },
36
+ alt_id: { dtype: "list" },
37
+ subset: { dtype: "list" },
38
+ replaced_by: { dtype: "list" },
39
+ consider: { dtype: "list" },
40
+ is_obsolete: { dtype: "bool" },
41
+ is_anonymous: { dtype: "bool" },
42
+ builtin: { dtype: "bool" },
43
+ created_by: { dtype: "string" },
44
+ creation_date: { dtype: "string" },
45
+ intersection_of: { dtype: "json" },
46
+ union_of: { dtype: "list" },
47
+ equivalent_to: { dtype: "list" },
48
+ disjoint_from: { dtype: "list" },
49
+ property_value: { dtype: "json" },
50
+ // Typedef frames, under typedefs: "nodes"
51
+ domain: { dtype: "string" },
52
+ range: { dtype: "string" },
53
+ inverse_of: { dtype: "string" },
54
+ transitive_over: { dtype: "list" },
55
+ disjoint_over: { dtype: "list" },
56
+ holds_over_chain: { dtype: "json" },
57
+ equivalent_to_chain: { dtype: "json" },
58
+ expand_assertion_to: { dtype: "json" },
59
+ expand_expression_to: { dtype: "json" },
60
+ is_cyclic: { dtype: "bool" },
61
+ is_reflexive: { dtype: "bool" },
62
+ is_symmetric: { dtype: "bool" },
63
+ is_anti_symmetric: { dtype: "bool" },
64
+ is_asymmetric: { dtype: "bool" },
65
+ is_transitive: { dtype: "bool" },
66
+ is_functional: { dtype: "bool" },
67
+ is_inverse_functional: { dtype: "bool" },
68
+ is_metadata_tag: { dtype: "bool" },
69
+ is_class_level: { dtype: "bool" },
70
+ // OBO Graphs only
71
+ propertyType: { dtype: "dict" },
72
+ // what has no column of its own
73
+ "obo.qualifiers": { dtype: "json" },
74
+ "obo.unrecognized": { dtype: "json" },
75
+ });
76
+
77
+ /** The edge columns of the OBO vocabulary. */
78
+ const OBO_EDGE_COLUMNS: Readonly<Record<string, OboColumnSpec>> = Object.freeze({
79
+ relation: { dtype: "dict", role: "kind" },
80
+ qualifiers: { dtype: "json" },
81
+ meta: { dtype: "json" },
82
+ });
83
+
84
+ /** The node column that marks a node made for an undeclared reference (design section 4.2). */
85
+ export const PLACEHOLDER_COLUMN = "graphty.placeholder";
86
+
87
+ /**
88
+ * The declaration of an OBO vocabulary column.
89
+ * @param domain - node or edge
90
+ * @param name - the column name (a key of OBO_NODE_COLUMNS / OBO_EDGE_COLUMNS, or the placeholder column)
91
+ * @returns the declaration, nullable, with origin `{ format: "obo", id: name }`
92
+ */
93
+ export function oboColumnDecl(domain: "node" | "edge", name: string): ColumnDecl {
94
+ if (name === PLACEHOLDER_COLUMN) {
95
+ return { name, dtype: "bool", nullable: true, origin: { format: "graphty", id: "placeholder" } };
96
+ }
97
+ const spec = (domain === "node" ? OBO_NODE_COLUMNS : OBO_EDGE_COLUMNS)[name];
98
+ const decl: ColumnDecl = { name, dtype: spec.dtype, nullable: true, origin: { format: "obo", id: name } };
99
+ if (spec.dtype === "list") {
100
+ decl.itemDtype = "string";
101
+ }
102
+ if (spec.role !== undefined) {
103
+ decl.role = spec.role;
104
+ }
105
+ return decl;
106
+ }
107
+
108
+ /** The OBO PURL base every OBO Foundry IRI starts with. */
109
+ const OBO_PURL = "http://purl.obolibrary.org/obo/";
110
+
111
+ /** The oboInOwl namespace of the OBO-to-OWL mapping's annotation properties. */
112
+ const OBO_IN_OWL = "http://www.geneontology.org/formats/oboInOwl#";
113
+
114
+ /**
115
+ * An IRI as the identifier the `.obo` file writes (the OBO 1.4 mapping, section 5.9, read
116
+ * backwards): `http://purl.obolibrary.org/obo/GO_0008150` is `GO:0008150` (the prefix is the text
117
+ * before the first underscore), and `http://purl.obolibrary.org/obo/go#regulates` (how the OWL
118
+ * translation writes an unprefixed OBO id: subsets, relations, synonym types) is `regulates`.
119
+ * Every other IRI, and an OBO PURL that fits neither form (`.../obo/T/Female`), is kept.
120
+ * @param iri - the IRI
121
+ * @returns the CURIE or local id, or the IRI unchanged
122
+ */
123
+ export function compactOboIri(iri: string): string {
124
+ if (!iri.startsWith(OBO_PURL)) {
125
+ return iri;
126
+ }
127
+ const rest = iri.slice(OBO_PURL.length);
128
+ const hash = rest.indexOf("#");
129
+ if (hash > 0) {
130
+ const local = rest.slice(hash + 1);
131
+ return local.length > 0 && !rest.slice(0, hash).includes("/") ? local : iri;
132
+ }
133
+ const underscore = rest.indexOf("_");
134
+ if (underscore <= 0 || rest.includes("/") || underscore === rest.length - 1) {
135
+ return iri;
136
+ }
137
+ return `${rest.slice(0, underscore)}:${rest.slice(underscore + 1)}`;
138
+ }
139
+
140
+ /** The OBO synonym scopes. */
141
+ export const SYNONYM_SCOPES: ReadonlySet<string> = new Set(["EXACT", "BROAD", "NARROW", "RELATED"]);
142
+
143
+ /**
144
+ * The OBO synonym scope of an OBO Graphs synonym predicate (`hasExactSynonym`, with or without the
145
+ * oboInOwl namespace).
146
+ * @param pred - the predicate
147
+ * @returns the scope, or null for a predicate that is not one of the four
148
+ */
149
+ export function synonymScopeOf(pred: string): string | null {
150
+ const local = pred.startsWith(OBO_IN_OWL) ? pred.slice(OBO_IN_OWL.length) : pred;
151
+ const match = /^has(Exact|Broad|Narrow|Related)Synonym$/.exec(local);
152
+ return match === null ? null : match[1].toUpperCase();
153
+ }
154
+
155
+ /**
156
+ * The OBO tag a `basicPropertyValues` predicate of OBO Graphs came from (the OBO-to-OWL mapping of
157
+ * the tags that are annotations), so the `.json` of an ontology fills the same columns as its
158
+ * `.obo`. `shorthand` is the relation's short name; every predicate not listed is a
159
+ * `property_value`.
160
+ */
161
+ export const OBOGRAPHS_PREDICATE_TAGS: ReadonlyMap<string, string> = new Map([
162
+ [`${OBO_IN_OWL}hasOBONamespace`, "namespace"],
163
+ [`${OBO_IN_OWL}hasAlternativeId`, "alt_id"],
164
+ [`${OBO_IN_OWL}created_by`, "created_by"],
165
+ [`${OBO_IN_OWL}creation_date`, "creation_date"],
166
+ [`${OBO_PURL}IAO_0100001`, "replaced_by"],
167
+ [`${OBO_IN_OWL}consider`, "consider"],
168
+ [`${OBO_IN_OWL}shorthand`, "shorthand"],
169
+ ]);