0

I am working on a single nucleus RNA sequencing dataset with samples from two different conditions and 4 timepoints each. I would like to run the same analysis on all of those timepoints for 4 different celltypes and wrote a for loop that seems to be working well except for saving graphs that I'm creating at the end of each loop. I've run into this problem before with shorter loops and worked around it by storing the graphs in a list while the loop was running and then manually creating and saving the plots for each of the conditions. But this is getting way to time-consuming for this task.

The whole for loop is very long, so it doesn't make sense to post the whole thing here. But basically the loop ends with creating the "circos_output" graph which has a chord plot stored in its "$p_circos" slot. When I run circos_output$p_circos in the console, it shows me the graph as expected in the plots panel. But when I run the following code in the loop:

png(filename = paste0("/home/jasper/scRNAseq/nphs2mut/DecontX Analysis/New Analysis Normal Workflow/figures/8-figures/nichenet/Circos_NicheNet_DE_", celltype_oi,"_", age_oi,"_weeks.png"), width = 1000, height = 1000)
circos_output$p_circos
title(paste0("Upregulated Signaling to", celltype_oi, " - ", age_oi, "weeks mut vs all WT"))
dev.off()

I get the error message: "plot.new has not been called yet".

Any help would be greatly appreciated!

I tried the following things:

  • I ran circos.clear() before and after the grpahics device command, no success.
  • I am using Rmarkdown and tried switching to "Chung output in console" because when I run the graphics device code individually (e.g. not within the for loop) it works and saves my plot as I want it to. But within the for loop still no success.
  • I tried other graphics devices (like jpeg, svg) without success

Here is my sessionInfo:

R version 4.2.2 Patched (2022-11-10 r83330) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.5 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] RColorBrewer_1.1-3 scCustomize_1.1.1 circlize_0.4.15 nichenetr_1.1.1 data.table_1.14.8 lubridate_1.9.2
[7] forcats_1.0.0 stringr_1.5.0 dplyr_1.1.1 purrr_1.0.1 readr_2.1.4 tidyr_1.3.0
[13] tibble_3.2.1 ggplot2_3.4.1 tidyverse_2.0.0 SeuratObject_4.1.3 Seurat_4.3.0

loaded via a namespace (and not attached): [1] utf8_1.2.3 spatstat.explore_3.1-0 reticulate_1.28 tidyselect_1.2.0 htmlwidgets_1.6.2
[6] Rtsne_0.16 pROC_1.18.0 munsell_0.5.0 codetools_0.2-19 ica_1.0-3
[11] future_1.32.0 miniUI_0.1.1.1 withr_2.5.0 spatstat.random_3.1-4 colorspace_2.1-0
[16] progressr_0.13.0 knitr_1.42 rstudioapi_0.14 stats4_4.2.2 ROCR_1.0-11
[21] ggsignif_0.6.4 tensor_1.5 listenv_0.9.0 labeling_0.4.2 polyclip_1.10-4
[26] farver_2.1.1 parallelly_1.35.0 vctrs_0.6.1 generics_0.1.3 ipred_0.9-14
[31] xfun_0.38 timechange_0.2.0 randomForest_4.7-1.1 R6_2.5.1 doParallel_1.0.17
[36] ggbeeswarm_0.7.1 clue_0.3-64 bitops_1.0-7 spatstat.utils_3.0-2 promises_1.2.0.1
[41] scales_1.2.1 nnet_7.3-18 beeswarm_0.4.0 gtable_0.3.3 Cairo_1.6-0
[46] globals_0.16.2 goftest_1.2-3 timeDate_4022.108 rlang_1.1.0 BBmisc_1.13
[51] GlobalOptions_0.1.2 splines_4.2.2 rstatix_0.7.2 lazyeval_0.2.2 ModelMetrics_1.2.2.2
[56] broom_1.0.4 spatstat.geom_3.1-0 checkmate_2.1.0 yaml_2.3.7 reshape2_1.4.4
[61] abind_1.4-5 backports_1.4.1 httpuv_1.6.9 Hmisc_5.0-1 caret_6.0-94
[66] DiagrammeR_1.0.9 tools_4.2.2 lava_1.7.2.1 ellipsis_0.3.2 proxy_0.4-27
[71] BiocGenerics_0.44.0 ggridges_0.5.4 Rcpp_1.0.10 plyr_1.8.8 base64enc_0.1-3
[76] visNetwork_2.1.2 ggpubr_0.6.0 rpart_4.1.19 deldir_1.0-6 ParamHelpers_1.14.1
[81] pbapply_1.7-0 GetoptLong_1.0.5 cowplot_1.1.1 S4Vectors_0.36.2 zoo_1.8-11
[86] ggrepel_0.9.3 cluster_2.1.4 magrittr_2.0.3 scattermore_0.8 lmtest_0.9-40
[91] RANN_2.6.1 fitdistrplus_1.1-8 matrixStats_0.63.0 hms_1.1.3 patchwork_1.1.2
[96] mime_0.12 evaluate_0.20 xtable_1.8-4 IRanges_2.32.0 gridExtra_2.3
[101] shape_1.4.6 compiler_4.2.2 KernSmooth_2.23-20 crayon_1.5.2 htmltools_0.5.5
[106] later_1.3.0 tzdb_0.3.0 ggprism_1.0.4 Formula_1.2-5 DBI_1.1.3
[111] ComplexHeatmap_2.14.0 MASS_7.3-58.3 car_3.1-1 Matrix_1.5-3 cli_3.6.1
[116] parallel_4.2.2 gower_1.0.1 igraph_1.4.1 pkgconfig_2.0.3 foreign_0.8-84
[121] sp_1.6-0 plotly_4.10.1 spatstat.sparse_3.0-1 recipes_1.0.5 paletteer_1.5.0
[126] foreach_1.5.2 vipor_0.4.5 hardhat_1.2.0 prodlim_2019.11.13 snakecase_0.11.0
[131] digest_0.6.31 sctransform_0.3.5 RcppAnnoy_0.0.20 janitor_2.2.0 spatstat.data_3.0-1
[136] fastmatch_1.1-3 rmarkdown_2.20 leiden_0.4.3 htmlTable_2.4.1 uwot_0.1.14
[141] shiny_1.7.4 rjson_0.2.21 lifecycle_1.0.3 nlme_3.1-162 jsonlite_1.8.4
[146] carData_3.0-5 viridisLite_0.4.1 limma_3.54.2 fansi_1.0.4 pillar_1.9.0
[151] lattice_0.20-45 ggrastr_1.0.1 fastmap_1.1.1 httr_1.4.5 survival_3.5-5
[156] glue_1.6.2 fdrtool_1.2.17 png_0.1-8 iterators_1.0.14 class_7.3-21
[161] stringi_1.7.12 rematch2_2.1.2 caTools_1.18.2 irlba_2.3.5.1 e1071_1.7-13
[166] future.apply_1.10.0

Smeerlap
  • 21
  • 2

0 Answers0