Seqff.r script is giving error while running
0
0
Entering edit mode
3.5 years ago

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

R • 1.6k views
ADD COMMENT
1
Entering edit mode

Errors are clear: datatype is NA. newtemp object doesn't exist.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

I am getting error in this particular code. Please have a look and help me, if you get the answer.

ADD REPLY
0
Entering edit mode

Is there anyone who can help me in this?

ADD REPLY
0
Entering edit mode

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:

$ cat test.sam 
@HD VN:1.0  SO:unsorted
@SQ SN:test_ref LN:17637
SRR1524970.144283   16  test_ref    1706    255 25M *   00  TGCTGATGAAGCAGAACAACTTTAA   ]YG[^baaaa^W`ab]]````aaba   AS:i:0  XN:i:0  XM:i:0  XO:i:0  XG:i:0  NM:i:0  MD:Z:25 YT:Z:UU
SRR1524970.316478   16  test_ref    1706    255 24M *   00  TGCTGATGAAGCAGAACAACTTTA    `\X_`aaaaaY]``b_aa_aaaaa    AS:i:0  XN:i:0  XM:i:0  XO:i:0  XG:i:0  NM:i:0  MD:Z:24 YT:Z:UU

R code:

> datatype="sam"
> if( datatype =="sam" ){
+     dat=read.table("test.sam",comment.char = "@", header=FALSE)[,c(3,4)]
+     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")
+ }

output:

> newtemp

     binName counts
1 test_ref_0      2

suggestion is to combine two ifs with if else code.

ADD REPLY
0
Entering edit mode

Thank you for this code. However, I am pasting the example data:

@RG     ID:10200106485  LB:10200106485  PL:ILLUMINA     PM:HISEQ        SM:10200106485
@PG     ID:bwa  PN:bwa  VN:0.7.17-r1188 CL:bwa mem -Y -M -R @RG\tID:10200106485\tLB:10200106485\tPL:ILLUMINA\tPM:HISEQ\tSM:10200106485 hg19.fa 50_IonXpress_010.fastq
2QC4F:07189:04737       0       chr2    243152517       0       53M     *       0       0       CCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTA   770762680//)/70793990:;388/88/55*55/58/88388*5/)/6)//   NM:i:0  MD:Z:53 AS:i:53 XS:i:53 RG:Z:10200106485
2QC4F:06025:06043       0       chr2    243152493       0       49M     *       0       0       CCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAAC       ;;4;;7;:5;;6;:4;:49928;4::28839:3::/55*55/58/5-)-       NM:i:0  MD:Z:49 AS:i:49 XS:i:49 RG:Z:10200106485
2QC4F:02378:12056       0       chr1    10355   0       34M     *       0       0       CCTAACCCTAACCCTAACCCTAACCCTAACCCTA      <7<<7<<4<;4:928:3::1:</57+7:4891//      NM:i:0  MD:Z:34 AS:i:34 XS:i:34 RG:Z:10200106485
ADD REPLY
0
Entering edit mode

Pasted data is not in correct example data format (sam).

ADD REPLY
0
Entering edit mode

It didnt work for me. It is showing another error.

ADD REPLY

Login before adding your answer.

Traffic: 1663 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6