library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
## 
## 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
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.4.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
library(stringr)

Read in the data files, and read in the csv files.

conditions <- read.csv("~/Desktop/BIN521L/conditions_annotation.csv")
CC <- read.table("labels_CC.csv",
                 sep = "\n",
                 header = FALSE,
                 stringsAsFactors = FALSE)

MF <- read.table("labels_MF.csv",
                 sep = "\n",
                 header = FALSE,
                 stringsAsFactors = FALSE)

BP <- read.table("labels_BP.csv",
                 sep = "\n",
                 header = FALSE,
                 stringsAsFactors = FALSE)
expression <- read.csv("SC_expression.csv")
colnames(conditions)
## [1] "ID"                     "primary"                "secondary"             
## [4] "additional_information"
head(conditions)
##       ID  primary   secondary additional_information
## 1 AFIQCI wildtype  wildtype 1                       
## 2 AFIQBR wildtype  wildtype 2                       
## 3 AFIINC     itc1 itc1-1_dUTP                       
## 4 AFNAQI     itc1 itc1-1_dUTP                       
## 5 AFNCCR     swr1 swr1 mutant                       
## 6 AFNCCA     swr1 swr1 mutant

Chose Swr1 for a condition after choosing one from the above summary.

swr1conditions <- conditions[grepl("swr1", conditions$primary),]
swr1Data <- expression[, c("X", swr1conditions$ID)]
head(swr1Data)
##         X    AFNCCR   AFNCCA
## 1 YAL008W 1.6045494 3.244893
## 2 YBR255W 3.4161373 7.346928
## 3 YGR164W 0.6314678 1.390668
## 4 YGR131W 0.4934421 1.128278
## 5 YNL003C 4.6790730 9.953338
## 6 YBR135W 3.9544378 7.361505

Turned the tables into columns and removed any data not needed for graphing.

CC <- str_split_fixed(CC$V1, ",", 3)
MF <- str_split_fixed(MF$V1, ",", 3)
BP <- str_split_fixed(BP$V1, ",", 3)

colnames(CC) <- c("gene", "validation", "localization")
colnames(MF) <- c("gene", "validation", "localization")
colnames(BP) <- c("gene", "validation", "localization")

CC <- as.data.frame(CC)
MF <- as.data.frame(MF)
BP <- as.data.frame(BP)

CC <- CC[CC$gene != "gene", ]
MF <- MF[MF$gene != "gene", ]
BP <- BP[BP$gene != "gene", ]

CC <- CC[!grepl("_", CC$gene), ]
MF <- MF[!grepl("_", MF$gene), ]
BP <- BP[!grepl("_", BP$gene), ]

Combined the three files above. Merged the newly created datafile into the Swr1 created above.

labeled <- full_join(CC, MF, by = "gene", suffix = c("_CC", "_MF"))
labeled <- full_join(labeled, BP, by = "gene")
head(labeled)
##      gene validation_CC    localization_CC validation_MF
## 1 YAL008W      Verified membrane,mitochond      Verified
## 2 YBR255W      Verified                         Verified
## 3 YGR164W       Dubious cellular_component       Dubious
## 4 YGR131W      Verified           membrane      Verified
## 5 YNL003C      Verified mitochond,membrane      Verified
## 6 YBR135W      Verified                         Verified
##             localization_MF validation            localization
## 1        molecular_function   Verified                     ion
## 2        molecular_function   Verified      biological_process
## 3        molecular_function    Dubious      biological_process
## 4        molecular_function   Verified             protein,ion
## 5 transmembrane,transporter   Verified           transport,ion
## 6            kinase,histone   Verified regulation,ion,positive
Data <- left_join(swr1Data, labeled, by = c("X" = "gene"))
head(Data)
##         X    AFNCCR   AFNCCA validation_CC    localization_CC validation_MF
## 1 YAL008W 1.6045494 3.244893      Verified membrane,mitochond      Verified
## 2 YBR255W 3.4161373 7.346928      Verified                         Verified
## 3 YGR164W 0.6314678 1.390668       Dubious cellular_component       Dubious
## 4 YGR131W 0.4934421 1.128278      Verified           membrane      Verified
## 5 YNL003C 4.6790730 9.953338      Verified mitochond,membrane      Verified
## 6 YBR135W 3.9544378 7.361505      Verified                         Verified
##             localization_MF validation            localization
## 1        molecular_function   Verified                     ion
## 2        molecular_function   Verified      biological_process
## 3        molecular_function    Dubious      biological_process
## 4        molecular_function   Verified             protein,ion
## 5 transmembrane,transporter   Verified           transport,ion
## 6            kinase,histone   Verified regulation,ion,positive
Dataext <- Data %>%
  pivot_longer(
    cols = c(AFNCCR, AFNCCA),
    names_to = "treatment",
    values_to = "count")

Made a summary Tibble for the combined data sets above.

treatment_summary <- Dataext %>%
  group_by(treatment) %>%
  summarise(
    mean = mean(count, na.rm = TRUE),
    median = median(count, na.rm = TRUE),
    count = n())

treatment_summary
## # A tibble: 2 × 4
##   treatment  mean median count
##   <chr>     <dbl>  <dbl> <int>
## 1 AFNCCA     165.   9.94  6071
## 2 AFNCCR     165.   4.71  6071

Plotted the data into a violin plot.

plotData <- Dataext %>%
  filter(count <= 328)

ggplot(plotData, aes(x = treatment, y = count)) +
  geom_violin() +
  geom_boxplot(width = 0.1) +
  labs(
    x = "Treatment",
    y = "Expression Count",
    title = "Distribution of Gene Expression for swr1")