-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguess.sample.data.R
More file actions
21 lines (21 loc) · 872 Bytes
/
guess.sample.data.R
File metadata and controls
21 lines (21 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#' Derive (guess) sample data from sample file names
#'
#' @param filenames Vector of sample file names.
#' @param splitchars Vector of delimiter characters for splitting filenames
#' @export
guess.sample.data <- function(filenames=NULL,splitchars=c('.','_','-')){
if(is.null(filenames)){
counts <- read.table('data/gene_counts.tsv',sep='\t',header=TRUE,row.names=1)
filenames <- colnames(counts)
}
split.pattern <- paste(c('[',splitchars,']'),collapse='')
df <- t(as.data.frame(strsplit(filenames,split=split.pattern)))
df <- as.data.frame(df)
rownames(df) <- filenames
cols <- 1:ncol(df)
#Is a particular column informative (i.e. does it vary over the samples)?
is.informative <- function(i) length(unique(df[,i])) > 1
df <- df[,sapply(cols,is.informative),drop=FALSE]
rownames(df) <- apply(df, 1, function(l) paste(l,collapse='.'))
df
}