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

  • Home
  • SEARCH
  • 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 7838757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:11:59+00:00 2026-06-02T15:11:59+00:00

I’m a python newbie but have programmed a while in other languages. I have

  • 0

I’m a python newbie but have programmed a while in other languages. I have a long string of DNA (lower case) and AA sequences (upper case). Further at the start of the file I have a protein name all in upper case. Thus my file looks like this.

PROTEINNAMEatcgatcg… JFENVKDFDFLK

I need to find the first non-uppercase letter in the string so I can then cut out the protein name. Thus, what I would want from the above is:

atcgatcg… JFENVKDFDFLK

I can do this with a loop but that seems like overkill and inefficient. Is there a simply python way to do it?

I can get all the uppercase letters using re.findall(“[A-Z]”,mystring) but then I would need to do a comparison to see where the result differs from the original string.

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-06-02T15:12:02+00:00Added an answer on June 2, 2026 at 3:12 pm

    You are almost there with your regex… but there are other methods besides findall:

    http://docs.python.org/library/re.html#re.sub

    >>> import re
    >>> protein_regex = re.compile('^[A-Z]+')
    >>> dna = 'PROTEINNAMEatcgatcg... JFENVKDFDFLK'
    >>> protein_regex.sub('', dna)
    'atcgatcg... JFENVKDFDFLK'
    

    Not sure about performance, but you could also do

    >>> import string
    >>> dna.lstrip(string.uppercase)
    'atcgatcg... JFENVKDFDFLK'
    

    And there you have it:

    python -m timeit -n 10000 -s 'import re' -s 'protein_regex = re.compile("^[A-Z]+")' -s 'dna = "PROTEINNAMEatcgatcg... JFENVKDFDFLK"' 'protein_regex.sub("", dna)'
    10000 loops, best of 3: 1.36 usec per loop
    
    python -m timeit -n 10000 -s 'import string' -s 'dna = "PROTEINNAMEatcgatcg... JFENVKDFDFLK"' 'dna.lstrip(string.uppercase)'
    10000 loops, best of 3: 0.444 usec per loop
    

    Second one looks to be ~3 times faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.