# Seurat

#### Check number of genes per cell and number of cells per gene

```
selected_c <- WhichCells(alldata, expression = nFeature_RNA > 200)
selected_f <- Matrix::rowSums(x = scRNA_obj[["RNA"]]@counts > 0) >= 100
scRNA_obj = scRNA_obj[selected_f,]
# check min number of cells expressed across all genes
min(Matrix::rowSums(x = scRNA_obj[["RNA"]]@counts > 0))
```

#### Convert h5ad to Seurat

```
library(reticulate)
library(Seurat)
sc = import("scanpy")
data <- sc$read_h5ad("RCC_upload_final_raw_counts.h5ad")
british_count_csc = data$X$transpose()
british_count_csc = british_count_csc$tocsc()

csc_to_dgc <- function(x) {
  new(
    "dgCMatrix",
    i = as.integer(reticulate:::as_r_value(x$indices)),
    p = as.integer(reticulate:::as_r_value(x$indptr)),
    x = as.vector(reticulate:::as_r_value(x$data)),
    Dim = as.integer(x$shape)
  )
  
}
british_count_dgc = csc_to_dgc(british_count_csc)
colnames(british_count_dgc) <- data$obs_names$to_list()
rownames(british_count_dgc) <- data$var_names$to_list()
# Create the Seurat object
british_seurat <- CreateSeuratObject(british_count_dgc, metadata = data$obs)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://juechen-yang.gitbook.io/juechen-s-codebook/seurat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
