Entering edit mode
3.5 years ago
smrutimayipanda
▴
20
Hi,
I am getting error while running this code:
if( datatype =="sam" )
{
#dat <- read.table(pipe(paste("cut -f3,4",file("S_57_IonXpress_001.sam"),sep=" ")), header=FALSE,colClasses= c("character","integer"))
dat <- read.table(file("stdin"), header=FALSE,colClasses= c("character","integer"))
colnames(dat)=c("refChr","begin")
dat=dat[dat$refChr!="*" & dat$refChr!="chrM" ,]
binindex = ifelse((dat$begin%%50000)==0,floor(dat$begin/50000)-1,floor(dat$begin/50000))
fastbincount = table(paste(dat$refChr,binindex, sep="_"))
newtemp=as.data.frame(matrix(NA, ncol=2, nrow=length(fastbincount)))
newtemp[,1]=paste(names(fastbincount))
newtemp[,2]=as.numeric(paste(fastbincount))
colnames(newtemp)=c("binName","counts")
}
if( datatype =="counts" )
{
newtemp <- read.table(file.name, header=FALSE,colClasses= c("character","integer"))
colnames(newtemp)=c("binName","counts")
}
bininfo = merge(bininfo, newtemp, by="binName",all.x=T)
bininfo=bininfo[order(bininfo$binorder),]
error is:
Error in if (datatype == "sam") { : missing value where TRUE/FALSE needed.
Error in if (datatype == "counts") { :
missing value where TRUE/FALSE needed.
Error in as.data.frame(y) : object 'newtemp' not found
Please tell me how would I rectify this error? I couldn't understand actually. Thanks in advance
Errors are clear: datatype is NA. newtemp object doesn't exist.
Please format your code by highlighting it and pressing the Code Sample button. Also that is a lot of code - I don't think anyone wants to step through all that, especially without a reproducible example. Could you try and locate the specific line the error occurs? Thanks.
I am getting error in this particular code. Please have a look and help me, if you get the answer.
Is there anyone who can help me in this?
without example data it is difficult to troubleshoot the code, however working code for loading sam file is here. See if this works for you:
R code:
output:
suggestion is to combine two ifs with if else code.
Thank you for this code. However, I am pasting the example data:
Pasted data is not in correct example data format (sam).
It didnt work for me. It is showing another error.