fgcz / rawDiag

Brings Orbitrap mass spectrometry data to life; multi-platform, fast and colorful R package
https://bioconductor.org/packages/rawDiag
36 stars 11 forks source link

overlays of different plots #54

Open cpanse opened 4 years ago

cpanse commented 4 years ago

code snippet by Dierk-Christoph Pöther

#Package handling
library(rawDiag)
library(ggplot2)
library(dplyr)
library(viridisLite)

#read .raw-file
raw<-read.raw(file.path("path","xy.raw"))

#BasePeak/TIC&InjectionTime
rawMS<-raw[raw$MSOrder=="Ms",]
ggplot(data=rawMS)+
  geom_line(aes(rawMS$StartTime,rawMS$BasePeakIntensity))+ #rawMS$TIC instead of BasePeakIntensity
  geom_jitter(aes(rawMS$StartTime,rawMS$IonInjectionTimems*5*10^6),size=0.1,col="red",alpha=0.2)+
  scale_y_continuous(sec.axis=sec_axis(~./(5*10^6)))

#BasePeak/TIC&CycleTime
CT<-calc.cycle.time(x = raw)
rawCT<-merge(x=raw[,c("StartTime","BasePeakIntensity","TIC")],y=CT[,c("StartTime","CycleTime")],by.x="StartTime",all.x=T)
ggplot(data=rawCT)+
  geom_line(aes(rawCT$StartTime,rawCT$BasePeakIntensity))+ #rawMS$TIC instead of BasePeakIntensity
  geom_jitter(aes(rawCT$StartTime,rawCT$CycleTime*1*10^9),size=0.1,col="red",alpha=0.2)+
  scale_y_continuous(sec.axis=sec_axis(~./(1*10^9)))

#BasePeak/TIC&CycleLoad
MSN<-na.omit(raw%>%dplyr::count(MasterScanNumber))
cycload<-merge(x=raw[,c("MasterScanNumber","StartTime","BasePeakIntensity","TIC")],y=MSN[,c("MasterScanNumber","n")],by.x="MasterScanNumber",all.x=T)
ggplot(data=cycload)+
  geom_line(aes(cycload$StartTime,cycload$BasePeakIntensity))+ #rawMS$TIC instead of BasePeakIntensity
  geom_jitter(aes(cycload$StartTime,cycload$n*1*10^8),size=0.1,col="red",alpha=0.2,height=0.1*10^8)+
  scale_y_continuous(sec.axis=sec_axis(~./(1*10^8)))

##BasePeak/TIC&precursor/RT
rawMS2<-raw[raw$MSOrder=="Ms2",]
MS2<-merge(x=raw[,c("StartTime","BasePeakIntensity","TIC")],y=rawMS2[,c("StartTime","PrecursorMass")],by.x="StartTime",all.x=T)
ggplot(data=MS2)+
  geom_line(aes(MS2$StartTime,MS2$BasePeakIntensity))+ #rawMS$TIC instead of BasePeakIntensity
  geom_hex(aes(MS2$StartTime,MS2$PrecursorMass*5*10^5),bins=50)+scale_fill_viridis_c(alpha=0.7)+
  scale_y_continuous(sec.axis=sec_axis(~./(5*10^5)))

pdf("C:/Users/Dierk/Desktop/overlays.pdf",paper="a4r",width=297/2.54,height=210/2.54)
print(Fig11)
print(Fig12)
print(Fig13)
print(Fig14)
dev.off()

overlays-3 overlays-2 overlays-1 overlays-0