Skip to content
Snippets Groups Projects
CalcOurMetadata.R 9.55 KiB

CalcOurMetadata <- function(ident, data, data.info){

	# first, all the info about the experiments
	seqindex = names(ident)
	seqindex = substr(seqindex,1,5)
	
	sample = seqindex
	sample = sub("d3s01", "8.1", sample, ignore.case=F, fixed =T)
	sample = sub("d3s02", "8.2", sample, ignore.case=F, fixed =T)
	sample = sub("d3s03", "8.2", sample, ignore.case=F, fixed =T)
	sample = sub("d3s04", "11.1", sample, ignore.case=F, fixed =T)
	sample = sub("d3s05", "11.1", sample, ignore.case=F, fixed =T)
	sample = sub("d3s06", "11.1", sample, ignore.case=F, fixed =T)
	sample = sub("d3s07", "11.2", sample, ignore.case=F, fixed =T)
	sample = sub("d3s08", "11.2", sample, ignore.case=F, fixed =T)
	sample = sub("d3s09", "11.2", sample, ignore.case=F, fixed =T)
	sample = sub("d3s10", "11.3", sample, ignore.case=F, fixed =T)
	sample = sub("d3s11", "11.3", sample, ignore.case=F, fixed =T)
	sample = sub("d4s01", "8.1", sample, ignore.case=F, fixed =T)
	sample = sub("d4s02", "8.1", sample, ignore.case=F, fixed =T)
	sample = sub("d4s03", "8.1", sample, ignore.case=F, fixed =T)
	sample = sub("d4s04", "8.1", sample, ignore.case=F, fixed =T)
	sample = sub("d4s05", "8.2", sample, ignore.case=F, fixed =T)
	sample = sub("d4s07", "12.1", sample, ignore.case=F, fixed =T)
	sample = sub("d4s08", "12.1", sample, ignore.case=F, fixed =T)
	sample = sub("d4s09", "12.2", sample, ignore.case=F, fixed =T)
	sample = sub("d4s10", "12.2", sample, ignore.case=F, fixed =T)
	sample = sub("d4s11", "12.3", sample, ignore.case=F, fixed =T)
	sample = sub("d5s01", "12.3", sample, ignore.case=F, fixed =T)
	sample = sub("d5s02", "12.3", sample, ignore.case=F, fixed =T)
	sample = sub("d5s03", "12.3", sample, ignore.case=F, fixed =T)
	sample = sub("d5s04", "12.3", sample, ignore.case=F, fixed =T)
	sample = sub("d5s05", "12.3", sample, ignore.case=F, fixed =T)
	sample = sub("d5s06", "15.1", sample, ignore.case=F, fixed =T)
	sample = sub("d5s07", "15.1", sample, ignore.case=F, fixed =T)
	sample = sub("d5s08", "15.2", sample, ignore.case=F, fixed =T)
	sample = sub("d5s09", "15.2", sample, ignore.case=F, fixed =T)
	sample = sub("d5s10", "15.2", sample, ignore.case=F, fixed =T)
	sample = sub("d5s11", "15.3", sample, ignore.case=F, fixed =T)
	sample = sub("d5s12", "15.3", sample, ignore.case=F, fixed =T)
	sample = sub("d6s01", "16.1", sample, ignore.case=F, fixed =T)
	sample = sub("d6s02", "16.1", sample, ignore.case=F, fixed =T)
	sample = sub("d6s03", "16.2", sample, ignore.case=F, fixed =T)
	sample = sub("d6s04", "16.2", sample, ignore.case=F, fixed =T)
	sample = sub("d6s05", "16.3", sample, ignore.case=F, fixed =T)
	sample = sub("d6s06", "16.3", sample, ignore.case=F, fixed =T)
	sample = sub("d6s07", "16.4", sample, ignore.case=F, fixed =T)
	sample = sub("d6s08", "16.4", sample, ignore.case=F, fixed =T)
	sample = sub("d6s09", "17.1", sample, ignore.case=F, fixed =T)
	sample = sub("d6s10", "17.1", sample, ignore.case=F, fixed =T)
	sample = sub("d6s11", "17.3", sample, ignore.case=F, fixed =T)
	sample = sub("d6s12", "17.3", sample, ignore.case=F, fixed =T)
	
	sample = sub("d7s01", "16.2", sample, ignore.case=F, fixed =T)
	sample = sub("d7s02", "16.2", sample, ignore.case=F, fixed =T)
	sample = sub("d7s03", "16.2", sample, ignore.case=F, fixed =T)
	sample = sub("d7s04", "17.2", sample, ignore.case=F, fixed =T)
	sample = sub("d7s05", "17.2", sample, ignore.case=F, fixed =T)
	sample = sub("d7s06", "17.2", sample, ignore.case=F, fixed =T)
	sample = sub("d7s07", "17.2", sample, ignore.case=F, fixed =T)
	sample = sub("d7s08", "17.2", sample, ignore.case=F, fixed =T)
	 
	library = seqindex
	library = sub("d3s01", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s02", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s03", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s04", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s05", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s06", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s07", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s08", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s09", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s10", "d3", library, ignore.case=F, fixed =T)
	library = sub("d3s11", "d3", library, ignore.case=F, fixed =T)
	library = sub("d4s01", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s02", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s03", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s04", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s05", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s07", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s08", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s09", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s10", "d4", library, ignore.case=F, fixed =T)
	library = sub("d4s11", "d4", library, ignore.case=F, fixed =T)
	library = sub("d5s01", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s02", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s03", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s04", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s05", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s06", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s07", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s08", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s09", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s10", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s11", "d5", library, ignore.case=F, fixed =T)
	library = sub("d5s12", "d5", library, ignore.case=F, fixed =T)
	library = sub("d6s01", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s02", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s03", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s04", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s05", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s06", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s07", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s08", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s09", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s10", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s11", "d6", library, ignore.case=F, fixed =T)
	library = sub("d6s12", "d6", library, ignore.case=F, fixed =T)
	library = sub("d7s01", "d7", library, ignore.case=F, fixed =T)
	library = sub("d7s02", "d7", library, ignore.case=F, fixed =T)
	library = sub("d7s03", "d7", library, ignore.case=F, fixed =T)
	library = sub("d7s04", "d7", library, ignore.case=F, fixed =T)
	library = sub("d7s05", "d7", library, ignore.case=F, fixed =T)
	library = sub("d7s06", "d7", library, ignore.case=F, fixed =T)
	library = sub("d7s07", "d7", library, ignore.case=F, fixed =T)
	library = sub("d7s08", "d7", library, ignore.case=F, fixed =T)
	
	area = sample
	area = sub("8.1", "cortex", area, ignore.case=F, fixed =T)
	area = sub("8.2", "cortex", area, ignore.case=F, fixed =T)
	area = sub("11.1", "cortex", area, ignore.case=F, fixed =T)
	area = sub("11.2", "cortex", area, ignore.case=F, fixed =T)
	area = sub("11.3", "DVR", area, ignore.case=F, fixed =T)
	area = sub("12.1", "cortex", area, ignore.case=F, fixed =T)
	area = sub("12.2", "cortex", area, ignore.case=F, fixed =T)
	area = sub("12.3", "DVR", area, ignore.case=F, fixed =T)
	area = sub("15.1", "DC", area, ignore.case=F, fixed =T)
	area = sub("15.2", "cortex ~DC", area, ignore.case=F, fixed =T)
	area = sub("15.3", "DVR", area, ignore.case=F, fixed =T)
	area = sub("16.1", "DC", area, ignore.case=F, fixed =T)
	area = sub("16.2", "postCtx", area, ignore.case=F, fixed =T)
	area = sub("16.3", "MC", area, ignore.case=F, fixed =T)
	area = sub("16.4", "DVR", area, ignore.case=F, fixed =T)
	area = sub("17.1", "DC+MC", area, ignore.case=F, fixed =T)
	area = sub("17.2", "postCtx", area, ignore.case=F, fixed =T)
	area = sub("17.3", "DVR", area, ignore.case=F, fixed =T)
	
	animal = sample
	animal = sub("8.1", "8", animal, ignore.case=F, fixed =T)
	animal = sub("8.2", "8", animal, ignore.case=F, fixed =T)
	animal = sub("11.1", "11", animal, ignore.case=F, fixed =T)
	animal = sub("11.2", "11", animal, ignore.case=F, fixed =T)
	animal = sub("11.3", "11", animal, ignore.case=F, fixed =T)
	animal = sub("12.1", "12", animal, ignore.case=F, fixed =T)
	animal = sub("12.2", "12", animal, ignore.case=F, fixed =T)
	animal = sub("12.3", "12", animal, ignore.case=F, fixed =T)
	animal = sub("15.1", "15", animal, ignore.case=F, fixed =T)
	animal = sub("15.2", "15", animal, ignore.case=F, fixed =T)
	animal = sub("15.3", "15", animal, ignore.case=F, fixed =T)
	animal = sub("16.1", "16", animal, ignore.case=F, fixed =T)
	animal = sub("16.2", "16", animal, ignore.case=F, fixed =T)
	animal = sub("16.3", "16", animal, ignore.case=F, fixed =T)
	animal = sub("16.4", "16", animal, ignore.case=F, fixed =T)
	animal = sub("17.1", "17", animal, ignore.case=F, fixed =T)
	animal = sub("17.2", "17", animal, ignore.case=F, fixed =T)
	animal = sub("17.3", "17", animal, ignore.case=F, fixed =T)
	
	seqindex = as.factor(seqindex)
	sampleident = as.factor(sample)
	areaident = as.factor(area)
	libraryident = as.factor(library)
	animalident = as.factor(animal)
	
	# then, percent mitochondrial genes CALCULATED FROM mitochondrial genes. 
	mito.genes = read.table("mitochondrial_genes.txt", header = F, quote="")
	mito.genes<-as.character(mito.genes[,1])
	percent.mito <- 100*(colSums(expm1(data[rownames(data) %in% mito.genes, ]))/colSums(expm1(data)))
	
	data.info.extended <- cbind(data.info, sampleident, areaident, libraryident, animalident, percent.mito)
	return(data.info.extended)

}