private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { string sourcePath = null; string sourceType = null; int runIndex = 0; if (listView.SelectedItems.Count > 0) { List <string> dataSourceList = new List <string>(); foreach (ListViewItem item in listView.SelectedItems) { var sourceInfo = item.Tag as SourceInfo; if (sourceInfo != null) { dataSourceList.Add(sourceInfo.path.ToString()); sourcePath = sourceInfo.path.Filepath; sourceType = sourceInfo.type; runIndex = sourceInfo.path.RunIndex; } else { dataSourceList.Add(item.SubItems[0].Text); sourcePath = Path.Combine(CurrentDirectory, sourcePathTextBox.Text); sourceType = getSourceType(sourcePath); } } sourcePathTextBox.Text = $"\"{String.Join("\" \"", dataSourceList.ToArray())}\""; } ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); if (listView.SelectedItems.Count != 1) { ticGraphControl.Visible = false; return; } if (!String.IsNullOrEmpty(sourceType) && sourceType != "File Folder") { using (MSData msd = new MSData()) { ReaderList.FullReaderList.read(sourcePath, msd, runIndex, SpectrumSource.GetReaderConfig()); using (ChromatogramList cl = msd.run.chromatogramList) { if (cl != null && !cl.empty() && cl.find("TIC") != cl.size()) { ticGraphControl.Visible = true; pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram(cl.find("TIC"), true); Map <double, double> sortedFullPointList = new Map <double, double>(); IList <double> timeList = tic.binaryDataArrays[0].data; IList <double> intensityList = tic.binaryDataArrays[1].data; int arrayLength = timeList.Count; for (int i = 0; i < arrayLength; ++i) { sortedFullPointList[timeList[i]] = intensityList[i]; } ZedGraph.PointPairList points = new ZedGraph.PointPairList( new List <double>(sortedFullPointList.Keys).ToArray(), new List <double>(sortedFullPointList.Values).ToArray()); ZedGraph.LineItem item = ticGraphControl.GraphPane.AddCurve("TIC", points, Color.Black, ZedGraph.SymbolType.None); item.Line.IsAntiAlias = true; ticGraphControl.AxisChange(); ticGraphControl.Refresh(); } else { ticGraphControl.Visible = false; } } } } else { ticGraphControl.Visible = false; } }
private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (listView.SelectedItems.Count > 1) { List <string> dataSourceList = new List <string>(); foreach (ListViewItem item in listView.SelectedItems) { if (item.SubItems[1].Text != "File Folder") { dataSourceList.Add(String.Format("\"{0}\"", item.SubItems[0].Text)); } } sourcePathTextBox.Text = String.Join(" ", dataSourceList.ToArray()); ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); ticGraphControl.Visible = false; } else if (listView.SelectedItems.Count > 0) { sourcePathTextBox.Text = listView.SelectedItems[0].SubItems[0].Text; ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); string sourcePath = Path.Combine(CurrentDirectory, sourcePathTextBox.Text); string sourceType = getSourceType(sourcePath); if (!String.IsNullOrEmpty(sourceType) && sourceType != "File Folder") { using (MSDataFile msData = new MSDataFile(sourcePath)) using (ChromatogramList cl = msData.run.chromatogramList) { if (cl != null && !cl.empty() && cl.find("TIC") != cl.size()) { ticGraphControl.Visible = true; pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram(cl.find("TIC"), true); Map <double, double> sortedFullPointList = new Map <double, double>(); IList <double> timeList = tic.binaryDataArrays[0].data; IList <double> intensityList = tic.binaryDataArrays[1].data; int arrayLength = timeList.Count; for (int i = 0; i < arrayLength; ++i) { sortedFullPointList[timeList[i]] = intensityList[i]; } ZedGraph.PointPairList points = new ZedGraph.PointPairList( new List <double>(sortedFullPointList.Keys).ToArray(), new List <double>(sortedFullPointList.Values).ToArray()); ZedGraph.LineItem item = ticGraphControl.GraphPane.AddCurve("TIC", points, Color.Black, ZedGraph.SymbolType.None); item.Line.IsAntiAlias = true; ticGraphControl.AxisChange(); ticGraphControl.Refresh(); } else { ticGraphControl.Visible = false; } } } else { ticGraphControl.Visible = false; } } else { sourcePathTextBox.Text = ""; } }
private void UpdateGraph() { if (_inUpdateGraph) { return; } try { _inUpdateGraph = true; _msGraphControl.GraphPane.GraphObjList.Clear(); _msGraphControl.GraphPane.CurveList.Clear(); dataGridView1.Rows.Clear(); int charge; try { charge = Convert.ToInt32(tbxCharge.Text); tbxCharge.BackColor = Color.White; } catch { charge = 0; tbxCharge.BackColor = Color.Red; } double massResolution; try { massResolution = double.Parse(tbxMassResolution.Text); tbxMassResolution.BackColor = Color.White; } catch { tbxMassResolution.BackColor = Color.Red; massResolution = .01; } var sequence = tbxSequence.Text; MassDistribution spectrum; if (string.IsNullOrEmpty(sequence)) { var formula = tbxFormula.Text; var molecule = Molecule.Parse(formula); if (molecule.Values.Sum() > 10000000) { tbxFormula.BackColor = Color.Red; return; } try { spectrum = Workspace.GetAminoAcidFormulas().GetMassDistribution(molecule, charge); tbxFormula.BackColor = Color.White; } catch { tbxFormula.BackColor = Color.Red; return; } } else { tbxFormula.Text = Workspace.GetAminoAcidFormulas().GetFormula(sequence).ToString(); var turnoverCalculator = new TurnoverCalculator(Workspace, sequence); var aminoAcidFormulas = Workspace.GetAminoAcidFormulasWithTracers(); aminoAcidFormulas = aminoAcidFormulas.SetMassResolution(massResolution); try { if (cbxTracerPercents.Checked) { var tracerPercentFormula = TracerPercentFormula.Parse(tbxTracerFormula.Text); spectrum = turnoverCalculator.GetAminoAcidFormulas(tracerPercentFormula) .GetMassDistribution(sequence, charge); } else { var tracerFormula = TracerFormula.Parse(tbxTracerFormula.Text); spectrum = aminoAcidFormulas.GetMassDistribution( turnoverCalculator.MoleculeFromTracerFormula(tracerFormula), charge); double massShift = aminoAcidFormulas.GetMassShift(sequence); if (charge > 0) { massShift /= charge; } spectrum = spectrum.OffsetAndDivide(massShift, 1); } tbxTracerFormula.BackColor = Color.White; } catch { tbxTracerFormula.BackColor = Color.Red; spectrum = aminoAcidFormulas.GetMassDistribution(sequence, charge); } } if (spectrum == null) { return; } var curveItem = _msGraphControl.AddGraphItem(_msGraphControl.GraphPane, new GraphItem { Title = "Intensity", Color = Color.Black, Points = new PointPairList( spectrum.Keys. ToArray(), spectrum.Values. ToArray()) }); curveItem.Label.IsVisible = false; _msGraphControl.AxisChange(); _msGraphControl.Invalidate(); var entries = spectrum.ToArray(); dataGridView1.Rows.Add(entries.Length); for (int i = 0; i < entries.Count(); i++) { var row = dataGridView1.Rows[i]; row.Cells[colMass.Index].Value = entries[i].Key; row.Cells[colIntensity.Index].Value = entries[i].Value; } } finally { _inUpdateGraph = false; } }