예제 #1
0
        private void AddNormalizedPeptideWeight(double weight, int pos, char replaceBy)
        {
            if (string.IsNullOrEmpty(WildTypePeptide))
            {
                return;
            }
            string s = "", e = "";

            if (pos > 0)
            {
                s = WildTypePeptide.Substring(0, pos);
            }
            if (pos < WildTypePeptide.Length - 1)
            {
                e = WildTypePeptide.Substring(pos + 1);
            }
            string peptide = s + replaceBy + e;

            if (/*peptide == WildTypePeptide && */ NormalizedPeptideWeights.ContainsKey(peptide))
            {
                return;
            }
            NormalizedPeptideWeights.Add(peptide, weight);
        }
예제 #2
0
        private void GenerateMatrices(string[,] values, out List <string> warnings, out string error)
        {
            error    = "";
            warnings = new List <string>();
            if (values == null)
            {
                return;
            }
            try
            {
                RowCount             = values.GetLength(0) - 1;
                ColCount             = values.GetLength(1) - 1;
                PeptideMatrix        = new string[RowCount, ColCount];
                QuantificationMatrix = new double[RowCount, ColCount];
                NormalizedMatrix     = new double[RowCount, ColCount];

                bool nswwarning = false;
                bool nspwarning = false;
                //Generate Permutation and Wildtype arrays
                if (PermutationXAxis)
                {
                    NormBy = new double[RowCount];
                    for (int iRow = 1; iRow <= RowCount; iRow++)
                    {
                        string s = values[iRow, 0].Trim();
                        if (AminoAcids.GetAminoAcid(s[0]) == null)
                        {
                            if (s.Length == 1)
                            {
                                if (!nswwarning)
                                {
                                    warnings.Add("Non-standard amino acid in wildtype peptide.");
                                }
                                nswwarning = true;
                            }
                            else
                            {
                                error = "Not a valid wildtype peptide";
                                return;
                            }
                        }
                        if (WildTypeYAxisTopToBottom)
                        {
                            WildTypePeptide += s[0];
                        }
                        else
                        {
                            WildTypePeptide = s[0] + WildTypePeptide; //read from bottom to top
                        }
                    }
                    Permutation = new char[ColCount];
                    for (int iCol = 1; iCol <= ColCount; iCol++)
                    {
                        string s = values[0, iCol].Trim();
                        if (AminoAcids.GetAminoAcid(s[0]) == null)
                        {
                            if (s.Length == 1)
                            {
                                if (!nspwarning)
                                {
                                    warnings.Add("Non-standard amino acid in permutation string.");
                                }
                                nspwarning = true;
                            }
                            else
                            {
                                error = "Not a valid permutation string";
                                return;
                            }
                        }
                        Permutation[iCol - 1] = s[0];
                    }
                }
                else //if(PermutationYAxis)
                {
                    NormBy = new double[ColCount];
                    for (int iCol = 1; iCol <= ColCount; iCol++)
                    {
                        string s = values[0, iCol].Trim();
                        if (AminoAcids.GetAminoAcid(s[0]) == null)
                        {
                            if (s.Length == 1)
                            {
                                if (!nswwarning)
                                {
                                    warnings.Add("Non-standard amino acid in wildtype peptide.");
                                }
                                nswwarning = true;
                            }
                            else
                            {
                                error = "Not a valid wildtype peptide";
                                return;
                            }
                        }
                        WildTypePeptide += s[0];
                    }

                    Permutation = new char[RowCount];
                    for (int iRow = 1; iRow <= RowCount; iRow++)
                    {
                        string s = values[iRow, 0].Trim();
                        if (AminoAcids.GetAminoAcid(s[0]) == null)
                        {
                            if (s.Length == 1)
                            {
                                if (!nspwarning)
                                {
                                    warnings.Add("Non-standard amino acid in permutation string.");
                                }
                                nspwarning = true;
                            }
                            else
                            {
                                error = "Not a valid permutation string";
                                return;
                            }
                        }
                        Permutation[iRow - 1] = s[0];
                    }
                }

                //Generate Matrices and Normalization values
                int wtl = WildTypePeptide.Length;

                int    counter   = 0;
                double totalNorm = 0;
                for (int iRow = 0; iRow < RowCount; iRow++)
                {
                    for (int iCol = 0; iCol < ColCount; iCol++)
                    {
                        if (double.TryParse(values[iRow + 1, iCol + 1], out double d))
                        {
                            QuantificationMatrix[iRow, iCol] = d;
                        }
                        else if (string.IsNullOrEmpty(values[iRow + 1, iCol + 1]))
                        {
                            d = 0;
                        }
                        else
                        {
                            error = "Wrongly formatted data.";
                            return;
                        }

                        if (PermutationXAxis) //wildTypeYAxis
                        {
                            if (WildTypeYAxisTopToBottom)
                            {
                                PeptideMatrix[iRow, iCol] = (iRow >= 1 ? WildTypePeptide.Substring(0, iRow) : "") + Permutation[iCol] + (iRow < WildTypePeptide.Length - 1 ? WildTypePeptide.Substring(iRow + 1) : "");
                            }
                            else  //from bottom to top
                            {
                                PeptideMatrix[iRow, iCol] = (iRow < wtl - 1 ? WildTypePeptide.Substring(0, wtl - iRow - 1) : "") + Permutation[iCol] + (iRow > 0 ? WildTypePeptide.Substring(wtl - iRow) : "");
                            }
                        }
                        else
                        {
                            PeptideMatrix[iRow, iCol] = (iCol >= 1 ? WildTypePeptide.Substring(0, iCol) : "") + Permutation[iRow] + (iCol < WildTypePeptide.Length - 1 ? WildTypePeptide.Substring(iCol + 1) : "");
                        }

                        if (PeptideMatrix[iRow, iCol] == WildTypePeptide)
                        {
                            if (d > 0)
                            {
                                counter++;
                                totalNorm += d;
                            }
                            if (PermutationXAxis)
                            {
                                NormBy[iRow] = d;
                            }
                            else
                            {
                                NormBy[iCol] = d;
                            }
                        }
                    }
                }
                if (counter > 0 && counter < NormBy.GetLength(0)) //fill the blanks with average
                {
                    for (int i = 0; i < NormBy.GetLength(0); i++)
                    {
                        if (NormBy[i] < 0.0001)
                        {
                            NormBy[i] = totalNorm / counter;
                        }
                    }
                }
                NormalizationValue = totalNorm / counter;
                GenerateNormalizedPeptideWeights();
            }
            catch (Exception exc)
            {
                error = "Unhandled exception: " + exc.Message;
            }
        }