BSAstandardSpectra <- read.csv('H3_PE600_Lp100_0001_H3_25-07-18_15-46_0001.txt')
BSAdigestSpectra <- read.table('H4_PE600_LP100_0001_H4_25-07-18_15-48_0001.txt', header = FALSE, skip = 8)
BSAstandardSpectra = BSAstandardSpectra[,1:2]
Clean up outliers
BSAdigestSpectra <- BSAdigestSpectra[-1,]
##rename columns to match BSAdigest
names(BSAstandardSpectra) <- c('V1', 'V2')
##remove outliers that are greater than 3000
BSAdigestSpectra <- BSAdigestSpectra [BSAdigestSpectra$V1<3000,]
BSAstandardSpectra <- BSAstandardSpectra [BSAstandardSpectra$V1<3000,]
##rename columns to be MZ and intensity
names(BSAdigestSpectra) <- c('m_z', 'intensity')
names(BSAstandardSpectra) <- c('m_z', 'intensity')
load tidyverse and merge data tables with them labeled under “type”
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.2 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── 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
##assign data type to new type column
BSAdigestSpectra$type <-'Sample'
BSAstandardSpectra$type <- 'Standard'
##make new data tavle with everything combined
ms_data <- rbind(BSAdigestSpectra, BSAstandardSpectra)
names(ms_data)<-c('m_z','intensity', 'type')
Plot merged data as scatter
ggplot(ms_data, aes(x = m_z,y=intensity))+
geom_point(aes(colour = type))+
scale_color_manual(values=c("#ffc868","#e5216b"))+
xlab("m/z ratio") + ylab("Millivolts")+
theme(legend.position="left")
Plot merged data as bar
ggplot(ms_data, aes(x = m_z,y=intensity))+
geom_col(aes(colour = type,fill=type))+
scale_color_manual(values=c("#ffc868","#e5216b"))+
scale_fill_manual(values=c("#ffc868","#e5216b"))+
xlab("m/z ratio") + ylab("Millivolts")+
##break up graphs by type and show them together
facet_wrap(~type,nrow=2)
matchSpectra <- merge(BSAdigestSpectra,BSAstandardSpectra, by="m_z")
write.csv(matchSpectra,"matchSpectra.csv")