Skip to content

Commit efcdf7c

Browse files
Merge pull request #1270 from gouttegd/fix-prefix-injection-in-obo
Partially fix prefix injection when writing to OBO.
2 parents 09f568a + 72e61b4 commit efcdf7c

File tree

4 files changed

+162
-3
lines changed

4 files changed

+162
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Fixed
1414
- Inherit OWLDocumentFormat when performing SPARQL update [#1267]
1515
- Updated obographs to [version 0.3.2](https://github.com/geneontology/obographs/releases/tag/v0.3.2)
16+
- Partial fix for prefix injections in OBO files [#1268]
1617

1718
## [1.9.8] - 2025-05-15
1819

docs/convert.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ In addition, the following special keywords are also accepted:
4848
- `true`: alias for `strict`.
4949
- `simple`: equivalent to `strict drop-untranslatable-axioms drop-gci-axioms`, to force the production of an OBO file that is not only valid, but also free of any `owl-axioms` header tag and GCI axioms (which, while perfectly valid with respect to the OBO specification, are not always handled correctly by all OBO parsers).
5050

51+
Of note, currently using the `--clean-obo` option is the only way to inject prefixes into an OBO file. The `--add-prefix` option has no effect when the ontology is saved to OBO without `--clean-obo`.
52+
5153
#### Examples
5254

5355
Convert a file to OBO and ensure the resulting file is compliant with the OBO specification, dropping supernumerary annotations if necessary:
@@ -68,6 +70,13 @@ Convert a file to a simple variant of the OBO format (without any `owl-axioms` t
6870
--clean-obo simple \
6971
--output results/cl_module-simple.obo
7072

73+
Convert a file to a simple variant of the OBO format while adding a custom prefix:
74+
75+
robot convert -i cl_module.ofn \
76+
--add-prefix "myp: https://example.org/myp_" \
77+
--clean-obo simple \
78+
--output results/cl_module-simple-with-added-prefix.obo
79+
7180
---
7281

7382
## Error Messages
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
format-version: 1.2
2+
idspace: myp https://example.org/myp_
3+
ontology: cl
4+
5+
[Term]
6+
id: CL:0000000
7+
name: cell
8+
def: "A material entity of anatomical origin (part of or deriving from an organism) that has as its parts a maximally connected cell compartment surrounded by a plasma membrane." [CARO:mah]
9+
comment: The definition of cell is intended to represent all cells, and thus a cell is defined as a material entity and not an anatomical structure, which implies that it is part of an organism (or the entirety of one).
10+
is_a: UBERON:0000061 ! anatomical structure
11+
12+
[Term]
13+
id: CL:0000113
14+
name: mononuclear phagocyte
15+
def: "A vertebrate phagocyte with a single nucleus." [GOC:add, GOC:tfm, ISBN:0781735149]
16+
is_a: CL:0000842 ! mononuclear cell
17+
property_value: RO:0002175 NCBITaxon:9606
18+
19+
[Term]
20+
id: CL:0000235
21+
name: macrophage
22+
def: "A mononuclear phagocyte present in variety of tissues, typically differentiated from monocytes, capable of phagocytosing a variety of extracellular particulate material, including immune complexes, microorganisms, and dead cells." [GO_REF:0000031, GOC:add, GOC:tfm, PMID:16213494, PMID:1919437]
23+
comment: Morphology: Diameter 30_M-80 _M, abundant cytoplasm, low N/C ratio, eccentric nucleus. Irregular shape with pseudopods, highly adhesive. Contain vacuoles and phagosomes, may contain azurophilic granules; markers: Mouse & Human: CD68, in most cases CD11b. Mouse: in most cases F4/80+; role or process: immune, antigen presentation, & tissue remodelling; lineage: hematopoietic, myeloid.
24+
synonym: "histiocyte" EXACT []
25+
is_a: CL:0000113 ! mononuclear phagocyte
26+
property_value: RO:0002175 NCBITaxon:9606
27+
28+
[Term]
29+
id: CL:0000583
30+
name: alveolar macrophage
31+
def: "A tissue-resident macrophage found in the alveoli of the lungs. Ingests small inhaled particles resulting in degradation and presentation of the antigen to immunocompetent cells. Markers include F4/80-positive, CD11b-/low, CD11c-positive, CD68-positive, sialoadhesin-positive, dectin-1-positive, MR-positive, CX3CR1-negative." [GO_REF:0000031, GOC:ana, GOC:dsd, GOC:tfm, MESH:D016676]
32+
comment: Markers: Mouse: F4/80mid, CD11b-/low, CD11c+, CD68+, sialoadhesin+, dectin-1+, MR+, CX3CR1-.
33+
synonym: "dust cell" EXACT []
34+
synonym: "MF.Lu" RELATED []
35+
xref: FMA:83023
36+
is_a: CL:0000235 ! macrophage
37+
property_value: RO:0002175 NCBITaxon:9606
38+
39+
[Term]
40+
id: CL:0000738
41+
name: leukocyte
42+
def: "An achromatic cell of the myeloid or lymphoid lineages capable of ameboid movement, found in blood or other tissue." [GOC:add, GOC:tfm, ISBN:978-0-323-05290-0]
43+
synonym: "immune cell" RELATED []
44+
synonym: "leucocyte" EXACT []
45+
synonym: "white blood cell" EXACT []
46+
is_a: CL:0000988 ! hematopoietic cell
47+
property_value: RO:0002175 NCBITaxon:9606
48+
49+
[Term]
50+
id: CL:0000842
51+
name: mononuclear cell
52+
def: "A leukocyte with a single non-segmented nucleus in the mature form." [GOC:add]
53+
synonym: "mononuclear leukocyte" EXACT []
54+
synonym: "peripheral blood mononuclear cell" NARROW []
55+
is_a: CL:0000738 ! leukocyte
56+
intersection_of: CL:0000738 ! leukocyte
57+
intersection_of: bearer_of PATO:0001407 ! mononucleate
58+
relationship: bearer_of PATO:0001407 ! mononucleate
59+
relationship: has_part GO:0005634 ! nucleus
60+
61+
[Term]
62+
id: CL:0000988
63+
name: hematopoietic cell
64+
def: "A cell of a hematopoietic lineage." [GO_REF:0000031, GOC:add]
65+
synonym: "haematopoietic cell" EXACT []
66+
synonym: "hemopoietic cell" EXACT []
67+
is_a: CL:0000000 ! cell
68+
69+
[Term]
70+
id: GO:0005634
71+
name: nucleus
72+
namespace: cellular_component
73+
def: "A membrane-bounded organelle of eukaryotic cells in which chromosomes are housed and replicated. In most cells, the nucleus contains all of the cell's chromosomes except the organellar chromosomes, and is the site of RNA synthesis and processing. In some species, or in specialized cell types, RNA metabolism or DNA replication may be absent." [GOC:go_curators]
74+
synonym: "cell nucleus" EXACT []
75+
synonym: "horsetail nucleus" NARROW [GOC:al, GOC:mah, GOC:vw, PMID:15030757]
76+
is_a: UBERON:0000061 ! anatomical structure
77+
relationship: has_part UBERON:0000061 ! anatomical structure
78+
79+
[Term]
80+
id: PATO:0001407
81+
name: mononucleate
82+
namespace: quality
83+
def: "A nucleate quality inhering in a bearer by virtue of the bearer's having one nucleus." [Biology-online:Biology-online]
84+
subset: cell_quality
85+
subset: mpath_slim
86+
subset: value_slim
87+
88+
[Term]
89+
id: PATO:0010006
90+
name: cell morphology
91+
namespace: quality
92+
def: "A quality of a single cell inhering in the bearer by virtue of the bearer's size or shape or structure." [https://orcid.org/0000-0002-7073-9172]
93+
comment: Use this term for morphologies that can *only* inhere in a cell, e.g. morphological qualities inhering in a cell by virtue of the presence, location or shape of one or more cell parts.
94+
property_value: http://purl.org/dc/terms/contributor https://orcid.org/0000-0002-7073-9172
95+
creation_date: 2021-01-23T11:31:53Z
96+
97+
[Term]
98+
id: UBERON:0000061
99+
name: anatomical structure
100+
namespace: uberon
101+
def: "Material anatomical entity that is a single connected structure with inherent 3D shape generated by coordinated expression of the organism's own genome." [CARO:0000003]
102+
synonym: "biological structure" EXACT []
103+
synonym: "connected biological structure" EXACT [CARO:0000003]
104+
is_a: UBERON:0000465 ! material anatomical entity
105+
property_value: RO:0002175 NCBITaxon:33090
106+
property_value: RO:0002175 NCBITaxon:33208
107+
property_value: RO:0002175 NCBITaxon:4751
108+
109+
[Term]
110+
id: UBERON:0000465
111+
name: material anatomical entity
112+
namespace: uberon
113+
def: "Anatomical entity that has mass." [http://orcid.org/0000-0001-9114-8737]
114+
is_a: UBERON:0001062 ! anatomical entity
115+
property_value: RO:0002175 NCBITaxon:33090
116+
property_value: RO:0002175 NCBITaxon:33208
117+
property_value: RO:0002175 NCBITaxon:4751
118+
119+
[Term]
120+
id: UBERON:0001062
121+
name: anatomical entity
122+
namespace: uberon
123+
def: "Biological entity that is either an individual member of a biological species or constitutes the structural organization of an individual member of a biological species." [FMA:62955, http://orcid.org/0000-0001-9114-8737]
124+
property_value: RO:0002175 NCBITaxon:33090
125+
property_value: RO:0002175 NCBITaxon:33208
126+
property_value: RO:0002175 NCBITaxon:4751
127+
128+
[Typedef]
129+
id: bearer_of
130+
name: has characteristic
131+
namespace: external
132+
def: "Inverse of characteristic_of" []
133+
xref: RO:0000053
134+
is_inverse_functional: true
135+
136+
[Typedef]
137+
id: has_part
138+
name: has part
139+
namespace: external
140+
def: "a core relation that holds between a whole and its part" []
141+
subset: http://purl.obolibrary.org/obo/valid_for_go_annotation_extension
142+
subset: http://purl.obolibrary.org/obo/valid_for_go_ontology
143+
subset: http://purl.obolibrary.org/obo/valid_for_gocam
144+
xref: BFO:0000051
145+
is_transitive: true
146+

robot-core/src/main/java/org/obolibrary/robot/IOHelper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ private byte[] getOntologyFileData(
17801780
String doc = OgJsonGenerator.render(gd);
17811781
data = doc.getBytes();
17821782
} else if (format instanceof OBODocumentFormat && (!checkOBO || !cleanOBO.isEmpty())) {
1783-
OBODoc oboOntology = makeCleanOBODocument(ontology, cleanOBO);
1783+
OBODoc oboOntology = makeCleanOBODocument(ontology, cleanOBO, format);
17841784
ByteArrayOutputStream baos = new ByteArrayOutputStream();
17851785
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(baos))) {
17861786
OBOFormatWriter oboWriter = new OBOFormatWriter();
@@ -1915,7 +1915,7 @@ private void saveOntologyFile(
19151915
} else if (format instanceof OBODocumentFormat && !cleanOBO.isEmpty()) {
19161916
// OBO format can be handled natively by the OWLAPI ontology manager, but in "clean" mode we
19171917
// need to call the OBO converter ourselves
1918-
OBODoc oboDoc = makeCleanOBODocument(ontology, cleanOBO);
1918+
OBODoc oboDoc = makeCleanOBODocument(ontology, cleanOBO, format);
19191919
OBOFormatWriter oboWriter = new OBOFormatWriter();
19201920
oboWriter.setCheckStructure(checkOBO);
19211921
oboWriter.write(oboDoc, new File(ontologyIRI.toURI()));
@@ -1986,9 +1986,11 @@ private void saveCompressedOntology(byte[] data, IRI ontologyIRI) throws IOExcep
19861986
*
19871987
* @param ontology the ontology to convert
19881988
* @param options option set dictating what should be cleaned in the ontology
1989+
* @param format the OWL document format to save in
19891990
* @return the resulting OBO document
19901991
*/
1991-
private OBODoc makeCleanOBODocument(OWLOntology ontology, EnumSet<OBOWriteOption> options) {
1992+
private OBODoc makeCleanOBODocument(
1993+
OWLOntology ontology, EnumSet<OBOWriteOption> options, OWLDocumentFormat format) {
19921994
if (options.contains(OBOWriteOption.DROP_GCI_AXIOMS)) {
19931995
Set<OWLClassAxiom> gciAxioms = ontology.getGeneralClassAxioms();
19941996
if (!gciAxioms.isEmpty()) {
@@ -2021,6 +2023,7 @@ private OBODoc makeCleanOBODocument(OWLOntology ontology, EnumSet<OBOWriteOption
20212023
OWLAPIOwl2Obo oboConverter = new OWLAPIOwl2Obo(ontology.getOWLOntologyManager());
20222024
oboConverter.setDiscardUntranslatable(
20232025
options.contains(OBOWriteOption.DROP_UNTRANSLATABLE_AXIOMS));
2026+
oboConverter.setPrefixManager(format.asPrefixOWLOntologyFormat());
20242027
return oboConverter.convert(ontology);
20252028
}
20262029
}

0 commit comments

Comments
 (0)