private void linkLoadFromFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { DialogResult dlg = dlgOpenQuantification.ShowDialog(); if (dlg != DialogResult.OK) { return; } SetText(dlgOpenQuantification); string filename = dlgOpenQuantification.FileName; if (System.IO.File.Exists(filename)) { PA = FileUtil.ReadPermutationArrayQuantificationData(filename); LoadQuantificationFromPermutationArrayToGrid(); dgPeptides.RowCount = dgPeptides.ColumnCount = 0; thresholdEntry.SetInitialValues(PA.GetPositiveThreshold(), PA.GetNegativeThreshold()); Run(); } } catch { MessageBox.Show("There is a problem with loading the quantification file.\r\nPlease make sure the quantification data is the only data in the loaded file.\r\n", Application.ProductName); } }
private void LoadProject() { try { DialogResult dlg = dlgOpenProject.ShowDialog(); if (dlg != DialogResult.OK) { return; } SetText(dlgOpenProject); string filename = dlgOpenProject.FileName; PA = PermutationArray.ReadFromFile(filename); thresholdEntry.SetInitialValues(PA.GetPositiveThreshold(), PA.GetNegativeThreshold()); cbWildTypeXAxis.Checked = !PA.PermutationXAxis; cbYAxisTopToBottom.Checked = PA.WildTypeYAxisTopToBottom; colCount = PA.ColCount; rowCount = PA.RowCount; SetRowColumnCount(); rbMeanValue.Checked = PA.NormMode == NormalizationMode.Mean; rbPerRowColumn.Checked = PA.NormMode != NormalizationMode.Mean; if (PA.PeptideMatrix != null) { LoadPeptidesFromPermutationArrayToGrid(); } if (PA.QuantificationMatrix != null) { LoadQuantificationFromPermutationArrayToGrid(); } if (PA.NormalizedMatrix != null) { LoadNormalizedMatrixFromPeptideArrayToGrid(); } bool gridsOK = ColorGrids(); eNotes.Text = PA.Notes; imageReference.Image = null; try { Image img = FileUtil.Base64ToImage(PA.ImageStr); imageReference.Image = img; } catch { } DrawColorMatrix(); if (!gridsOK) { MessageBox.Show("There is a problem in loading the file. It is highly recommended to re-run the analysis.", Analyzer.ProgramName); } } catch { MessageBox.Show("There is a problem in loading the file. It is highly recommended to re-run the analysis.", Analyzer.ProgramName); } linkRun.Visible = true; }
private void Run() { string[,] values = new string[dgQuantification.RowCount, dgQuantification.ColumnCount]; for (int iRow = 0; iRow < dgQuantification.RowCount; iRow++) { for (int iCol = 0; iCol < dgQuantification.ColumnCount; iCol++) { values[iRow, iCol] = dgQuantification[iCol, iRow].Value?.ToString() ?? ""; } } bool xPossible = true, yPossible = true; PermutationArray.CheckPermutationAxis(values, ref xPossible, ref yPossible); if (xPossible && !yPossible) { cbWildTypeXAxis.Checked = false; } else if (yPossible && !xPossible) { cbWildTypeXAxis.Checked = true; } else if (!xPossible && !yPossible) { MessageBox.Show("Please make sure one the axes have permutation array (each amino acid has to exist at most once)", Analyzer.ProgramName); return; } ; PA = new PermutationArray(values, !cbWildTypeXAxis.Checked, cbYAxisTopToBottom.Checked, out List <string> warnings, out string error); if (error != "") { MessageBox.Show(error, Analyzer.ProgramName); return; } if (warnings.Count > 0) { warnings.Insert(0, "Warning:"); MessageBox.Show(String.Join("\r\n", warnings), Analyzer.ProgramName); } PA.SetPositiveThreshold(thresholdEntry.PositiveThreshold, out bool negChanged); PA.SetNegativeThreshold(thresholdEntry.NegativeThreshold, out bool posChanged2); LoadPeptidesFromPermutationArrayToGrid(); LoadNormalizedMatrixFromPeptideArrayToGrid(); dgPeptides.Rows[0].DefaultCellStyle = dgPeptides.ColumnHeadersDefaultCellStyle; dgPeptides.Columns[0].DefaultCellStyle = dgPeptides.ColumnHeadersDefaultCellStyle; dgNormalized.Rows[0].DefaultCellStyle = dgPeptides.ColumnHeadersDefaultCellStyle; dgNormalized.Columns[0].DefaultCellStyle = dgPeptides.ColumnHeadersDefaultCellStyle; ColorGrids(); DrawColorMatrix(); }
private void btnSave_Click(object sender, EventArgs e) { dlgSaveProject.FileName = ProjectName; DialogResult dlg = dlgSaveProject.ShowDialog(); if (dlg != DialogResult.OK) { return; } PA.Notes = eNotes.Text; PA.ImageStr = FileUtil.ImageToBase64(imageReference.Image); SetText(dlgSaveProject); string filename = dlgSaveProject.FileName; if (PermutationArray.SaveToFile(filename, PA)) { MessageBox.Show(filename + " is saved", Analyzer.ProgramName); } }
/// <summary> /// Dictionary of discrimination factor for each char at every position: D = Avrg(v[i!=j]) / v[i] - 1 /// </summary> /// <param name="PA"></param> /// <returns></returns> static public Dictionary <int, Dictionary <char, double> > GenerateDiscriminationFactors(PermutationArray PA, out List <char> ExistingAminoAcids) { ExistingAminoAcids = new List <char>(); try { Dictionary <int, double> totalWeightsPerPos; Dictionary <int, Dictionary <char, double> > weights; int pepsize = PA.ModifiedPeptides[0].Length; totalWeightsPerPos = new Dictionary <int, double>(); weights = new Dictionary <int, Dictionary <char, double> >(); for (int i = 0; i < pepsize; i++) { totalWeightsPerPos.Add(i, 0); weights.Add(i, new Dictionary <char, double>()); } foreach (string s in PA.ModifiedPeptides) { for (int i = 0; i < pepsize; i++) { char c = s[i]; if (!ExistingAminoAcids.Contains(c)) { ExistingAminoAcids.Add(c); } if (c == PA.WildTypePeptide[i]) { if (weights[i].ContainsKey(c)) { continue; //skip wildtype char if already added } } double weight = PA.PeptideWeights[s]; totalWeightsPerPos[i] += weight; weights[i].Add(c, weight); break;//there can be one aa change per peptide } } for (int i = 0; i < pepsize; i++) { List <char> charlist = weights[i].Keys.ToList(); foreach (char c in charlist) { weights[i][c] /= totalWeightsPerPos[i]; /*double curWeight = weights[i][c]; * double avrRest = (totalWeightsPerPos[i] - curWeight) / (weights[i].Count - 1); * if (curWeight == avrRest) * weights[i][c] = 1; * else * weights[i][c] = curWeight / (curWeight - avrRest); //avrRest / curWeight - 1;*/ } } return(weights); } catch (Exception exc) { //Logger.Log(LogEntryType.SevereException, exc); return(null); } }