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

anndataToGiotto only support scr_matrix format anndata object #216

Closed
wwang-chcn opened this issue Aug 4, 2024 · 0 comments
Closed

anndataToGiotto only support scr_matrix format anndata object #216

wwang-chcn opened this issue Aug 4, 2024 · 0 comments

Comments

@wwang-chcn
Copy link
Contributor

Description

anndataToGiotto function only support scr_matrix format anndata object.

There are four types (ndarray, spmatrix, DataFrame, None) of expression matrix format support in anndata. However, anndataToGiotto function only support spmatrix for now.


Reproducible code

## load libs
library(Giotto)
library(reticulate)

use_condaenv("giotto_env", required = TRUE)

## create h5ad
### import Python libs
sc <- import("scanpy", convert = FALSE)
ad <- import("anndata", convert = FALSE)
scipy <- import("scipy", convert = FALSE)
pd <- import("pandas", convert = FALSE)
np <- import("numpy", convert = FALSE)

### create various types of gene expression
npArrayCounts <- np$random$poisson(1, size=c(10L,20L)) # numpy.array
cellNames <- paste0("Cell_", rep(1:10)) # cell names
geneNames <- paste0("Gene_", rep(1:20)) # gene names
csrMatrixCounts <- scipy$sparse$csr_matrix(npArrayCounts,
                                           dtype=np$float32) # csr matrix
dataFrameCounts <- pd$DataFrame(npArrayCounts,
                                columns = geneNames,
                                index = cellNames) # pandas.DataFrame

### adata with numpy.array
adataNpArray <- ad$AnnData(npArrayCounts)
adataNpArray$obs$index <- cellNames
adataNpArray$var$index <- geneNames
adataNpArray$write("adataNpArray.h5ad")

### adata with csr matrix
adataSpMatrix <- ad$AnnData(csrMatrixCounts)
adataSpMatrix$obs$index <- cellNames
adataSpMatrix$var$index <- geneNames
adataSpMatrix$write("adataSpMatrix.h5ad")

### adata with pandas.DataFrame
adataPdDF <- ad$AnnData(dataFrameCounts)
adataPdDF$write("adataPdDF.h5ad")

## convert into giotto
### csr matrix: success
giottoFromAdSpMatrix <- anndataToGiotto(anndata_path =  "adataSpMatrix.h5ad")
### pandas.DataFrame: fail
giottoFromPdDataFrame <- anndataToGiotto(anndata_path =  "adataPdDF.h5ad")
### numpy.array: fail
giottoFromNpArray <- anndataToGiotto(anndata_path =  "adataNpArray.h5ad")

Session info

R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.6.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reticulate_1.38.0 Giotto_4.1.0      GiottoClass_0.3.3

loaded via a namespace (and not attached):
 [1] tidyr_1.3.1         plotly_4.10.4       utf8_1.2.4          generics_0.1.3     
 [5] gtools_3.9.5        stringi_1.8.4       lattice_0.22-6      digest_0.6.35      
 [9] magrittr_2.0.3      grid_4.4.0          RColorBrewer_1.1-3  fastmap_1.2.0      
[13] plyr_1.8.9          jsonlite_1.8.8      Matrix_1.7-0        ggrepel_0.9.5      
[17] backports_1.5.0     scattermore_1.2     httr_1.4.7          purrr_1.0.2        
[21] fansi_1.0.6         viridisLite_0.4.2   scales_1.3.0        lazyeval_0.2.2     
[25] codetools_0.2-20    cli_3.6.3           rlang_1.1.4         cowplot_1.1.3      
[29] munsell_0.5.1       withr_3.0.1         colorRamp2_0.1.0    parallel_4.4.0     
[33] tools_4.4.0         reshape2_1.4.4      deldir_2.0-4        GiottoUtils_0.1.10 
[37] checkmate_2.3.2     dplyr_1.1.4         colorspace_2.1-0    ggplot2_3.5.1      
[41] vctrs_0.6.5         R6_2.5.1            png_0.1-8           matrixStats_1.3.0  
[45] lifecycle_1.0.4     magick_2.8.4        stringr_1.5.1       htmlwidgets_1.6.4  
[49] GiottoVisuals_0.2.4 dbscan_1.2-0        pkgconfig_2.0.3     terra_1.7-78       
[53] pillar_1.9.0        gtable_0.3.5        data.table_1.15.4   glue_1.7.0         
[57] Rcpp_1.0.13         xfun_0.44           tibble_3.2.1        tidyselect_1.2.1   
[61] rstudioapi_0.16.0   knitr_1.47          htmltools_0.5.8.1   igraph_2.0.3       
[65] compiler_4.4.0      sp_2.1-4  
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