Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple mismatches in DNA search sequence regex
    primarykey
    data
    text
    <p>I have written this barbaric script to create permutations of a string of characters that contain n (up to n=4) $'s in all possible combinations of positions within the string. I will eventually <code>.replace('$','(\\w)')</code> to use for mismatches in a dna search sequence. Because of the way I wrote the script, some of the permutations have less than the requested number of $'s. I then wrote a script to remove them, but it doesn't seem to be effective, and each time I run the removal script, it removes more of the unwanted permutations. In the code pasted below, you will see that I test the function with a simple sequence with 4 mismatches. I then run a series of removal scripts that count how many expressions are removed each time...in my experience, it takes about 8 times to remove all expressions with less than 4 wild-card $'s. I have a couple questions about this:</p> <ol> <li><p>Is there a built in function for searches with 'n' mismatches? Maybe even in biopython? So far, I've seen the Paul_McGuire_regex function:<br> <a href="https://stackoverflow.com/questions/2420412/search-for-string-allowing-for-one-mismatch-in-any-location-of-the-string">Search for string allowing for one mismatch in any location of the string</a>,<br> which seems only to generate 1 mismatch. I must admit, I don't fully understand all of the code in the remainining functions on that page, as I am a very new coder.</p></li> <li><p>Since I see this as a good exercise for me, is there a better way to write this entire script?...Can I iterate Paul_McGuire_regex function as many times as I need?</p></li> <li><p>Most perplexing to me, why won't the removal script work 100% the first time?</p></li> </ol> <p>Thanks for any help you can provide!</p> <pre><code>def Mismatch(Search,n): List = [] SearchL = list(Search) if n &gt; 4: return("Error: Maximum of 4 mismatches") for i in range(0,len(Search)): if n == 1: SearchL_i = list(Search) SearchL_i[i] = '$' List.append(''.join(SearchL_i)) if n &gt; 1: for j in range (0,len(Search)): if n == 2: SearchL_j = list(Search) SearchL_j[i] = '$' SearchL_j[j] = '$' List.append(''.join(SearchL_j)) if n &gt; 2: for k in range(0,len(Search)): if n == 3: SearchL_k = list(Search) SearchL_k[i] = '$' SearchL_k[j] = '$' SearchL_k[k] = '$' List.append(''.join(SearchL_k)) if n &gt; 3: for l in range(0,len(Search)): if n ==4: SearchL_l = list(Search) SearchL_l[i] = '$' SearchL_l[j] = '$' SearchL_l[k] = '$' SearchL_l[l] = '$' List.append(''.join(SearchL_l)) counter=0 for el in List: if el.count('$') &lt; n: counter+=1 List.remove(el) return(List) List_RE = Mismatch('abcde',4) counter = 0 for el in List_RE: if el.count('$') &lt; 4: List_RE.remove(el) counter+=1 print("Filter2="+str(counter)) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload