Пример #1
0
        /// <summary>
        /// Builds difference list from match list
        /// </summary>
        /// <param name="matchList">List of matching segments</param>
        /// <param name="sequence1">First sequence</param>
        /// <param name="sequence2">Second sequence</param>
        /// <returns>List of difference nodes</returns>
        public static List <DifferenceNode> BuildDiffList(List <WordMatch> matchList, ISequence sequence1, ISequence sequence2)
        {
            // Sort match list according to start indices
            matchList.Sort(CompareDifferenceNode);

            List <DifferenceNode> diffList = new List <DifferenceNode>();

            int mismatchStart1, mismatchStart2, mismatchEnd1, mismatchEnd2;

            mismatchStart1 = 0;
            mismatchStart2 = 0;

            // There might be some mutation at starting
            WordMatch first = matchList[0];

            if (first.Sequence1Start > 0 || first.Sequence2Start > 0)
            {
                diffList.Add(new DifferenceNode(0, 0, first.Sequence1Start - 1, first.Sequence2Start - 1));
            }

            // Primer for starting iteration
            matchList.RemoveAt(0);
            mismatchStart1 = first.Sequence1Start + first.Length;
            mismatchStart2 = first.Sequence2Start + first.Length;

            foreach (WordMatch n in matchList)
            {
                mismatchEnd1 = n.Sequence1Start - 1;
                mismatchEnd2 = n.Sequence2Start - 1;
                diffList.Add(new DifferenceNode(mismatchStart1, mismatchStart2, mismatchEnd1, mismatchEnd2));
                mismatchStart1 = n.Sequence1Start + n.Length;
                mismatchStart2 = n.Sequence2Start + n.Length;
            }

            // There might be some mutation at the end
            mismatchEnd1 = sequence1.Count - 1;
            mismatchEnd2 = sequence2.Count - 1;
            if (mismatchStart1 <= mismatchEnd1 || mismatchStart2 <= mismatchEnd2)
            {
                diffList.Add(new DifferenceNode(mismatchStart1, mismatchStart2, mismatchEnd1, mismatchEnd2));
            }

            return(diffList);
        }
Пример #2
0
 /// <summary>
 /// Comparison of two word match list nodes
 /// based on the first sequence start indices
 /// </summary>
 /// <param name="n1">First match list node</param>
 /// <param name="n2">Second match list node</param>
 /// <returns>Integer value indicating zero if equal.</returns>
 public static int CompareDifferenceNode(WordMatch n1, WordMatch n2)
 {
     return(n1.Sequence1Start - n2.Sequence1Start);
 }