Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Updated MFAssign functions to work with R version 4.2.0
  • Loading branch information
skschum authored Jun 16, 2022
1 parent 8e14a5f commit 800f268
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 40 deletions.
35 changes: 24 additions & 11 deletions MFAssignR/R/MFAssign.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ MFAssign <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=1000, P
#############
#LCMS adjustment
cols <- ncol(peaks)
if(isopeaks != "none") {cols2 <- ncol(isopeaks)} else{cols2 <- 0}
ifelse(isopeaks != "none", cols2 <- ncol(isopeaks), cols2 <- 0)
if(cols == 3){
if(cols == 3) {monoSave <- peaks[c(1,2,3)]}
if(cols2 == 4 & isopeaks != "none") {isoSave <- isopeaks[c(1,2,3)]}
if(cols2 == 0 & isopeaks == "none") {isoSave <- data.frame(mass = -42, abund = -42, RT = -42)}
ifelse(cols2 == 4 & isopeaks != "none",isoSave <- isopeaks[c(1,2,3)], print("No Iso List Included"))
ifelse(cols2 == 0 & isopeaks == "none",isoSave <- data.frame(mass = -42, abund = -42, RT = -42), isoSave <- isoSave)
names(isoSave)[1] <- "exp_mass"
names(isoSave)[2] <- "abundance"
names(isoSave)[3] <- "RT"
Expand All @@ -214,7 +214,7 @@ MFAssign <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=1000, P
peaks <- peaks[peaks$mass >= lowMW,]
peaks <- peaks[peaks$mass <= highMW,]

isopeaks2 <- if(isopeaks != "none") isopeaks else data.frame(x=10^9,y=0,Tag = 0)
ifelse(isopeaks != "none", isopeaks2 <- isopeaks, isopeaks2 <- data.frame(x=0,y=0,Tag=0))

if(cols2 == 4){isopeaks2 <- isopeaks2[c(2,1,4)]} #LC Change
if(cols2 == 3){ isopeaks2 <- isopeaks2[c(2,1,3)]} #LC Change
Expand Down Expand Up @@ -690,7 +690,11 @@ records <- vector("list")
#Sulf <- records1[records1$S == 1,]
##################
###S34 isotope check QA
if(isopeaks != "none" & SulfCheck == "on"){
check <-0
ifelse(isopeaks != "none" , check <- 1, print(""))
#ifelse(cols2 == 4 & isopeaks != "none",isoSave <- isopeaks[c(1,2,3)], print("No Iso List Included"))

if(check == 1 & SulfCheck == "on"){
#The next line was changed for the new isotoping
SIso <- isopeaks2[isopeaks2$Tag == "S34"|isopeaks2$Tag == "C13_S34"|isopeaks2$Tag == "2C13_S34",]
SIso <- unlist(SIso[2])
Expand Down Expand Up @@ -2517,8 +2521,6 @@ records <- vector("list")
Ambigout <- Ambigout[Ambigout$group != "Dummy",]
Unambig <- Unambig[Unambig$Tag != "Ambiguous",]
PD <- rbind(Ambigout, Unambig)


PDG <- subset( PD, group == "CHO"|group == "CHNO"|group == "CHOS"|group == "CHNOS"|group == "CH"|group == "CHN")
PDB <- subset( PD, group != "CHO"&group != "CHNO"&group != "CHOS"&group != "CHNOS"&group != "CH"&group != "CHN")
PDBdummy <- data.frame(Exp_mass = 1)
Expand All @@ -2532,6 +2534,19 @@ records <- vector("list")
unassigned <- unassigned[unassigned$mass > 0,]


##########Palettes for plots
group_colors <- data.frame(group = c("CHO", "CHNO", "CHOS", "CHNOS", "CH", "CHN", "Other"),
color = c("green", "blue", "red", "purple", "gold", "cyan", "grey67"))



form_group <- data.frame(group = unique(PD$Tag2))

form_palette <- merge(form_group, group_colors, by.x = "group", by.y = "group")
form_palette <- setNames(form_palette$color, form_palette$group)
#print(form_palette)
###############

MZ<-ggplot2::ggplot() + ggplot2::geom_segment(data=records1, size=0.7,ggplot2::aes_string(x = "Exp_mass", xend = "Exp_mass", y = 0, yend = "RA"), color = "green")+
ggplot2::geom_segment(data=records1, size=0.7,ggplot2::aes_string(x = "C13_mass", xend = "C13_mass", y = 0, yend = "C13_Abund"), color = "blue")+
ggplot2::geom_segment(data=records1, size=0.7,ggplot2::aes_string(x = "C13_mass2", xend = "C13_mass2", y = 0, yend = "C13_Abund2"), color = "blue")+
Expand Down Expand Up @@ -2559,8 +2574,7 @@ records <- vector("list")

MZgroups<-ggplot2::ggplot() + ggplot2::geom_segment(data=PD, size=0.7,ggplot2::aes_string(x = "Exp_mass", xend = "Exp_mass", y = 0, yend = "RA", color = "Tag2"))+
ggplot2::facet_wrap(~Tag, ncol = 1, scales = 'free_y')+
ggplot2::scale_colour_manual(name = "Groups", values = c(CHO = "green", CHNO = "blue", CHOS = "red", CHNOS = "purple",
CH = "gold", CHN = "cyan", Other = "grey67")) +
ggplot2::scale_colour_manual(name = "Groups", values = form_palette) +
ggplot2::theme_bw()+ggplot2::labs(x = "Ion Mass", y = "Abundance", title = "Assignment Mass Spectrum", color = "DBE")+
ggplot2::theme(axis.title=ggplot2::element_text(size = 15, face = "bold"), strip.text=ggplot2::element_text(size=15,face="bold"),
axis.text=ggplot2::element_text(size=15, face = "bold"), legend.title=ggplot2::element_text(face="bold", size = 12),
Expand All @@ -2571,8 +2585,7 @@ records <- vector("list")
VK <- ggplot2::ggplot() + ggplot2::geom_point(data=PD, ggplot2::aes_string(x = "O_C", y = "H_C", color = "Tag2"), alpha = 1/3) +
ggplot2::facet_wrap(~Tag, ncol = 2)+
#ggplot2::coord_cartesian(xlim = c(min(PD$O_C), max(PD$O_C), ylim = c(min(PD$H_C), max(PD$H_C)))) +
ggplot2::scale_colour_manual(name = "Groups", values = c(CHO = "green", CHNO = "blue", CHOS = "red", CHNOS = "purple",
CH = "gold", CHN = "cyan", Other = "grey67")) +
ggplot2::scale_colour_manual(name = "Groups", values = form_palette) +
ggplot2::labs(x = "Oxygen-to-Carbon Ratio", y = "Hydrogen-to-Carbon Ratio", color = "Groups", title = "van Krevelen Plot") + ggplot2::theme_bw() +
ggplot2::theme(axis.title=ggplot2::element_text(size = 15, face = "bold"), strip.text=ggplot2::element_text(size=15,face="bold"),
axis.text=ggplot2::element_text(size=15, face = "bold"), legend.title=ggplot2::element_text(face="bold", size = 11),
Expand Down
32 changes: 23 additions & 9 deletions MFAssignR/R/MFAssignCHO.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ MFAssignCHO <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=1000
#LCMS adjustment
cols <- ncol(peaks)
#isopeaks = Iso
if(isopeaks != "none") {cols2 <- ncol(isopeaks)} else{cols2 <- 0}
ifelse(isopeaks != "none", cols2 <- ncol(isopeaks), cols2 <- 0)
#if(isopeaks != "none") {cols2 <- ncol(isopeaks)} else{cols2 <- 0}
if(cols == 3){
if(cols == 3) {monoSave <- peaks[c(1,2,3)]}
if(cols2 == 4 & isopeaks != "none") {isoSave <- isopeaks[c(1,2,3)]}
if(cols2 == 0 & isopeaks == "none") {isoSave <- data.frame(mass = -42, abund = -42, RT = -42)}
#if(cols2 == 4 & isopeaks != "none") {isoSave <- isopeaks[c(1,2,3)]}
ifelse(cols2 == 4 & isopeaks != "none",isoSave <- isopeaks[c(1,2,3)], print("No Iso List Included"))
ifelse(cols2 == 0 & isopeaks == "none",isoSave <- data.frame(mass = -42, abund = -42, RT = -42), isoSave <- isoSave)
#if(cols2 == 0 & isopeaks == "none") {isoSave <- data.frame(mass = -42, abund = -42, RT = -42)}
names(isoSave)[1] <- "exp_mass"
names(isoSave)[2] <- "abundance"
names(isoSave)[3] <- "RT"
Expand All @@ -160,8 +163,8 @@ MFAssignCHO <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=1000
peaks <- peaks[peaks$mass >= lowMW,]
peaks <- peaks[peaks$mass <= highMW,]

isopeaks2 <- if(isopeaks != "none") isopeaks else data.frame(x=0,y=0,Tag = 0)

#isopeaks2 <- if(isopeaks != "none") isopeaks else data.frame(x=0,y=0,Tag = 0)
ifelse(isopeaks != "none", isopeaks2 <- isopeaks, isopeaks2 <- data.frame(x=0,y=0,Tag=0))


if(cols2 == 4){isopeaks2 <- isopeaks2[c(2,1,4)]} #LC Change
Expand Down Expand Up @@ -1673,6 +1676,19 @@ MFAssignCHO <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=1000
Unambig <- Unambig[!is.na(Unambig$RA),]
records1 <- records1[!is.na(records1$RA),]

##########Palettes for plots
group_colors <- data.frame(group = c("CHO", "CHNO", "CHOS", "CHNOS", "CH", "CHN", "Other"),
color = c("green", "blue", "red", "purple", "gold", "cyan", "grey67"))



form_group <- data.frame(group = unique(PD$Tag2))

form_palette <- merge(form_group, group_colors, by.x = "group", by.y = "group")
form_palette <- setNames(form_palette$color, form_palette$group)
#print(form_palette)
###########



MZ<-ggplot2::ggplot() + ggplot2::geom_segment(data=records1, size=0.7,ggplot2::aes_string(x = "Exp_mass", xend = "Exp_mass", y = 0, yend = "RA"), color = "green")+
Expand Down Expand Up @@ -1703,8 +1719,7 @@ MFAssignCHO <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=1000

MZgroups<-ggplot2::ggplot() + ggplot2::geom_segment(data=PD, size=0.7,ggplot2::aes_string(x = "Exp_mass", xend = "Exp_mass", y = 0, yend = "RA", color = "Tag2"))+
ggplot2::facet_wrap(~Tag, ncol = 1, scales = 'free_y')+
ggplot2::scale_colour_manual(name = "Groups", values = c(CHO = "green", CHNO = "blue", CHOS = "red", CHNOS = "purple",
CH = "gold", CHN = "cyan", Other = "grey67")) +
ggplot2::scale_colour_manual(name = "Groups", values = form_palette) +
ggplot2::theme_bw()+ggplot2::labs(x = "Ion Mass", y = "Abundance", title = "Assignment Mass Spectrum", color = "DBE")+
ggplot2::theme(axis.title=ggplot2::element_text(size = 15, face = "bold"), strip.text=ggplot2::element_text(size=15,face="bold"),
axis.text=ggplot2::element_text(size=15, face = "bold"), legend.title=ggplot2::element_text(face="bold", size = 12),
Expand All @@ -1715,8 +1730,7 @@ MFAssignCHO <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=1000
VK <- ggplot2::ggplot() + ggplot2::geom_point(data=PD, ggplot2::aes_string(x = "O_C", y = "H_C", color = "Tag2"), alpha = 1/3) +
ggplot2::facet_wrap(~Tag, ncol = 2)+
#ggplot2::coord_cartesian(xlim = c(min(PD$O_C), max(PD$O_C), ylim = c(min(PD$H_C), max(PD$H_C)))) +
ggplot2::scale_colour_manual(name = "Groups", values = c(CHO = "green", CHNO = "blue", CHOS = "red", CHNOS = "purple",
CH = "gold", CHN = "cyan", Other = "grey67")) +
ggplot2::scale_colour_manual(name = "Groups", values = form_palette) +
ggplot2::labs(x = "Oxygen-to-Carbon Ratio", y = "Hydrogen-to-Carbon Ratio", color = "Groups", title = "van Krevelen Plot") + ggplot2::theme_bw() +
ggplot2::theme(axis.title=ggplot2::element_text(size = 15, face = "bold"), strip.text=ggplot2::element_text(size=15,face="bold"),
axis.text=ggplot2::element_text(size=15, face = "bold"), legend.title=ggplot2::element_text(face="bold", size = 11),
Expand Down
32 changes: 23 additions & 9 deletions MFAssignR/R/MFAssignCHO_RMD.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ MFAssignCHO_RMD <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=
#LCMS adjustment
cols <- ncol(peaks)
#isopeaks = Iso
if(isopeaks != "none") {cols2 <- ncol(isopeaks)} else{cols2 <- 0}
ifelse(isopeaks != "none", cols2 <- ncol(isopeaks), cols2 <- 0)
#if(isopeaks != "none") {cols2 <- ncol(isopeaks)} else{cols2 <- 0}
if(cols == 3){
if(cols == 3) {monoSave <- peaks[c(1,2,3)]}
if(cols2 == 4 & isopeaks != "none") {isoSave <- isopeaks[c(1,2,3)]}
if(cols2 == 0 & isopeaks == "none") {isoSave <- data.frame(mass = -42, abund = -42, RT = -42)}
#if(cols2 == 4 & isopeaks != "none") {isoSave <- isopeaks[c(1,2,3)]}
ifelse(cols2 == 4 & isopeaks != "none",isoSave <- isopeaks[c(1,2,3)], print("No Iso List Included"))
ifelse(cols2 == 0 & isopeaks == "none",isoSave <- data.frame(mass = -42, abund = -42, RT = -42), isoSave <- isoSave)
#if(cols2 == 0 & isopeaks == "none") {isoSave <- data.frame(mass = -42, abund = -42, RT = -42)}
names(isoSave)[1] <- "exp_mass"
names(isoSave)[2] <- "abundance"
names(isoSave)[3] <- "RT"
Expand All @@ -160,8 +163,8 @@ MFAssignCHO_RMD <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=
peaks <- peaks[peaks$mass >= lowMW,]
peaks <- peaks[peaks$mass <= highMW,]

isopeaks2 <- if(isopeaks != "none") isopeaks else data.frame(x=0,y=0,Tag = 0)

#isopeaks2 <- if(isopeaks != "none") isopeaks else data.frame(x=0,y=0,Tag = 0)
ifelse(isopeaks != "none", isopeaks2 <- isopeaks, isopeaks2 <- data.frame(x=0,y=0,Tag=0))


if(cols2 == 4){isopeaks2 <- isopeaks2[c(2,1,4)]} #LC Change
Expand Down Expand Up @@ -1673,6 +1676,19 @@ MFAssignCHO_RMD <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=
Unambig <- Unambig[!is.na(Unambig$RA),]
records1 <- records1[!is.na(records1$RA),]

##########Palettes for plots
group_colors <- data.frame(group = c("CHO", "CHNO", "CHOS", "CHNOS", "CH", "CHN", "Other"),
color = c("green", "blue", "red", "purple", "gold", "cyan", "grey67"))



form_group <- data.frame(group = unique(PD$Tag2))

form_palette <- merge(form_group, group_colors, by.x = "group", by.y = "group")
form_palette <- setNames(form_palette$color, form_palette$group)
#print(form_palette)
###########



MZ<-ggplot2::ggplot() + ggplot2::geom_segment(data=records1, size=0.7,ggplot2::aes_string(x = "Exp_mass", xend = "Exp_mass", y = 0, yend = "RA"), color = "green")+
Expand Down Expand Up @@ -1703,8 +1719,7 @@ MFAssignCHO_RMD <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=

MZgroups<-ggplot2::ggplot() + ggplot2::geom_segment(data=PD, size=0.7,ggplot2::aes_string(x = "Exp_mass", xend = "Exp_mass", y = 0, yend = "RA", color = "Tag2"))+
ggplot2::facet_wrap(~Tag, ncol = 1, scales = 'free_y')+
ggplot2::scale_colour_manual(name = "Groups", values = c(CHO = "green", CHNO = "blue", CHOS = "red", CHNOS = "purple",
CH = "gold", CHN = "cyan", Other = "grey67")) +
ggplot2::scale_colour_manual(name = "Groups", values = form_palette) +
ggplot2::theme_bw()+ggplot2::labs(x = "Ion Mass", y = "Abundance", title = "Assignment Mass Spectrum", color = "DBE")+
ggplot2::theme(axis.title=ggplot2::element_text(size = 15, face = "bold"), strip.text=ggplot2::element_text(size=15,face="bold"),
axis.text=ggplot2::element_text(size=15, face = "bold"), legend.title=ggplot2::element_text(face="bold", size = 12),
Expand All @@ -1715,8 +1730,7 @@ MFAssignCHO_RMD <- function(peaks, isopeaks = "none", ionMode, lowMW=100,highMW=
VK <- ggplot2::ggplot() + ggplot2::geom_point(data=PD, ggplot2::aes_string(x = "O_C", y = "H_C", color = "Tag2"), alpha = 1/3) +
ggplot2::facet_wrap(~Tag, ncol = 2)+
#ggplot2::coord_cartesian(xlim = c(min(PD$O_C), max(PD$O_C), ylim = c(min(PD$H_C), max(PD$H_C)))) +
ggplot2::scale_colour_manual(name = "Groups", values = c(CHO = "green", CHNO = "blue", CHOS = "red", CHNOS = "purple",
CH = "gold", CHN = "cyan", Other = "grey67")) +
ggplot2::scale_colour_manual(name = "Groups", values = form_palette) +
ggplot2::labs(x = "Oxygen-to-Carbon Ratio", y = "Hydrogen-to-Carbon Ratio", color = "Groups", title = "van Krevelen Plot") + ggplot2::theme_bw() +
ggplot2::theme(axis.title=ggplot2::element_text(size = 15, face = "bold"), strip.text=ggplot2::element_text(size=15,face="bold"),
axis.text=ggplot2::element_text(size=15, face = "bold"), legend.title=ggplot2::element_text(face="bold", size = 11),
Expand Down
Loading

0 comments on commit 800f268

Please sign in to comment.