public void QTLPosition(int amountOfTraits, List <LineChartXY> charts, int amountOfChromosomes) { Dictionary <int, List <List <ObservablePoint> > > chromosomes = new Dictionary <int, List <List <ObservablePoint> > >(); for (int i = 0; i < amountOfChromosomes; i++) { //each list is a chromosome List <List <ObservablePoint> > p = new List <List <ObservablePoint> >(); p.Add(new List <ObservablePoint>()); chromosomes.Add(i, p); } double maxVal = getLongestChr(this.db.GenomeOrganization.Chromosome, amountOfChromosomes); foreach (LineChartXY chartXy in charts) { chartXy.AxisXTitle = "Position on chromosome"; chartXy.AxisYTitle = "-Log(P-Value)"; chartXy.SetXAxisMaxValue = maxVal; } double temp, tempLogVal = 0.0; int chrNum = 0; //we calcualte for the g traits the qtl position for (int g = 0; g < amountOfTraits; g++) { //here we calculate to all of the markers its p value according to a a few traits for (int i = 0; i < this.db.SubData[0].Genotype.Length; i++) { List <double> no = new List <double>(); List <double> n1 = new List <double>(); for (int k = 0; k < this.db.SubData.Count; k++) { if (this.db.SubData[k].Genotype[0, i] == 0) { no.Add(this.db.SubData[k].TraitValue[0, g]); } else if (this.db.SubData[k].Genotype[0, i] == 1) { n1.Add(this.db.SubData[k].TraitValue[0, g]); } //calculate the pvalue for trait and genotype and put in the correct bin } temp = StatisticCalculations.PValueTStatistic(no, n1); tempLogVal = ((-1.0 * Math.Log(temp))); chrNum = Convert.ToInt32(this.db.SubData[0].Locus[i].Position.Chromosome.Name); if (chrNum <= amountOfChromosomes) { chrNum--; int seriresNum = chromosomes[chrNum].Count - 1; chromosomes[chrNum][seriresNum].Add(new ObservablePoint(this.db.SubData[0].Locus[i].Position.PositionChrGenetic, tempLogVal)); } } foreach (KeyValuePair <int, List <List <ObservablePoint> > > entry in chromosomes) { entry.Value.Add(new List <ObservablePoint>()); } } int counter = 0; foreach (KeyValuePair <int, List <List <ObservablePoint> > > entry in chromosomes) { foreach (List <ObservablePoint> l in entry.Value) { l.Sort((x, y) => x.X.CompareTo(y.X)); charts[counter].AddLineChart(l, 5); } counter++; } }
public void PValueHistogram(CartesianChart chart) { if (PValhistChart == null) { PValhistChart = new HistogramChart(chart); } PValhistChart.AxisXTitle = "P-Value"; PValhistChart.AxisYTitle = "Proportion of Markers %"; PValhistChart.RemvoeColumnSeries(); int twentyPercent = 0; int fortyPercent = 0; int sixtyPercent = 0; int eightyPercent = 0; int oneHundrerdPercent = 0; double temp = 0.0; double popSize = (db.SubData[0].Genotype.Length) * (db.SubData[0].TraitValue.Length) * 1.0; //go over all the individuals of first marker and first trait and calculate p value //get the answer and put it in the correct bin for (int i = 0; i < this.db.SubData[0].Genotype.Length; i++) { //we get the wanted genotype index for (int j = 0; j < this.db.SubData[0].TraitValue.Length; j++) { //we get the wanted trait index List <double> no = new List <double>(); List <double> n1 = new List <double>(); for (int k = 0; k < this.db.SubData.Count; k++) { if (this.db.SubData[k].Genotype[0, i] == 0) { no.Add(this.db.SubData[k].TraitValue[0, j]); } else if (this.db.SubData[k].Genotype[0, i] == 1) { n1.Add(this.db.SubData[k].TraitValue[0, j]); } //iterate over all the people and gather two groups of n0 and n1 } //calculate the pvalue for trait and genotype and put in the correct bin //temp=result of p value temp = StatisticCalculations.PValueTStatistic(no, n1); pLogValues.Add((-1.0 * Math.Log(temp))); if (temp >= 0.0 && temp < 0.2) { twentyPercent++; } else if (temp >= 0.2 && temp < 0.4) { fortyPercent++; } else if (temp >= 0.4 && temp < 0.6) { sixtyPercent++; } else if (temp >= 0.6 && temp < 0.8) { eightyPercent++; } else if (temp >= 0.8 && temp <= 1.0) { oneHundrerdPercent++; } } } List <double> pValues = new List <double>(); pValues.Add(twentyPercent / popSize); pValues.Add(fortyPercent / popSize); pValues.Add(sixtyPercent / popSize); pValues.Add(eightyPercent / popSize); pValues.Add(oneHundrerdPercent / popSize); List <string> pTitles = new List <string>(); pTitles.Add("0-20%"); pTitles.Add("20-40%"); pTitles.Add("40-60%"); pTitles.Add("60-80%"); pTitles.Add("80-100%"); PValhistChart.AddColumnSeries(pTitles, pValues, ColorConstants.highliteColor); }