Skip to content

Commit

Permalink
update object_creation tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
josschavezf committed Feb 16, 2024
1 parent 8890355 commit a1eb78b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 51 deletions.
Binary file added vignettes/images/object_creation/0-spatPlot2D.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file modified vignettes/images/object_creation/cell_clusters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 81 additions & 48 deletions vignettes/object_creation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ results_directory = paste0(getwd(),'/gobject_results/')
# alternatively, "/path/to/store/the/results/"
# Download osmFISH dataset to data_directory
getSpatialDataset(dataset = 'osmfish_SS_cortex', directory = data_directory, method = 'wget')
getSpatialDataset(dataset = 'osmfish_SS_cortex',
directory = data_directory,
method = 'wget')
```


Expand All @@ -53,22 +55,19 @@ Here, creating a `giotto` object with the minimum requirements is shown in two e
osm_exprs = paste0(data_directory, "osmFISH_prep_expression.txt")
osm_locs = paste0(data_directory, "osmFISH_prep_cell_coordinates.txt")
minimum_gobject1 = createGiottoObject(expression = osm_exprs,
spatial_locs = osm_locs)
minimum_gobject1 <- createGiottoObject(expression = osm_exprs,
spatial_locs = osm_locs)
# Example 2.
# Create a Giotto object using objects already loaded into workspace
expression_matrix = readExprMatrix(path = osm_exprs) # fast method to read expression matrix
cell_locations = data.table::fread(file = osm_locs)
minimum_gobject2 = createGiottoObject(expression = expression_matrix,
spatial_locs = cell_locations)
minimum_gobject2 <- createGiottoObject(expression = expression_matrix,
spatial_locs = cell_locations)
```



Expression file formatting

**Expression file formatting**

Expression count matrices accepted by *Giotto* should have columns correlating to individual cells (**cell IDs**) and rows to individual features (**feature IDs**).

Expand All @@ -78,9 +77,7 @@ Expression count matrices accepted by *Giotto* should have columns correlating t
already incorporated as the rownames.



Locations file formatting

**Locations file formatting**

Numerical columns will be interpreted in order of x, y, and (optionally) z coordinate. The first non-numerical column will be taken as **cell IDs**

Expand All @@ -96,10 +93,10 @@ custom_matrix = expression_matrix * 0.5
# Provide multiple expression matrices at once to the Giotto Object
# If these matrices are stored in files rather than in the workspace,
# file paths may be provided instead of variables
multi_expr_gobject = createGiottoObject(expression = list(raw = expression_matrix,
scaled = scaled_matrix,
custom = custom_matrix),
spatial_locs = cell_locations)
multi_expr_gobject <- createGiottoObject(expression = list(raw = expression_matrix,
scaled = scaled_matrix,
custom = custom_matrix),
spatial_locs = cell_locations)
```


Expand Down Expand Up @@ -150,19 +147,20 @@ instrs = createGiottoInstructions(python_path = my_python_path,
width = 9)
# Create Giotto object
custom_gobject = createGiottoObject(expression = osm_exprs,
spatial_locs = osm_locs,
instructions = instrs)
custom_gobject <- createGiottoObject(expression = osm_exprs,
spatial_locs = osm_locs,
instructions = instrs)
# Add field annotations as cell metadata
metadata = data.table::fread(file = meta_path)
custom_gobject = addCellMetadata(custom_gobject,
new_metadata = metadata,
by_column = T,
column_cell_ID = 'CellID')
custom_gobject <- addCellMetadata(custom_gobject,
new_metadata = metadata,
by_column = T,
column_cell_ID = 'CellID')
# Show the Giotto instructions associated with the Giotto object
instructions(custom_gobject)
showGiottoInstructions(custom_gobject)
```


Expand All @@ -175,14 +173,17 @@ The `giottoInstructions` may be changed, or completely replaced:

```{r, eval=FALSE}
# Change a specific previously set parameter, e.g. change dpi = 200 to dpi = 300
instructions(custom_gobject, 'dpi') = 300
custom_gobject <- changeGiottoInstructions(custom_gobject,
params = 'dpi',
new_values = 300)
# Observe that the instructions have changed
instructions(custom_gobject, 'dpi')
# Create new instructions using a named list
sub_results_directory = paste0(results_directory, 'specific_results/')
my_python_path = instructions(custom_gobject, 'python_path')
new_instrs = list(python_path = my_python_path,
show_plot = TRUE,
return_plot = FALSE,
Expand All @@ -199,7 +200,7 @@ new_instrs = list(python_path = my_python_path,
instructions(custom_gobject) = new_instrs
# Observe that the instructions have changed
instructions(custom_gobject)
showGiottoInstructions(custom_gobject)
```


Expand Down Expand Up @@ -229,7 +230,11 @@ Options` tutorial for alternative methods to save plots.
```{r, eval=FALSE}
# Plot according to Giotto Instructions (default)
spatPlot(custom_gobject)
```

![](images/object_creation/0-spatPlot2D.jpg)

```{r, eval=FALSE}
# Plot clusters, create, and save to a new subdirectory, all while overwriting formatting
spatPlot(custom_gobject,
cell_color = 'ClusterName',
Expand All @@ -244,37 +249,65 @@ spatPlot(custom_gobject,
base_width = 9))
```


![](images/object_creation/cell_clusters.png)

For a more in-depth look at the `giotto` object structure, take a look at the [introduction to giotto classes](./classes_intro.html)

## 2. Session Info


```{r, eval=FALSE}
sessionInfo()
```

```{r, eval=FALSE}
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur ... 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.2.1 fastmap_1.1.1 cli_3.6.1 tools_4.2.1
[5] htmltools_0.5.5 rstudioapi_0.14 yaml_2.3.7 rmarkdown_2.21
[9] knitr_1.42 xfun_0.39 digest_0.6.31 jsonlite_1.8.4
[13] rlang_1.1.1 evaluate_0.21
R version 4.3.2 (2023-10-31)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.3.1
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.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.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] GiottoData_0.2.7.0 GiottoUtils_0.1.5 Giotto_4.0.2 GiottoClass_0.1.3
loaded via a namespace (and not attached):
[1] tidyselect_1.2.0 farver_2.1.1 dplyr_1.1.4
[4] GiottoVisuals_0.1.4 bitops_1.0-7 fastmap_1.1.1
[7] SingleCellExperiment_1.24.0 RCurl_1.98-1.14 digest_0.6.34
[10] lifecycle_1.0.4 processx_3.8.3 terra_1.7-71
[13] magrittr_2.0.3 compiler_4.3.2 rlang_1.1.3
[16] tools_4.3.2 utf8_1.2.4 yaml_2.3.8
[19] data.table_1.15.0 knitr_1.45 S4Arrays_1.2.0
[22] labeling_0.4.3 reticulate_1.35.0 DelayedArray_0.28.0
[25] RColorBrewer_1.1-3 abind_1.4-5 withr_3.0.0
[28] BiocGenerics_0.48.1 grid_4.3.2 stats4_4.3.2
[31] fansi_1.0.6 colorspace_2.1-0 ggplot2_3.4.4
[34] scales_1.3.0 gtools_3.9.5 SummarizedExperiment_1.32.0
[37] cli_3.6.2 rmarkdown_2.25 crayon_1.5.2
[40] ragg_1.2.7 generics_0.1.3 remotes_2.4.2.1
[43] rstudioapi_0.15.0 rjson_0.2.21 zlibbioc_1.48.0
[46] parallel_4.3.2 XVector_0.42.0 matrixStats_1.2.0
[49] vctrs_0.6.5 Matrix_1.6-5 jsonlite_1.8.8
[52] callr_3.7.3 IRanges_2.36.0 S4Vectors_0.40.2
[55] systemfonts_1.0.5 magick_2.8.2 pak_0.7.1
[58] glue_1.7.0 codetools_0.2-19 ps_1.7.6
[61] cowplot_1.1.3 gtable_0.3.4 GenomeInfoDb_1.38.6
[64] GenomicRanges_1.54.1 munsell_0.5.0 tibble_3.2.1
[67] pillar_1.9.0 htmltools_0.5.7 GenomeInfoDbData_1.2.11
[70] R6_2.5.1 textshaping_0.3.7 evaluate_0.23
[73] lattice_0.22-5 Biobase_2.62.0 png_0.1-8
[76] backports_1.4.1 SpatialExperiment_1.12.0 Rcpp_1.0.12
[79] SparseArray_1.2.4 checkmate_2.3.1 colorRamp2_0.1.0
[82] xfun_0.42 MatrixGenerics_1.14.0 pkgconfig_2.0.3
```

0 comments on commit a1eb78b

Please sign in to comment.