markowetzlab / CNsignatures

This is data and code from our first paper on copy number signatures (Macintyre et al., Nat Gen, 2018).
https://www.nature.com/articles/s41588-018-0179-8?proof=trueInJun
MIT License
6 stars 2 forks source link

getSegSize error #2

Closed vymao closed 4 years ago

vymao commented 4 years ago

Hi,

I'm trying to run this using a file formatted in the specified way (a text file with columns "chromosome", "start", "end", and "segVal"). However, I am getting an error:

 Error in `colnames<-`(`*tmp*`, value = `*vtmp*`) : 
  attempt to set 'colnames' on an object with less than two dimensions 
4.
stop("attempt to set 'colnames' on an object with less than two dimensions") 
3.
`colnames<-`(`*tmp*`, value = `*vtmp*`) at helper_functions.R#87
2.
getSegsize(CN_data) at main_functions.R#100
1.
extractCopynumberFeatures(data) 

I looked into the script here:

getSegsize<-function(abs_profiles)
{
    out<-c()
    samps<-getSampNames(abs_profiles)
    for(i in samps)
    {
        if(class(abs_profiles)=="QDNAseqCopyNumbers")
        {
            segTab<-getSegTable(abs_profiles[,which(colnames(abs_profiles)==i)])
        }
        else
        {
            segTab<-abs_profiles[[i]]
            colnames(segTab)[4]<-"segVal"
        }
        segTab$segVal[as.numeric(segTab$segVal)<0]<-0
        seglen<-(as.numeric(segTab$end)-as.numeric(segTab$start))
        seglen<-seglen[seglen>0]
        out<-rbind(out,cbind(ID=rep(i,length(seglen)),value=seglen))
    }
    rownames(out)<-NULL
    data.frame(out,stringsAsFactors = F)
}

I believe the error is in colnames(segTab)[4]<-"segVal". segTab should be an atomic vector, no? Since you are iterating through columns? So I'm not sure why you are assigning a new header to the fourth column of a 1-column vector.

Please advise, thanks.

vymao commented 4 years ago

Never mind, I figured this out.