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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:21:50+00:00 2026-06-08T17:21:50+00:00

Given a DNA string for example AGC . I am trying to generate all

  • 0

Given a DNA string for example AGC. I am trying to generate all possible uniq strings allowing upto #n (user defined number) mismatches in the given string.

I am able to do this for one mismatch in the following way but not able to implement the recursive solution to generate all the possible combinations based on #n mismatch, DNA string and mutation set(AGCTN)

temp_dict = {}
sequence = 'AGC'

    for x in xrange(len(sequence)):
        prefix = sequence[:x]
        suffix = sequence[x+1:]
        temp_dict.update([ (prefix+base+suffix,1) for base in 'ACGTN'])
    print temp_dict

An example:

for a given sample string : ACG, the following are the 13 uniq sequences allowing upto one mismatch

{'ACC': 1, 'ATG': 1, 'AAG': 1, 'ANG': 1, 'ACG': 1, 'GCG': 1, 'AGG': 1, 
'ACA': 1, 'ACN': 1, 'ACT': 1, 'TCG': 1, 'CCG': 1, 'NCG': 1}

I want to generalize this so that the program can take a 100 characters long DNA string and return a list/dict of uniq strings allowing user defined #mismatches

Thanks!
-Abhi

  • 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-08T17:21:51+00:00Added an answer on June 8, 2026 at 5:21 pm

    Assuming I understand you, I think you can use the itertools module. The basic idea is to choose locations where there’s going to be a mismatch using combinations and then construct all satisfying lists using product:

    import itertools
    
    def mismatch(word, letters, num_mismatches):
        for locs in itertools.combinations(range(len(word)), num_mismatches):
            this_word = [[char] for char in word]
            for loc in locs:
                orig_char = word[loc]
                this_word[loc] = [l for l in letters if l != orig_char]
            for poss in itertools.product(*this_word):
                yield ''.join(poss)
    

    For your example case:

    >>> mismatch("ACG", "ACGTN", 0)
    <generator object mismatch at 0x1004bfaa0>
    >>> list(mismatch("ACG", "ACGTN", 0))
    ['ACG']
    >>> list(mismatch("ACG", "ACGTN", 1))
    ['CCG', 'GCG', 'TCG', 'NCG', 'AAG', 'AGG', 'ATG', 'ANG', 'ACA', 'ACC', 'ACT', 'ACN']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a MySQL table of real estate data, I would like to generate a
Given that an input String may be specified as follows: read(xpath(‘...’)) or xpath(‘...’) or
Given the following string: s = 'abcdefg*' How can I match it or any
Given a table of structure: CREATE TABLE [dbo].[Example]( [FiscalYear] INT NOT NULL, [Hours] [decimal](28,
Given a class: class foo { public string a = ; public int b
I'm attempting to write a basic dna sequencer. In that, given two sequences of
Given: class StringRecord : INotifyPropertyChanged { public string Key { get; set; } //
Given SQL Server 2008, I have written a simple find in string function as
I need to generate a random walk based on the DNA sequence of a
Given are a number of finite sets of integers, for example: A = {1,2,3}

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.