用简单基础R语言代码对于给定的实验数据expression.txt和samples_annotation.txt,其中,实验数据samples_annotation.txt中的元素为Samples Phenotype;expression.txt里的元素为ENSG GeneSymbol RHV022-0 RHV024-0 RHV029-0 RHV030-0 RHV031-0 RHV048-0 RHV053-0 RHV061-0 RHV063-0 RHV071-0 RHV072-0 RHV078-0 RHV093-0 RHV094-0 RHV095-0 RHV100-0 RHV101-0 RHV102-0 RHV010-3 RHV011-3 RHV019-3 RHV020-3 RHV025-3 RHV026-3 RHV027-3 RHV033-3 RHV035-3 RHV036-3 RHV041-3 RHV049-3 RHV052-3 RHV058-3 RHV060-3 RHV067-3 RHV068-3 RHV083-3 RHV084-3 RHV091-3 RHV012-6 RHV018-6 RHV028-6 RHV034-6 RHV042-6 RHV043-6 RHV044-6 RHV050-6 RHV051-6 RHV059-6 RHV065-6 RHV066-6 RHV073-6 RHV074-6 RHV075-6 RHV076-6 RHV082-6 RHV090-6 RHV092-6 RHV098-6 RHV099-6 RHV013-12 RHV014-12 RHV015-12 RHV016-12 RHV021-12 RHV023-12 RHV037-12 RHV038-12 RHV039-12 RHV046-12 RHV054-12 RHV055-12 RHV056-12 RHV062-12 RHV064-12 RHV069-12 RHV070-12 RHV077-12 RHV079-12 RHV085-12 RHV086-12 RHV103-12完成以下实验内容: 计算基因表达谱(行为基因,列为样本),基因的官方名字为行名。一个基因名称对应多个ENSG编号,将其多个ENSG的值求均表示该基因的表达值
时间: 2023-06-19 09:03:51 浏览: 112
首先,我们需要读取两个文件并将它们合并为一个数据框:
```r
#读取expression.txt文件
expr <- read.table("expression.txt", header = T, row.names = 1, sep = "\t")
#读取samples_annotation.txt文件
anno <- read.table("samples_annotation.txt", header = T, sep = "\t")
#将两个数据框合并为一个,以样本编号为键值
data <- merge(expr, anno, by.x = colnames(expr)[1], by.y = "Samples")
```
然后,我们需要对基因进行分组,找到每个基因对应的所有ENSG编号,然后计算它们的平均值:
```r
#找到每个基因对应的所有ENSG编号
gene_groups <- split(colnames(data)[-ncol(data)], sapply(colnames(data)[-ncol(data)], function(x) strsplit(x, "\\.")[[1]][1]))
#计算每个基因的平均值
gene_expr <- sapply(gene_groups, function(x) rowMeans(data[,x]))
#将结果转化为数据框并设置行名为基因官方名字
gene_expr <- as.data.frame(gene_expr)
row.names(gene_expr) <- names(gene_groups)
```
现在,gene_expr就是我们想要的基因表达谱,每一行代表一个基因,每一列代表一个样本。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)