extract the "start" position of matchPattern()
1
0
Entering edit mode
jie • 0
@61d03a3e
Last seen 2.9 years ago
United States

Hi, guys:

For the following code, how could I extract the "start" position of the match and then calculate the average, which will be (1+5)/2=3?

enter image description here

How could I do this for "A", "C", "G", "T", without writing a loop?

Thank you very much & Best regards, Jie

matchpatterns • 384 views
ADD COMMENT
0
Entering edit mode
shepherl 3.9k
@lshep
Last seen 16 hours ago
United States

Average of start values:

> temp = matchPattern("A", "ACGTA", max.mismatch=0)
> vls = start(temp)
> mean(vls)

You will have to loop in some fashion, I would suggest a vapply:

> vapply(X = c("A", "C", "G", "T"), 
 FUN.VALUE  = numeric(1), 
 FUN  = function(dna, stringTomatch){ 
     views = matchPattern(dna, stringTomatch, max.mismatch=0) 
     vls = start(views)
     return(mean(vls))
 }, 
 stringTomatch="ACGTA")


A C G T 
3 2 3 4
ADD COMMENT

Login before adding your answer.

Traffic: 918 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6