restrictionSites method
Returns the restriction sites of this sequence.
Alter the length of the restriction sites by modifying minSiteLen
and maxSiteLen
.
Implementation
Map<String, List<Map<String, int>>> restrictionSites({
int minSiteLen = 4,
int maxSiteLen = 8,
}) {
// Fetch a reverse complementary sequence to this sequence.
String revComp = complementary(rev: true);
// Fetch all possible combinations of this sequence.
List<String> origSeqCombos = combinations();
// Fetch only the combinations whose length is equato to or between [minSiteLen] and [maxSiteLen].
Iterable<String> seqIter =
origSeqCombos.where((seq) => (seq.length >= minSiteLen) && (seq.length <= maxSiteLen));
// Fecth only the unique combinations.
List<String> restSeqs = seqIter.toSet().toList();
Map<String, List<Map<String, int>>> restSiteSeqs = {};
List<Map<String, int>> restSiteLocations = [];
// Loop through each combination.
for (String restSeq in restSeqs) {
restSiteLocations = [];
RegExp regRestExp = RegExp(restSeq);
// Find all matches between the combination and the reverse complementary sequence.
Iterable<RegExpMatch> matches = regRestExp.allMatches(revComp);
// Loop through each match.
for (RegExpMatch match in matches) {
int startIdx = this.seq.length - (restSeq.length + match.start);
int endIdx = startIdx + restSeq.length;
// Detect palindrome.
// Check if the sub-sequence matches the current combination.
if (this.seq.substring(startIdx, endIdx) == restSeq) {
restSiteLocations.add({kStartIndex: startIdx, kEndIndex: endIdx});
restSiteSeqs[restSeq] = restSiteLocations;
}
;
}
}
return restSiteSeqs;
}