Files
cellxgene/backend/test/decode_fbs.py
Madison Dunitz 78c9d24ed4 Refactor czi_hosted and server into backend directory, pull common code into backend/common, refactor tests (#2102)
* move local_server -> backend/server server-> backend/czi_hosted, pull common code into backend/common update imports, tests and make commands
2021-03-26 00:27:07 -05:00

32 lines
1.0 KiB
Python

"""
Code to decode, for testing purposes, the flatbuffer encoded blobs.
This code will need to be updated if fbs/matrix.fbs changes. For more information, see fbs/matrix.fbs and
server/data_common/fbs/
"""
import backend.common.fbs.NetEncoding.Matrix as Matrix
from backend.common.fbs.matrix import deserialize_typed_array
def decode_matrix_FBS(buf):
"""
Given a FBS Matrix, return an decoded Python dict containing same info in native format.
NOTE / TODO: row_idx not currently implemented
"""
df = Matrix.Matrix.GetRootAsMatrix(buf, 0)
n_rows = df.NRows()
n_cols = df.NCols()
columns_length = df.ColumnsLength()
decoded_columns = []
for col_idx in range(0, columns_length):
col = df.Columns(col_idx)
tarr = (col.UType(), col.U())
decoded_columns.append(deserialize_typed_array(tarr))
cidx = deserialize_typed_array((df.ColIndexType(), df.ColIndex()))
return {"n_rows": n_rows, "n_cols": n_cols, "columns": decoded_columns, "col_idx": cidx, "row_idx": None}