Here is my problem:
data
set.seed(123)
randDNA = function(n) paste(sample(c("A", "C", "T", "G"), n, replace = TRUE), collapse = "")
bigse <- randDNA(50000000)
I want to see how many times the following small five letters match ("ATTGG", "TTTTT", "CCCCC", "ATATG"), in this large single unit vector bigse. Randomly generated just for an example
I tried Biostrings, unsuccessful but base R solution are also welcome.
require(Biostrings)
pmatch (c("ATTGG", "TTTTT", "CCCCC", "ATATG"), bigse)
[1] NA NA NA NA
I believe that it is matching from one end, return NA. What I want is to these character can match to anywhere but need in the same sequence. If they are repeted twice, I need that information too…thanks…
I would be surprised if pkg:Biostrings had masked the base function
pmatch, and I am guessing you are seeing the expected behavior ofbase::pmatch. Like joran, I thought your 50 million length test was excessive to I paired it down to something where the output of my successful use of thematchPattern“Biostrings” call would fit on this page, but do scroll past it for the full test. It was surprisingly fast on the full test. Much faster than constructing the string in fact.I looked at the differences with stringr and see that it relates to how one counts matches with the highly duplicated segments. Given that you are working on biological data I think I would accept the Biostrings conventions unless you have specific reasons not to. In that case you should be looking further at the details of the functions and the more complete output
Output of the more informative matchPattern with length= 5,000
But just for kicks I ran it with your big string:
Here are the speed comparisons: