“Lesson 02&03 for Plotting in R for Biologists”
Lesson02主要讲了如何从Excel导入数据以及如何从UCSC、ENSEMBL和RENCODE上下载数据,因此我就将Lesson02并入Lesson03一起讲了。
从ECXEl中导入数据
数据来源于文献
“Gene expression profiling of breast cell lines identifies potential new basal markers”的补充数据集Supplementary Table 1。将之下载到工作目录区。数据读取的话只需要用read.csv()
即可,指定sep
。gtf、bed文件都可以通过read.csv()
读取。即使是没有后缀的文件,只要知道其分隔符,就可以通过设置sep
来读取数据。
my_data <- read.csv("micro_array_results_table1.txt", sep = '\t', header = TRUE)
head(my_data[,c(1:6)])
## Probe.Set.ID Gene.Symbol Type X184B5 BrCa.MZ.01 BT.20
## 1 1007_s_at DDR1 gene 1113.91 815.53 1564.76
## 2 1053_at RFC2 gene 159.02 253.24 320.22
## 3 117_at HSPA6 gene 60.76 33.91 26.39
## 4 121_at PAX8 gene 197.76 121.33 122.81
## 5 1255_g_at GUCA1A gene 6.73 7.88 6.28
## 6 1294_at UBE1L gene 118.82 57.24 432.24
试试读取gtf文件
Brassica_gtf <- read.csv("E:/Brassica napus database/Brassica_napus.annotation_v5.gtf", sep = "\t", header = FALSE)
head(Brassica_gtf)
## V1 V2 V3 V4 V5 V6 V7 V8 V9
## 1 chrA01 GazeA2 exon 831 1437 7.80 + . transcript_id BnaA01g00010D;
## 2 chrA01 GazeA2 CDS 1070 1345 . + 0 transcript_id BnaA01g00010D;
## 3 chrA01 GazeA2 exon 1487 2124 2.15 - . transcript_id BnaA01g00020D;
## 4 chrA01 GazeA2 exon 2256 2436 3.19 - . transcript_id BnaA01g00020D;
## 5 chrA01 GazeA2 CDS 1645 2124 . - 0 transcript_id BnaA01g00020D;
## 6 chrA01 GazeA2 CDS 2256 2282 . - 0 transcript_id BnaA01g00020D;
其他格式文件我这里就不试了,有兴趣的话可以自己去尝试。
数据探索
library(tidyverse)
#读取数据
my_data <- read.csv("Encode_HMM_data.txt", sep = "\t", header = FALSE)
dim(my_data)
## [1] 571339 9
head(my_data[, c(1:6)])
## V1 V2 V3 V4 V5 V6
## 1 chr1 10000 10600 15_Repetitive/CNV 0 .
## 2 chr1 10600 11137 13_Heterochrom/lo 0 .
## 3 chr1 11137 11737 8_Insulator 0 .
## 4 chr1 11737 11937 11_Weak_Txn 0 .
## 5 chr1 11937 12137 7_Weak_Enhancer 0 .
## 6 chr1 12137 14537 11_Weak_Txn 0 .
对数据部分列进行重命名
names(my_data)[1:4] <- c("chrom", "start", "stop", "type")
可视化
先初步看一下不同染色体上的type类型
ggplot(my_data, aes(x=chrom, fill=type))+geom_bar()
从这个图中可以看到还有很多缺陷
- 染色体顺序错乱,前缀chr在坐标轴上排列乱
- 类型太多了,我们只需要可视化我们感兴趣的type
- 类型的名字乱
这几个问题将在Lesson04解决
SessionInfo()
sessionInfo()
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 16299)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Chinese (Simplified)_China.936
## [2] LC_CTYPE=Chinese (Simplified)_China.936
## [3] LC_MONETARY=Chinese (Simplified)_China.936
## [4] LC_NUMERIC=C
## [5] LC_TIME=Chinese (Simplified)_China.936
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] forcats_0.2.0 stringr_1.2.0 dplyr_0.7.4
## [4] purrr_0.2.4 readr_1.1.1 tidyr_0.7.2
## [7] tibble_1.4.2 ggplot2_2.2.1.9000 tidyverse_1.2.1
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.15 cellranger_1.1.0 pillar_1.1.0
## [4] compiler_3.4.3 plyr_1.8.4 bindr_0.1
## [7] tools_3.4.3 digest_0.6.14 lubridate_1.7.1
## [10] jsonlite_1.5 evaluate_0.10.1 nlme_3.1-131
## [13] gtable_0.2.0 lattice_0.20-35 pkgconfig_2.0.1
## [16] rlang_0.1.6 psych_1.7.8 cli_1.0.0
## [19] rstudioapi_0.7 yaml_2.1.16 parallel_3.4.3
## [22] haven_1.1.1 bindrcpp_0.2 xml2_1.2.0
## [25] httr_1.3.1 knitr_1.18 hms_0.4.1
## [28] rprojroot_1.3-2 grid_3.4.3 glue_1.2.0
## [31] R6_2.2.2 readxl_1.0.0 foreign_0.8-69
## [34] rmarkdown_1.8 modelr_0.1.1 reshape2_1.4.3
## [37] magrittr_1.5 backports_1.1.2 scales_0.5.0.9000
## [40] htmltools_0.3.6 rvest_0.3.2 assertthat_0.2.0
## [43] mnormt_1.5-5 colorspace_1.3-2 labeling_0.3
## [46] stringi_1.1.6 lazyeval_0.2.1 munsell_0.4.3
## [49] broom_0.4.3 crayon_1.3.4