public void UpdateGrid() { using (var session = Workspace.OpenSession()) { IEnumerable<TableData> tableDatas = null; using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Querying Table Sizes")) { var broker = new LongOperationBroker(b => { tableDatas = RequeryGrid(b, session); }, longWaitDialog , session); if (!broker.LaunchJob() || tableDatas == null) { return; } dataGridView1.Rows.Clear(); foreach (var tableData in tableDatas) { var row = dataGridView1.Rows[dataGridView1.Rows.Add()]; row.Cells[colTableName.Index].Value = tableData.Name; row.Cells[colRowCount.Index].Value = tableData.RowCount; row.Cells[colDataFileSize.Index].Value = tableData.DataFileSize; row.Cells[colFreeSpace.Index].Value = tableData.FreeSpace; row.Cells[colIndexSize.Index].Value = tableData.IndexSize; } } } }
// ReSharper disable AccessToDisposedClosure private void UpdateWorkspaceVersion(WorkspaceChangeArgs v) { using (var session = Workspace.OpenSession()) { using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Updating Workspace")) { var broker = new LongOperationBroker(b => { session.BeginTransaction(); Workspace.UpdateWorkspaceVersion(b, session, v); session.Transaction.Commit(); }, longWaitDialog, session); broker.LaunchJob(); } } }
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))); }
private void Requery() { var locks = new List<DbLock>(); using (var session = Workspace.OpenSession()) { using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Querying Database")) { var broker = new LongOperationBroker(b => session.CreateCriteria(typeof (DbLock)).List(locks), longWaitDialog, session); if (broker.LaunchJob()) { BeginInvoke(new Action<List<DbLock>>(DisplayResults), locks); } } } }
public override bool RunLongJob(Control owner, Action<IProgressMonitor> job) { using (var longWaitDialog = new LongWaitDialog(owner.TopLevelControl, Program.AppName)) { var longOperationBroker = new LongOperationBroker( broker => job.Invoke(ProgressMonitorImpl.NewProgressMonitorImpl(new ProgressStatus("Working"), iProgress => { try { broker. UpdateStatusMessage( iProgress + "% complete"); return true; } catch (JobCancelledException) { return false; } })), longWaitDialog); longOperationBroker.LaunchJob(); return !longOperationBroker.WasCancelled; } }
private void btnRequery_Click(object sender, EventArgs e) { var lstResultData = new List<ResultData>(); var activeCohortKeys = new HashSet<CohortKey>(); using (var session = Workspace.OpenSession()) { var query = session.CreateQuery("SELECT d.PeptideFileAnalysis.Id," + "\nd.PeptideFileAnalysis.PeptideAnalysis.Peptide.Id," + "\nd.PeptideFileAnalysis.MsDataFile.TimePoint," + "\nd.PeptideFileAnalysis.MsDataFile.Cohort," + "\nd.PeptideFileAnalysis.MsDataFile.Sample," + "\nd.TracerPercent," + "\nd.TotalArea," + "\nd.RatioToBase," + "\nd.PeptideFileAnalysis.Turnover * 100," + "\nd.PeptideFileAnalysis.PrecursorEnrichment * 100" + "\nFROM DbPeak d" + "\nWHERE d.PeptideFileAnalysis.DeconvolutionScore > :minScore " + "\nAND d.PeptideFileAnalysis.ValidationStatus <> " + (int) ValidationStatus.reject); if (!string.IsNullOrEmpty(tbxMinScore.Text)) { query.SetParameter("minScore", double.Parse(tbxMinScore.Text)); } else { query.SetParameter("minScore", 0.0); } var rowDataArrays = new List<object[]>(); using (var longWaitDialog = new LongWaitDialog(TopLevelControl, "Executing query")) { var broker = new LongOperationBroker(b => query.List(rowDataArrays), longWaitDialog, session); if (!broker.LaunchJob()) { return; } } bool groupByCohort = cbxGroupByCohort.Checked; bool groupByTimePoint = cbxGroupByTimePoint.Checked; bool groupBySample = cbxGroupBySample.Checked; var rawRows = rowDataArrays.Select(r => new RawRow() { PeptideFileAnalysisId = (long) r[0], PeptideId = (long) r[1], CohortKey = new CohortKey( groupByCohort ? (string) r[3] : null, groupByTimePoint ? (double?) r[2] : null, groupBySample ? (string) r[4] : null), TracerPercent = (double) r[5], TotalArea = (double) r[6], RatioToBase = (double) r[7], Turnover = (double?) r[8], PrecursorEnrichment = (double?) r[9], }); var rowDatas = rawRows.GroupBy(r => r.PeptideFileAnalysisId, (id,peaks) => AggregatePeaks(id, peaks)); var byProtein = cbxByProtein.Checked; var groupedRowDatas = new Dictionary<string, IList<RowData>>(); foreach (var rowData in rowDatas) { var peptide = Workspace.Peptides.GetChild(rowData.PeptideId); if (peptide == null) { continue; } var key = byProtein ? peptide.ProteinName : peptide.Sequence; IList<RowData> list; if (!groupedRowDatas.TryGetValue(key, out list)) { list = new List<RowData>(); groupedRowDatas.Add(key, list); } list.Add(rowData); } var resultRows = new List<ResultRow>(); foreach (var entry in groupedRowDatas) { resultRows.Add(GetResultRow(entry.Value, byProtein)); } dataGridView1.Rows.Clear(); if (resultRows.Count > 0) { dataGridView1.Rows.Add(resultRows.Count()); for (int iRow = 0; iRow < resultRows.Count; iRow ++) { var resultRow = resultRows[iRow]; var row = dataGridView1.Rows[iRow]; row.Cells[colPeptide.Index].Value = resultRow.PeptideSequence; row.Cells[colProteinName.Index].Value = resultRow.ProteinName; row.Cells[colProteinKey.Index].Value = resultRow.ProteinKey; row.Cells[colProteinDescription.Index].Value = row.Cells[colProteinDescription.Index].ToolTipText = resultRow.ProteinDescription; foreach (var entry in resultRow.ResultDatas) { Columns columns; if (!_columnsDict.TryGetValue(entry.Key, out columns)) { string cohortName = entry.Key.Cohort ?? ""; if (entry.Key.TimePoint != null) { cohortName += " " + entry.Key.TimePoint; } columns = AddColumns(string.IsNullOrEmpty(cohortName) ? "" : cohortName + " "); _columnsDict.Add(entry.Key, columns); } row.Cells[columns.ReplicateCountColumn.Index].Value = entry.Value.TracerPercentByArea.Length; SetColumnValues(columns.TracerAmountsByAreaColumns, row, entry.Value.TracerPercentByArea); SetColumnValues(columns.TracerAmountsBySlopeColumns, row, entry.Value.TracerPercentBySlope); SetColumnValues(columns.PrecursorEnrichmentColumns, row, entry.Value.PrecursorEnrichment); SetColumnValues(columns.TurnoverColumns, row, entry.Value.Turnover); SetColumnValues(columns.AreaUnderCurveColumns, row, entry.Value.AreaUnderCurve); lstResultData.Add(entry.Value); activeCohortKeys.Add(entry.Key); } } } } dataGridViewSummary.Rows.Clear(); SetSummary("Tracer % (area)", lstResultData.Select(r=>r.TracerPercentByArea)); SetSummary("Tracer % (slope)", lstResultData.Select(r => r.TracerPercentBySlope)); SetSummary("Precursor Enrichment", lstResultData.Select(r => r.PrecursorEnrichment)); SetSummary("Turnover", lstResultData.Select(r => r.Turnover)); SetSummary("Area Under Curve", lstResultData.Select(r => r.AreaUnderCurve)); foreach (var entry in _columnsDict.ToArray()) { if (!activeCohortKeys.Contains(entry.Key)) { dataGridView1.Columns.Remove(entry.Value.ReplicateCountColumn); RemoveDataColumns(entry.Value.TracerAmountsByAreaColumns); RemoveDataColumns(entry.Value.TracerAmountsBySlopeColumns); RemoveDataColumns(entry.Value.PrecursorEnrichmentColumns); RemoveDataColumns(entry.Value.TurnoverColumns); RemoveDataColumns(entry.Value.AreaUnderCurveColumns); _columnsDict.Remove(entry.Key); } } UpdateColumnVisibility(); }
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; }
public override void Delete() { IList<MsDataFile> dataFiles = GetSelectedRows<DataFileRow>(_form.gridView).Select(row=>row.MsDataFile).ToArray(); if (dataFiles.Count == 0) { return; } string message; if (dataFiles.Count == 1) { message = "Are you sure you want to remove this data file from the workspace?"; } else { message = string.Format( "Are you sure you want to remove these {0} data files from the workspace?", dataFiles.Count); } message += "\nAll search results and analyses of these files will also be deleted."; if (MessageBox.Show(_form, message, Program.AppName, MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } using (var longWaitDialog = new LongWaitDialog(_form, "Deleting data files")) { var dataFileIds = dataFiles.Select(dataFile => dataFile.Id).ToArray(); var longWaitBroker = new LongOperationBroker((b => _form.DeleteDataFiles(b, dataFileIds)), longWaitDialog); longWaitBroker.LaunchJob(); } _form.Workspace.DatabasePoller.LoadAndMergeChanges(null); }
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); }