comparison center_scale.R @ 1:a96cc346819c draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/gsc_center_scale commit 7865eb7eb9d862e9967fe519d28df705d973fbaf
author artbio
date Fri, 12 Jul 2019 11:44:50 -0400
parents bcbd7179d8ec
children 163befe5f05b
comparison
equal deleted inserted replaced
0:bcbd7179d8ec 1:a96cc346819c
41 41
42 transform <- function(df, center=TRUE, scale=TRUE) { 42 transform <- function(df, center=TRUE, scale=TRUE) {
43 transfo <- scale( 43 transfo <- scale(
44 t(df), 44 t(df),
45 center=center, 45 center=center,
46 scale=center 46 scale=scale
47 ) 47 )
48 return(as.data.frame(t(transfo))) 48 return(as.data.frame(t(transfo)))
49 } 49 }
50 50
51 opt = parse_args(OptionParser(option_list = option_list), 51 opt = parse_args(OptionParser(option_list = option_list),
68 ) 68 )
69 colnames(data.factor) <- c("cellid", "level") 69 colnames(data.factor) <- c("cellid", "level")
70 data.transformed <- data.frame(row.names=rownames(data), stringsAsFactors=FALSE) 70 data.transformed <- data.frame(row.names=rownames(data), stringsAsFactors=FALSE)
71 for (group in levels(data.factor$level)){ 71 for (group in levels(data.factor$level)){
72 subcells <- as.data.frame(subset(data.factor, level==group, select=cellid)) 72 subcells <- as.data.frame(subset(data.factor, level==group, select=cellid))
73 subdata <- as.data.frame(subset(data, select=subcells$cellid)) 73 subdata <- as.data.frame(subset(data, select=as.vector(subcells$cellid)))
74 subdata.transformed <- transform(subdata, center=opt$center, scale=opt$scale) 74 subdata.transformed <- transform(subdata, center=as.logical(opt$center),
75 scale=as.logical(opt$scale))
75 data.transformed <- cbind(data.transformed, subdata.transformed) 76 data.transformed <- cbind(data.transformed, subdata.transformed)
76 } 77 }
77 } else { 78 } else {
78 data.transformed <- transform(data, center=opt$center, scale=opt$scale) 79 data.transformed <- transform(data, center=as.logical(opt$center),
80 scale=as.logical(opt$scale))
79 } 81 }
80 82
81 83
82 write.table( 84 write.table(
83 cbind(gene=rownames(data.transformed), data.transformed), 85 cbind(gene=rownames(data.transformed), data.transformed),