Пример #1
0
 public Node(int index, T value)
 {
     Index    = index;
     Children = new NodeChildren <T>();
     Value    = value;
     Traverse = new NodeTraverser <T>(this);
 }
Пример #2
0
        public Folder(string path, DateTime created, DateTime modified, long count)
            : base(path, created, modified)
        {
            Count = count;

            Children = new NodeChildren(this);
        }
        void GroupProteinsOrPeptides(
            IDictionary <string, Node> entities,
            IReadOnlyList <string> entityNames,
            Type entityType,
            GlobalIDContainer globalIDTracker)
        {
            for (var count = 0; count != entityNames.Count; count++)
            {
                // Is the key there?
                if (!entities.ContainsKey(entityNames[count]))
                {
                    continue;
                }

                // Get the protein or peptide
                var entity = entities[entityNames[count]];

                // Only proceed if the correct type
                if (entity.GetType() != entityType)
                {
                    continue;
                }

                var duplicates = new NodeChildren <Node>();

                // Look for duplicates and add to a duplicate list
                duplicates.AddRange(FindDuplicates(entity));

                if (duplicates.Count <= 1)
                {
                    continue;
                }

                // Create a protein or peptide group from the duplicates
                Group newGroup;

                if (entityType == typeof(Protein))
                {
                    newGroup = new ProteinGroup(duplicates, globalIDTracker);
                }
                else if (entityType == typeof(Peptide))
                {
                    newGroup = new PeptideGroup(duplicates, globalIDTracker);
                }
                else
                {
                    throw new Exception("Invalid type: must be Protein or Peptide");
                }

                foreach (var duplicateItem in duplicates)
                {
                    // Remove entities from the library, add the new group
                    entities.Remove(duplicateItem.NodeName);
                }

                entities.Add(newGroup.NodeName, newGroup);
            }
        }
        private NodeChildren <Node> FindDuplicates(Node node)
        {
            node.Children.Sort();
            var candidates = new NodeChildren <Node>();

            candidates.AddRange(node.Children[0].Children);
            candidates.Remove(node);

            var count = 0;

            // Pulls out candidates with different counts of children than the master
            while (candidates.Count != count)
            {
                if (node.Children.Count != candidates[count].Children.Count)
                {
                    candidates.RemoveAt(count);
                }
                else
                {
                    count++;
                }
            }

            // May want to change the List to a Hashset to be faster.
            // Finds identical sets.
            foreach (var childNode in node.Children)
            {
                count = 0;
                while (candidates.Count != count)
                {
                    if (!childNode.Children.Contains(candidates[count]))
                    {
                        candidates.RemoveAt(count);
                    }
                    else
                    {
                        count++;
                    }
                }
            }
            candidates.Add(node);
            return(candidates);
        }
Пример #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="nodeType"></param>
        /// <param name="groupedNodes"></param>
        /// <param name="globalIDTracker"></param>
        public Group(NodeTypeName nodeType, NodeChildren <Node> groupedNodes, GlobalIDContainer globalIDTracker)
            : base(nodeType)
        {
            // Copies inputted nodes to be grouped into a list
            // Copies the grouped nodes' children as the groups children.
            // In this case since they should be identical we just grab the first member
            var tempNode = new NodeChildren <Node>(groupedNodes);

            nodeGroup = new NodeChildren <Node>(groupedNodes);
            Children  = new NodeChildren <Node>(groupedNodes[0].Children);

            mNodeNameList = new List <string>();
            var nodeNameGlobalIDs = new List <int>();

            foreach (var item in groupedNodes)
            {
                mNodeNameList.Add(item.NodeName);
                var globalID = globalIDTracker.GetGlobalID(item.NodeName);
                nodeNameGlobalIDs.Add(globalID);
            }
            NodeName = string.Join(LIST_SEP_CHAR.ToString(), nodeNameGlobalIDs);

            var toRemove = tempNode.Count;

            foreach (var child in Children)
            {
                for (var i = 0; i < toRemove; i++)
                {
                    child.Children.Remove(tempNode[i]);
                }
            }

            foreach (var child in Children)
            {
                child.Children.Add(this);
            }
        }
 public PeptideGroup(NodeChildren <Node> groupedNodes, GlobalIDContainer globalIDTracker)
     : base(NodeTypeName.PeptideGroup, groupedNodes, globalIDTracker)
 {
 }
Пример #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Node(NodeTypeName nodeType, string nodeName) : this(nodeType)
 {
     NodeName = nodeName;
     Children = new NodeChildren <Node>();
 }
 /// <summary>
 /// Constructor that takes a set grouped nodes
 /// </summary>
 /// <param name="groupedNodes"></param>
 /// <param name="globalIDTracker"></param>
 public ProteinGroup(NodeChildren <Node> groupedNodes, GlobalIDContainer globalIDTracker)
     : base(NodeTypeName.ProteinGroup, groupedNodes, globalIDTracker)
 {
     UntakenPeptides = Children.Count;
 }