Convert h5ad anndata to a Seurat single-cell R object

  Рет қаралды 10,464

Sanbomics

Sanbomics

Күн бұрын

Пікірлер: 48
@ylg9025
@ylg9025 6 ай бұрын
have been searching this for days! you are my life saver!
@sanbomics
@sanbomics 2 ай бұрын
There are a bunch of ways to do it at this point that all are kind of just bad. If your data are small the easiest way is probably just to save it as a csv
@scott12
@scott12 2 жыл бұрын
This is exactly what I need! thank you dude, you saved my day :D
@sanbomics
@sanbomics 2 жыл бұрын
No problem! All existing methods seem to have some sort of issue and/or overly complicated
@karlacatacora235
@karlacatacora235 Жыл бұрын
Omg finally a clear and easy to understand answer !! thanks :)
@sanbomics
@sanbomics Жыл бұрын
Glad it helped!
@sanbomics
@sanbomics Жыл бұрын
Although the best solution is just to do your analysis in Python xD
@ilyasimutin
@ilyasimutin 2 жыл бұрын
I am wondering if it's possible to include in the metadata the scores for scvi and umap (stored in the .obsm slot)? And then run the umap plots (and clustering) in seurat on the same latent space coordinates? Thanks again!
@sanbomics
@sanbomics 2 жыл бұрын
Hmm I haven't tried it... but that is an interesting question. I bet there is a way. It might be easier to run umap in scanpy then save the x,y coordinates as a csv and save it to the seurat UMAP slot.
@ilyasimutin
@ilyasimutin 2 жыл бұрын
@@sanbomics yes, exactly. That's what I am thinking about. How to add these coordinates to metadata csv and then plot in Seurat...
@takhoa5302
@takhoa5302 2 жыл бұрын
Hi llia Simutin, I have a same question like yours. Have you solved it? Thank you
@bowenJiang-h7n
@bowenJiang-h7n Жыл бұрын
I got the same problem .read10x get an error Error in scan(file, nmax = 1, what = what, quiet = TRUE, ...) :scan() expected 'an integer', got '0.00000000e+00'. I found that after 'sc.pp.scale' adata.X will convert to array , rather than the oridinary sparse matrix
@sanbomics
@sanbomics Жыл бұрын
It might be better to break it down and sending it over via rpy2 and anndata2ri. This is my preferred method now
@sarahbonnin3410
@sarahbonnin3410 Жыл бұрын
Thank you, that was very useful!
@sanbomics
@sanbomics Жыл бұрын
No problem!
@valilali7084
@valilali7084 10 ай бұрын
Hi thanks for the tutorial! Is there also a way to keep the workflow that was done (preprocessing, normalization, dimensionality reduction and clustering)? Or do you always have to redo this once you create a Seurat Object?
@marwanmohamed3844
@marwanmohamed3844 2 жыл бұрын
please keep going and keep posting vidios u are amazing, thanks alot it would be great to descripe how to convert from seurat to scanpy because it seems impossible to me to do it
@sanbomics
@sanbomics 2 жыл бұрын
Thank you! Hmm, may be easiest way if it is the raw data would just to be to save it as a csv then open it in scanpy with a .T to transpose
@MrMadcaw
@MrMadcaw Жыл бұрын
When I try to read the files in R using read10x i always get an error Error in scan(file, nmax = 1, what = what, quiet = TRUE, ...) :scan() expected 'an integer', got '0.00000000e+00'. what can I do?
@sanbomics
@sanbomics Жыл бұрын
hmm, you can try converting the matrix to int. Something like astype(int). Before saving it. I've never had this issue though.
@hadijatmakinde1643
@hadijatmakinde1643 2 жыл бұрын
This was very helpful! Thank you so much. For some reason, I am stuck at the -io.mmwrite('matrix_files/matrix', adata.X.T)- step. My kernel just says busy. I have restarted the kernel but no luck. Any tips?
@hadijatmakinde1643
@hadijatmakinde1643 2 жыл бұрын
Nevermind, it was just such a large file that it took a while. Thank you again for this helpful tutorial.
@sanbomics
@sanbomics 2 жыл бұрын
No problem! Haha, yeah that happens to me sometimes too: "is it broken or is it just taking forever?"
@dhkwnr97
@dhkwnr97 2 жыл бұрын
What a really nice tip!
@sanbomics
@sanbomics 2 жыл бұрын
Thank you!
@alicetownsend-q5y
@alicetownsend-q5y Жыл бұрын
is there a way to do this but using the normalized matrix? or integrated matrix? instead of the raw
@sanbomics
@sanbomics Жыл бұрын
Yes, this video is a little outdated now. You can use something like anndata2ri and rpy2 to pass the components to R and construct them into a seurat object
@stefisjustthebest
@stefisjustthebest Жыл бұрын
Could you do a video on this?! Ive so far managed to get the h5ad file into a SCE using anndata2ri...
@Reza_Ghamsari
@Reza_Ghamsari Жыл бұрын
Do you have any suggestion how I can convert multiome .h5ad to a Seurat object? Thank you
@sanbomics
@sanbomics Жыл бұрын
I haven't done it, but it might involve breaking it down and sending it over via rpy2 and anndata2ri This video is a little outdated per how i convert now using the above steps. If you want an example: check out my most recent video (ambient rna) I break something down and send it to R from python
@Reza_Ghamsari
@Reza_Ghamsari Жыл бұрын
@@sanbomics Thank you.
@oliviaringham8706
@oliviaringham8706 2 жыл бұрын
Is there a way to convert an RDS to an h5ad object? been trying to do this without good results
@sanbomics
@sanbomics 2 жыл бұрын
Yeah "theoretically" there is. But when I go to use seuratDisk or any of those things I always have issues. I think the best way is to do something similar to this where you export the underlying data. Scanpy can read even a csv table that is genes x cells and then you can read in metadata directly as a pandas dataframe into the obs slot. I've never tried it though
@bioinfo3
@bioinfo3 Жыл бұрын
Could you please do the same for converting a R object (Seurat or SingleCellExperiment) to a h5ad anndata object? The tools out there are not good at doing this smoothly (Ive tried a lot of them!).
@sanbomics
@sanbomics Жыл бұрын
save the counts and metadata as a csv if the dataset isn't too large and just read it into scanpy like that
@sanbomics
@sanbomics Жыл бұрын
but transpose the counts
@bioinfo3
@bioinfo3 Жыл бұрын
@@sanbomics with scanpy "scanpy.read_csv()" ? can both df's be read in in 1 function call?
@wangmengfei5462
@wangmengfei5462 Жыл бұрын
Thank you for your excellent work! I was stopped at : io.mmwrite('matrix_files/matrix', adata.X.T) The error message is : AttributeError: Module 'scipy' has no attribute 'mmwrite'. I changed the version as :python=3.9, scipy=1.11.1, numpy=1.24. But it didn't work. Could you please give me some help? Thank you for your work and help.
@wangmengfei5462
@wangmengfei5462 Жыл бұрын
Finally it works. I think it's not because of the version, but the deficiency of package "scvelo". I found another similar video, and use: import numpy as np import pandas as pd import matplotlib.pyplot as pl import scanpy as sc import igraph import scvelo as scy import loompy as lmp import anndata from scipy import io from scipy.sparse import coo_matrix,csr_matrix import os After this step, it remindered me to download package "scvelo". And then, it works well. Actually, I still don't kwon why it didn't work, and how could I find the right way to work it out. :)
@sanbomics
@sanbomics Жыл бұрын
Great, glad you were able to figure it out! Sometimes things just don't make sense xD
@68ai
@68ai Жыл бұрын
I am new to scRNAseq and your videos are great. I am tasked with converting h5ad to Seurat and this video is very helpful. I was able to reproduce the example with the PBMC dataset from h5ad to Seurat object. But when I try it on a dataset from a publication, after I create the barcodes, features, and matrix file, the Seurat::Read10X returns a error: Error in scan(file, nmax = 1, what = what, quiet = TRUE, ...) : scan() expected 'an integer', got '0.00000000e+00' I know you are not a Seurat developer, but do you have any ideas why? As far as I can tell the matrix.mtx.gz isn't corrupted Thanks for any input .
@sanbomics
@sanbomics Жыл бұрын
Were the data the raw counts or normalized counts?
@68ai
@68ai Жыл бұрын
@@sanbomics raw counts ...
@68ai
@68ai Жыл бұрын
When I look at the matrix.mtx from the PBMC example I see the format as: %%MatrixMarket matrix coordinate real general % 13714 2638 2238732 30 1 1.6358733e+00 74 1 1.6358733e+00 81 1 2.2265546e+00 But the matrix.mtx file I generated in the same manner with my dataset of interest is : %%MatrixMarket matrix array real general % 27341 599926 0.00000000e+00 0.00000000e+00 0.00000000e+00 I"m pretty sure this why Seurat is throwing an error, but I can't figure out why my file is formatted like that.
@ilyasimutin
@ilyasimutin 2 жыл бұрын
Great, thank you!
@sanbomics
@sanbomics 2 жыл бұрын
No problem!
@anaburgos4969
@anaburgos4969 2 жыл бұрын
Thank you :D
@sanbomics
@sanbomics 2 жыл бұрын
No problem! I know its sad when we have to do something in R instead of python.. but it happens sometimes xD
Single-cell gene co-expression | single-cell RNAseq methods
5:59
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Single-cell gene set activity with AUCell
11:53
Sanbomics
Рет қаралды 6 М.
Introduction to single cell ATAC data analysis in R
17:36
Sanbomics
Рет қаралды 16 М.
Creating a Seurat Object from a GEO Dataset 📊
18:27
chatomics
Рет қаралды 3,1 М.
9 R packages that EVERY Data Scientist must know (in 9-minutes)
9:26
🔥 Matt Dancho 🔥 (Business Science)
Рет қаралды 5 М.
No Code Seurat Analysis | Azimuth First Look
14:42
LiquidBrain Bioinformatics
Рет қаралды 1,9 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН