library(stringr)
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.4.3
## Warning: package 'tibble' was built under R version 4.4.3
## Warning: package 'tidyr' was built under R version 4.4.3
## Warning: package 'readr' was built under R version 4.4.3
## Warning: package 'purrr' was built under R version 4.4.3
## Warning: package 'dplyr' was built under R version 4.4.3
## Warning: package 'lubridate' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.0 ✔ purrr 1.2.1
## ✔ forcats 1.0.1 ✔ readr 2.2.0
## ✔ ggplot2 4.0.2 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Load in all the data files: CC, MF, and BP.
CC <- read.table("~/Desktop/BIN521L/labels_CC.csv",sep = "\n", header = FALSE, stringsAsFactors = FALSE)
MF <- read.table("~/Desktop/BIN521L/labels_MF.csv",sep = "\n", header = FALSE, stringsAsFactors = FALSE)
BP <- read.table("~/Desktop/BIN521L/labels_BP.csv",sep = "\n", header = FALSE, stringsAsFactors = FALSE)
Create a concise file for all three data sets. Separate the files
into three coloumns, and name each coloumn. Remove any extra rows that
have no named genes, and the status coloumn.
datalist <- list(CC, MF, BP)
datalist <- lapply(datalist, function(x) {
str_split_fixed(x$V1, ",", 3)
})
datalist <- lapply(datalist, as.data.frame)
datalist[[1]] <- setNames(datalist[[1]], c("gene", "status", "CC"))
datalist[[2]] <- setNames(datalist[[2]], c("gene", "status", "MF"))
datalist[[3]] <- setNames(datalist[[3]], c("gene", "status", "BP"))
datalist <- lapply(datalist, function(x) {
x <- x[x$gene != "gene", ]
x <- x[!grepl("_", x$gene), ]
x
})
datalist[[2]]$status <- NULL
datalist[[3]]$status <- NULL
Merge together all of the three datafiles. Look at the final product
and then download it as a new csv file.
merged <- Reduce(function(x, y) {
merge(x, y, by = "gene", all = TRUE)
}, datalist)
head(merged)
## gene status CC MF
## 1 YAL001C Verified nucle RNA polymerase,transcription
## 2 YAL002W Verified membrane
## 3 YAL003W Verified
## 4 YAL004W Dubious cellular_component molecular_function
## 5 YAL005C Verified membrane,nucle,cytoplasm tRNA,ATP
## 6 YAL007C Verified molecular_function
## BP
## 1 ion,protein
## 2 protein,targeting,transport
## 3 ion,regulation,negative
## 4 biological_process
## 5 protein,ion,targeting,catabolic process,negative,regulation
## 6 protein,ion,transport
write.csv(merged, "yeastPt1.csv", row.names = FALSE)