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

Error in if (file == "") stdin() else file(file) : the condition has length > 1 #1008

Open
13954380607 opened this issue Aug 7, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@13954380607
Copy link

13954380607 commented Aug 7, 2024

visium_kidney = createGiottoVisiumObject(visium_dir = data_path,

  •                                      expr_data = 'raw',
    
  •                                      png_name = image_name,
    
  •                                      gene_column_index = 2,
    
  •                                      instructions = instrs)
    

A structured visium directory will be used
Error in if (file == "") stdin() else file(file) :
the condition has length > 1

@13954380607 13954380607 added the bug Something isn't working label Aug 7, 2024
@13954380607 13954380607 changed the title Not yet implemented. Error in if (file == "") stdin() else file(file) : the condition has length > 1 Aug 7, 2024
@jiajic
Copy link
Member

jiajic commented Aug 7, 2024

Hi, could you provide any more details about the dataset used and what value is stored in the image_name variable?

It doesn't look like the following error is from code directly in Giotto (maybe it's part of some package we use for reading things in), so it's hard to figure out what's going on.

Error in if (file == "") stdin() else file(file) :
the condition has length > 1

Not sure if the dataset you were using was the publicly available Visium Mouse Kidney dataset, but I tested the following calls and was not able to reproduce an error.

p <- "/Users/george/Library/CloudStorage/[email protected]/Shared drives/Dries_lab/Datasets/Public_data/Spatial/Sequencing/Visium/Visium_Mouse_Kidney_data"

g <- createGiottoVisiumObject(visium_dir = p)
g <- createGiottoVisiumObject(visium_dir = p, expr_data = "raw")
g <- createGiottoVisiumObject(visium_dir = p, expr_data = "raw", gene_column_index = 2)
g <- createGiottoVisiumObject(visium_dir = p, expr_data = "raw", gene_column_index = 2, png_name = "tissue_hires_image.png")

spatPlot2D(g, show_image = T, point_alpha = 0.5)

image

> sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.4

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] Giotto_4.1.0      GiottoClass_0.3.4

loaded via a namespace (and not attached):
  [1] colorRamp2_0.1.0            DBI_1.2.2                   MAST_1.30.0                 deldir_2.0-4               
  [5] rlang_1.1.4                 magrittr_2.0.3              GiottoUtils_0.1.10          matrixStats_1.3.0          
  [9] compiler_4.4.0              png_0.1-8                   vctrs_0.6.5                 reshape2_1.4.4             
 [13] stringr_1.5.1               pkgconfig_2.0.3             SpatialExperiment_1.14.0    crayon_1.5.2               
 [17] fastmap_1.2.0               backports_1.5.0             magick_2.8.4                XVector_0.44.0             
 [21] labeling_0.4.3              utf8_1.2.4                  UCSC.utils_1.0.0            purrr_1.0.2                
 [25] bit_4.0.5                   zlibbioc_1.50.0             GenomeInfoDb_1.40.0         jsonlite_1.8.8             
 [29] DelayedArray_0.30.0         terra_1.7-78                parallel_4.4.0              R6_2.5.1                   
 [33] stringi_1.8.4               RColorBrewer_1.1-3          limma_3.60.0                reticulate_1.38.0          
 [37] GenomicRanges_1.56.0        scattermore_1.2             Rcpp_1.0.13                 assertthat_0.2.1           
 [41] SummarizedExperiment_1.34.0 R.utils_2.12.3              IRanges_2.38.0              Matrix_1.7-0               
 [45] igraph_2.0.3                tidyselect_1.2.1            rstudioapi_0.16.0           abind_1.4-5                
 [49] codetools_0.2-20            lattice_0.22-6              tibble_3.2.1                intervals_0.15.4           
 [53] plyr_1.8.9                  Biobase_2.64.0              withr_3.0.0                 pillar_1.9.0               
 [57] MatrixGenerics_1.16.0       checkmate_2.3.1             stats4_4.4.0                plotly_4.10.4              
 [61] generics_0.1.3              dbscan_1.2-0                sp_2.1-4                    S4Vectors_0.42.0           
 [65] ggplot2_3.5.1               munsell_0.5.1               scales_1.3.0                GiottoData_0.2.14          
 [69] gtools_3.9.5                multinet_4.1.2              glue_1.7.0                  lazyeval_0.2.2             
 [73] tools_4.4.0                 GiottoVisuals_0.2.4         data.table_1.15.4           cowplot_1.1.3              
 [77] grid_4.4.0                  tidyr_1.3.1                 colorspace_2.1-0            SingleCellExperiment_1.26.0
 [81] GenomeInfoDbData_1.2.12     cli_3.6.3                   fansi_1.0.6                 S4Arrays_1.4.0             
 [85] viridisLite_0.4.2           arrow_16.1.0                dplyr_1.1.4                 gtable_0.3.5               
 [89] R.methodsS3_1.8.2           digest_0.6.35               progressr_0.14.0            BiocGenerics_0.50.0        
 [93] SparseArray_1.4.1           ggrepel_0.9.5               rjson_0.2.21                htmlwidgets_1.6.4          
 [97] farver_2.1.2                R.oo_1.26.0                 htmltools_0.5.8.1           lifecycle_1.0.4            
