Пример #1
0
        public void RemoveSubtree(GlycanTreeNode argTree, GlycanTreeNode argRemoveTree)
        {
            int            TargetLevel = argRemoveTree.DistanceRoot;
            GlycanTreeNode CurrentTree = argTree;
            Queue          ChildQuene  = new Queue();

            do
            {
                if (CurrentTree.DistanceRoot < TargetLevel)
                {
                    if (CurrentTree.GetChildren() == null) //Other Branch
                    {
                        CurrentTree = (GlycanTreeNode)ChildQuene.Dequeue();
                    }
                    else
                    {
                        if (CurrentTree.GetChildren().Count > 1)
                        {
                            for (int i = 1; i < CurrentTree.GetChildren().Count; i++)
                            {
                                ChildQuene.Enqueue(CurrentTree.GetChildren()[i]);
                            }
                        }
                        CurrentTree = CurrentTree.GetChildren()[0];
                    }
                }
                else
                {
                    if (CurrentTree.GetIUPACString() == argRemoveTree.GetIUPACString())
                    {
                        CurrentTree = CurrentTree.Parent;
                        CurrentTree.GetChildren().Remove(argRemoveTree);
                    }
                }
            } while (true);
        }
Пример #2
0
        public static List <GlycanTreeNode> FragementGlycanTree(GlycanTreeNode argTree)
        {
            List <GlycanTreeNode> _fragment = new List <GlycanTreeNode>();
            Queue          ChildQueue       = new Queue();
            GlycanTreeNode CurrentTree      = argTree;

            do
            {
                GlycanTreeNode tmpTree = (GlycanTreeNode)argTree.Clone();
                if (CurrentTree.GetChildren() != null)
                {
                    if (CurrentTree.GetChildren().Count == 1)
                    {
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        _fragment.Add(tmpTree);
                        CurrentTree = CurrentTree.GetChildren()[0];
                    }
                    else if (CurrentTree.GetChildren().Count == 2)
                    {
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        _fragment.Add(tmpTree);

                        ChildQueue.Enqueue(CurrentTree.GetChildren()[1]);
                        CurrentTree = CurrentTree.GetChildren()[0];
                    }
                    else if (CurrentTree.GetChildren().Count == 3)
                    {
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        ChildQueue.Enqueue(CurrentTree.GetChildren()[1]);
                        ChildQueue.Enqueue(CurrentTree.GetChildren()[2]);
                        CurrentTree = CurrentTree.GetChildren()[0];
                    }
                    else if (CurrentTree.GetChildren().Count == 4)
                    {
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[3]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[3]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[3]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[3]);
                        _fragment.Add(tmpTree);


                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[3]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[0]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[3]);
                        _fragment.Add(tmpTree);

                        tmpTree = (GlycanTreeNode)argTree.Clone();
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[1]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[2]);
                        tmpTree.RemoveGlycan(CurrentTree.GetChildren()[3]);
                        _fragment.Add(tmpTree);


                        ChildQueue.Enqueue(CurrentTree.GetChildren()[1]);
                        ChildQueue.Enqueue(CurrentTree.GetChildren()[2]);
                        ChildQueue.Enqueue(CurrentTree.GetChildren()[3]);
                        CurrentTree = CurrentTree.GetChildren()[0];
                    }
                }
                else
                {
                    if (ChildQueue.Count != 0)
                    {
                        CurrentTree = (GlycanTreeNode)ChildQueue.Dequeue();
                    }
                    else
                    {
                        break;
                    }
                }
            } while (true);

            //Filter out duplicate tree
            List <GlycanTreeNode> tmpGlycanTree = new List <GlycanTreeNode>();

            foreach (GlycanTreeNode t in _fragment)
            {
                if (!tmpGlycanTree.Contains(t))
                {
                    tmpGlycanTree.Add(t);
                }
            }
            tmpGlycanTree.Sort(delegate(GlycanTreeNode T1, GlycanTreeNode T2)
            {
                return(GlycanMass.GetGlycanMasswithCharge(new GlycanCompound(T1.NoOfHexNac, T1.NoOfHex, T1.NoOfDeHex, T1.NoOfNeuAc), argTree.Charge).CompareTo(
                           GlycanMass.GetGlycanMasswithCharge(new GlycanCompound(T2.NoOfHexNac, T2.NoOfHex, T2.NoOfDeHex, T2.NoOfNeuAc), argTree.Charge)));
            });

            return(tmpGlycanTree);
        }