Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();
            dataGridPeptideFiles.DataContext         = DataFilesObservableCollection;
            dataGridDatabaseFiles.DataContext        = DatabasesObservableCollection;
            DisplayedSamplesDataGrid.DataContext     = FilesToDisplayObservableCollection;
            HiddenSamplesDataGrid.DataContext        = FilesToHideObservableCollection;
            DisplayAnalyzedFilesDataGrid.DataContext = DataFilesObservableCollection;
            HalfLifeHistogramPlot.Configure(enableScrollWheelZoom: false);
            PrecisionPlot.Configure(enableScrollWheelZoom: false);
            HalfLifeComparisonPlot.Configure(enableScrollWheelZoom: false);
            RatioComparisonPlot.Configure(enableScrollWheelZoom: false);
            peptideRadioButton.IsChecked         = true;
            proteinSpecificRadioButton.IsChecked = DisplayProteinInSpecificTable;

            DisplayPeptidesView = CollectionViewSource.GetDefaultView(PeptidesToDisplay);
            DisplayPeptidesDataGrid.DataContext = DisplayPeptidesView;
            Loaders.LoadElements();
            PopulateChoices();
        }
Esempio n. 2
0
        private void PlotHalfLifeHistogram(List <PeptideTurnoverObject> peptidesToPlot)
        {
            HalfLifeHistogramPlot.plt.Clear();
            HalfLifeHistogramPlot.plt.GetPlottables().Clear();
            double[]  halflives = peptidesToPlot.Select(x => Math.Log(2, Math.E) / x.Kbi).ToArray();
            Histogram histogram = new Histogram(halflives, 0, 100, 0.5);

            double barWidth = histogram.binSize * 1.2; // slightly over-side to reduce anti-alias rendering artifacts

            HalfLifeHistogramPlot.plt.Axis(0, 50, 0, histogram.counts.Max() * 1.1);
            HalfLifeHistogramPlot.plt.PlotBar(histogram.bins, histogram.counts, barWidth: barWidth, outlineWidth: 0);
            if (peptideRadioButton.IsChecked.Value)
            {
                HalfLifeHistogramPlot.plt.YLabel("Frequency (# Peptides)");
            }
            else
            {
                HalfLifeHistogramPlot.plt.YLabel("Frequency (# Proteins)");
                HalfLifeHistogramPlot.plt.YLabel("Number of Proteins", fontSize: 24);
            }
            HalfLifeHistogramPlot.plt.XLabel("Half-life (Days)", fontSize: 24);
            HalfLifeHistogramPlot.plt.Axis(0, 50, 0, histogram.counts.Max() * 1.1);
            HalfLifeComparisonPlot.Render(); HalfLifeComparisonPlot.Render();
        }
