public void GroupTest2()
        {
            // AACGTNA
            // TACGNAT
            // CCCTTAN
            // CNTAAGG
            // ATTAGCA
            // ATAGCAT
            var groupAlignment =
                new GroupAlignment(
                    new[]
                        {
                            new Sequence(new[] { Nucleotide.A, Nucleotide.A, Nucleotide.C, Nucleotide.G, Nucleotide.T, Nucleotide.C, Nucleotide.A }),
                            new Sequence(new[] { Nucleotide.T, Nucleotide.A, Nucleotide.C, Nucleotide.G, Nucleotide.G, Nucleotide.A, Nucleotide.T }),
                            new Sequence(new[] { Nucleotide.C, Nucleotide.G, Nucleotide.C, Nucleotide.T, Nucleotide.T, Nucleotide.A, Nucleotide.C }),
                            new Sequence(new[] { Nucleotide.C, Nucleotide.C, Nucleotide.T, Nucleotide.A, Nucleotide.A, Nucleotide.G, Nucleotide.G }),
                            new Sequence(new[] { Nucleotide.A, Nucleotide.T, Nucleotide.T, Nucleotide.A, Nucleotide.G, Nucleotide.C, Nucleotide.A }),
                            new Sequence(new[] { Nucleotide.A, Nucleotide.T, Nucleotide.A, Nucleotide.G, Nucleotide.C, Nucleotide.A, Nucleotide.T })
                        },
                    true);

            var estimator = new OperationDistanceEstimator(3, 2, 0, 1);
            var groupAlgorithm = new GroupAlignmentAlgorithm(estimator);
            groupAlgorithm.Condensate(groupAlignment);
        }
 /// <summary>
 /// The condensate process - groups sequences into many multiple alignments.
 /// </summary>
 /// <param name="alignment">The group alignment.</param>
 public void Condensate(GroupAlignment alignment)
 {
     this.InitializeCondensateMap(alignment);
     while (alignment.Groups.Count > 1)
     {
         this.CondensateStep(alignment);
     }
 }
        /// <summary>
        /// The step of condensate method.
        /// </summary>
        /// <param name="alignment">The pair alignment.</param>
        public void CondensateStep(GroupAlignment alignment)
        {
            var newGroup =
                alignment.CondensateMap.OrderBy(item => item.Value.Diameter)
                         .ThenBy(item => item.Value.Size)
                         .ThenBy(item => item.Value.Id)
                         .First().Value;

            alignment.Groups.Remove(newGroup.First);
            alignment.Groups.Remove(newGroup.Second);
            alignment.Groups.Add(newGroup);
            alignment.AllGroups.Add(newGroup);

            this.UpdateCondensateMap(alignment, newGroup);
        }
        public void GroupTest1()
        {
            // AACGTAG
            // ATACTAC
            // GACCTAC
            // GTACTTG
            // GTCGTTG
            var groupAlignment =
                new GroupAlignment(
                    new[]
                        {
                            new Sequence(new[] { Nucleotide.A, Nucleotide.A, Nucleotide.C, Nucleotide.G, Nucleotide.T, Nucleotide.A, Nucleotide.G }),
                            new Sequence(new[] { Nucleotide.A, Nucleotide.T, Nucleotide.A, Nucleotide.C, Nucleotide.T, Nucleotide.A, Nucleotide.C }),
                            new Sequence(new[] { Nucleotide.G, Nucleotide.A, Nucleotide.C, Nucleotide.C, Nucleotide.T, Nucleotide.A, Nucleotide.C }),
                            new Sequence(new[] { Nucleotide.G, Nucleotide.T, Nucleotide.A, Nucleotide.C, Nucleotide.T, Nucleotide.T, Nucleotide.G }),
                            new Sequence(new[] { Nucleotide.G, Nucleotide.T, Nucleotide.C, Nucleotide.G, Nucleotide.T, Nucleotide.T, Nucleotide.G })
                        },
                    true);

            var estimator = new OperationDistanceEstimator(4, 2, 0, 1);
            var groupAlgorithm = new GroupAlignmentAlgorithm(estimator);
            groupAlgorithm.Condensate(groupAlignment);
        }
