sharedMotif method
Returns the longest shared motif between this sequence and oSeq
.
Implementation
String sharedMotif({required Sequence oSeq}) {
if (this._type != oSeq.type) {
Errors.unequalSeqTypes(func: 'sharedMotif');
}
// Return all possible combinates of this sequence sorted from longest to shortest.
List<String> combos = combinations(sorted: true);
String longestShared = '';
for (var comb in combos) {
// Assume the combination is contained in the other sequence unless set otherwise.
bool isMatch = true;
if (!oSeq.seq.contains(comb)) {
// The combination is not contained in the other sequence.
isMatch = false;
}
if (isMatch) {
// The combination must be present in the other sequence.
// Because the combinations were sorted from longest to
// shortest, this must be the longest shared motif.
longestShared = comb;
break;
}
}
return longestShared;
}