R/annotationMatrix_withSubpopProp.R

Defines functions annotationMatrix_withSubpopProp

Documented in annotationMatrix_withSubpopProp

#' Adds subpopulation proportion for the annotation matrix for the clades
#' 
#' @param aggregateMatrix_withAnnotation the annotated clade matrix
#' @return Annotated clade matrix with subpopulation proportions
#' @export


annotationMatrix_withSubpopProp<-function(aggregateMatrix_withAnnotation){
  annotationMatrix_prop<-matrix(0,0,0)
  for(i in 1:length(unique(aggregateMatrix_withAnnotation[,3]))){
    sampleID_i<-unique(aggregateMatrix_withAnnotation[,3])[i]
    sampleMeans<-aggregateMatrix_withAnnotation[which(aggregateMatrix_withAnnotation[,3]==sampleID_i),]
    counts<-sampleMeans[,ncol(sampleMeans)]
    subpop_proportion<-counts/sum(counts)
    subpop_proportion<-signif(subpop_proportion*100, digits=4)
    annotationMatrix_prop<-rbind(annotationMatrix_prop,cbind(sampleMeans,subpop_proportion))
  }
  
  write.table(annotationMatrix_prop, file="annotationMatrix_withSubpopProp.xls", sep="\t", row.names=FALSE)
  return(annotationMatrix_prop)
}

Try the PAC package in your browser

Any scripts or data that you put into this service are public.

PAC documentation built on Feb. 18, 2021, 9:06 a.m.