在 R 中正确读取序列矩阵

标签 r text-files

我下载了 GSE60341_series_matrix.txt.gz 发现 here当我将它读入 R 表作为,

x <-read.table("GSE60341_series_matrix.txt", fill = TRUE)

我按行获取所有信息。换句话说,我得到一个大小矩阵
(42977 行和 3 列),而样本数应为 1951。
所以理想情况下,我应该得到一个包含 1951 行和(代表每个样本的 k 列)的表格。

打开文本文件让我,
    sapiens"    "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"  "Homo sapiens"
!Sample_title   "20120811_NC18_NC18_01" "20120811_NC18_NC18_02" "20120811_NC18_NC18_03" "20120811_NC18_NC18_04" "20120811_NC18_NC18_05"
    !Sample_characteristics_ch1 "stimulation: Unstim"   "stimulation: Activated"    "stimulation: IFNb" "stimulation: Unstim"   "stimulation: Activated"    "stimulation: IFNb" "stimulation: Unstim"   "stimulation: Activated"    "stimulation: IFNb" "stimulation: Unstim"   "stimulation: Activated"    "stimulation: IFNb" "stimulation: Unstim"   "stimulation: Activated"    "stimulation: IFNb" "stimulation: Unstim"   "stimulation: Activated"    "stimulation: IFNb" "stimulation: Unstim"   "stimulation: Activated"

"lane: 9"   "lane: 11"  "lane: 12"  "lane: 1"   "lane: 2"   "lane: 3"   "lane: 4"   "lane: 5"   "lane: 6"   "lane: 7"   "lane: 8"   "lane: 9"   "lane: 10"  "lane: 11"  "lane: 12"  "lane: 1"   "lane: 2"   "lane: 3"

类别( lanestimulationSample_title )中的信息作为行连接,但我希望它们在列中。我可以有一个表格,其中行代表样本,列代表 ,比如 [Sample_title, stimulation] ?

最佳答案

read.table用于读取通用 ASCII 表格式,该文件采用 NCBI 基因表达综合 (GEO) 使用的特殊格式。

以下是您需要做的:

  • 通过将此代码粘贴到 R 中来安装用于读取 GEO 文件的 GEOQuery 包:
    source("http://bioconductor.org/biocLite.R")
    biocLite("GEOquery")
    
  • 使用以下行将包加载到内存中:
    library("GEOquery")
    
  • 编辑以下行,将工作目录到文件的完整路径放在引号内,将数据作为对象读入内存 gse :
    gse=getGEO(filename="~/Downloads/GSE60341_series_matrix.txt.gz")
    
  • 现在,如果你运行 View(gse)您将在 gse 中看到一个格式良好的表格,其中包含 1950 行。

    查看 GEOquery Documentation了解更多信息。
  • 关于在 R 中正确读取序列矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28179032/

    相关文章:

    r - If 语句错误/不应用 if 语句

    R 热图,值低于 0 红色,高于 0 蓝色渐变

    使用 .htaccess 处理 PHP 错误并写入 php_error.log 文本文件

    c++ - 尝试从 R 调用 C++ 函数时出现 fatal error

    graphics - 基本R图形的改进

    c# - 上传日志(.txt 文件)与在数据库中每个事件插入 1 条记录,记录日志的效率

    c - c - 如何在c中比fprintf更快地写入文本文件?

    c - 在 C 中将字符串写入文本文件会留下一些字符

    r - 将 MIN 和 MAX 组合成 R 中的 rowise 函数

    c# - 如何从 C# 中的文本文件中删除一行?