Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue convert anndata to seurat object #21

Open
djlisko01 opened this issue Sep 27, 2023 · 0 comments
Open

Issue convert anndata to seurat object #21

djlisko01 opened this issue Sep 27, 2023 · 0 comments

Comments

@djlisko01
Copy link

hello all,

I've written the following code reference your youtube video:

However I get the following error when I try to load it into R using using Read10X from seurat:

Error in readMM(file = matrix.loc) :
'readMM()' is not yet implemented for representation 'array'

Any help is greatly appreciated!

Here's the code I wrote based on the youtube video (note I've tried different formats for the sparse matrix - int, int64, etc.)

  • See attached file for reference

 @staticmethod
    def create_10x_files(adata, dir, raw_layer):
        RhapsodyReader.create_barcodes_table(adata=adata, save_path=f"{dir}/barcodes.tsv")
        RhapsodyReader.create_features_table(adata, f"{dir}/features.tsv")
        RhapsodyReader.create_matrix(adata, f"{dir}/matrix.mtx", layer=raw_layer)
        # RhapsodyReader.gzip_files_in_directory(dir)

    
    @staticmethod
    def create_matrix(adata, save_path, layer=None):
        if layer:
            matrix = adata.layers[layer].T
        else:
            matrix = adata.X.T
            
        io.mmwrite(save_path, matrix.astype(np.int64))

    @staticmethod
    def create_barcodes_table(adata, save_path):
        with open(save_path, "w") as file:
            for item in adata.obs_names:
                file.write(item + "\n")
    
    @staticmethod
    def create_features_table(adata, save_path):
        tab_var_names = ["\t".join([x, x, "Gene Expression"]) for x in adata.var_names]

        with open(save_path, "w") as file:
            for var_name in tab_var_names:
                file.write(var_name + "\n")

matrix.mtx.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant