public void Extend(SnpDataSet dataSet) { int newStart = this.GetStart(); int newEnd = this.GetEnd(); ArrayList newEndingSequence = new ArrayList(); while (newEnd < dataSet.GetSnpCount() - 1) { int data = -1; bool flag = false; for (int i = 1; i < this.group.Length; i++) { if (data == -1) { if (dataSet.GetSnp(this.group[i], newEnd + 1) != 1) { data = dataSet.GetSnp(this.group[i], newEnd + 1); } } else if (Math.Abs(dataSet.GetSnp(this.group[i], newEnd + 1) - data) == 2) { flag = true; break; } } if (flag) { break; } if (data == -1) { newEndingSequence.Add(1); } else if (data == 0) { newEndingSequence.Add(0); } else { newEndingSequence.Add(2); } newEnd++; } ArrayList newStartingSequence = new ArrayList(); while (newStart > 0) { int data = -1; bool flag = false; for (int i = 1; i < this.GetGroup().Length; i++) { if (data == -1) { if (dataSet.GetSnp(this.group[i], newStart - 1) != 1) { data = dataSet.GetSnp(this.group[i], newStart - 1); } } else if (Math.Abs(dataSet.GetSnp(this.group[i], newStart - 1) - data) == 2) { flag = true; break; } } if (flag) { break; } if (data == -1) { newStartingSequence.Add(1); } else if (data == 0) { newStartingSequence.Add(0); } else { newStartingSequence.Add(2); } newStart--; } newStartingSequence.Reverse(); int[] newWholeSequence = new int[this.sequence.Length + newStartingSequence.Count + newEndingSequence.Count]; newStartingSequence.CopyTo(newWholeSequence); this.GetSequence().CopyTo(newWholeSequence, newStartingSequence.Count); newEndingSequence.CopyTo(newWholeSequence, newStartingSequence.Count + this.sequence.Length); this.SetSequence(newWholeSequence); this.SetStart(newStart); this.SetEnd(newEnd); if (this.GetEnd() - this.GetEnd() > 170) { ; } while (newEnd < dataSet.GetSnpCount()) { ArrayList group0 = new ArrayList(); ArrayList group1 = new ArrayList(); ArrayList group2 = new ArrayList(); for (int i = 0; i < this.GetGroup().Length; i++) { if (this.GetGroup(i) == 0) { group0.Add(this.GetGroup(i)); } else if (this.GetGroup(i) == 2) { group2.Add(this.GetGroup(i)); } else { group1.Add(this.GetGroup(i)); } } } }
public void inWindowExtend(ArrayList group, int snpPosition, SnpDataSet dataSet, ArrayList shareWindowListRef) { if (snpPosition == this.end) //when it reached the end of the window { ShareWindow newShareWindow = new ShareWindow(); //construct a shareWindow object newShareWindow.windowStart = this; newShareWindow.windowLast = this; newShareWindow.group = group; group.Sort(); shareWindowListRef.Add(newShareWindow); // Add newShareWindow to shareWindow List; return; } ArrayList group0 = new ArrayList(); //store the individuals that the data of this snp is 0 ArrayList group1 = new ArrayList(); //store the individuals that the data of this snp is 1 ArrayList group2 = new ArrayList(); //store the individuals that the data of this snp is 2 foreach (int individual in group) { if (dataSet.GetSnp(individual, snpPosition) == 0) // the data is 0 { group0.Add(individual); } else if (dataSet.GetSnp(individual, snpPosition) == 1) //the data is 1 { group1.Add(individual); } else //the data is 2 { group2.Add(individual); } } if (group2.Count + group1.Count >= 3) // construct a new group if group2+group1>=3 { ArrayList group12 = new ArrayList(); foreach (int ind in group2) //add group2 and group1 into group21 { group12.Add(ind); } foreach (int ind in group1) { group12.Add(ind); } //group12.ToArray(); inWindowExtend(group12, snpPosition + 1, dataSet, shareWindowListRef); //use group21 to do the next Extend } if (group0.Count + group1.Count >= 3) // construct a new group if group0+group1>=3, similar to last. { ArrayList group01 = new ArrayList(); foreach (int ind in group0) { group01.Add(ind); } foreach (int ind in group1) { group01.Add(ind); } //group01.ToArray(); inWindowExtend(group01, snpPosition + 1, dataSet, shareWindowListRef); //do the next Extend } }
private bool CheckCommon(SnpDataSet dataSet) //check snp data between rare blocks { int[] error = new int[this.group.Length]; //error data. this.sequence = new int[this.end - this.start + 1]; for (int e = 0; e < error.Length; e++) // all is 0 at the begining. { error[e] = 0; } for (int i = start; i < end; i++) //loop from start to end for snp { int count0 = 0; //count how many 0 int count2 = 0; //count how many 2 int[] dataTmp = new int[this.group.Length]; //store the data, avoid multi data accessing //for (int d = 0; d < dataTmp.Length; d++) // // d = 0; int j = 0; foreach (int ind in this.group) // for each guy in group ,check this snp data { int data = dataSet.GetSnp(ind, i); if (data == 2) { count2++; } else if (data == 0) { count0++; } dataTmp[j] = data; //store the data. j++; } if (count2 <= count0) //two minor allele is the outlier in the group { for (int m = 0; m < this.group.Length; m++) { if (dataTmp[m] == 2) { error[m]++; } } sequence[i - start] = 0; } else //two major allele is the outlier in the group { for (int m = 0; m < this.group.Length; m++) { if (dataTmp[m] == 0) { error[m]++; } } sequence[i - start] = 2; } if (count2 == 0 && count0 == 0) { sequence[i - start] = 1; } } ArrayList newGroup = new ArrayList(); for (int n = 0; n < this.group.Length; n++) { if (!(error[n] > 0)) //no error or little error, keep this guy. { newGroup.Add(this.group[n]); } } if (newGroup.Count < 3) { return(false); } else { this.group = (int[])newGroup.ToArray(typeof(int)); return(true); } }