Beispiel #5
0
        void AlignSelectedNodes(GroupAlignment alignment)
        {
            int len = _process.selection.selectedNodes.Count;

            if (len <= 1)
            {
                return;
            }

            GUI.changed = true;
            Vector2 shift       = _process.areaShift;
            Vector2 alignVector = Vector2.zero;

            switch (alignment)
            {
            case GroupAlignment.Left:
                for (int i = 0; i < len; ++i)
                {
                    Rect r = _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea;
                    if (i == 0)
                    {
                        alignVector = new Vector2(r.x, 0);
                    }
                    else if (r.x < alignVector.x)
                    {
                        alignVector.x = r.x;
                    }
                }
                for (int i = 0; i < len; ++i)
                {
                    IEditorGUINode node = _process.selection.selectedNodes[i];
                    node.guiPosition = new Vector2(alignVector.x - shift.x, node.guiPosition.y);
                }
                break;

            case GroupAlignment.Right:
                for (int i = 0; i < len; ++i)
                {
                    Rect r = _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea;
                    if (i == 0)
                    {
                        alignVector = new Vector2(r.xMax, 0);
                    }
                    else if (r.xMax > alignVector.x)
                    {
                        alignVector.x = r.xMax;
                    }
                }
                for (int i = 0; i < len; ++i)
                {
                    IEditorGUINode node = _process.selection.selectedNodes[i];
                    node.guiPosition = new Vector2(
                        alignVector.x - _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea.width - shift.x,
                        node.guiPosition.y
                        );
                }
                break;

            case GroupAlignment.VCenter:
                for (int i = 0; i < len; ++i)
                {
                    Rect r = _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea;
                    if (i == 0)
                    {
                        alignVector = new Vector2(r.center.x, 0);
                    }
                    else if (r.center.x > alignVector.x)
                    {
                        alignVector.x += (r.center.x - alignVector.x) * 0.5f;
                    }
                    else if (r.center.x < alignVector.x)
                    {
                        alignVector.x -= (alignVector.x - r.center.x) * 0.5f;
                    }
                }
                for (int i = 0; i < len; ++i)
                {
                    IEditorGUINode node = _process.selection.selectedNodes[i];
                    node.guiPosition = new Vector2(
                        alignVector.x - _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea.width * 0.5f - shift.x,
                        node.guiPosition.y
                        );
                }
                break;

            case GroupAlignment.Top:
                for (int i = 0; i < len; ++i)
                {
                    Rect r = _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea;
                    if (i == 0)
                    {
                        alignVector = new Vector2(0, r.y);
                    }
                    else if (r.y < alignVector.y)
                    {
                        alignVector.y = r.y;
                    }
                }
                for (int i = 0; i < len; ++i)
                {
                    IEditorGUINode node = _process.selection.selectedNodes[i];
                    node.guiPosition = new Vector2(node.guiPosition.x, alignVector.y - shift.y);
                }
                break;

            case GroupAlignment.Bottom:
                for (int i = 0; i < len; ++i)
                {
                    Rect r = _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea;
                    if (i == 0)
                    {
                        alignVector = new Vector2(0, r.yMax);
                    }
                    else if (r.yMax > alignVector.y)
                    {
                        alignVector.y = r.yMax;
                    }
                }
                for (int i = 0; i < len; ++i)
                {
                    IEditorGUINode node = _process.selection.selectedNodes[i];
                    node.guiPosition = new Vector2(
                        node.guiPosition.x,
                        alignVector.y - _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea.height - shift.y
                        );
                }
                break;

            case GroupAlignment.HCenter:
                for (int i = 0; i < len; ++i)
                {
                    Rect r = _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea;
                    if (i == 0)
                    {
                        alignVector = new Vector2(0, r.center.y);
                    }
                    else if (r.center.y > alignVector.y)
                    {
                        alignVector.y += (r.center.y - alignVector.y) * 0.5f;
                    }
                    else if (r.center.y < alignVector.y)
                    {
                        alignVector.y -= (alignVector.y - r.center.y) * 0.5f;
                    }
                }
                for (int i = 0; i < len; ++i)
                {
                    IEditorGUINode node = _process.selection.selectedNodes[i];
                    node.guiPosition = new Vector2(
                        node.guiPosition.x,
                        alignVector.y - _process.nodeToGUIData[_process.selection.selectedNodes[i]].fullArea.height * 0.5f - shift.y
                        );
                }
                break;
            }
        }
 /// <summary>
 /// The generate method.
 /// </summary>
 /// <param name="alignment">The pair alignment.</param>
 public void FillPairAlignmentsMap(GroupAlignment alignment)
 {
     alignment.PairAlignmentsMap = this.GeneratePairAlignmentsMap(alignment);
     alignment.MinBound = alignment.PairAlignmentsMap.Values.Min(p => p.Distance);
     alignment.MaxBound = alignment.PairAlignmentsMap.Values.Max(p => p.Distance);
     alignment.AvgBound = alignment.PairAlignmentsMap.Values.Average(p => p.Distance);
 }
        /// <summary>
        /// The dynamic table fill.
        /// </summary>
        /// <param name="alignment">The group alignment.</param>
        /// <param name="newGroup">The new group.</param>
        public void UpdateCondensateMap(GroupAlignment alignment, MultipleAlignment newGroup)
        {
            // clean parent elements from condensate map
            var removed = alignment.CondensateMap
                .Where(item => item.Key.Item1 == newGroup.First.Id || item.Key.Item2 == newGroup.First.Id ||
                               item.Key.Item1 == newGroup.Second.Id || item.Key.Item2 == newGroup.Second.Id)
                .ToList();
            foreach (var keyValuePair in removed)
            {
                alignment.CondensateMap.Remove(keyValuePair.Key);
            }

            // except the diagonal element
            foreach (var group1 in alignment.Groups.Where(a => a.Id != newGroup.Id))
            {
                MultipleAlignment m;
                if (group1.Diameter < newGroup.Diameter
                    || (group1.Diameter == newGroup.Diameter && group1.Size < newGroup.Size))
                {
                    m = new MultipleAlignment(alignment.GroupsCounter, group1, newGroup);
                }
                else
                {
                    m = new MultipleAlignment(alignment.GroupsCounter, newGroup, group1);
                }

                alignment.GroupsCounter++;
                this.MultipleAlignmentAlgorithm.FillAlignedSequences(m, alignment.PairAlignmentsMap);
                alignment.CondensateMap[new Index(group1.Id, newGroup.Id)] = m;
                alignment.CondensateMap[new Index(newGroup.Id, group1.Id)] = m;
            }
        }
 /// <summary>
 /// The generate method.
 /// </summary>
 /// <param name="alignment">The pair alignment.</param>
 public void InitializeGroups(GroupAlignment alignment)
 {
     alignment.Groups = alignment.Select(s => new MultipleAlignment(s.Id, new[] { s }, this.Estimator)).ToList();
     alignment.AllGroups.AddRange(alignment.Groups);
     alignment.GroupsCounter = alignment.Groups.Max(g => g.Id) + 1;
 }
        /// <summary>
        /// The dynamic table fill.
        /// </summary>
        /// <param name="alignment">The group alignment.</param>
        public void InitializeCondensateMap(GroupAlignment alignment)
        {
            if (alignment.PairAlignmentsMap == null || !alignment.PairAlignmentsMap.Any())
            {
                this.FillPairAlignmentsMap(alignment);
            }

            if (alignment.Groups == null || !alignment.Groups.Any())
            {
                this.InitializeGroups(alignment);
            }

            var map = new Dictionary<Index, MultipleAlignment>();
            foreach (var group1 in alignment.Groups)
            {
                // except the diagonal elements and filled cells (the table is been filling for symmetrical elements in one step)
                foreach (var group2 in alignment.Groups.Where(a => a.Id != group1.Id && !map.ContainsKey(new Index(group1.Id, a.Id))))
                {
                    var m = new MultipleAlignment(alignment.GroupsCounter, group1, group2);
                    alignment.GroupsCounter++;
                    this.MultipleAlignmentAlgorithm.FillAlignedSequences(m, alignment.PairAlignmentsMap);
                    map[new Index(group1.Id, group2.Id)] = m;
                    map[new Index(group2.Id, group1.Id)] = m;
                }
            }

            alignment.CondensateMap = map;
        }