aertslab / pySCENIC

pySCENIC is a lightning-fast python implementation of the SCENIC pipeline (Single-Cell rEgulatory Network Inference and Clustering) which enables biologists to infer transcription factors, gene regulatory networks and cell types from single-cell RNA-seq data.
http://scenic.aertslab.org
GNU General Public License v3.0
400 stars 176 forks source link

Import the aucell output file to R to visualize--resolved #300

Open Zymaniswenzai opened 3 years ago

Zymaniswenzai commented 3 years ago

Hi, Thank you for developing this great tool. And I need a little instruction in maybe the final step , after nearly a month of struggling, I finally got the output file through run these command lines:

!pyscenic aucell \
    {f_loom_path_scenic} \
    reg.csv \
    --output {f_pyscenic_output} \
    --num_workers 20

I got both.loom and .csv file. I checked the .csv file, it is like this: image

Can I get this type of picture from using this .csv file?

image

The official tutorial is really confusing to me, since I started doing analysis on PCs and servers using SCENIC R packages. But the slow speed and failure to find a solution later prompted me to start looking into Python code, even though I had never used Python. In the process of trying to meet the same problem with #294. but so far do not know the solution. I've switched to another approach, where the code mentioned above gets a similar type of result to the one in R.

There are R code in scaling and visualization. I guess AUCell's output .csv file should be similar to regulonActivity_byCellType?

regulonAUC <- regulonAUC[onlyNonDuplicatedExtended(rownames(regulonAUC)),] regulonActivity_byCellType <- sapply(split(rownames(cellInfo), cellInfo$CellType), function(cells) rowMeans(getAUC(regulonAUC)[,cells])) regulonActivity_byCellType_Scaled <- t(scale(t(regulonActivity_byCellType), center = T, scale=T)) ComplexHeatmap::Heatmap(regulonActivity_byCellType_Scaled1, name="Regulon activity")

And I also run

import umap

# UMAP
runUmap = umap.UMAP(n_neighbors=10, min_dist=0.4, metric='correlation').fit_transform
dr_umap = runUmap( auc_mtx )
pd.DataFrame(dr_umap, columns=['X', 'Y'], index=auc_mtx.index).to_csv( "scenic_umap.txt", sep='\t')
# tSNE
tsne = TSNE( n_jobs=20 )
dr_tsne = tsne.fit_transform( auc_mtx )
pd.DataFrame(dr_tsne, columns=['X', 'Y'], index=auc_mtx.index).to_csv( "scenic_tsne.txt", sep='\t')

and get tSNE and UMAP text file, what can they do?

Thanks for any help!

Zymaniswenzai commented 3 years ago

regulonAUC <- importAUCfromText("aucell.csv")

I have figured it out. This R script can load the results from:

!pyscenic aucell \
    sample.loom \
    reg.csv \
    --output aucell.csv \
    --num_workers 20
ZJ-zuojing commented 2 years ago

Hi, after reading your answer, I want to ask you a question. when I finish the progress of pySCENIC, I got 3 csv files:

C11_adjacencies.txt C11_AUC.txt C11_adjacencies.txt

I got .loom by this script:

export2loom(ex_mtx = ex_matrix, auc_mtx = auc_mtx, regulons = [r.rename(r.name.replace('(',' (')) for r in regulons], out_fname = "./C11_DA.loom")

but when I load this .loom in R to do visualization , I got a Error :

pyScenicLoomFile <- file.path(pyScenicDir, "C11.loom") loom <- open_loom(pyScenicLoomFile, mode="r") regulons_incidMat <- get_regulons(loom)

Error in get_regulons(loom) :

The attribute 'MotifRegulons' is not available in this loom file. Possible values include: Regulons. Try setting the 'column.attr.name' argument to one of these values (i.e., get_regulons(loom, column.attr.name='Regulons')).

and this is the .loom

loom Class: H5File Filename: /mnt/12/C11_DA/SCENIC/pySCENIC/C11_DA.loom Access type: H5F_ACC_RDONLY Attributes: last_modified Listing: name obj_type dataset.dims dataset.type_class attrs H5I_GROUP col_attrs H5I_GROUP col_graphs H5I_GROUP layers H5I_GROUP matrix H5I_DATASET 23686 x 35035 H5T_FLOAT row_attrs H5I_GROUP row_graphs H5I_GROUP

So can you tell me how you get the .loom and .csv file.

Zymaniswenzai commented 2 years ago

Hi,@ZJ-zoujing. I didn't finish that step because it reported errors. export2loom(ex_mtx = ex_matrix, auc_mtx = auc_mtx, regulons = [r.rename(r.name.replace('(',' (')) for r in regulons], out_fname = "./C11_DA.loom")

as you can see, I just run this step in R:

regulonAUC <- importAUCfromText("C11_AUC.txt")

But the results looked different from the one produced by SCENIC: image

They did not have '_extended' like this pic: image