Filter loom file using cell ids in R using seurat.disk or with loompy in python
1
3
Entering edit mode
3.1 years ago
ZheFrench ▴ 590

Trying to filter loom file in R.

I have done analysis with seurat and trying to add another layer with velocity analysis scvelo (python). I could probably also do it in python with loompy library. From what I saw, the velocity analysis start from the 10x directory but I have already filtered seurat object and save it in an rds file. I have a list of ids in a csv files. I want only use these cells for the analysis of velocity.

I'm using ReadVelocity to read the loom file and then convert to seurat but then I'm trying to subset the object .

I'm trying to keep only the cells I previously kept after cleaning by mito and ribo thresholds in seurat saving into rds and exported in csv file...

But loom file come into the game and it's not fun.

Any help would be welcome. Thanks.

ldat <- ReadVelocity(file = "data.loom")
bm <- as.Seurat(x = ldat)

ids <- read.csv(file = 'daata_cellID_obs.csv', header = TRUE)

bm[["RNA"]] <- bm[["spliced"]]
dim(ids)
colnames(ids) <- "cells" 
dim(bm)
bm <- subset(object = bm, cells = ids$cells)

It says "argument x is missing with no default value."

[1] 11178 1 [1] 33694 12011 Error in UpdateSlots(object = x) :
l'argument "x" est manquant, avec aucune valeur par défaut Calls: subset ... subset.Seurat -> UpdateSlots -> sapply -> lapply -> slotNames -> is Exécution arrêtée

loompy cells single seurat • 3.0k views
ADD COMMENT
3
Entering edit mode
3.1 years ago
ZheFrench ▴ 590

Finally end up with the python way.

import numpy as np
import pandas as pd

from anndata import AnnData
from scanpy import read

import scvelo as scv

import loompy

# export HDF5_USE_FILE_LOCKING='FALSE'
# ssh -X

print("sample_obs")
sample_obs    = pd.read_csv("/data/villemin/data/toulouse/scRNA-ALL/CellRanger/clusters/4006_rouge.4006_verte.CTL_Rouges.CTL_Vertes_cellID_obs.csv")
sample_obs.rename(columns={'Cells(seurat.Object)':'CellID'}, inplace=True )

sample_obs['CellID'] = sample_obs['CellID'].str[::-1]
sample_obs['CellID'] = sample_obs['CellID'].str.replace('_',':',1)
sample_obs['CellID'] = sample_obs['CellID'].str[::-1]
sample_obs['CellID'] = sample_obs['CellID'].str.replace('-1','x')

print(sample_obs.head())


filename = "/data/villemin/code/singleCell/python/4006_CTL_OSI.loom"
outputname = "/data/villemin/code/singleCell/python/4006_CTL_OSI.filtered.loom"

with loompy.connect(filename) as ds:
    view = ds.view[:, np.isin(ds.ca.CellID, sample_obs['CellID'])]

loompy.create(outputname, view.layers, view.ra, view.ca)
ADD COMMENT
0
Entering edit mode

Hello @ZheFrench, Thank you for posting the solution. I have a question regarding analysis of RNA velocity by using 'velocyto' and 'scvelo'. I have ran the pipeline of seurat to get the seuratobject. I used 'loomR' package to convert seuratobject into loom file. However, when I tried to run the following codes given in vignette http://htmlpreview.github.io/?https://github.com/satijalab/seurat-wrappers/blob/master/docs/scvelo.html , it gave me an error. I found another method -

But this particular method indicate to convert human genome gtf file to convert into spliced and unspliced loom files. I am confused now. Could you please help me with this issue? Thank you in advance.

ADD REPLY

Login before adding your answer.

Traffic: 2402 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6