Chapter 27 Writing files to file

Update the metadata file: write to file:

  • updated ext data table
  • spatial information summary
  • star aligned table
  • colData information
  • collapsed information on wsi/facs
write.xlsx(Cdata, file=sprintf("../metadata/Ext_Data_Table_updated_%s.xlsx", Sys.Date()))

#colnames(Cdata)

x1=match(rownames(df.Spatial), gsub("_","", Cdata$TumorID))
df.Spatial$NewID=Cdata$NewID[x1]
dfB=Cdata[x1, c("NewID", "TumorID","TumorAreaWSI", "Tumor.diameter.sac.mm", "CD45.Frac.FACS",   
"DN.Frac.FACS", "EpCAM.Frac.FACS")]

write.csv(df.Spatial, file="nature-tables/summary_spatial_information.csv")

colnames(allstarFinal)=infoTableFinal$TumorIDnew[match(colnames(allstarFinal), rownames(infoTableFinal))]
infoTableFinal2=infoTableFinal[ ,c("TumorIDnew","Growth", "CD8Frac", "TumSize", "Time.NMU2Sac", 
                                   "Age.Injection","Treatment","Cohort", "SizeCat")]
write.csv(infoTableFinal2, file="nature-tables/infoTableFinal2_output.csv")
write.csv(allstarFinal, file="nature-tables/allstarFinal_output.csv")


colTestCD8=c("CD8.EpBoundingBox", "CD8.TumSize", "CD45.FACS", "CD8.FACS", "OverallCD8_Fig4c.Manual", "TIL_Fig4d.Manual", "T.cell.CD8._TIMER", "T.cell.CD8._CIBERSORT","T.cell.CD8._CIBERSORT.ABS", "T.cell.CD8._EPIC")

# colTestCD8=c("CD8.EpDomTiles","CD8.EpBoundingBox", "CD8.TumSize", "CD45.FACS", "CD8.FACS", "OverallCD8_Fig4c.Manual", "TIL_Fig4d.Manual", )
indx1=c("CD8.WSI", "CD8Frac.WSI", "CD8_EPorSMARatio.WSI","CD8_AnyEPRatio.WSI", "CD8_EPRatio.WSI","CD8normTumSize", "CD8.EpBoundingBox")

df.Spatial2=merge(df.Spatial, dfB, by.x="NewID", by.y="NewID", all=T)
#head(df.Spatial2)

colnames(ProgSpecCD45)=gsub("_CD45", "", colnames(ProgSpecCD45))
#colnames(ProgSpecCD45)=gsub("_", "", colnames(ProgSpecCD45))
rownames(ProgSpecCD45)=ProgSpecCD45[ ,1]
ProgSpecCD45B=t(ProgSpecCD45[grep("CD8",rownames(ProgSpecCD45)), -1 ])
ProgSpecCD45B=data.frame(ProgSpecCD45B, sample=rownames(ProgSpecCD45B))

df.Spatial3=merge(df.Spatial2, ProgSpecCD45B, by.x="TumorID", by.y="sample", all=T)
df.Spatial3$TumorID2=gsub("_", "", df.Spatial3$TumorID)

SummaryData$TumorID2=rownames(SummaryData)

df.Spatial4=merge(df.Spatial3, SummaryData[ ,c(6:8,17:19, ncol(SummaryData))], by.x="TumorID2", by.y="TumorID2", all=T)

write.csv(df.Spatial4, file="../metadata/summary_new_210330.csv")

## merge he data from df.Spatial with the data from 

#df1=data.frame(CD8.WSI=df.Spatial$)

 #  df2=data.frame(CD8.WSI=t(WSIvals[ 1, ]), 
 #                 CD8Frac.WSI=t(WSIvalFracs[ ,2]), 
 #                 CD8_EPorSMARatio.WSI=(WSIvals[1,  ]/colSums(WSIvals[2:4, ])),
 #                 CD8_AnyEPRatio.WSI=(WSIvals[1,  ]/colSums(WSIvals[2:3, ])),
 #                 CD8_EPRatio.WSI=(WSIvals[1,  ]/(WSIvals[2, ])),
 #                 CD8normTumSize=(WSIvals[1,  ]/df.Spatial))
 # #                )

Below is the session info

sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS  10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.0/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] grid      stats4    parallel  stats     graphics  grDevices utils    
##  [8] datasets  methods   base     
## 
## other attached packages:
##  [1] writexl_1.3.1               xlsx_0.6.4.2               
##  [3] vcfR_1.12.0                 tcR_2.3.2                  
##  [5] igraph_1.2.6                gridExtra_2.3              
##  [7] spatstat_1.64-1             rpart_4.1-15               
##  [9] nlme_3.1-149                spatstat.data_1.4-3        
## [11] scales_1.1.1                RColorBrewer_1.1-2         
## [13] rmarkdown_2.6               reshape2_1.4.4             
## [15] pamr_1.56.1                 survival_3.2-7             
## [17] cluster_2.1.0               limma_3.44.3               
## [19] knitr_1.31                  kableExtra_1.2.1           
## [21] HTSanalyzeR2_0.99.19        heatmap.plus_1.3           
## [23] GSVA_1.36.3                 GSEABase_1.50.1            
## [25] graph_1.66.0                annotate_1.66.0            
## [27] XML_3.99-0.5                gplots_3.1.0               
## [29] ggrepel_0.8.2               ggplot2_3.3.2              
## [31] GenVisR_1.20.0              forestplot_1.10.1          
## [33] checkmate_2.0.0             magrittr_1.5               
## [35] EnsDb.Hsapiens.v86_2.99.0   ensembldb_2.12.1           
## [37] AnnotationFilter_1.12.0     GenomicFeatures_1.40.1     
## [39] AnnotationDbi_1.50.3        DT_0.17                    
## [41] dplyr_1.0.2                 DESeq2_1.28.1              
## [43] SummarizedExperiment_1.18.2 DelayedArray_0.14.1        
## [45] matrixStats_0.57.0          Biobase_2.48.0             
## [47] GenomicRanges_1.40.0        GenomeInfoDb_1.24.2        
## [49] colorspace_1.4-1            Biostrings_2.56.0          
## [51] XVector_0.28.0              IRanges_2.22.2             
## [53] S4Vectors_0.26.1            biomaRt_2.44.4             
## [55] beeswarm_0.2.3              AnnotationHub_2.20.2       
## [57] BiocFileCache_1.12.1        dbplyr_1.4.4               
## [59] BiocGenerics_0.34.0        
## 
## loaded via a namespace (and not attached):
##   [1] shinydashboard_0.7.1          tidyselect_1.1.0             
##   [3] RSQLite_2.2.1                 htmlwidgets_1.5.2            
##   [5] BiocParallel_1.22.0           gmp_0.6-1                    
##   [7] munsell_0.5.0                 codetools_0.2-16             
##   [9] preprocessCore_1.50.0         miniUI_0.1.1.1               
##  [11] withr_2.3.0                   Category_2.54.0              
##  [13] highr_0.8                     rstudioapi_0.11              
##  [15] robustbase_0.93-6             splots_1.54.0                
##  [17] tensor_1.5                    rJava_0.9-13                 
##  [19] labeling_0.4.2                GenomeInfoDbData_1.2.3       
##  [21] polyclip_1.10-0               hwriter_1.3.2                
##  [23] farver_2.0.3                  bit64_4.0.5                  
##  [25] vctrs_0.3.4                   generics_0.0.2               
##  [27] xfun_0.21                     R6_2.4.1                     
##  [29] locfit_1.5-9.4                msigdbr_7.2.1                
##  [31] spatstat.utils_1.17-0         bitops_1.0-6                 
##  [33] fgsea_1.14.0                  assertthat_0.2.1             
##  [35] promises_1.1.1                pinfsc50_1.2.0               
##  [37] gtable_0.3.0                  affy_1.66.0                  
##  [39] goftest_1.2-2                 cellHTS2_2.52.0              
##  [41] rlang_0.4.8                   genefilter_1.70.0            
##  [43] splines_4.0.2                 rtracklayer_1.48.0           
##  [45] lazyeval_0.2.2                abind_1.4-5                  
##  [47] BiocManager_1.30.10           yaml_2.2.1                   
##  [49] crosstalk_1.1.0.1             backports_1.1.10             
##  [51] httpuv_1.5.4                  RBGL_1.64.0                  
##  [53] tools_4.0.2                   bookdown_0.21                
##  [55] affyio_1.58.0                 ellipsis_0.3.1               
##  [57] Rcpp_1.0.5                    plyr_1.8.6                   
##  [59] progress_1.2.2                zlibbioc_1.34.0              
##  [61] purrr_0.3.4                   RCurl_1.98-1.2               
##  [63] prettyunits_1.1.1             deldir_0.1-29                
##  [65] openssl_1.4.3                 viridis_0.5.1                
##  [67] data.table_1.13.2             colourpicker_1.1.0           
##  [69] mvtnorm_1.1-1                 ProtGenerics_1.20.0          
##  [71] xlsxjars_0.6.1                hms_0.5.3                    
##  [73] mime_0.9                      evaluate_0.14                
##  [75] xtable_1.8-4                  compiler_4.0.2               
##  [77] tibble_3.0.4                  KernSmooth_2.23-17           
##  [79] crayon_1.3.4                  htmltools_0.5.0              
##  [81] mgcv_1.8-33                   pcaPP_1.9-73                 
##  [83] later_1.1.0.1                 geneplotter_1.66.0           
##  [85] rrcov_1.5-5                   DBI_1.1.0                    
##  [87] MASS_7.3-53                   rappdirs_0.3.1               
##  [89] Matrix_1.2-18                 permute_0.9-5                
##  [91] vsn_3.56.0                    RankProd_3.14.0              
##  [93] pkgconfig_2.0.3               GenomicAlignments_1.24.0     
##  [95] xml2_1.3.2                    foreach_1.5.1                
##  [97] prada_1.63.0                  stringdist_0.9.6.3           
##  [99] webshot_0.5.2                 rvest_0.3.6                  
## [101] BioNet_1.47.0                 stringr_1.4.0                
## [103] VariantAnnotation_1.34.0      digest_0.6.26                
## [105] vegan_2.5-6                   fastmatch_1.1-0              
## [107] curl_4.3                      shiny_1.5.0                  
## [109] Rsamtools_2.4.0               gtools_3.8.2                 
## [111] FField_0.1.0                  jsonlite_1.7.1               
## [113] lifecycle_0.2.0               viridisLite_0.3.0            
## [115] askpass_1.1                   BSgenome_1.56.0              
## [117] pillar_1.4.6                  lattice_0.20-41              
## [119] KEGGREST_1.28.0               fastmap_1.0.1                
## [121] httr_1.4.2                    DEoptimR_1.0-8               
## [123] GO.db_3.11.4                  interactiveDisplayBase_1.26.3
## [125] glue_1.4.2                    png_0.1-7                    
## [127] shinythemes_1.1.2             iterators_1.0.13             
## [129] BiocVersion_3.11.1            bit_4.0.4                    
## [131] stringi_1.5.3                 blob_1.2.1                   
## [133] caTools_1.18.0                memoise_1.1.0                
## [135] Rmpfr_0.8-1                   ape_5.4-1