I’ve created the following matrix in R:
positions = cbind(seq(from = 20, to = 68, by = 4),seq(from = 22, to = 70, by = 4))
I also have the following string:
"SEQRES 1 L 36 THR PHE GLY SER GLY GLU ALA ASP CYS GLY LEU ARG PRO "
I’m trying to use an apply function to make a list of substring(mystring, start.position, end.position) where the first index comes from positions[,1] and the second comes from positions[,2]. I can do this easily with a for loop but I think apply would be faster.
I can get it working as follows, but I’m wondering if there’s a cleaner way:
parse.me = cbind(seq(from = 20, to = 68, by = 4),seq(from = 22, to = 70, by = 4), input)
apply(parse.me, MARGIN = 1, get.AA.seqres)
get.AA.seqres <- function(items){
start.position = as.numeric(items[1])
end.position = as.numeric(items[2])
string = items[3]
return (substr(string, start.position, end.position) )
}
Try this: