Document¶
OboDoc
¶
-
class
fastobo.doc.
OboDoc
(header=None, entities=None)¶ The abstract syntax tree corresponding to an OBO document.
- Parameters
header (HeaderFrame, optional) – the header to use in the document. If
None
is given, an empty header is used instead.entities (collections.abc.Iterable, optional) – an iterable of entity frames, either
TermFrame
,TypedefFrame
orInstanceFrame
.
-
__getitem__
(key, /)¶ Return self[key].
-
__len__
()¶ Return len(self).
-
__new__
(**kwargs)¶ Create and return a new object. See help(type) for accurate signature.
-
__str__
()¶ Return str(self).
-
append
(object)¶ Append object to the end of the list.
- Raises
TypeError – when the object is not of the right type for this container (see type-level documentation for the required type).
-
clear
()¶ Remove all items from list.
-
compact_ids
()¶ Create a semantically equivalent OBO document with compact identifiers.
The OBO specification describes how to perform an URI decompaction using either ID spaces declared in the document header, builtin ID spaces, or a default rule using the
purl.obolibrary.org
domain. By applying the reverse operation, a new ontology can be created with compact identifiers. Some URLs may not have a compact representation if they don’t correspond to any decompaction rule.Example
>>> doc = fastobo.loads(textwrap.dedent( ... """ ... idspace: MassBank http://www.massbank.jp/jsp/FwdRecord.jsp?id= ... ... [Term] ... id: http://purl.obolibrary.org/obo/CHEBI_27958 ... xref: http://www.massbank.jp/jsp/FwdRecord.jsp?id=EA281701 ... """ ... )) >>> compact_doc = doc.compact_ids() >>> print(compact_doc[0]) [Term] id: CHEBI:27958 xref: MassBank:EA281701
See also
The Translation of Identifiers section of the OBO format version 1.4 specification.
-
copy
()¶ Return a shallow copy of the list.
-
count
(value)¶ Return number of occurrences of value.
- Raises
TypeError – when the object is not of the right type for this container (see type-level documentation for the required type).
-
decompact_ids
()¶ Create a semantically equivalent OBO document with IRI identifiers.
The OBO specification describes how to perform an URI decompaction using either ID spaces declared in the document header, builtin ID spaces, or a default rule using the
purl.obolibrary.org
domain.Example
>>> doc = fastobo.loads(textwrap.dedent( ... """ ... idspace: MassBank http://www.massbank.jp/jsp/FwdRecord.jsp?id= ... ... [Term] ... id: CHEBI:27958 ... xref: MassBank:EA281701 ... """ ... )) >>> url_doc = doc.decompact_ids() >>> print(url_doc[0]) [Term] id: http://purl.obolibrary.org/obo/CHEBI_27958 xref: http://www.massbank.jp/jsp/FwdRecord.jsp?id=EA281701
See also
The Translation of Identifiers section of the OBO format version 1.4 specification.
-
header
¶ the header containing ontology metadata.
- Type
-
insert
(index, object)¶ Insert
object
beforeindex
.If
index
is greater than the number of elements in the list,object
will be added at the end of the list.
-
pop
(index=- 1)¶ Remove and return item at index (default last).
- Raises
IndexError – when list is empty or index is out of range.
-
reverse
()¶ Reverse IN PLACE.