add function to read adat files into widely used AnnData object#11
add function to read adat files into widely used AnnData object#11gitbenlewis wants to merge 2 commits intoSomaLogic:mainfrom
Conversation
read_adat_2_AnnData()
Returns an adata object instead a somalogic adat file path from the filepath/name.
Parameters
----------
path_or_buf : Union[str, TextIO]
Path or buffer that the file will be read from
Examples
--------
>>> adata=read_adat_2_AnnData(example_data_file)
Returns
-------
adata object instead of : Adat object
add function to read read adat files into widely used AnnData object
|
Hi @MegaDesk! First, thank you for your contribution! To maintain a lightweight codebase, we would prefer to avoid introducing additional dependencies, such as import somadata as sd
import anndata as ad
adat = sd.read_adat("tests/data/control_data.adat")
row_metadata = {name: adat.index.get_level_values(name).tolist() for name in adat.index.names}
column_metadata = {name: adat.columns.get_level_values(name).tolist() for name in adat.columns.names}
header_metadata = {key: str(value) for key, value in adat.header_metadata.items()}
adata = ad.AnnData(X = adat.values, obs = row_metadata, var = column_metadata, uns = header_metadata)Alternatively, I updated the code (1.2.0) to streamline using from somadata import parse_file
import anndata as ad
import numpy as np
rfu_matrix, row_metadata, column_metadata, header_metadata = parse_file("tests/data/control_data.adat", compatibility_mode=True)
adata = ad.AnnData(X = np.array(rfu_matrix), obs = row_metadata, var = column_metadata, uns = header_metadata)Please reach out if there's any questions. Happy to discuss further! |
|
Hi @kyoung73 , Yes these are all workable solutions to access the somadata.io.adat.file.parse_file() function. I look forward to the addition of AnnData as an optional dependency. It is a perfect for this type of data (feature matrix with row/column metadata). The multi index panda dataframe based object is not very end-user friendly in comparison to operations on an Anndata object. Also storing the the data matrix and column/row metadata in Anndata object would remove the need for most of the helper functions in the somadata code base. |
add function to read adat files into widely used AnnData object
read_adat_2_AnnData()
Returns an adata object instead a somalogic adat file path from the filepath/name.
Parameters
----------
path_or_buf : Union[str, TextIO]
Path or buffer that the file will be read from
Examples
--------
>>> adata=read_adat_2_AnnData(example_data_file)
Returns
-------
adata object instead of : Adat object