Example #1
0
        public void Combine(int i, ArrayList rareBlockList, ArrayList combinedBlockList, SnpDataSet dataSet)
        {
            if (i == rareBlockList.Count - 1)
            {
                return;                               //reach the end of the rareBlockList.
            }
            ArrayList newGroup    = new ArrayList();
            ArrayList remainGroup = new ArrayList();
            bool      flag        = true;

            for (int j = i + 1; j < i + 50 && j < rareBlockList.Count; j++) // find combined block from this block to 100 blocks away.
            {
                RareBlock block = new RareBlock();
                //Console.WriteLine("{0} {1}", i, j);
                block = (RareBlock)((RareBlock)rareBlockList[j]).MemberwiseClone();

                if (block.GetStart() < this.GetEnd())
                {
                    continue;
                }
                int m = 0;
                int n = 0;
                newGroup.Clear();
                remainGroup.Clear();
                for (m = 0; m < this.GetGroup().Length; m++)   //find the intersection of the two group of individuals.
                {
                    if (n == block.GetGroup().Length)
                    {
                        remainGroup.Add(this.GetGroup(m));
                        break;
                    }
                    if (this.group[m] == block.GetGroup(n))
                    {
                        newGroup.Add(this.group[m]);
                        n++;
                    }
                    else if (this.group[m] > block.GetGroup(n))
                    {
                        n++;
                        m--;
                    }
                    else
                    {
                        remainGroup.Add(this.GetGroup(m));
                    }
                }

                if (newGroup.Count > 2) //more than 1 guys appare in the two rare blocks
                {
                    //Console.Write("{0} {1} {2}\t", i, j, newGroup.Count);
                    //foreach (int ind in newGroup)
                    //    Console.Write("{0} ",ind);
                    //Console.WriteLine();
                    //Console.ReadKey();
                    RareBlock newRareBlock = new RareBlock();
                    newRareBlock.SetStart(this.GetStart());
                    newRareBlock.SetEnd(block.GetEnd());
                    newRareBlock.SetGroup((int[])newGroup.ToArray(typeof(int)));
                    if (newRareBlock.CheckCommon(dataSet)) //check the snp data between the rare blocks
                    //if (true)
                    {
                        if (newRareBlock.GetGroup().Length == 3)
                        {
                            newRareBlock.Extend(dataSet);
                            if (newRareBlock.GetEnd() - newRareBlock.GetStart() > 170)
                            {
                                if (combinedBlockList.Count > 0)
                                {
                                    RareBlock lastRareBlock = (RareBlock)((RareBlock)combinedBlockList[combinedBlockList.Count - 1]).MemberwiseClone();

                                    if (!lastRareBlock.CheckSame(this))
                                    {
                                        if (this.CheckContain(lastRareBlock))
                                        {
                                            combinedBlockList[combinedBlockList.Count - 1] = this.GetCopy();
                                        }
                                        else
                                        {
                                            combinedBlockList.Add(this.GetCopy());
                                        }
                                    }
                                }
                                else
                                {
                                    combinedBlockList.Add(this.GetCopy());
                                }
                            }
                        }
                        else
                        {
                            newRareBlock.Combine(j, rareBlockList, combinedBlockList, dataSet);//if pass, continue combining.
                        }
                        //break;       //When we find another block to combine to this block ,stop searching for this block.
                        //Time saving a lot, can miss some, discuss later on.
                        if (this.group.Length - newRareBlock.group.Length == 0)
                        {
                            flag = false;
                            break;
                        }
                        //else if (newRareBlock.group.Length / (this.group.Length - newRareBlock.group.Length) >= 3) break;
                    }

                    /*
                     * if (this.group.Length - newRareBlock.group.Length >= 3)
                     * {
                     *  RareBlock remainGroupBlock = new RareBlock();
                     *  remainGroupBlock.start = this.start;
                     *  remainGroupBlock.end = this.end;
                     *  remainGroupBlock.sequence = this.sequence;
                     *  remainGroupBlock.group = (int[])remainGroup.ToArray(typeof(int));
                     *  remainGroupBlock.Combine(j, rareBlockList, combinedBlockList, dataSet);
                     * }
                     */
                }
            }
            if (flag && (this.GetEnd() - this.GetEnd()) > 70)
            {
                if (combinedBlockList.Count > 0)
                {
                    RareBlock lastRareBlock = (RareBlock)combinedBlockList[combinedBlockList.Count - 1];

                    if (!lastRareBlock.CheckSame(this))
                    {
                        if (this.CheckContain(lastRareBlock))
                        {
                            combinedBlockList[combinedBlockList.Count - 1] = this.GetCopy();
                        }
                        else
                        {
                            combinedBlockList.Add(this.GetCopy());
                        }
                    }
                }
                else
                {
                    combinedBlockList.Add(this.GetCopy());
                }
            }
        }