API ¶
Data in Axes in Files.
This is a thin wrapper for the
DataAxesFormats.jl
Julia package, with the following adaptations:
-
In Julia, the API is defined as a set of functions, which take the
Dafobject as the 1st parameter. In Python, this is implemented as member functions of theDafReaderandDafWriterclasses that wrap the matching Julia objects (e.g., Julia’sget_vector(data, "gene", "is_marker")becomes Python’sdata.get_vector("gene", "is_marker"). -
Python doesn’t support the
!trailing character in function names (to indicate modifying the object), so it is removed from the wrapper Python method names (e.g., Julia’sset_vector!(data, "gene", "is_marker", mask)becomes Python’sdata.set_vector("gene", "is_marker", mask). -
Python wrappers for Julia functions that take a callback as their first parameter should be invoked using the
withstatement (e.g., Julia’sempty_dense_vector(data, "gene", "is_marker") do empty_vector ... endbecomes Python’swith data.empty_dense_vector("gene", "is_marker") as empty_vector: .... Since Python only allows a single parameter towithblocks, if Julia provides multiple such parameters (e.g.empty_sparse_*), they are packed in a tuple. -
Dense numeric data (that is,
np.ndarray) is passed as a zero-copy between Python and Julia. Passing anything else creates an in-memory copy. This, alas, includes sparse matrices, because Julia uses 1-based indices in the internal sparse representation, while Python uses zero-based indices (e.g Julia’scolptris equal to 1 plus Python’sindptr). This forces us to copy and increment/decrement these indices when passing the data between the languages. Also note that when invokingempty_sparse_*, you should fill the empty indices array(s) with Julia (1-based) values. -
Julia “likes” column-major matrices. All the matrices given to and returned by the API are therefore in column-major layout. In contrast, Python “likes” row-major matrices. To convert between the two, flip the order of the axes, and
transposethe data. This is a zero-copy view so is very efficient (e.g., to get a row-major UMIs matrix with a row per cell and a column per gene, writedata.get_np_matrix("gene", "cell", "UMIs").transpose()). -
Python has no notion of sparse vectors because “reasons”, while Julia (and R) sensibly do support them. Therefore reading a sparse Julia
Dafvector automatically converts it to a dense Pythonnumpyone. You can however still store sparse vectors from Python intoDafby passing a sparse matrix with a single row or column, or by callingempty_sparse_vector. -
Sparse matrices are not supported inside
pandas. Therefore reading sparseDafdata into apandasDataFrameautomatically converts it to a dense Pythonnumpymatrix. Therefore, you should take care not to ask for a data frame of a large sparse matrix (e.g., the UMIs matrix of a large data set), as this will consume a lot of memory.
Otherwise, the API works “just the same” :-) The documentation therefore mostly just links to the relevant entry in the Julia documentation .
- julia_import
-
data
-
DafReader-
DafReader.name -
DafReader.description() -
DafReader.has_scalar() -
DafReader.get_scalar() -
DafReader.scalars_set() -
DafReader.has_axis() -
DafReader.axes_set() -
DafReader.axis_length() -
DafReader.axis_np_vector() -
DafReader.axis_np_entries() -
DafReader.axis_dict() -
DafReader.axis_np_indices() -
DafReader.axis_pd_indices() -
DafReader.has_vector() -
DafReader.vectors_set() -
DafReader.get_np_vector() -
DafReader.get_pd_vector() -
DafReader.has_matrix() -
DafReader.matrices_set() -
DafReader.get_np_matrix() -
DafReader.get_pd_matrix() -
DafReader.empty_cache() -
DafReader.has_query() -
DafReader.get_np_query() -
DafReader.get_pd_query() -
DafReader.get_pd_frame() -
DafReader.read_only()
-
-
DafReadOnly -
DafWriter-
DafWriter.set_scalar() -
DafWriter.delete_scalar() -
DafWriter.add_axis() -
DafWriter.delete_axis() -
DafWriter.set_vector() -
DafWriter.empty_dense_vector() -
DafWriter.empty_sparse_vector() -
DafWriter.delete_vector() -
DafWriter.set_matrix() -
DafWriter.empty_dense_matrix() -
DafWriter.empty_sparse_matrix() -
DafWriter.relayout_matrix() -
DafWriter.delete_matrix()
-
-
CacheGroup
-
- reconstruction
- storage_types
- queries
- operations
- formats
- views
- copies
- adapters
- concat
- anndata_format
- generic_functions
- example_data