I am trying to compare two DNA sequences with wobbles and report mismatches. To explain DNA and wobbles in programming sense, they are strings of characters(bases) A,T,C and G and wobbles are characters assigned to more than one bases e.g. R is ‘A’ or ‘G’.
Here !N in if() condition corresponds to the declared array N. I have to manually edit this each time to change it to !R, !Y, or !K etc in the condition.
const R = ['A', 'G'];
const Y = ['C', 'T'];
const K = ['G', 'T'];
const N = ['A', 'G', 'C', 'T'];
const wob = ['R', 'Y', 'K', 'M', 'S', 'W', 'N']
let mismatchPositions = [];
for (let i = 0; i < referenceLength; i++) {
if (!N.includes(seq.sequence[i]) && wob.includes(referenceSeq[i]) &&
referenceSeq[i] !== seq.sequence[i]) {
const mismatch = `(${i+1} ${referenceSeq[i]} > ${seq.sequence[i]})`;
mismatchPositions.push(mismatch);
} else if (!wob.includes(referenceSeq[i]) && referenceSeq[i] !== seq.sequence[i]) {
const mismatch = `(${i+1} ${referenceSeq[i]} > ${seq.sequence[i]})`;
mismatchPositions.push(mismatch);
}
I tried putting all the arrays in one variable with flat() but it loses its functionality because there are same bases in few of the wobbles. Is there any way to individually switch the arrays in if() condition from !N to !R and so. I want it make as a user input variable.
Example: for reference sequence:
GTAAGTTGNACG
Output:
GTAAGTTGAATG -(11 C > T Mismatch)
GTAAGTTAAACG -(8 G > A Mismatch)
For Mismatch at N it is not showing any mismatch because of the if()
condition. If the ref-seq had Y or K instead of N it would show mismatch at 9th position.
2
Answers
You can declare an object containing the RYKN arrays:
As long as you have some string variable containing which of "R", "Y", "K", "N" to use, you can modify your if:
to
You could put the bases into an object and iterate the keys.