Exemple #1
0
 public void WriteLine(IClusterableMatch match, int overlapCount)
 {
     _overlapWriter.GenericObject = overlapCount;
     _col = 1;
     _col = _writers.WriteColumns(_row, _col, match, null);
     ++_row;
 }
Exemple #2
0
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode)
 {
     if (!string.IsNullOrEmpty(match.Match.Note))
     {
         cell.Value = match.Match.Note;
     }
 }
 public int WriteColumns(int row, int col, IClusterableMatch match, LeafNode leafNode)
 {
     foreach (var writer in _writers)
     {
         writer.WriteValue(_ws.Cells[row, col++], match, leafNode);
     }
     return(col);
 }
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode)
 {
     cell.StyleName = "HyperLink";
     cell.Hyperlink = new ExcelHyperLink($"https://{_ancestryHostName}/discoveryui-matches/compare-ng/{_testTakerTestId}/with/{match.Match.TestGuid}/trees", UriKind.Absolute)
     {
         Display = "Link"
     };
     //cell.Hyperlink = new ExcelHyperLink($"https://{_ancestryHostName}/discoveryui-matches/compare-ng/{_testTakerTestId}/with/{match.Match.TestGuid}/sharedmatches", UriKind.Absolute) { Display = "Link" };
 }
 // A direct match is when match B appears on the shared match list of match A.
 // When the shared match list of match A contains match B, then matrix[A][B] is set to _directCorrelationValue.
 private void ExtendMatrixDirect(ConcurrentDictionary <int, float[]> matrix, IClusterableMatch match, int maxIndex)
 {
     if (match.Index <= maxIndex)
     {
         var row = matrix.GetOrAdd(match.Index, _ => new float[maxIndex + 1]);
         foreach (var coord2 in match.Coords.Where(coord2 => coord2 < row.Length))
         {
             row[coord2] = _directCorrelationValue;
         }
     }
 }
Exemple #6
0
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode)
 {
     if (!string.IsNullOrWhiteSpace(match.Match.TreeUrl))
     {
         cell.StyleName = "HyperLink";
         cell.Hyperlink = new ExcelHyperLink(match.Match.TreeUrl, UriKind.Absolute)
         {
             Display = "Tree"
         };
     }
 }
Exemple #7
0
        public void WriteHeader(IClusterableMatch match)
        {
            if (match == null)
            {
                return;
            }

            _overlapWriter.GenericObject = match.Count;
            _col = 1;
            _col = _writers.WriteColumns(_row, _col, match, null);
            ++_row;
        }
Exemple #8
0
 public void WriteLine(IClusterableMatch match, int overlapCount)
 {
     _stringBuilder.AppendLine(//$"{Math.Sqrt(closestMatch.DistSquared):N2}\t" +
         $"{match.Count}" +
         $"\t{overlapCount}" +
         $"\t{match.Match.SharedCentimorgans:####.0}" +
         $"\t{match.Match.SharedSegments}" +
         //$"\t{closestMatch.OtherMatch.Match.TreeType}" +
         //$"\t{closestMatch.OtherMatch.Match.TreeSize}" +
         $"\t{match.Match.Name}" +
         $"\t{match.Match.TestGuid}" +
         $"\t{match.Match.Note}");
 }
Exemple #9
0
        public void WriteHeader(IClusterableMatch match)
        {
            if (match == null)
            {
                return;
            }

            _stringBuilder.AppendLine($"{match.Count}" +
                                      $"\t{match.Count}" +
                                      $"\t{match.Match.SharedCentimorgans:####.0}" +
                                      $"\t{match.Match.SharedSegments}" +
                                      //$"\t{match.Match.TreeType}" +
                                      //$"\t{match.Match.TreeSize}" +
                                      $"\t{match.Match.Name}" +
                                      $"\t{match.Match.TestGuid}" +
                                      $"\t{match.Match.Note}");
        }
Exemple #10
0
        public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode)
        {
            var clusterNumber            = _clusterNumberWriter.GetClusterNumber(match);
            var correlatedClusterNumbers = _leafNodes
                                           .Where(leafNode2 => !_immediateFamilyIndexes.Contains(leafNode2.Index) &&
                                                  leafNode.Coords.TryGetValue(leafNode2.Index, out var correlationValue) && correlationValue >= 1)
                                           .Select(leafNode2 => _indexClusterNumbers.TryGetValue(leafNode2.Index, out var correlatedClusterNumber) ? correlatedClusterNumber : 0)
                                           .Where(correlatedClusterNumber => correlatedClusterNumber != 0 && correlatedClusterNumber != clusterNumber)
                                           .GroupBy(n => n)
                                           .Where(g => g.Count() >= _minClusterSize)
                                           .Select(g => g.Key)
                                           .OrderBy(n => n)
                                           .ToList();

            if (correlatedClusterNumbers.Count > 0)
            {
                cell.Value = string.Join(", ", correlatedClusterNumbers);
            }
        }
        public void CalculateSimilarity(
            HashSet <int> coords,
            Dictionary <int, List <IClusterableMatch> > buckets,
            IClusterableMatch excludeMatch,
            Func <IClusterableMatch, int, bool> inclusionFunc,
            int maxClusterSize,
            ISimilarityWriter writer)
        {
            writer.WriteHeader(excludeMatch);

            var results = (
                from otherMatch in coords
                .Where(coord => buckets.ContainsKey(coord))
                .SelectMany(coord => buckets[coord])
                .GroupBy(m => m).Where(g => g.Count() >= _minClusterSize).Select(g => g.Key)
                where otherMatch != excludeMatch
                let overlapCount = coords.Intersect(otherMatch.Coords).Count()
                                   where inclusionFunc(otherMatch, overlapCount)
                                   select new
            {
                OtherMatch = otherMatch,
                OverlapCount = overlapCount,
            }
                )
                          .OrderByDescending(pair => (double)pair.OverlapCount * pair.OverlapCount / coords.Count / pair.OtherMatch.Count)
                          .Take(maxClusterSize)
                          .ToList();

            if (results.Count == 0)
            {
                return;
            }

            _progressData.Reset($"Writing {results.Count} similar matches...", results.Count);

            foreach (var closestMatch in results)
            {
                writer.WriteLine(closestMatch.OtherMatch, closestMatch.OverlapCount);
                _progressData.Increment();
            }
            writer.SkipLine();
        }
