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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:01:44+00:00 2026-05-26T05:01:44+00:00

I have a function calc_dG that, for any array corresponding to a short DNA

  • 0

I have a function calc_dG that, for any array corresponding to a short DNA sequence (3 to 15 bases or so), gives me the binding energy of that sequence. Actually, it’s just an array lookup. nndG is an array of binding energies for adjacent pairs of bases, and thus the binding energies can be calculated with nndG[4*S[:-1]+S[1:]] when using an a,g,c,t -> 0,1,2,3 way of denoting sequences numerically: this means that arrays of many sequences can be calculated at once very quickly in numpy.

I need to find, for a length L, every sequence that both fits some template and results in a binding energy value in a certain range.

This is very easy to do with iterators: just iterate through every possible array input, calculate the binding energy, and then record the arrays that are in the range. This, however, is far too slow when implemented in Python (for length 15 with 4 possible values for each element there are 4**15 possible arrays, etc etc). I could use Weave or some other method of implementing it in C, but I’d prefer to find an array-based solution that is simple and fast.

For example, if every element has the same possible values (eg, [0,1,2,3]), then generating an array of every possible length L 1D array with those values can be done with lambda x: indices(repeat([4],L)).reshape((L,-1)).transpose(); then I can just do calc_dG( result ), and use result[results that are in the desired range] to get the arrays that I want as a final result. This is much faster than using Python iterators, and likely almost as fast, if not faster, than using C iterators. Unfortunately, it doesn’t work for arbitrary templates, and for longer sequences, will run out of memory, as it has to store every possible array in memory before calculating values.

Is there some way to do all of this without resorting to C?

  • 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-26T05:01:44+00:00Added an answer on May 26, 2026 at 5:01 am

    If I understand your problem correctly, you are maximizing a function f(i_1, i_2, ..., i_n) over integers in the set {0, 1, 2, 3}.

    You can use a combination of iteration and vectorized indexing.

    import numpy as np
    import itertools
    
    def cartesian_chunked(n, n_items=4, chunk_dim=3):
        if n > chunk_dim:
            p = n - chunk_dim
            q = chunk_dim
            outer = itertools.product(*([range(n_items)] * (n - chunk_dim)))
        else:
            p = 0
            q = n
            def outer_iter():
                yield ()
            outer = outer_iter()
    
        chunk = np.zeros([n_items**q, n], dtype=int)
        chunk[:,p:] = np.indices(np.repeat([n_items], q)).reshape(q, -1).T
        for seq in outer:
            chunk[:,:p] = seq
            yield chunk
    
    def compute_energy(indices):
        base_energies = np.array([-1, 4, 8, 2.4])
        return (base_energies[indices]).sum(axis=1) 
    
    max_energy = 0
    max_config = None
    
    # try out 4**10 ~ 1e6 combinations, in chunks of 4**8
    for chunk in cartesian_chunked(n=10, n_items=4, chunk_dim=8):
        energies = compute_energy(chunk)
        j = np.argmax(energies)
        if energies[j] > max_energy:
            max_energy = energies[j]
            max_config = chunk[j].copy() # copy! the chunk is modified
    
    print max_energy
    print max_config
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a calc function in java script that takes three integer parameters, following
I have function getCartItems in cart.js and I want to call that function in
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have a function that gets x(a value) and xs(a list) and removes all
I have a C# ClassLibrary that contains a function to sum two numbers: namespace
I have javascript function that automatically adds input fields together, but adding numbers like
I have function in C that reads byte by byte from a given buffer
I have this function that export a datagridView in Excel sheet : public void

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.