[R] Problems w/ creating object

William Dunlap wdun|@p @end|ng |rom t|bco@com
Mon Apr 22 23:09:16 CEST 2019


  file.info( "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt" )
would tell about the permissions on the file, if it exists (and give NA's
if it did not).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Apr 22, 2019 at 2:00 PM David Winsemius <dwinsemius using comcast.net>
wrote:

>
> On 4/22/19 11:49 AM, Spencer Brackett wrote:
> > Hello R users,
> >
> > I am trying to create an object out of some data a colleague sent my way,
> > so to duplicate the following code...
> >
> > library(data.table)
> > anno = as.data.frame(fread(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t",
> > header = T))
>
>
> At first glance it appeared that you sent the list a rather extensive
> bit of code and asked us to figure something out, but after looking at
> the error message it instead appears the it was the first effort at
> reading data from disk that threw an error. So the rest of the code is
> at best unnecessary and at worst seriously distracting (to us and more
> crucially to you).
>
> You should run your code one line at a time so you and the rest of us
> are not completely distracted. This was the error message:
>
> > anno = as.data.frame(fread(file =
>
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t",
> header = T))
> Error in fread(file =
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt",  :
>    File '/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt' does
> not exist or is non-readable.
>
> You claim this file exists, but I'm uncertain how convincing that
> assertion should be "scored". What do either of these show?
>
>   list.files(pattern =".txt$")
>
> # Or
>
> "mapper.txt" %in% list.files( paste0 ( getwd(),
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K"))
>
> --
>
> David.
>
>
> PS Please learn to post in plain-text. It didn't cause a problem this
> time but it probably will at some time in the future.
>
> > meth = read.table(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt", sep  ="\t",
> > header = T, row.names = 1)
> > meth = as.matrix(meth)
> > """ the loop just formats the methylation column names to match format"""
> > colnames(meth) = sapply(colnames(meth), function(i){
> >    c1 = strsplit(i,split = '.', fixed = T)[[1]]
> >    c1[4] = paste(strsplit(c1[4],split = "",fixed = T)[[1]][1:2],collapse
> =
> > "")
> >    paste(c1,collapse = ".")
> > })
> > exp = read.table(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep = "\t",
> > header = T, row.names = 1)
> > exp = as.matrix(exp)
> > c = intersect(colnames(exp),colnames(meth))
> > exp = exp[,c]
> > meth = meth[,c]
> > m = apply(meth, 1, function(i){
> >    log2(i/(1-i))
> > })
> > m = t(as.matrix(m))
> > an = anno[anno$probe %in% rownames(m),]
> > an = an[an$gene %in% rownames(exp),]
> > an = an[an$location %in% c("TSS200","TSS1500"),]
> >
> > p = apply(an,1,function(i){
> >    tryCatch(summary(lm(exp[as.character(i[2]),] ~
> > m[as.character(i[1]),]))$coefficient[2,4], error= function(e)NA)
> > })
> > t = apply(an,1,function(i){
> >    tryCatch(summary(lm(exp[as.character(i[2]),] ~
> > m[as.character(i[1]),]))$coefficient[2,3], error= function(e)NA)
> > })
> > an1 =cbind(an,p)
> > an1 = cbind(an1,t)
> > an1$q = p.adjust(as.numeric(an1$p))
> > summary(lm(exp["MAOB",] ~ m["cg00121904",]$coefficient[2,c(3:4)]
> > ###############################################
> >
> > m2 = m
> > ll = list()
> > for(i in colnames(m2)){
> >    str = strsplit(i, split = ".", fixed = T)[[1]]
> >    if(str[4] == "11"){
> >
> >    }else{
> >      ll = c(ll,i)
> >    }
> > }
> > ll = unlist(ll)
> > m2 = m2[,ll]
> > colnames(m2) = sapply(colnames(m2), function(i){
> >    str = strsplit(i,split = ".", fixed = T)[[1]]
> >    p = paste(str[c(1:3)], collapse = "-")
> > })
> >
> >
> > clin = as.data.frame(fread(file =
> >
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/survival/FireHose/GBM/GBM.clin.merged.txt",
> > sep = "\t", header = F))
> > clin = t(clin)
> > colnames(clin) = clin[1,]
> > rownames(clin) = toupper(clin[,"patient.bcr_patient_barcode"])
> > clin = clin[2:length(clin[,1]),]
> > #"patient.stage_event.pathologic_stage"
> > clin1 =
> >
> clin[,c("patient.age_at_initial_pathologic_diagnosis","patient.days_to_death","patient.days_to_last_followup","patient.vital_status")]
> > clin1 = cbind(clin1,rep("bla",length(clin1[,1])))
> > clin2 = as.matrix(clin1)
> > colnames(clin2)[length(colnames(clin2))] = "time"
> >
> > for(i in rownames(clin2)){
> >
> >    if(clin2[i,"patient.vital_status"] %in% c("alive")){
> >      clin2[i,"patient.vital_status"] =0
> >    }else if(clin2[i,"patient.vital_status"] %in% c("dead")){
> >      clin2[i,"patient.vital_status"] =1
> >    }else{
> >      clin2[i,"patient.vital_status"] = "NA"
> >    }
> >
> >    if(is.na(clin2[i,"patient.days_to_last_followup"])){
> >      clin2[i,"time"] = clin2[i,"patient.days_to_death"]
> >    }else{
> >      clin2[i,"time"] = clin2[i,"patient.days_to_last_followup"]
> >    }
> > }
> >
> > clin2 = clin2[!is.na(clin2[,"time"]),]
> > clin2 = clin2[!is.na(clin2[,"patient.vital_status"]),]
> >
> > library(survival)
> > p = intersect(colnames(m2), rownames(clin2))
> > surv =
> >
> Surv(as.numeric(clin2[p,"time"]),as.numeric(clin2[p,"patient.vital_status"]))
> >
> > an_m = anno[anno$probe %in% rownames(m2),]
> > an_m = an[an$gene %in% rownames(exp),]
> >
> > sur_z = apply(an_m, 1, function(i){
> >    tryCatch(summary(coxph(surv ~
> >
> as.numeric(m2[as.character(i[1]),p])+as.numeric(clin2[p,"patient.age_at_initial_pathologic_diagnosis"])))$coefficients[1,c("z")],
> > error = function(e) NA)
> > })
> >
> > sur_p = apply(an_m, 1, function(i){
> >    tryCatch(summary(coxph(surv ~
> >
> as.numeric(m2[as.character(i[1]),p])+as.numeric(clin2[p,"patient.age_at_initial_pathologic_diagnosis"])))$coefficients[1,c("Pr(>|z|)")],
> > error = function(e) NA)
> > })
> >
> > qsur = p.adjust(as.numeric(sur_p))
> > sur = cbind(sur_z,sur_p)
> > sur = cbind(sur,qsur)
> >
> >
> > The file is a text file
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", which is
> > then proceeded by another txt. file
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt, which I wish to
> > load subsequently. However, when i tried copying the procedure above I
> > received the following error message..
> >
> > library(data.table)
> >> anno = as.data.frame(fread(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t",
> > header = T))
> > Error in fread(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt",  :
> >    File '/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt'
> does
> > not exist or is non-readable.
> > getwd()=='C:/Users/Spencer/Documents'
> >
> > The file does exit so in what context is it 'unreadable' and how might I
> > solve this situation?
> >
> > Best,
> >
> > Spencer
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list