[101] httr_1.4.7                  statmod_1.5.0               bit64_4.0.5     

@13954380607
Copy link
Author

Thank you so much! Sorry for the confusion, but now it gives me this message:
Error in file == "" :
comparison (==) is possible only for atomic and list types

@13954380607
Copy link
Author

The dataset I used was the publicly available Visium Mouse Kidney dataset, but one thing I don't know is the structure of the dataset, like which files in which fold. Thank you!

@13954380607
Copy link
Author

visium_kidney = createGiottoVisiumObject(visium_dir = data_path,

  •                                      expr_data = data_path_F2_h5,
    
  •                                      png_name = data_path_F2_image,
    
  •                                      gene_column_index = data_path_F2_scalefactors,
    
  •                                      instructions = instrs)
    

[1] "visium_dir length: 1"
[1] "expr_data length: 1"
[1] "png_name length: 1"
[1] "gene_column_index length: 1"
[1] "instructions length: 11"
Error in file == "" :
comparison (==) is possible only for atomic and list types

I don't know why it always gave me this error message. Thank you!

@jiajic
Copy link
Member

jiajic commented Aug 7, 2024

The only things that really matter are that you have the spatial folder and also the expression matrix you want to use unzipped.

My directory looks like this:

> fs::dir_tree(p)
/Users/george/Library/CloudStorage/[email protected]/Shared drives/Dries_lab/Datasets/Public_data/Spatial/Sequencing/Visium/Visium_Mouse_Kidney_data
├── V1_Mouse_Kidney_image.tif
├── V1_Mouse_Kidney_metrics_summary.csv
├── V1_Mouse_Kidney_raw_feature_bc_matrix.tar.gz
├── analysis
│   ├── clustering
│   │   ├── graphclust
│   │   │   └── clusters.csv
│   │   ├── kmeans_10_clusters
│   │   │   └── clusters.csv
│   │   ├── kmeans_2_clusters
│   │   │   └── clusters.csv
│   │   ├── kmeans_3_clusters
│   │   │   └── clusters.csv
│   │   ├── kmeans_4_clusters
│   │   │   └── clusters.csv
│   │   ├── kmeans_5_clusters
│   │   │   └── clusters.csv
│   │   ├── kmeans_6_clusters
│   │   │   └── clusters.csv
│   │   ├── kmeans_7_clusters
│   │   │   └── clusters.csv
│   │   ├── kmeans_8_clusters
│   │   │   └── clusters.csv
│   │   └── kmeans_9_clusters
│   │       └── clusters.csv
│   ├── diffexp
│   │   ├── graphclust
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_10_clusters
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_2_clusters
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_3_clusters
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_4_clusters
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_5_clusters
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_6_clusters
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_7_clusters
│   │   │   └── differential_expression.csv
│   │   ├── kmeans_8_clusters
│   │   │   └── differential_expression.csv
│   │   └── kmeans_9_clusters
│   │       └── differential_expression.csv
│   ├── pca
│   │   └── 10_components
│   │       ├── components.csv
│   │       ├── dispersion.csv
│   │       ├── features_selected.csv
│   │       ├── projection.csv
│   │       └── variance.csv
│   ├── tsne
│   │   └── 2_components
│   │       └── projection.csv
│   └── umap
│       └── 2_components
│           └── projection.csv
├── filtered_feature_bc_matrix
│   ├── barcodes.tsv.gz
│   ├── features.tsv.gz
│   └── matrix.mtx.gz
├── raw_feature_bc_matrix
│   ├── barcodes.tsv.gz
│   ├── features.tsv.gz
│   └── matrix.mtx.gz
└── spatial
    ├── aligned_fiducials.jpg
    ├── detected_tissue_image.jpg
    ├── scalefactors_json.json
    ├── tissue_hires_image.png
    ├── tissue_lowres_image.png
    └── tissue_positions_list.csv

