Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6573873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:11:19+00:00 2026-05-25T15:11:19+00:00

Here is my problem: data set.seed(123) randDNA = function(n) paste(sample(c("A", "C", "T", "G"), n,

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:11:19+00:00Added an answer on May 25, 2026 at 3:11 pm

    I would be surprised if pkg:Biostrings had masked the base function pmatch, and I am guessing you are seeing the expected behavior of base::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 the matchPattern “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

    set.seed(123) 
    randDNA = function(n) paste(sample(c("A", "C", "T", "G"), 
              n, replace = TRUE), collapse = "")            
    bigse <- randDNA(10000)
    # There is  a countPattern function that might  narrowly give you what you wanted.
     sapply(c("ATTGG", "TTTTT", "CCCCC", "ATATG"), countPattern, subject=bigse)
    
    #ATTGG TTTTT CCCCC ATATG 
    #    2    11     7     6 
    

    Output of the more informative matchPattern with length= 5,000

    sapply(c("ATTGG", "TTTTT", "CCCCC", "ATATG"), matchPattern, subject=bigse)
    #
    $ATTGG
      Views on a 5000-letter BString subject
    subject: CGCGGATGTCGCTTAGAACGGTTGTTTTCAG...AGCGGCGAGAAGATTCCGCACGAGTCAGATA
    views:
        start  end width
    [1]  2035 2039     5 [ATTGG]
    
    $TTTTT
      Views on a 5000-letter BString subject
    subject: CGCGGATGTCGCTTAGAACGGTTGTTTTCAG...AGCGGCGAGAAGATTCCGCACGAGTCAGATA
    views:
        start  end width
    [1]   555  559     5 [TTTTT]
    [2]   834  838     5 [TTTTT]
    [3]  1905 1909     5 [TTTTT]
    [4]  1906 1910     5 [TTTTT]
    [5]  4419 4423     5 [TTTTT]
    
    $CCCCC
      Views on a 5000-letter BString subject
    subject: CGCGGATGTCGCTTAGAACGGTTGTTTTCAG...AGCGGCGAGAAGATTCCGCACGAGTCAGATA
    views:
        start  end width
    [1]   798  802     5 [CCCCC]
    [2]  3268 3272     5 [CCCCC]
    [3]  3629 3633     5 [CCCCC]
    
    $ATATG
      Views on a 5000-letter BString subject
    subject: CGCGGATGTCGCTTAGAACGGTTGTTTTCAG...AGCGGCGAGAAGATTCCGCACGAGTCAGATA
    views:
        start  end width
    [1]  1264 1268     5 [ATATG]
    [2]  2924 2928     5 [ATATG]
    [3]  3103 3107     5 [ATATG]
    

    But just for kicks I ran it with your big string:

     sapply(c("ATTGG", "TTTTT", "CCCCC", "ATATG"), countPattern, subject=bigse)
    # ATTGG TTTTT CCCCC ATATG 
    # 48850 48933 49111 49073 
    

    Here are the speed comparisons:

    > system.time( sapply(c("ATTGG", "TTTTT", "CCCCC", "ATATG"), 
                       countPattern, subject=bigse) )
       user  system elapsed 
      1.507   0.119   1.618 
    
    > system.time(str_count(bigse,c("ATTGG", "TTTTT", "CCCCC", "ATATG")))
       user  system elapsed 
      6.332   0.017   6.337 
    
    # Added the gregexpr solution timing (not surprising to see similarity with stingr times)
    > system.time( sapply(motif,function(x) length(gregexpr(x,bigse)[[1]])) )
       user  system elapsed 
      6.768   0.046   6.794 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so here's my problem. We are looking at purchasing a data set from
Here is my dataset. set.seed (1234) mydf <- data.frame (Id = c(dis, 1:5), V1.a
Database is OracleXE and here is the problem: data gets entered in tables UPS
Here's my problem. I built a web app, and naturally kept the data in
I have encountered a problem of placing data into the Table View. Here is
Okay, here is my problem... I created a Data Layer using the RTM Fluent
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
Here is an example of the data set I am working with. I am
I have the following problem. I have a data set that has the beginning
What is the problem here? (Besides having redundant code). $.getJSON works as expected. However

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.