public bool CkeckSubGroup(RareBlock rareBlockToCheck) { if (this.GetStart() != rareBlockToCheck.GetStart() || this.GetEnd() != rareBlockToCheck.GetEnd() || this.GetGroup().Length <= rareBlockToCheck.GetGroup().Length) { return(false); } int i = 0; int j = 0; while (j < rareBlockToCheck.GetGroup().Length) { if (this.GetGroup(i) == rareBlockToCheck.GetGroup(j)) { i++; j++; } else if (this.GetGroup(i) < rareBlockToCheck.GetGroup(j)) { i++; } else { return(false); } if (i == this.GetGroup().Length&& j != rareBlockToCheck.GetGroup().Length) { return(false); } } return(true); }
public bool CheckContain(RareBlock rareBlockToCheck) //check if RareBlockToCheck is in the region of "this" with same group. { if (this.GetGroup().Length != rareBlockToCheck.GetGroup().Length) { return(false); } if (this.GetEnd() > rareBlockToCheck.GetEnd()) { return(false); } if (this.GetStart() < rareBlockToCheck.GetStart()) { return(false); } for (int i = 0; i < this.GetGroup().Length; i++) { if (this.GetGroup(i) != rareBlockToCheck.GetGroup(i)) { return(false); } } return(true); }
public bool CheckSame(RareBlock rareBlockToCheck) //check if two rare blocks are the same or not. { if (this.GetStart() != rareBlockToCheck.GetStart()) { return(false); } if (this.GetEnd() != rareBlockToCheck.GetEnd()) { return(false); } if (this.GetGroup().Length != rareBlockToCheck.GetGroup().Length) { return(false); } for (int i = 0; i < this.GetGroup().Length; i++) { if (this.GetGroup(i) != rareBlockToCheck.GetGroup(i)) { return(false); } } return(true); }
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()); } } }