##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Read in all label files from the unzipped yeast transcriptomics data.
allLabels <- list.files("Labels", pattern = "*.csv",
full.names = TRUE)
Convert the label values imported into R into a list of data frames.
dataList <- lapply(allLabels,
function(x){
read.table(file=x,sep="\n")
})
Divide the text string every row into three columns using the first two commas.
dataList <- lapply(dataList,
function(x){
as.data.frame(str_split_fixed(x$V1, ",", 3))
})
Remove the rows that don’t have gene names, as we cannot place the data to an identifier.
dataList <- lapply(dataList,
function(x){
x[!grepl("_",x$V1),]
x[!grepl("gene",x$V1),]
})
Remove extra columns and deleted validation data from the second and third data frames.
dataList[[2]] <- dataList[[2]][,-2]
dataList[[3]] <-dataList[[3]][,-2]
Merge data that are in list format.
newYeast <- dataList %>% reduce(left_join, by = "V1")
names(newYeast) <- c("gene","validation","BP","CC","MF")
write.csv(newYeast,"mergedYeast.csv",row.names = FALSE)