Created
April 4, 2013 21:52
-
-
Save dgrapov/5314726 to your computer and use it in GitHub Desktop.
Data processing script to get maximum m/z ion intensity pair from Agilent recursive analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#directory (file path) where the file is | |
#note make sure all \ are changed to \\ or / | |
dir<-"ZZZ" | |
setwd(dir) # change directory | |
#name of file, should be .csv | |
file.name<-"XXX.csv" | |
#load data into R this assumes there is a header | |
input<-read.csv(file.name, header = TRUE) | |
#now process each string and extract highest intensity pair | |
# if seems to take to long tell me and I will write the code to do this in parallel | |
#define function to do the work | |
get.max.pair<-function(input, save=TRUE){ | |
#input is imported list which is assumed to be a data.frame | |
# if save = TRUE the results will be saved as "max.pair.csv" in the working directory | |
input<-as.matrix(input) | |
out<-do.call("rbind",lapply(1:nrow(input), function(i) | |
{ | |
obj<-gsub(")","",unlist(gsub("(","",unlist(strsplit(input[i,],split=")(",fixed = TRUE)), fixed=TRUE)),fixed=TRUE) | |
obj2<-matrix(as.numeric(unlist(strsplit(as.character(obj),"\\,"))),ncol=2, byrow=TRUE) | |
obj2[which.max(obj2[,2]),] | |
})) | |
colnames (out)<-c("max intensity m/z","intensity") | |
if (save == TRUE){ | |
write.csv(as.data.frame(out),file="max.pair.csv") | |
} else { | |
return(out) | |
} | |
} | |
#now run the function on your uploaded data | |
get.max.pair(input, save=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment