【发布时间】:2014-09-01 21:12:35
【问题描述】:
大家好##。
我遇到了一些无法解决的 R 问题:目前我正在使用 GEOquery 包,我想检索 gse 文件元数据中的一些信息。
更准确地说,我正在寻找频道标签(例如 Cye3)。这是我的代码示例:
>library(GEOquery)
>gse<-getGEO("GSE2253",GSEMatrix=TRUE,destdir=".")
>gse<-gse[[1]]
>gse$label_ch1[1]
V2
Levels: According to Affymetrix protocol (biotin)`
这是我的问题
`> is.na(gse$label_ch1[1])
V2
FALSE
> is.null(gse$label_ch1[1])
[1] FALSE`
此 GSE 文件是一个文本文件,在与标签 (!Sample_label_ch1) 对应的行中没有值。所以,这是我为我的工作所做的:
`if(is.na(gse$label_ch1[1])){
color<-"Non specified"
} else {
label<-gse$label_ch1[1]
}`
所以,如果我没有得到频道的信息,我只会说“未指定”,否则,我会返回该值。但是我的脚本中的 if/else 语句有错误:
Error in if (file == "") file <- stdout() else if (is.character(file)) { :
the length of argument is null
对不起,如果错误翻译不准确,我的R版本是法语^^。
我试过了
if(as.character(gse$label_ch1[1])=="")
但它也不起作用
如果有人有想法可以帮助我^^
提前致谢!
脚本:
sample<-NULL
output<-NULL
gse<-NULL
color<-NULL
series_matrix<-dir(getwd(),pattern="*series_matrix.txt")
series_matrix<-unlist(strsplit(series_matrix,"_")[1])
for(i in 1:length(series_matrix)){
gse<-getGEO(series_matrix[i],GSEMatrix=TRUE,destdir=".")
gse<-gse[[1]]
if(length(gse$label_ch1[1])==0){
color<-"Non specified"
} else {
color<-gse$label_ch1[1]
}
print (color)
sample<-cbind(as.character(gse$title),as.character(gse$geo_accession))
outputsample<-paste(getwd(),"/sample.txt",sep="")
write.table(paste("txt",color,sep=""),output,
row.names=FALSE,col.names=FALSE,sep="\t",quote=FALSE)
write.table(sample,outputsample,
row.names=FALSE,col.names=FALSE,sep="\t",quote=FALSE,append=TRUE)
Feature_Num<-list(1:length(featureNames(gse)))
Gene_Symbol<-pData(featureData(gse)[,11])
Probe_Name<-pData(featureData(gse)[,1])
Control_Type<-pData(featureData(gse)[,3])
liste<-as.character(sampleNames(gse))
for(i in 1:lenght(liste)){
values<-cbind(Feature_Num,Gene_Symbol,Probe_name,Control_Type,exprs(gse)[,i])
colnames(values)<-c("Feature_Num","Gene_Symbol",
"Probe_Name","Control_Type","gMedianSignal")
write.table(values,paste(getwd(),"/Ech",liste[i],".txt",sep=""),
row.names=FALSE,quote=FALSE,sep="\t")
}
}
如果您想了解此脚本中的行,请不要犹豫
【问题讨论】:
-
如果这是 is.na 应该起作用的一个因素,你能给出类和类型吗?
-
oooh 参数长度为空...您可以尝试
if(length(gse$label_ch1[1])==0)如果这不起作用,您可以随时尝试使用 double[获取变量,例如gse$label_ch1[[1]] -
非常感谢您的回答。它工作得很好^^但不幸的是我总是有这个文件错误。我从 R 开始,所以我不太舒服。因为我总是有这个错误,也许它不是来自我的 if?我让你写我写的脚本(编辑第一条消息)也许你能发现哪里出了问题
-
准确地说:它在 if 被传递后起作用 ^^ 但它仍然是我的“空”变量的问题