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 7928707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:49:13+00:00 2026-06-03T19:49:13+00:00

I’m having a problem getting my code to do exactly what I want. I

  • 0

I’m having a problem getting my code to do exactly what I want. I would like to define a function that takes two numbers as the arguments and used the numbers to look at a section of the RNA code which is previously stored as a string.

Then I would like to count all possible base pairs in the section so that ‘a’ and ‘u’ pair and ‘g’ and ‘c’ pair. However there has to be a gap of 3 characters between the pairs and the pairs cannot crossover. e.g. if rna[4] pairs with rna[10], rna[5] cannot pair with rna[12]. however if a pair occurred between 4 and 10 i.e. 5 and 9 that would be ok.

so far I have

def base_pairs(x,y):
return (x=='a' and y=='u' or
    x=='u' and y=='a' or
    x=='c' and y=='g' or
    x=='g' and y=='c' or
    x=='g' and y=='u' or
    x=='u' and y=='g' )

rna = raw_input('Enter RNA sequence: ')
n = len(rna)

def opt(x,y):
    for i in range(x,y-5):
        j = i+4
        if base_pairs(rna[i],rna[j])==1:
            print i,j
            a = i
            b = j
            if b-a > 3:
                if base_pairs(a+1,b-1)==1:
                    print a+1,b-1
                    a = a+1
                    b = b-1
        else:
            j=j+1

for example when I input accguugacgcag I would like to use opt(0,12) and get 0,4 5,11 6,10
currently I only get 0,4

  • 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-03T19:49:16+00:00Added an answer on June 3, 2026 at 7:49 pm

    I’ve started on a new version of your function. I’ve incorporated the ideas I mentioned in the comments on your question. In addition, I’ve made the rna string a parameter, but this could be removed fairly easily. This version doesn’t produce the output you asked for, but it might be adaptable to meet your needs. The output on my machine is o,4 and 5,9. I couldn’t figure out why you would prefer 5,11 over 5,9 so I couldn’t change it to give that result.

    def is_base_pair(x, y):
        return (x=='a' and y=='u' or
                x=='u' and y=='a' or
                x=='c' and y=='g' or
                x=='g' and y=='c' or
                x=='g' and y=='u' or
                x=='u' and y=='g' )
    
    # start and end are the inclusive range of places in which to look for pairs
    def opt(rna, start, end):
        # if the range is too small, give up
        if start + 4 > end:
            return
    
        # the next left side to try to match
        nextLeft = start
    
        while nextLeft + 4 <= end:
            # find the right nucleobase to match the one at nextLeft
            #   start looking at the minimal distance and incrementally get bigger
            potentialRight = nextLeft + 4
            while not is_base_pair (rna[nextLeft], rna[potentialRight]) and potentialRight <= end:
                potentialRight += 1
    
            if is_base_pair (rna[nextLeft], rna[potentialRight]):
                print nextLeft, potentialRight
                # recursively search for pairs between the elements of this pair
                opt(rna, nextLeft + 1, potentialRight - 1)
                nextLeft = potentialRight + 1
            else:
                nextLeft += 1
    

    Let me know if you have any questions on how this works.

    • 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&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.