private void GenerateMyPeptidesFromScans() { MyPeptides = (from s in MyScans.AsParallel() group s by s.PeptideSequenceCleaned into peptide select new PeptideResult(peptide.Key, peptide.ToList())).ToList(); Parallel.ForEach(MyPeptides, p => { p.MyScans.Sort((a, b) => b.BayesianScore.CompareTo(a.BayesianScore)); } ); MyPeptides.Sort((a, b) => b.MyScans[0].BayesianScore.CompareTo(a.MyScans[0].BayesianScore)); }
private void ProcessPeptideQuantitationReport2() { KeyValuePair <List <FastaItem>, List <PepQuant> > kvp = UniQTools.ParsePeptideReport(peptideQuantitationReportFile); //Some error checking if (classLabels.Count > kvp.Value[0].MyQuants[0].MarkerIntensities.Count) { MessageBox.Show("Parameter Min no Quants per reading cannot be greater than number of channels specidied in the class menu."); return; } if (classLabels.Count != kvp.Value[0].MyQuants[0].MarkerIntensities.Count) { MessageBox.Show("Make sure you properly labeled your class labels followed with spaces as they do not match those from the peptide quantitation report."); return; } UniQTools.ScorePepQuants(classLabels, kvp.Value); MyPeptides = kvp.Value; MyFastaItems = kvp.Key; protPepDict = new Dictionary <FastaItem, List <PepQuant> >(); //Parallel.ForEach(MyFastaItems, fi => foreach (FastaItem fi in MyFastaItems) { List <PepQuant> pepts = MyPeptides.FindAll(a => fi.Sequence.Contains(a.CleanPeptideSequence)); if (pepts.Count > 0) { protPepDict.Add(fi, pepts); } foreach (PepQuant pq in pepts) { pq.MappableProteins.Add(fi.SequenceIdentifier); } } //); return; }
public void CleanToMeetFDR(double fdr) { double DecoyPeptides = NoLabeledDecoyPeptides; double currentFDR = (double)(DecoyPeptides) / (double)MyPeptides.Count; //Remodel the Bayesian Scores //FindCuttoff if (currentFDR > fdr) { //We need to be sure of this foreach (PeptideResult p in MyPeptides) { p.MyScans.Sort((a, b) => b.BayesianScore.CompareTo(a.BayesianScore)); } int cutoff = MyPeptides.Count; double removedPeptides = 0; for (int i = MyPeptides.Count - 1; i >= 0; i--) { removedPeptides++; if (MyPeptides[i].MyScans[0].CountNumberForwardNames(myParams.LabeledDecoyTag) == 0) { //This is a peptide of a decoy protein DecoyPeptides--; currentFDR = (double)(DecoyPeptides) / ((double)MyPeptides.Count - removedPeptides); cutoff = i; if (currentFDR < fdr) { break; } } } MyPeptides.RemoveRange(cutoff, MyPeptides.Count - cutoff); //And now, rebuild scans from peptides MyScans = (from peptide in MyPeptides from s in peptide.MyScans select s).ToList(); } }
public void CalculateSpectralPresenceScore() { ////Recalculate the presence score //double pmax = Math.Log(MyPeptides.Max(a => a.MyScans.Count)); //double pmin = Math.Log(MyPeptides.Min(a => a.MyScans.Count)); //double diff = pmax - pmin; //if (diff == 0) { diff = 1; } //foreach (PeptideResult p in MyPeptides) //{ // double presenceScore = (Math.Log(p.MyScans.Count) - pmin) / (diff); // foreach (SQTScan s in p.MyScans) // { // s.Bayes_PresenceScore = presenceScore; // } //} //Lets do this by rank List <int> allPossibleCounts = MyPeptides.Select(a => a.MyScans.Count).Distinct().ToList(); allPossibleCounts.Sort(); foreach (PeptideResult p in MyPeptides) { double rank = (double)allPossibleCounts.IndexOf(p.MyScans.Count); double presenceScore = Math.Log(rank + 1) / Math.Log((allPossibleCounts.Count + 2)); foreach (SQTScan s in p.MyScans) { s.Sibblings = p.MyScans.Count; s.Bayes_PresenceScore = presenceScore; } } }
private void ShowPeptideWindow(Dictionary <string, object> ao) { PlotModel MyModel = new PlotModel(); PepQuant sc = MyPeptides.Find(a => a.Sequence.Equals(ao["Sequence"])); //ObservableCollection<MyDataPoint> BarChartData = new ObservableCollection<MyDataPoint>(); SignalViewer ws = new SignalViewer(); ws.Title = "Peptide: " + sc.Sequence; MyModel.Title = sc.Sequence; // -------------------------------------------------------------------------------------------------------- MyModel.Title = sc.Sequence; MyModel.LegendOrientation = LegendOrientation.Horizontal; MyModel.LegendPlacement = LegendPlacement.Outside; MyModel.LegendPosition = LegendPosition.BottomCenter; DataTable dtDataGridView = new DataTable("PepScans"); DataSet dataSetBarChart = new DataSet(); DataTable dtBarChart = new DataTable("PepScans"); dataSetBarChart.Tables.Add(dtBarChart); dtBarChart.Columns.Add("channel", typeof(string)); dtDataGridView.Columns.Add("File Name", typeof(string)); dtDataGridView.Columns.Add("Precursor Charge", typeof(int)); dtDataGridView.Columns.Add("Scan Number", typeof(int)); List <DataRow> dataRowBarChartList = new List <DataRow>(); var categoryAxis = new CategoryAxis(); var valueAxis = new LinearAxis(); valueAxis.Title = "Intensity"; valueAxis.Position = AxisPosition.Left; MyModel.Axes.Add(valueAxis); for (int i = 0; i < sc.MyQuants[0].MarkerIntensities.Count; i++) { if (classLabels[i] >= 0) { DataRow newRowBarChart = dtBarChart.NewRow(); newRowBarChart["channel"] = "Channel " + (i + 1); dataRowBarChartList.Add(newRowBarChart); dtBarChart.Rows.Add(newRowBarChart); dtDataGridView.Columns.Add(new DataColumn("Channel " + (i + 1).ToString(), typeof(double))); categoryAxis.Labels.Add(new DataColumn("Channel " + (i + 1).ToString(), typeof(double)).ToString()); } } MyModel.Axes.Add(categoryAxis); bool insertYaxisBarChart = true; int counter = 0; List <int> categoryIndex = new List <int>(); List <double> value = new List <double>(); foreach (Quant q in sc.MyQuants) { if (insertYaxisBarChart) { // Set the Y-Axis value for (int i = 0; i < sc.MyQuants.Count; i++) { dtBarChart.Columns.Add("spec" + i, typeof(double)); //ws.BarChart1.ValueField.Add("spec" + i); categoryIndex.Add(i); } insertYaxisBarChart = false; } DataRow newRow_datagridview = dtDataGridView.NewRow(); newRow_datagridview["File Name"] = q.FileName; newRow_datagridview["Scan Number"] = q.ScanNumber; newRow_datagridview["Precursor Charge"] = q.Z; var columnSeries = new ColumnSeries(); columnSeries.Title = q.FileName; int negativeClass = 0; var solution = classLabels.GroupBy(i => i > 0).SelectMany(g => g).ToArray(); //classLabels.Sort((a, b) => b.CompareTo(a)); for (int i = 0; i < q.MarkerIntensities.Count; i++) { if (classLabels[i] >= 0) { DataRow newRow_barChart = dataRowBarChartList[i - negativeClass]; newRow_barChart["spec" + counter] = q.MarkerIntensities[i]; newRow_datagridview[i + 3 - negativeClass] = q.MarkerIntensities[i]; //BarChartData.Add(new MyDataPoint(i, q.MarkerIntensities[i], "Row" + " " + counter)); columnSeries.Items.Add(new ColumnItem(q.MarkerIntensities[i], (i - negativeClass))); } else { negativeClass++; } } counter++; MyModel.Series.Add(columnSeries); dtDataGridView.Rows.Add(newRow_datagridview); } // Set the chart tooltip. {field} will be replaced by current bar value. // Need to improve in this little templating. //ws.BarChart1.ToolTipText = "Signal Intensity: {field}"; // Set the x-axis data field //ws.BarChart1.XAxisField = "channel"; //-------------------------------------------------------------------------------------------------------- //ws.MyBarChart.HorizontalPropertyName = "X"; //ws.BarChart1.DataSource = dataSetBarChart; //ws.MyBarChart.Items = BarChartData; //ws.BarChart1.Generate(); //ws.MyBarChart.Draw(); //ws.MyBarChart.Refresh(); ws.MyDataGridSpec.ItemsSource = dtDataGridView.DefaultView; ws.Show(); ws.MyBarChart.Model = MyModel; }
public void UpdateGUI() { //Lets take care of which peptides to consider in our analysis if ((bool)CheckBoxConsiderOnlyUniquePeptides.IsChecked) { myPeptidesTMP = MyPeptides.FindAll(a => a.MappableProteins.Count == 1); } else { myPeptidesTMP = MyPeptides.FindAll(a => a.MappableProteins.Count > 0); } int removedFold = myPeptidesTMP.RemoveAll(a => Math.Abs(a.AVGLogFold) < Math.Round((double)DoubleUpDownPeptideLogFold.Value, 2)); ///Need to fix here.... int removedProb1 = myPeptidesTMP.RemoveAll(a => (a.TTest > Math.Round((double)DoubleUpDownPeptidePValueCutoff.Value, 2))); List <PepQuant> survival = MyPeptides.FindAll(a => !myPeptidesTMP.Exists(b => b.Sequence.Equals(a.Sequence))); protPepDictTMP = new Dictionary <FastaItem, List <PepQuant> >(); //New way foreach (FastaItem fi in MyFastaItems) { List <PepQuant> pepts = myPeptidesTMP.FindAll(a => a.MappableProteins.Contains(fi.SequenceIdentifier)); if (pepts.Count > 0) { protPepDictTMP.Add(fi, pepts); } } try { var protDisplay = from kvp in protPepDictTMP where kvp.Value.Count >= IntegerUpDown.Value select new { ProtID = kvp.Key.SequenceIdentifier, Daltons = Math.Round(kvp.Key.MonoisotopicMass, 2), PeptideCount = kvp.Value.Count, UniquePeptideCount = kvp.Value.Count(a => a.MappableProteins.Count == 1), SpecCount = protPepDictTMP[kvp.Key].Sum(a => a.MyQuants.Count), AvgLogFold = Math.Round(kvp.Value.Average(a => a.AVGLogFold), 3), StouffersPValue = ProteinPValue(kvp.Value), Coverage = GenerateMicroChart(kvp), Description = kvp.Key.Description }; int noProteins = protDisplay.Count(); LabelNoProteins.Content = noProteins; if (noProteins == 0) { MessageBox.Show("No protein satisfies current constraints."); return; } //Find out how many peptides and spec counts are there List <PepQuant> validPepQuants = new List <PepQuant>(); if ((bool)CHeckBoxShowPeptidesOfFilteredProteinsOnly.IsChecked) { List <string> IDsProteinsDisplay = protDisplay.Select(a => a.ProtID).ToList(); foreach (string pID in IDsProteinsDisplay) { FastaItem fi = MyFastaItems.Find(a => a.SequenceIdentifier.Equals(pID)); validPepQuants.AddRange(protPepDictTMP[fi]); } validPepQuants = validPepQuants.Distinct().ToList(); } else { validPepQuants = MyPeptides; } DataGridAllPeptidesView.ItemsSource = validPepQuants.Select (a => new { Sequence = a.Sequence, Binomial_PValue = Math.Round(a.BinomialProbability, 4), Paired_TTest_Pvalue = Math.Round(a.TTest, 4), AVGLogFold = Math.Round(a.AVGLogFold, 4), Redundancy = a.MappableProteins.Count, SpecCount = a.MyQuants.Count, MissingValues = a.MissingValues, MappableProts = string.Join(" ", ( from prot in protDisplay where a.MappableProteins.Contains(prot.ProtID) select "(" + prot.ProtID + "::" + prot.Description + ")").ToList() ) } ); LabelNoPeptides.Content = validPepQuants.Count(); LabelSpecCount.Content = validPepQuants.Sum(a => a.MyQuants.Count); LabelAvgFilteredPepLogFold.Content = Math.Round(validPepQuants.Average(a => a.AVGLogFold), 3); DataGridProteinView.ItemsSource = protDisplay; myPeptidesTMP = validPepQuants; double correctedP = PatternTools.pTools.BenjaminiHochbergFDR(0.01, protDisplay.Select(a => a.StouffersPValue).ToList(), false); LabelCorrectedP.Content = correctedP; LabelTotalPeptides.Content = MyPeptides.Count; } catch (Exception) { return; } //Update the graphs PlotQuants(); }