Esempio n. 1
0
        /// <summary>
        /// Propagate the color of the skeleton color throught the ABruijn Graph
        /// </summary>
        /// <param name="blockColors"> A list of Blocks. The color ID of each block is also its its position in the list </param>
        /// <param name="propagationRadius"> The maximum radius that the color can propagate </param>
        /// <returns>a mapping between nodeids and their colors</returns>
        public IDictionary <int, int> PropagateSkeletonColor(IList <IList <int> > blockColors, int propagationRadius)
        {
            SimpleLinkList <int> origialSequence = new SimpleLinkList <int>();

            origialSequence.AddList(_sequence);
            IDictionary <int, IList <Node <int> > > graph = GenerateGraph(origialSequence);

            IDictionary <int, int> colorByNodeID = new Dictionary <int, int>();

            //initially, all nodes are uncolored ( -1)
            foreach (int i in _sequence)
            {
                colorByNodeID[i] = -1;
            }

            //add colors
            for (int i = 0; i < blockColors.Count; i++)
            {
                foreach (int nodeID in blockColors[i])
                {
                    colorByNodeID[nodeID] = i;
                }
            }
            HashSet <int> unColorNodes = new HashSet <int>();

            foreach (KeyValuePair <int, int> pair in colorByNodeID)
            {
                if (pair.Value == -1)
                {
                    unColorNodes.Add(pair.Key);
                }
            }
            for (int i = 0; i < propagationRadius; i++)
            {
                for (int j = 0; j < blockColors.Count; j++)
                {
                    HashSet <int> modifiedUnColoredNodes = new HashSet <int>(unColorNodes);
                    foreach (int node in modifiedUnColoredNodes)
                    {
                        int newColor = FindDominantColor(node, colorByNodeID, graph);
                        if (newColor != -1)
                        {
                            colorByNodeID[node] = newColor;
                            unColorNodes.Remove(node);
                        }
                    }
                }
            }
            return(colorByNodeID);
        }
Esempio n. 2
0
        /// <summary>
        /// Thread a sequence of integer through an ABruijn Graph
        /// </summary>
        /// <param name="sequence">sequence wanted to thread</param>
        public void ThreadSequence(IList <int> sequence)
        {
            _sequence = sequence;
            _workingSequence.AddList(sequence);        //把List转换成单链表
            _sourceSequence.AddList(sequence);         //把List转换成单链表
            IList <Node <int> > _workingMembers = _workingSequence.GetMembers();
            IList <Node <int> > _sourceMembers  = _sourceSequence.GetMembers();

            IList <IList <Node <int> > > sourceSequencesChrs = new List <IList <Node <int> > >();       //获得原序列对应的坐标
            IList <Node <int> >          chr = new List <Node <int> >();

            for (int i = 1; i < _sourceMembers.Count - 1; i++)
            {
                if (_sourceMembers[i].Value >= 0)
                {
                    chr.Add(_sourceMembers[i]);
                }
                else
                {
                    sourceSequencesChrs.Add(chr);
                    chr = new List <Node <int> >();
                    while (i < _sourceMembers.Count && _sourceMembers[i].Value < 0)
                    {
                        i++;
                    }
                    i--;
                }
            }
            sourceSequencesChrs.Add(chr);         //拆分成Chrs

            for (int i = 0; i < sourceSequencesChrs.Count; i++)
            {
                for (int j = 0; j < sourceSequencesChrs[i].Count; j++)
                {
                    _nodeToIndex.Add(sourceSequencesChrs[i][j], new Pair <int>(i, j));
                }
            }
            for (int i = 0; i < _workingMembers.Count; i++)         //生成map
            {
                _workToSource.Add(_workingMembers[i], _sourceMembers[i]);
            }
            _graph = GenerateGraph(_workingSequence);
            _graphTool.setWorkToSource(_workToSource);
        }
Esempio n. 3
0
 /// <summary>
 /// Thread a sequence of integer through an ABruijn Graph
 /// </summary>
 /// <param name="sequence">sequence wanted to thread</param>
 public void ThreadSequence(IList <int> sequence)
 {
     _sequence = sequence;
     _workingSequence.AddList(sequence);         //把List转换成单链表
     _graph = GenerateGraph(_workingSequence);
 }