Esempio n. 3
0
        private void PlotPeptideData(List <PeptideTurnoverObject> peptidesToPlot)
        {
            RatioComparisonPlot.plt.Clear();
            RatioComparisonPlot.plt.Legend(false);
            HalfLifeComparisonPlot.plt.GetPlottables().Clear();
            //if (PlotAminoAcidPoolCheckBox.IsChecked.Value)
            //{
            //    foreach (string file in FilesToDisplayObservableCollection)
            //    {
            //        PlotFit(PoolParameterDictionary[file], Path.GetFileNameWithoutExtension(file)+" Free Amino Acids");
            //    }
            //}

            double minError    = double.PositiveInfinity;
            double maxError    = double.NegativeInfinity;
            double minHalfLife = double.PositiveInfinity;
            double maxHalfLife = double.NegativeInfinity;
            int    debug       = 0;

            foreach (PeptideTurnoverObject peptide in peptidesToPlot)
            {
                debug++;
                //get the title
                int fontSize = Math.Max(Math.Min(24, 100 / (int)Math.Round(Math.Sqrt(peptide.DisplayPeptideSequence.Length))), 12);
                RatioComparisonPlot.plt.Title(peptide.DisplayPeptideSequence, fontSize: fontSize);

                string protein  = peptide.DisplayProteinOrProteoform;
                string filepath = peptide.FileName;
                string filename = Path.GetFileNameWithoutExtension(filepath);
                //plot actual data
                RatioComparisonPlot.plt.PlotScatter(peptide.Timepoints, peptide.RelativeFractions, markerSize: 4, lineWidth: 0, label: filename + " Observed Ratios");

                //Plot protein info
                List <PeptideTurnoverObject> peptidesSharingProteinAndFile = PeptidesToDisplay.Where(x => x.DisplayProteinOrProteoform.Equals(protein) && x.FileName.Equals(filepath)).ToList();
                double[] errors         = peptidesSharingProteinAndFile.Select(x => x.Error).ToArray();
                double[] halfLives      = peptidesSharingProteinAndFile.Select(x => Math.Log(2, Math.E) / x.Kbi).ToArray();
                double[] negativeErrors = peptidesSharingProteinAndFile.Select(x => (Math.Log(2, Math.E) / x.Kbi) - (Math.Log(2, Math.E) / x.HighKbi)).ToArray();
                double[] positiveErrors = peptidesSharingProteinAndFile.Select(x => (Math.Log(2, Math.E) / x.LowKbi) - (Math.Log(2, Math.E) / x.Kbi)).ToArray();

                HalfLifeComparisonPlot.plt.Title(protein, fontSize: 24);
                HalfLifeComparisonPlot.plt.Layout(titleHeight: 20, xLabelHeight: 40, y2LabelWidth: 20);
                HalfLifeComparisonPlot.plt.YLabel("Half-life (Days)", fontSize: 20);
                HalfLifeComparisonPlot.plt.XLabel("Error (MSE)", fontSize: 20);
                HalfLifeComparisonPlot.plt.Ticks(fontSize: 18);

                double errorDiff = errors.Max() - errors.Min();
                if (errorDiff == 0)
                {
                    errorDiff = 0.01;
                }
                double halflifeDiff = halfLives.Max() - halfLives.Min();
                if (halflifeDiff == 0)
                {
                    halflifeDiff = 0.01;
                }
                var scatter = HalfLifeComparisonPlot.plt.PlotScatter(errors, halfLives, lineWidth: 0, label: filename + " peptides", color: Color.SteelBlue);//debug == 1 ? Color.DodgerBlue : Color.Red);
                //plot the single point of the selected peptie separately (overlay) so that we know which one it is
                var point = HalfLifeComparisonPlot.plt.PlotPoint(peptide.Error, Math.Log(2, Math.E) / peptide.Kbi, color: Color.Black);
                //plot errors
                HalfLifeComparisonPlot.plt.PlotErrorBars(errors, halfLives, null, null, positiveErrors, negativeErrors, scatter.color);
                HalfLifeComparisonPlot.plt.PlotErrorBars(new double[] { peptide.Error }, new double[] { Math.Log(2, Math.E) / peptide.Kbi },
                                                         null, null, new double[] { (Math.Log(2, Math.E) / peptide.LowKbi) - (Math.Log(2, Math.E) / peptide.Kbi) },
                                                         new double[] { (Math.Log(2, Math.E) / peptide.Kbi) - (Math.Log(2, Math.E) / peptide.HighKbi) }, color: point.color);

                minError    = Math.Min(minError, errors.Min() - errorDiff * 0.2);
                maxError    = Math.Max(maxError, errors.Max() + errorDiff * 0.2);
                minHalfLife = Math.Min(minHalfLife, halfLives.Min() - negativeErrors.Max() - halflifeDiff * 0.2);
                maxHalfLife = Math.Max(maxHalfLife, halfLives.Max() + positiveErrors.Max() + halflifeDiff * 0.2);

                double ySpacingFactor = (maxHalfLife - minHalfLife) * 0.2;
                HalfLifeComparisonPlot.plt.Axis(minError, maxError, minHalfLife - ySpacingFactor, maxHalfLife + ySpacingFactor);
                HalfLifeComparisonPlot.plt.Axis();

                PeptideTurnoverObject currentProtein = DisplayProteinInSpecificTable ?
                                                       AnalyzedProteins.Where(x => x.Protein.Equals(protein) && x.FileName.Equals(filepath)).FirstOrDefault() :
                                                       AnalyzedProteoforms.Where(x => x.Proteoform.Equals(protein) && x.FileName.Equals(filepath)).FirstOrDefault();

                if (currentProtein == null)
                {
                    MessageBox.Show("Unable to find the protein for this peptide. There may be an issue with the loaded file.");
                    return;
                }

                //plot the fit
                if (PlotBestFitCheckBox.IsChecked.Value)
                {
                    //peptide level
                    PlotFit(PoolParameterDictionary[filepath], filename + " Fit (" + (Math.Log(2, Math.E) / peptide.Kbi).ToString("F1") + " d)", peptide.Kbi);
                    //protein level
                    double halfLife = Math.Log(2, Math.E) / currentProtein.Kbi;
                    HalfLifeComparisonPlot.plt.PlotHLine(halfLife, label: filename + " Half-life (" + halfLife.ToString("F1") + ")", color: Color.OrangeRed);//debug == 1 ? Color.DodgerBlue : Color.Red);
                }
                //plt the confidence intervals
                if (PlotCICheckBox.IsChecked.Value)
                {
                    //peptide level
                    PlotFit(PoolParameterDictionary[filepath], filename + " Upper CI (" + (Math.Log(2, Math.E) / peptide.LowKbi).ToString("F1") + " d)", peptide.LowKbi);
                    PlotFit(PoolParameterDictionary[filepath], filename + " Lower CI (" + (Math.Log(2, Math.E) / peptide.HighKbi).ToString("F1") + " d)", peptide.HighKbi);
                    //protein level
                    double upperHL = Math.Log(2, Math.E) / currentProtein.LowKbi;
                    double lowerHL = Math.Log(2, Math.E) / currentProtein.HighKbi;
                    HalfLifeComparisonPlot.plt.PlotHLine(upperHL, label: filename + " Upper CI (" + upperHL.ToString("F1") + ")", color: Color.Green);
                    HalfLifeComparisonPlot.plt.PlotHLine(lowerHL, label: filename + " Lower CI (" + lowerHL.ToString("F1") + ")", color: Color.Red);
                }
            }
            if (PlotAminoAcidPoolCheckBox.IsChecked.Value)
            {
                foreach (string file in FilesToDisplayObservableCollection)
                {
                    PlotFit(PoolParameterDictionary[file], Path.GetFileNameWithoutExtension(file) + " Free Amino Acids");
                }
            }

            if (DisplayLegendCheckBox.IsChecked.Value)
            {
                HalfLifeComparisonPlot.plt.Legend();
            }
            else
            {
                HalfLifeComparisonPlot.plt.Legend(false);
            }
            HalfLifeComparisonPlot.Render();
        }