Esempio n. 1
0
        private void BtnRequeryOnClick(object sender, EventArgs e)
        {
            var halfLifeSettings = HalfLifeSettings;

            Settings.Default.Reload();
            Settings.Default.HalfLifeSettings = halfLifeSettings;
            Settings.Default.Save();
            var calculator = new HalfLifeCalculator(Workspace, halfLifeSettings)
            {
                ExcludedTimePoints = UpdateTimePoints(),
            };

            using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Calculating Half Lives"))
            {
                var longOperationBroker = new LongOperationBroker(calculator.Run, longWaitDialog);
                if (!longOperationBroker.LaunchJob())
                {
                    return;
                }
            }
            var viewInfo = bindingSource1.ViewInfo;
            var rows     = calculator.ResultRows.Select(row => new ResultRow(this, row)).ToArray();

            if (viewInfo == null || "default" == viewInfo.Name)
            {
                viewInfo = new ViewInfo(ColumnDescriptor.RootColumn(bindingSource1.ViewInfo.DataSchema, typeof(ResultRow)),
                                        GetDefaultViewSpec(calculator.ByProtein));
                bindingSource1.SetViewContext(GetViewContext(rows), viewInfo);
            }
            bindingSource1.RowSource = rows;
        }
Esempio n. 2
0
 private bool IsIncluded(HalfLifeSettings halfLifeSettings, PeptideFileAnalysis peptideFileAnalysis)
 {
     if (!string.IsNullOrEmpty(Cohort))
     {
         if (Cohort != HalfLifeCalculator.GetCohort(peptideFileAnalysis.MsDataFile, GetHalfLifeSettings().BySample))
         {
             return(false);
         }
     }
     if (peptideFileAnalysis.MsDataFile.TimePoint == null)
     {
         return(false);
     }
     if (IsTimePointExcluded(peptideFileAnalysis.MsDataFile.TimePoint.Value))
     {
         return(false);
     }
     if (halfLifeSettings.PrecursorPoolCalculation == PrecursorPoolCalculation.Individual)
     {
         if (null == peptideFileAnalysis.CalculatedPeaks || !peptideFileAnalysis.CalculatedPeaks.Turnover.HasValue)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 3
0
        private void UpdateCohortCombo()
        {
            var cohortSet = new HashSet <String> {
                ""
            };

            foreach (var msDataFile in Workspace.MsDataFiles)
            {
                cohortSet.Add(HalfLifeCalculator.GetCohort(msDataFile, GetHalfLifeSettings().BySample));
            }
            var selectedCohort = (string)comboCohort.SelectedItem;
            var cohorts        = new List <String>(cohortSet);

            cohorts.Sort();
            if (Lists.EqualsDeep(cohorts, comboCohort.Items))
            {
                return;
            }
            comboCohort.Items.Clear();
            foreach (var cohort in cohorts)
            {
                comboCohort.Items.Add(cohort);
            }
            comboCohort.SelectedIndex = Math.Max(0, cohorts.IndexOf(selectedCohort));
        }
Esempio n. 4
0
        private void BtnRequeryOnClick(object sender, EventArgs e)
        {
            var calculator = new HalfLifeCalculator(Workspace, HalfLifeSettings.Default)
            {
                MaxResults = MaxResults,
            };

            using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Calculating Half Lives"))
            {
                var longOperationBroker = new LongOperationBroker(calculator.Run, longWaitDialog);
                if (!longOperationBroker.LaunchJob())
                {
                    return;
                }
            }
            UpdateRows(calculator);
        }
Esempio n. 5
0
        private void UpdateRows(HalfLifeCalculator halfLifeCalculator)
        {
            var resultRows = halfLifeCalculator.RowDatas.Select(rd => new PerReplicateResult(halfLifeCalculator.ComputeAvgTurnover(rd))).ToArray();

            bindingSourceResults.RowSource = new StaticRowSource(resultRows);
        }
        private void btnRequery_Click(object sender, EventArgs e)
        {
            var halfLifeCalculator = new HalfLifeCalculator(Workspace, HalfLifeSettings)
            {
                ByFile = cbxGroupByFile.Checked,
            };

            using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Calculating Half Lives"))
            {
                var longOperationBroker = new LongOperationBroker(halfLifeCalculator.Run, longWaitDialog);
                if (!longOperationBroker.LaunchJob())
                {
                    return;
                }
            }
            bool byCohort    = cbxGroupByCohort.Checked;
            bool byTimePoint = cbxGroupByTimePoint.Checked;
            bool bySample    = cbxGroupBySample.Checked;
            bool byFile      = cbxGroupByFile.Checked;
            var  displayRows = new List <DisplayRow>();

            foreach (var resultRow in halfLifeCalculator.ResultRows)
            {
                var displayRow       = new DisplayRow(halfLifeCalculator, resultRow);
                var rowDatasByCohort = new Dictionary <GroupKey, List <HalfLifeCalculator.ProcessedRowData> >();
                foreach (var halfLife in resultRow.HalfLives)
                {
                    if (resultRow.HalfLives.Count > 1 && string.IsNullOrEmpty(halfLife.Key) != byCohort)
                    {
                        continue;
                    }
                    foreach (var rowData in halfLife.Value.FilteredRowDatas)
                    {
                        GroupKey cohortKey = new GroupKey(
                            byCohort ? rowData.RawRowData.MsDataFile.Cohort : null,
                            byTimePoint ? rowData.RawRowData.MsDataFile.TimePoint : null,
                            bySample ? rowData.RawRowData.MsDataFile.Sample : null,
                            byFile ? rowData.RawRowData.MsDataFile.Name : null);
                        List <HalfLifeCalculator.ProcessedRowData> list;
                        if (!rowDatasByCohort.TryGetValue(cohortKey, out list))
                        {
                            list = new List <HalfLifeCalculator.ProcessedRowData>();
                            rowDatasByCohort.Add(cohortKey, list);
                        }
                        list.Add(rowData);
                    }
                }
                foreach (var cohortRowDatas in rowDatasByCohort)
                {
                    displayRow.Results.Add(cohortRowDatas.Key, new GroupResult(this, displayRow, cohortRowDatas.Key, new ResultData(cohortRowDatas.Value)));
                }
                displayRows.Add(displayRow);
            }
            var viewInfo   = bindingSource1.ViewInfo;
            var dataSchema = new TopographDataSchema(Workspace);

            if (viewInfo == null || "default" == viewInfo.Name)
            {
                viewInfo = new ViewInfo(ColumnDescriptor.RootColumn(dataSchema, typeof(DisplayRow)),
                                        GetDefaultViewSpec(halfLifeCalculator.ByProtein));
            }
            var viewContext = new TopographViewContext(Workspace, typeof(DisplayRow), displayRows,
                                                       GetDefaultViewSpec(halfLifeCalculator.ByProtein));

            bindingSource1.SetViewContext(viewContext, viewInfo);
            bindingSource1.RowSource = displayRows;
            dataGridViewSummary.Rows.Clear();
            SetSummary("Tracer %", displayRows.Select(dr => dr.Results).SelectMany(r => r.Values
                                                                                   .Select(cohortResult => cohortResult.GetResultData().TracerPercentByArea)));
            SetSummary("Precursor Enrichment", displayRows.Select(dr => dr.Results).SelectMany(r => r.Values
                                                                                               .Select(cohortResult => cohortResult.GetResultData().IndPrecursorEnrichment)));
            SetSummary("Turnover", displayRows.Select(dr => dr.Results).SelectMany(r => r.Values
                                                                                   .Select(cohortResult => cohortResult.GetResultData().IndTurnover)));
            SetSummary("Area Under Curve", displayRows.Select(dr => dr.Results).SelectMany(r => r.Values
                                                                                           .Select(cohortResult => cohortResult.GetResultData().AreaUnderCurve)));
        }
 internal DisplayRow(HalfLifeCalculator halfLifeCalculator, HalfLifeCalculator.ResultRow resultRow)
 {
     _resultRow          = resultRow;
     _halfLifeCalculator = halfLifeCalculator;
     Results             = new Dictionary <GroupKey, GroupResult>();
 }
Esempio n. 8
0
        private HalfLifeCalculator UpdateGraph(List <PeptideFileAnalysis> peptideFileAnalyses, HalfLifeSettings halfLifeSettings, out HalfLifeCalculator.ResultData resultData)
        {
            var halfLifeCalculator = new HalfLifeCalculator(Workspace, halfLifeSettings);
            var halfLife           = resultData = halfLifeCalculator.CalculateHalfLife(peptideFileAnalyses);

            _zedGraphControl.GraphPane.CurveList.Clear();
            _zedGraphControl.GraphPane.GraphObjList.Clear();
            _pointsCurve = null;
            _peptideFileAnalysisPoints = null;
            var xValues                 = new List <double>();
            var yValues                 = new List <double>();
            var fileAnalysisPoints      = new List <PeptideFileAnalysis>();
            var filteredFileAnalysisIds =
                new HashSet <long>(resultData.FilteredRowDatas.Select(rd => rd.RawRowData.PeptideFileAnalysisId));

            foreach (var peptideFileAnalysis in peptideFileAnalyses)
            {
                if (!filteredFileAnalysisIds.Contains(peptideFileAnalysis.Id))
                {
                    continue;
                }
                double?value;
                var    processedRowData = halfLifeCalculator.ToRowData(peptideFileAnalysis);
                if (!processedRowData.Turnover.HasValue)
                {
                    continue;
                }
                if (LogPlot)
                {
                    value = 2 - Math.Log10(100 - processedRowData.Turnover.Value * 100);
                }
                else
                {
                    value = processedRowData.Turnover.Value * 100;
                }
                if (double.IsInfinity(value.Value) || double.IsNaN(value.Value))
                {
                    continue;
                }
                Debug.Assert(peptideFileAnalysis.MsDataFile.TimePoint != null);
                xValues.Add(peptideFileAnalysis.MsDataFile.TimePoint.Value);
                yValues.Add(value.Value);
                fileAnalysisPoints.Add(peptideFileAnalysis);
            }
            UpdateStatsGrid(xValues, yValues);
            var pointsCurve = _zedGraphControl.GraphPane.AddCurve("Data Points", xValues.ToArray(), yValues.ToArray(), Color.Black);

            pointsCurve.Line.IsVisible  = false;
            pointsCurve.Label.IsVisible = false;
            Func <double, double> funcMiddle = x => halfLife.YIntercept + halfLife.RateConstant * x;
            Func <double, double> funcMin    = x => halfLife.YIntercept + (halfLife.RateConstant - halfLife.RateConstantError) * x;
            Func <double, double> funcMax    = x => halfLife.YIntercept + (halfLife.RateConstant + halfLife.RateConstantError) * x;
            Func <double, double> funcConvertToDisplayedValue;

            if (LogPlot)
            {
                _zedGraphControl.GraphPane.YAxis.Title.Text = "-Log(100% - % Newly Synthesized)";
                funcConvertToDisplayedValue = x => - x / Math.Log(10);
            }
            else
            {
                _zedGraphControl.GraphPane.YAxis.Title.Text = "% Newly Synthesized";
                funcConvertToDisplayedValue = x => (1 - Math.Exp(x)) * 100;
            }
            // ReSharper disable ImplicitlyCapturedClosure
            AddFunction("Best Fit", x => funcConvertToDisplayedValue(funcMiddle(x)), Color.Black);
            AddFunction("Minimum Bound", x => funcConvertToDisplayedValue(funcMin(x)), Color.LightBlue);
            AddFunction("Maximum Bound", x => funcConvertToDisplayedValue(funcMax(x)), Color.LightGreen);
            // ReSharper restore ImplicitlyCapturedClosure
            _zedGraphControl.GraphPane.AxisChange();
            _zedGraphControl.Invalidate();
            _pointsCurve = pointsCurve;
            _peptideFileAnalysisPoints = fileAnalysisPoints;
            tbxRateConstant.Text       = resultData.RateConstant.ToString("0.##E0") + "+/-" +
                                         resultData.RateConstantError.ToString("0.##E0");
            tbxHalfLife.Text = resultData.HalfLife.ToString("0.##") + "(" + resultData.MinHalfLife.ToString("0.##") + "-" +
                               resultData.MaxHalfLife.ToString("0.##") + ")";
            if (resultData.RSquared.HasValue)
            {
                tbxCorrelationCoefficient.Text = Math.Sqrt(resultData.RSquared.Value).ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                tbxCorrelationCoefficient.Text = "";
            }
            return(halfLifeCalculator);
        }