public static IEnumerable <Coverage> SplitTrackMatchedRegions(this IEnumerable <MatchedWith> entries, double queryLength, double trackLength, double fingerprintLength, double permittedGap) { var list = new List <Coverage>(); var ordered = entries.OrderBy(_ => _.TrackMatchAt).ToList(); if (!ordered.Any()) { return(list); } var stack = new Stack <MatchedWith>(); stack.Push(ordered.First()); foreach (var matchedWith in ordered.Skip(1)) { var prev = stack.Peek(); var trackGap = SubFingerprintsToSeconds.GapLengthToSeconds(matchedWith.TrackMatchAt, prev.TrackMatchAt, fingerprintLength); var queryGap = SubFingerprintsToSeconds.GapLengthToSeconds(matchedWith.QueryMatchAt, prev.QueryMatchAt, fingerprintLength); if (trackGap > permittedGap || queryGap > permittedGap) { list.AddRange(GetMatchedWithsFromStack(stack, queryLength, trackLength, fingerprintLength, permittedGap)); stack = new Stack <MatchedWith>(); } stack.Push(matchedWith); } list.AddRange(GetMatchedWithsFromStack(stack, queryLength, trackLength, fingerprintLength, permittedGap)); return(list); }
private static double CalculateExactQueryLength(IEnumerable <HashedFingerprint> hashedFingerprints, FingerprintConfiguration fingerprintConfiguration) { double startsAt = double.MaxValue, endsAt = double.MinValue; foreach (var hashedFingerprint in hashedFingerprints) { startsAt = System.Math.Min(startsAt, hashedFingerprint.StartsAt); endsAt = System.Math.Max(endsAt, hashedFingerprint.StartsAt); } return(SubFingerprintsToSeconds.AdjustLengthToSeconds(endsAt, startsAt, fingerprintConfiguration.FingerprintLengthInSeconds)); }
public static double QueryLength(this IEnumerable <HashedFingerprint> hashedFingerprints, FingerprintConfiguration configuration) { double startsAt = double.MaxValue, endsAt = double.MinValue; foreach (var hashedFingerprint in hashedFingerprints) { startsAt = System.Math.Min(startsAt, hashedFingerprint.StartsAt); endsAt = System.Math.Max(endsAt, hashedFingerprint.StartsAt); } return(SubFingerprintsToSeconds.MatchLengthToSeconds(endsAt, startsAt, configuration.FingerprintLengthInSeconds)); }
private static IEnumerable <Gap> FindGaps(this IEnumerable <Tuple <uint, float> > entries, double permittedGap, double fingerprintLength) { Tuple <uint, float>[] matches = entries.ToArray(); for (int i = 1; i < matches.Length; ++i) { float startsAt = matches[i - 1].Item2; float endsAt = matches[i].Item2; float gap = (float)SubFingerprintsToSeconds.GapLengthToSeconds(endsAt, startsAt, fingerprintLength); bool sequenceNumberIncremented = matches[i].Item1 - matches[i - 1].Item1 > 1; float start = endsAt - gap; if (!(endsAt <= start) && gap > permittedGap && sequenceNumberIncremented) { yield return(new Gap(start, endsAt, false)); } } }