Exemple #12
0
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode) => cell.Value = GenericObject;
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode) => cell.Value = match.Match.SharedSegments;
        // An indirect match is when two matches A and B appear together on the shared match list of some other match C.
        // Matches are rated on a scale of 0...1
        // If two matches A and B never appear on the same match list, then matrix[A][B] has a value of 0.
        // If match A appears in 4 shared match lists, and match B appears in 3 of those lists, then matrix[A][B] has a value of 0.75
        // If every shared match list that contains match A also contains match B, then matrix[A][B] has a value of 1.
        private static void ExtendMatrixIndirect(ConcurrentDictionary <int, float[]> matrix, IClusterableMatch match, IReadOnlyDictionary <int, int> appearances, int maxIndex)
        {
            foreach (var coord1 in match.Coords)
            {
                if (!appearances.TryGetValue(coord1, out var numAppearances))
                {
                    continue;
                }

                var row = matrix.GetOrAdd(coord1, _ => new float[maxIndex + 1]);

                if (coord1 == match.Index)
                {
                    if (coord1 < row.Length)
                    {
                        row[coord1] += 1.0f / numAppearances;
                    }
                }
                else
                {
                    foreach (var coord2 in match.Coords.Where(coord2 => coord2 != match.Index && coord2 <= maxIndex))
                    {
                        row[coord2] += 1.0f / numAppearances;
                    }
                }
            }
        }
Exemple #15
0
 public int?GetClusterNumber(IClusterableMatch match) => _indexClusterNumbers.TryGetValue(match.Index, out var clusterNumber) ? clusterNumber : (int?)null;
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode)
 => cell.Value = match.Match.CommonAncestors?.Count > 0
         ? string.Join(", ", match.Match.CommonAncestors)
         : null;
        // An indirect match is when two matches A and B appear together on the shared match list of some other match C.
        // Matches are rated with a value of (n * indirectCorrelationValue),
        // where n is the number of shared match lists that contain both match A and match B.
        private static void ExtendMatrixIndirect(ConcurrentDictionary <int, float[]> matrix, IClusterableMatch match, int maxIndex, float indirectCorrelationValue)
        {
            foreach (var coord1 in match.Coords)
            {
                var row = matrix.GetOrAdd(coord1, _ => new float[maxIndex + 1]);

                if (coord1 == match.Index)
                {
                    if (coord1 < row.Length)
                    {
                        row[coord1] += indirectCorrelationValue;
                    }
                }
                else
                {
                    foreach (var coord2 in match.Coords.Where(coord2 => coord2 != match.Index && coord2 <= maxIndex))
                    {
                        row[coord2] += indirectCorrelationValue;
                    }
                }
            }
        }
Exemple #18
0
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode) => cell.Value = match.Match.TagIds?.Contains(_tag.TagId) == true ? "." : null;
Exemple #19
0
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode) => cell.Value = match.Match.HasHint ? "*" : null;
Exemple #20
0
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode) => cell.Value = !string.IsNullOrEmpty(match.Match.Note) ? match.Match.Note : null;
Exemple #21
0
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode) => cell.Value = GetClusterNumber(match);
 public void WriteValue(ExcelRange cell, IClusterableMatch match, LeafNode leafNode) => cell.Value = match.Match.TestGuid;
 // A direct match is when match B appears on the shared match list of match A.
 // When the shared match list of match A contains match B, then matrix[A][B] is incremented by a given amount.
 private static void ExtendMatrixDirect(ConcurrentDictionary <int, float[]> matrix, IClusterableMatch match, int maxIndex, int maxSharedIndex, float increment)
 {
     if (match.Index <= maxIndex)
     {
         var row = matrix.GetOrAdd(match.Index, _ => new float[maxSharedIndex + 1]);
         foreach (var coord2 in match.Coords.Where(coord2 => coord2 < row.Length))
         {
             row[coord2] += increment;
         }
     }
 }