@13954380607
Copy link
Author

Thank you, also my image name is: image_name = 'tissue_lowres_image.png', is this correct?

@jiajic
Copy link
Member

jiajic commented Aug 7, 2024

Yes that should work.
I just ran the following and it also worked

> g <- createGiottoVisiumObject(visium_dir = p, expr_data = "raw", gene_column_index = 2, png_name = "tissue_lowres_image.png")
A structured visium directory will be used
 - found image
 - found scalefactors. attempting automatic alignment for the 'lowres' image

a giotto python environment was found
Using python path:
 "/Users/george/Library/r-miniconda-arm64/envs/giotto_env/bin/pythonw"
> g
An object of class giotto 
>Active spat_unit:  cell 
>Active feat_type:  rna 
[SUBCELLULAR INFO]
polygons      : cell 
[AGGREGATE INFO]
expression -----------------------
  [cell][rna] raw
spatial locations ----------------
  [cell] raw
attached images ------------------
images      : image 


Use objHistory() to see steps and params used
> spatPlot2D(g, show_image = T, point_alpha = 0.5)
> g@images$image
An object of class giottoLargeImage : "image"
Image extent            : 0, 11300.00002825, -11300.00002825, 0 (xmin, xmax, ymin, ymax)
Original image extent   : 0, 11300.00002825, -11300.00002825, 0 (xmin, xmax, ymin, ymax)
Scale factor            : 18.8333333804167, 18.8333333804167 (x, y)
Resolution              : 0.053097345, 0.053097345 (x, y)
Layers                  : 3 
Estimated max intensity : 174 
Estimated min intensity : 17 
Values                  : integers
File path               : '/Users/george/Library/CloudStorage/[email protected]/Shared drives/Dries_lab/Datasets/Public_data/Spatial/Sequencing/Visium/Visium_Mouse_Kidney_data/spatial//tissue_lowres_image.png'

Not that the giottoLargeImage is indeed pointing to the tissue_lowres_image.png since that's the png_name asked for.

image

@jiajic
Copy link
Member

jiajic commented Aug 7, 2024

visium_kidney = createGiottoVisiumObject(visium_dir = data_path,
expr_data = data_path_F2_h5,

Oh wait it looks like you are using the h5 expression instead of the zipped folder with .mtx files. Please use the h5 params instead if you are using the .h5 expression information.

  h5_visium_path = NULL,
  h5_gene_ids = c("symbols", "ensembl"),
  h5_tissue_positions_path = NULL,
  h5_image_png_path = NULL,
  h5_json_scalefactors_path = NULL,

@13954380607
Copy link
Author

data_path = '/home/dl2373/new/'

fs::dir_tree(data_path)
/home/dl2373/new/
├── raw_feature_bc_matrix
│ ├── barcodes.tsv
│ ├── features.tsv
│ ├── matrix.mtx
│ ├── raw_feature_bc_matrix
│ └── raw_feature_bc_matrix.h5
├── spatial
│ ├── scalefactors_json.json
│ │ └── tissue_lowres_image.png
│ └── tissue_lowres_image.png
│ └── scalefactors_json.json
└── tissue_positions_list.csv
Is this directory correct?

@13954380607
Copy link
Author

13954380607 commented Aug 7, 2024

library(Giotto)

results_folder = '/home/dl2373/new'

python_path = NULL
instrs = createGiottoInstructions(save_dir = results_folder,
save_plot = TRUE,
show_plot = FALSE,
python_path = python_path)

data_path = '/home/dl2373/new/'
fs::dir_tree(data_path)
image_name = 'tissue_lowres_image.png'

visium_kidney = createGiottoVisiumObject(
visium_dir = data_path,
expr_data = 'raw',
png_name = image_name,
gene_column_index = 2,
instructions = instrs
)
This is my full code. Thank you!

@jiajic
Copy link
Member

jiajic commented Aug 7, 2024

That directory and code do look mostly correct.

I'm not sure why inside of raw_feature_bc_matrix, you have these extra files.

 raw_feature_bc_matrix
 raw_feature_bc_matrix.h5

For the code, I would just suggest that results be a different folder than the data folder so that things don't get messy.

I ran your code and it worked on my side.
It's pretty rare but maybe they have changed something with the output somehow since we last downloaded this dataset?
I can try downloading a fresh copy and trying again in the morning if it's still not working for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants