motifToRe static method
Returns a regex valid version of a biological motif
.
motifToRe(motif: 'N{P}[ST]{P}') == 'N[^P][S|T|][^P]'
Implementation
static String motifToRe({required String motif}) {
String re = '';
List<String> chars = motif.split('');
bool inBrac = false;
for (String char in chars) {
if (char == '[') {
inBrac = true;
re += char;
} else if (char == ']') {
inBrac = false;
re += char;
} else {
if (inBrac) {
re += char + '|';
} else {
re += char;
}
}
}
return re.replaceAll('{', '[^').replaceAll('}', ']');
}