X_to_mtx

besca.export.X_to_mtx(adata: AnnData, outpath: Optional[str] = None, write_metadata: bool = False, geneannotation: str = 'SYMBOL', additional_geneannotation: str = 'ENSEMBL') None[source]

export adata object to mtx format (matrix.mtx, genes.tsv, barcodes.tsv)

exports the counts contained in adata.X to a matrix.mtx file (in sparse format), genes taken from adata.var_names (and if applicable adata.var) to genes.tsv and the cellbarcodes from adata.obs_names to barcodes.tsv. If annotation = True, then the entire pd.Dataframe contained in adata.obs is in addition exported to metadata.tsv. Through the parameter geneannotation you can specify which type of geneidentifer is saved in adata.var_names. You can pass an additional string to the parameter additional_geneannotation which specifies under which column name in adata.var an additional geneannotation can be found. Currently this function is only capable of dealing with geneannotation of the type ENSEMBL or SYMBOL. This feature is intended to conserve the correct order of ENSEMBL IDs and SYMBOLS in the genes.tsv file. If the outpath directory does not exist, this function automatically generates it.

Parameters:
  • adata (AnnData) – the AnnData object that should be exported

  • directory (outpath str | default = current working) – filepath to the directory in which the results should be outputed, if no directory is specified it outputs the results to the current working directory.

  • write_metadata (bool | default = False) – boolian indicator if the annotation contained in adata.obs should be exported as well

  • geneannotation (‘ENSEMBL’ or ‘SYMBOL’) – string indicator of the type of gene annotation saved in adata.var_names

  • additional_geneannotation (str | default = None) – string identifying the coloumn name in which either the SYMBOL or the ENSEMBL geneids are contained as additional gene annotation in adata.var

Returns:

writes out files to the specified output directory

Return type:

None