####### #######MSVs2D.V1.R #######V1 José Fabricio López Hernández. 14th March 2013 ####### fabricio.lo.hdz@gmail.com #######This program allows the coupling of 2D Scanning with MS Scans. This process used to be made by hand, now its automatic. ################################################---------INTRODUCE PARAMETER FROM THIS PART---------########################################################## #######DEVOLOPER RECOMMENDS USING NOTEPAD++, R SCRIPT EDITOR OR OTHER TEXT EDITOR TO EDIT THE PARAMETERS. ######Usando notepad++, abres este archivo, lo copias a otro archivo que será el editado. En notepad++ seleccionas lenguaje-> R-> R. Y te aparecerán colorcitos. #######The program inputs are: #######Name and path of the table generated by 2D robot. #######e.g. "/Users/Fabricio/Desktop/RW/20130226_185013.dat" #######Introduce here: Tabla2D<-read.table("PutPathAndFileHere.dat",header=FALSE) #######Name and path of the table generated by ProteoWizard selecction WHOLE columns and rows. #######e.g. "/Users/Fabricio/Desktop/RW/130226_IMGMON3.mzML.fil.txt" #######Introduce here: TablaMS<-read.table("PutPathAndFileHere.txt",header=FALSE)[,4:5] #######The number of scans in MS at each 2D scan. It means 1:3 one of Plasma2D and 3 for MS. #######The program takes the time of 2D scanning and divides by the number of MS scans e.g. 3 and 6000 ms (mili secs). The time by each MS scan will be 2000 ms. #######i.e. BarridosMS<-3 ####### TiempoDeEscaneo2D<-6000 #######Introduce here: BarridosMS<-"Put Number Of MS scans by each 2D scan (see e.g. above) Don´t forget to delete "", put just a number" TiempoDeEscaneo2D<-"Put the time in ms of 2D scan (see e.g. above) Don´t forget to delete "", put just a number " #####The last parameter is the path and name the output file, this file will be used in mzlConverter to load coordinates. #####NombreDeArchivoDeSalida<-"TableToConverter.txt" NombreDeArchivoDeSalida<-"PathAndFileNameHere.txt" #######Once the script is edited, save this script, and Run it in R. #######WAYS TO USE: ######1.-Enter in R and type: ###### source("/PathAElProgramaQueEditaste/MSVs2D.V1.R") ######1.-Open an IDE (e.g. RDesktop), select whole script and run it: ########################################################################################################################################################### ########################################################################################################################################################### ########################################################################################################################################################### ########----------------------------DON NOT EDIT BELOW THIS PART, UNLESS YOU KNOW WHAT YOU ARE DOING!!!!!!!!!!-----------------------------########## Tabla2D<-Tabla2D[2:nrow(Tabla2D),] #Takes away the first line of 2D file, this lines is no longer needed beacause is the inizitialization of 2D coordinates. dif.t<-NULL for(i in 1:nrow(Tabla2D)) ###This part creates the difference between previous scan and current. { if(i==1) { dif.t<-append(dif.t,Tabla2D[i,1]-TiempoDeEscaneo2D) # in case of i == 1 Just inialize with (1st scan time) - (TiempoDeEscaneo2D) } if(i>1) # in case of i > 1. Put the difference in comparison with the previous time. { dif.t<-append(dif.t,Tabla2D[i,1]-Tabla2D[i-1,1]-TiempoDeEscaneo2D) } } Tabla2D<-cbind(Tabla2D,dif.t) # Joining to the table the difference Tabla2D.temp<-Tabla2D ## flag=1 ##Using this flag to stop the adding of rows. i=0 while(flag==1) { i=i+1 ##counter of each raw if(Tabla2D[i,2]==Tabla2D[i+1,2] && Tabla2D[i,3]==Tabla2D[i+1,3]) #If coordinates x and y are the SAME with the next row: { for(j in 1:(BarridosMS-2)) #Add the Number of Scans (BarridosMS)-2. The number two is owed CurrentRow+RepeatedCoordinatesRow #In case of BarridoMS=3 Repeated=2, it just add 1 row, in case of BarridoMS=5 Repeated=2 it add 3 rows. { Tabla2D.temp<-rbind(Tabla2D.temp,Tabla2D[i,]) #Adding the rows. } Tabla2D.temp[i+1,]<-Tabla2D[i,] #Changing the time of repeated coordinates to the same as the created one(s). i=i+2 # Skiping the reapeated. } if(Tabla2D[i,2]!=Tabla2D[i+1,2]||Tabla2D[i,3]!=Tabla2D[i+1,3]) ##If coordinates x and y are the DIFFERENT with the next row: { for(j in 1:(BarridosMS-1)) ###Add the number of measuer -1, the number 1 is the original measure { Tabla2D.temp<-rbind(Tabla2D.temp,Tabla2D[i,]) #Addin Number of measures - 1 times. } } if(i==(nrow(Tabla2D)-1)) #If the counter i == to the same as number of rows of Table2D. { for(j in 1:(BarridosMS-1)) { Tabla2D.temp<-rbind(Tabla2D.temp,Tabla2D[i+1,]) #Add the last ones rows. } flag=0### So end the while. } } Tabla2D.temp<-Tabla2D.temp[ order(as.numeric(Tabla2D.temp[,1])), ] #sorting the Table2D.temp Tabla2D.temp<-cbind(Tabla2D.temp,TablaMS[1:nrow(Tabla2D.temp),2]*1000) # Adding the Time in milisec of MS scans. colnames(Tabla2D.temp)<-c("T_ms_2D","x","y","dif.t","T_ms_MS") #Naming columns. dif.t.ms<-Tabla2D.temp[1,"T_ms_MS"]-TiempoDeEscaneo2D/BarridosMS #Getting the difference between 1st scan and 2nd one. for(i in 2:nrow(Tabla2D.temp)) #Giving the difference in the complete times. { dif.t.ms<-append(dif.t.ms,Tabla2D.temp[i,"T_ms_MS"]-Tabla2D.temp[i-1,"T_ms_MS"]-(TiempoDeEscaneo2D/BarridosMS)) #This time is the current time - past time- MSscan } Tabla2D.temp<-cbind(Tabla2D.temp,dif.t.ms) #joining this differences to Tabla2D.temp Tabla2D.temp<-cbind(Tabla2D.temp,Tabla2D.temp[,"T_ms_2D"]-Tabla2D.temp[,"T_ms_MS"])#Getting the differences entre 2D scans and MS scans. colnames(Tabla2D.temp)<-c("T_ms_2D","x","y","dif.t","T_ms_MS","dif.t.ms","Dif2DMS") #Naming the columns. NotNoImage<-NULL #Those that wonn´t be taken to the image. ToImage<-NULL #Thos that will be taken. for(i in seq(1,nrow(Tabla2D.temp),BarridosMS)) { ####Give the coordinates that are >0, choose the minimun value by each set of coordinates. ToImage<-append(ToImage,which(Tabla2D.temp[which(Tabla2D.temp[i:(i+BarridosMS-1),"Dif2DMS"]>0),"Dif2DMS"]==min( Tabla2D.temp[which(Tabla2D.temp[i:(i+BarridosMS-1),"Dif2DMS"]>0),"Dif2DMS"]))+i-1) } outersect <- function(x, y) { ####this funciton is completely opposite to intersecte. sort(c(setdiff(x, y), setdiff(y, x))) } NotToImage<-outersect (x=c(ToImage),y=c(1:nrow(Tabla2D.temp))) #Selecting those that are goin to be -1. Tabla2D.temp[NotToImage,c("x","y")]<--1 #Asigning thos with -1 in x,y coordinates. write.table(Tabla2D.temp[,c("x","y")],NombreDeArchivoDeSalida,sep="\t",row.names=FALSE,col.names=FALSE)