Ejemplo n.º 1
0
        internal static (string ResolvedString, Dictionary <string, int> ResolvedValue) Resolve(IEnumerable <Dictionary <int, Modification> > enumerable)
        {
            var list = enumerable.ToList();
            Dictionary <string, int> firstDict = list[0].Values.OrderBy(b => b.IdWithMotif).GroupBy(b => b.IdWithMotif).ToDictionary(b => b.Key, b => b.Count());

            bool equals = true;

            foreach (var dict in list)
            {
                Dictionary <string, int> okTest = dict.Values.OrderBy(b => b.IdWithMotif).GroupBy(b => b.IdWithMotif).ToDictionary(b => b.Key, b => b.Count());
                if (!firstDict.SequenceEqual(okTest))
                {
                    equals = false;
                    break;
                }
            }
            if (!equals)
            {
                var returnString = string.Join("|", list.Select(b => string.Join(" ", b.Values.Select(c => c.IdWithMotif).OrderBy(c => c))));
                returnString = GlobalVariables.CheckLengthOfOutput(returnString);
                return(returnString, null);
            }
            else
            {
                return(string.Join(" ", list[0].Values.Select(c => c.IdWithMotif).OrderBy(c => c)), firstDict);
            }
        }
Ejemplo n.º 2
0
        //Get unique and identified peptides for output
        //Convert the output if it's a SILAC experiment
        public void GetIdentifiedPeptidesOutput(List <SilacLabel> labels)
        {
            var SharedPeptides = AllPeptides.Except(UniquePeptides);

            if (labels == null)
            {
                //TODO add unit test with displaymodsonpeptides
                if (!DisplayModsOnPeptides)
                {
                    UniquePeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", UniquePeptides.Select(p => p.BaseSequence).Distinct()));
                    SharedPeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", SharedPeptides.Select(p => p.BaseSequence).Distinct()));
                }
                else
                {
                    UniquePeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", UniquePeptides.Select(p => p.FullSequence).Distinct()));
                    SharedPeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", SharedPeptides.Select(p => p.FullSequence).Distinct()));
                }
            }
            else
            {
                if (!DisplayModsOnPeptides)
                {
                    UniquePeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", UniquePeptides.Select(p => SilacConversions.GetAmbiguousLightSequence(p.BaseSequence, labels, true)).Distinct()));
                    SharedPeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", SharedPeptides.Select(p => SilacConversions.GetAmbiguousLightSequence(p.BaseSequence, labels, true)).Distinct()));
                }
                else
                {
                    UniquePeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", UniquePeptides.Select(p => SilacConversions.GetAmbiguousLightSequence(p.FullSequence, labels, false)).Distinct()));
                    SharedPeptidesOutput = GlobalVariables.CheckLengthOfOutput(string.Join("|", SharedPeptides.Select(p => SilacConversions.GetAmbiguousLightSequence(p.FullSequence, labels, false)).Distinct()));
                }
            }
        }
Ejemplo n.º 3
0
        private static void AddPeptideSequenceData(Dictionary <string, string> s, PeptideSpectralMatch peptide, IReadOnlyDictionary <string, int> ModsToWritePruned)
        {
            bool pepWithModsIsNull = peptide == null || peptide.CompactPeptides.First().Value.Item2 == null;

            var pepsWithMods = pepWithModsIsNull ? null : peptide.CompactPeptides.SelectMany(b => b.Value.Item2)
                               .OrderBy(p => p.Sequence)
                               .ThenBy(p => p.Protein.Accession)
                               .ThenBy(p => p.OneBasedStartResidueInProtein).ToList();

            s["Peptides Sharing Same Peaks"] = pepWithModsIsNull ? " " :
                                               GlobalVariables.CheckLengthOfOutput(string.Join("|", peptide.CompactPeptides.Select(b => b.Value.Item2.Count.ToString(CultureInfo.InvariantCulture))));
            s["Base Sequence"]      = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.BaseSequence)).Item1;
            s["Full Sequence"]      = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Sequence)).Item1;
            s["Essential Sequence"] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.EssentialSequence(ModsToWritePruned))).Item1;
            s["Mods"] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.AllModsOneIsNterminus)).Item1;
            s["Mods Chemical Formulas"] = pepWithModsIsNull ? " " :
                                          Resolve(pepsWithMods.Select(b => string.Join("|", b.AllModsOneIsNterminus.OrderBy(c => c.Key)
                                                                                       .Where(c => c.Value is ModificationWithMassAndCf).Select(c => (c.Value as ModificationWithMassAndCf).chemicalFormula.Formula)))).Item1;
            s["Mods Combined Chemical Formula"] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.AllModsOneIsNterminus.Select(c => (c.Value as ModificationWithMassAndCf)))).Item1;
            s["Num Variable Mods"]         = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.NumVariableMods)).Item1;
            s["Missed Cleavages"]          = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.MissedCleavages.ToString(CultureInfo.InvariantCulture))).Item1;
            s["Peptide Monoisotopic Mass"] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.MonoisotopicMass)).Item1;
            s["Mass Diff (Da)"]            = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => peptide.ScanPrecursorMass - b.MonoisotopicMass)).Item1;
            s["Mass Diff (ppm)"]           = pepWithModsIsNull ? " " : ResolveF2(pepsWithMods.Select(b => ((peptide.ScanPrecursorMass - b.MonoisotopicMass) / b.MonoisotopicMass * 1e6))).Item1;
            s["Protein Accession"]         = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.Accession)).Item1;
            s["Protein Name"]        = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.FullName)).Item1;
            s["Gene Name"]           = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => string.Join(", ", b.Protein.GeneNames.Select(d => d.Item1 + ":" + d.Item2)))).Item1;
            s["Sequence Variations"] = pepWithModsIsNull ? " " :
                                       Resolve(pepsWithMods.Select(b => string.Join(", ", b.Protein.SequenceVariations
                                                                                    .Where(d => peptide.OneBasedStartResidueInProtein <= d.OneBasedBeginPosition && d.OneBasedBeginPosition <= peptide.OneBasedEndResidueInProtein)
                                                                                    .Select(d => d.OriginalSequence + d.OneBasedBeginPosition.ToString() + d.VariantSequence)))).Item1;
            s["Organism Name"]       = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.Organism)).Item1;
            s["Contaminant"]         = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.IsContaminant ? "Y" : "N")).Item1;
            s["Decoy"]               = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.Protein.IsDecoy ? "Y" : "N")).Item1;
            s["Peptide Description"] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.PeptideDescription)).Item1;
            s["Start and End Residues In Protein"] =
                pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => ("[" + b.OneBasedStartResidueInProtein.ToString(CultureInfo.InvariantCulture) + " to " +
                                                                            b.OneBasedEndResidueInProtein.ToString(CultureInfo.InvariantCulture) + "]"))).Item1;
            s["Previous Amino Acid"] = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.PreviousAminoAcid.ToString())).Item1;
            s["Next Amino Acid"]     = pepWithModsIsNull ? " " : Resolve(pepsWithMods.Select(b => b.NextAminoAcid.ToString())).Item1;

            string allScores            = " ";
            string theoreticalsSearched = " ";

            if (!pepWithModsIsNull && peptide.FdrInfo != null && peptide.FdrInfo.CalculateEValue)
            {
                allScores            = string.Join(";", peptide.AllScores.Select(p => p.ToString("F2", CultureInfo.InvariantCulture)));
                theoreticalsSearched = peptide.AllScores.Count.ToString();
            }

            s["All Scores"]               = allScores;
            s["Theoreticals Searched"]    = theoreticalsSearched;
            s["Decoy/Contaminant/Target"] = pepWithModsIsNull ? " " : peptide.IsDecoy ? "D" : pepsWithMods.Any(c => c.Protein.IsContaminant) ? "C" : "T";
        }
Ejemplo n.º 4
0
        private Tuple <string, double?> Resolve(IEnumerable <double> enumerable)
        {
            var list = enumerable.ToList();

            if (list.Max() - list.Min() < tolForDoubleResolution)
            {
                return(new Tuple <string, double?>(list.Average().ToString("F5", CultureInfo.InvariantCulture), list.Average()));
            }
            else
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list.Select(b => b.ToString("F5", CultureInfo.InvariantCulture))));
                return(new Tuple <string, double?>(returnString, null));
            }
        }
Ejemplo n.º 5
0
        internal static (string ResolvedString, double?ResolvedValue) ResolveF2(IEnumerable <double> enumerable)
        {
            var list = enumerable.ToList();

            if (list.Max() - list.Min() < ToleranceForDoubleResolutionF2)
            {
                return(list.Average().ToString("F2", CultureInfo.InvariantCulture), list.Average());
            }
            else
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list.Select(b => b.ToString("F2", CultureInfo.InvariantCulture))));
                return(returnString, null);
            }
        }
Ejemplo n.º 6
0
        internal static (string ResolvedString, int?ResolvedValue) Resolve(IEnumerable <int> enumerable)
        {
            var list  = enumerable.ToList();
            var first = list[0];

            if (list.All(b => first.Equals(b)))
            {
                return(first.ToString(CultureInfo.InvariantCulture), first);
            }
            else
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list.Select(b => b.ToString(CultureInfo.InvariantCulture))));
                return(returnString, null);
            }
        }
Ejemplo n.º 7
0
        private Tuple <string, int?> Resolve(IEnumerable <int> enumerable)
        {
            var list  = enumerable.ToList();
            var first = list[0];

            if (list.All(b => first.Equals(b)))
            {
                return(new Tuple <string, int?>(first.ToString(CultureInfo.InvariantCulture), first));
            }
            else
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list.Select(b => b.ToString(CultureInfo.InvariantCulture))));
                return(new Tuple <string, int?>(returnString, null));
            }
        }
Ejemplo n.º 8
0
        internal static (string ResolvedString, string ResolvedValue) Resolve(IEnumerable <string> enumerable)
        {
            var    list  = enumerable.ToList();
            string first = list.FirstOrDefault(b => b != null);

            // Only first if list is either all null or all equal to the first
            if (list.All(b => b == null) || list.All(b => first.Equals(b)))
            {
                return(first, first);
            }
            else
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list));
                return(returnString, null);
            }
        }
Ejemplo n.º 9
0
        private Tuple <string, string> Resolve(IEnumerable <string> enumerable)
        {
            var list  = enumerable.ToList();
            var first = list.FirstOrDefault(b => b != null);

            // Only first if list is either all null or all equal to the first
            if (list.All(b => b == null) || list.All(b => first.Equals(b)))
            {
                return(new Tuple <string, string>(first, first));
            }
            else
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list));
                return(new Tuple <string, string>(returnString, null));
            }
        }
Ejemplo n.º 10
0
        internal static void AddMatchScoreData(Dictionary <string, string> s, PeptideSpectralMatch peptide)
        {
            string localizedScores     = " ";
            string improvementPossible = " ";

            if (peptide != null && peptide.LocalizedScores != null)
            {
                localizedScores     = GlobalVariables.CheckLengthOfOutput(("[" + string.Join(",", peptide.LocalizedScores.Select(b => b.ToString("F3", CultureInfo.InvariantCulture))) + "]"));
                improvementPossible = (peptide.LocalizedScores.Max() - peptide.Score).ToString("F3", CultureInfo.InvariantCulture);
            }
            s[PsmTsvHeader.LocalizedScores]     = localizedScores;
            s[PsmTsvHeader.ImprovementPossible] = improvementPossible;

            string cumulativeTarget      = " ";
            string cumulativeDecoy       = " ";
            string qValue                = " ";
            string cumulativeTargetNotch = " ";
            string cumulativeDecoyNotch  = " ";
            string qValueNotch           = " ";
            string eValue                = " ";
            string eScore                = " ";

            if (peptide != null && peptide.FdrInfo != null)
            {
                cumulativeTarget      = peptide.FdrInfo.CumulativeTarget.ToString(CultureInfo.InvariantCulture);
                cumulativeDecoy       = peptide.FdrInfo.CumulativeDecoy.ToString(CultureInfo.InvariantCulture);
                qValue                = peptide.FdrInfo.QValue.ToString("F6", CultureInfo.InvariantCulture);
                cumulativeTargetNotch = peptide.FdrInfo.CumulativeTargetNotch.ToString(CultureInfo.InvariantCulture);
                cumulativeDecoyNotch  = peptide.FdrInfo.CumulativeDecoyNotch.ToString(CultureInfo.InvariantCulture);
                qValueNotch           = peptide.FdrInfo.QValueNotch.ToString("F6", CultureInfo.InvariantCulture);
                if (peptide.FdrInfo.CalculateEValue)
                {
                    eValue = peptide.FdrInfo.EValue.ToString("F6", CultureInfo.InvariantCulture);
                    eScore = peptide.FdrInfo.EScore.ToString("F6", CultureInfo.InvariantCulture);
                }
            }
            s[PsmTsvHeader.CumulativeTarget]      = cumulativeTarget;
            s[PsmTsvHeader.CumulativeDecoy]       = cumulativeDecoy;
            s[PsmTsvHeader.QValue]                = qValue;
            s[PsmTsvHeader.CumulativeTargetNotch] = cumulativeTargetNotch;
            s[PsmTsvHeader.CumulativeDecoyNotch]  = cumulativeDecoyNotch;
            s[PsmTsvHeader.QValueNotch]           = qValueNotch;
            s[PsmTsvHeader.EValue]                = eValue;
            s[PsmTsvHeader.EScore]                = eScore;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Resolve Methods()
        /// if all 'values' are the same this returns the one value otherwise you get a separated list of all values in their original order.
        /// for example:
        /// Notches 1,1,1,1 returns as 1
        /// Notches 1,0,1,0 returns as 1|0|1|0
        /// </summary>
        internal static (string ResolvedString, ChemicalFormula ResolvedValue) Resolve(IEnumerable <IEnumerable <Modification> > enumerable)
        {
            var             list             = enumerable.ToList();
            ChemicalFormula firstChemFormula = new ChemicalFormula();

            foreach (var firstMods in list[0])
            {
                if (firstMods == null || firstMods.ChemicalFormula == null)
                {
                    return("unknown", null);
                }
                firstChemFormula.Add(firstMods.ChemicalFormula);
            }

            bool equals = true;
            List <ChemicalFormula> formulas = new List <ChemicalFormula>();

            foreach (var anEnum in list)
            {
                ChemicalFormula fhere = new ChemicalFormula();
                foreach (var mod in anEnum)
                {
                    if (mod == null || mod.ChemicalFormula == null)
                    {
                        return("unknown", null);
                    }
                    fhere.Add(mod.ChemicalFormula);
                }
                if (!firstChemFormula.Equals(fhere))
                {
                    equals = false;
                }
                formulas.Add(fhere);
            }
            if (!equals)
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", formulas.Select(b => b.Formula)));
                return(returnString, null);
            }
            else
            {
                return(firstChemFormula.Formula, firstChemFormula);
            }
        }
Ejemplo n.º 12
0
        private static (string, ChemicalFormula) Resolve(IEnumerable <IEnumerable <ModificationWithMassAndCf> > enumerable)
        {
            ChemicalFormula f = new ChemicalFormula();
            {
                var firstEnum = enumerable.First();
                foreach (var mod in firstEnum)
                {
                    if (mod == null)
                    {
                        return("unknown", null);
                    }
                    f.Add(mod.chemicalFormula);
                }
            }
            bool equals = true;
            List <ChemicalFormula> formulas = new List <ChemicalFormula>();

            foreach (var anEnum in enumerable)
            {
                ChemicalFormula fhere = new ChemicalFormula();
                foreach (var mod in anEnum)
                {
                    if (mod == null)
                    {
                        return("unknown", null);
                    }
                    fhere.Add(mod.chemicalFormula);
                }
                if (!f.Equals(fhere))
                {
                    equals = false;
                }
                formulas.Add(fhere);
            }
            if (!equals)
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", formulas.Select(b => b.Formula)));
                return(returnString, null);
            }
            else
            {
                return(f.Formula, f);
            }
        }
Ejemplo n.º 13
0
        internal static (string ResolvedString, string ResolvedValue) Resolve(IEnumerable <string> enumerable, string ambiguousIfNull)
        {
            var    list  = enumerable.ToList();
            string first = list.FirstOrDefault(b => b != null);

            // Only first if list is either all null or all equal to the first
            if (list.All(b => b == null) || list.All(b => first.Equals(b)))
            {
                return(first, first);
            }
            // use only distinct names if all of the base sequences are the same
            else if (ambiguousIfNull != null)
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list.Distinct()));
                return(returnString, null);
            }
            else
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", list));
                return(returnString, null);
            }
        }
Ejemplo n.º 14
0
        private Tuple <string, Dictionary <string, int> > Resolve(IEnumerable <Dictionary <int, ModificationWithMass> > enumerable)
        {
            Dictionary <string, int> ok = enumerable.First().Values.OrderBy(b => b.id).GroupBy(b => b.id).ToDictionary(b => b.Key, b => b.Count());
            bool notEqual = false;

            foreach (var ha in enumerable)
            {
                Dictionary <string, int> okTest = ha.Values.OrderBy(b => b.id).GroupBy(b => b.id).ToDictionary(b => b.Key, b => b.Count());
                if (!ok.SequenceEqual(okTest))
                {
                    notEqual = true;
                    break;
                }
            }
            if (notEqual)
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", enumerable.Select(b => string.Join(" ", b.Values.Select(c => c.id).OrderBy(c => c)))));
                return(new Tuple <string, Dictionary <string, int> >(returnString, null));
            }
            else
            {
                return(new Tuple <string, Dictionary <string, int> >(string.Join(" ", enumerable.First().Values.Select(c => c.id).OrderBy(c => c)), ok));
            }
        }
Ejemplo n.º 15
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            // list of protein accession numbers
            sb.Append(ProteinGroupName);
            sb.Append("\t");

            // genes
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ListOfProteinsOrderedByAccession.Select(p => p.GeneNames.Select(x => x.Item2).FirstOrDefault()))));
            sb.Append("\t");

            // organisms
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ListOfProteinsOrderedByAccession.Select(p => p.Organism).Distinct())));
            sb.Append("\t");

            // list of protein names
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ListOfProteinsOrderedByAccession.Select(p => p.FullName).Distinct())));
            sb.Append("\t");

            // list of masses
            var           sequences = ListOfProteinsOrderedByAccession.Select(p => p.BaseSequence).Distinct();
            List <double> masses    = new List <double>();

            foreach (var sequence in sequences)
            {
                try
                {
                    masses.Add(new Proteomics.AminoAcidPolymer.Peptide(sequence).MonoisotopicMass);
                }
                catch (System.Exception)
                {
                    masses.Add(double.NaN);
                }
            }
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", masses)));
            sb.Append("\t");

            // number of proteins in group
            sb.Append("" + Proteins.Count);
            sb.Append("\t");

            // list of unique peptides
            if (!DisplayModsOnPeptides)
            {
                sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", UniquePeptides.Select(p => p.BaseSequence).Distinct())));
            }
            else
            {
                sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", UniquePeptides.Select(p => p.Sequence).Distinct())));
            }
            sb.Append("\t");

            // list of shared peptides
            var SharedPeptides = AllPeptides.Except(UniquePeptides);

            if (!DisplayModsOnPeptides)
            {
                sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SharedPeptides.Select(p => p.BaseSequence).Distinct())));
            }
            else
            {
                sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SharedPeptides.Select(p => p.Sequence).Distinct())));
            }
            sb.Append("\t");

            // number of peptides
            if (!DisplayModsOnPeptides)
            {
                sb.Append("" + AllPeptides.Select(p => p.BaseSequence).Distinct().Count());
            }
            else
            {
                sb.Append("" + AllPeptides.Select(p => p.Sequence).Distinct().Count());
            }
            sb.Append("\t");

            // number of unique peptides
            if (!DisplayModsOnPeptides)
            {
                sb.Append("" + UniquePeptides.Select(p => p.BaseSequence).Distinct().Count());
            }
            else
            {
                sb.Append("" + UniquePeptides.Select(p => p.Sequence).Distinct().Count());
            }
            sb.Append("\t");

            // sequence coverage percent
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SequenceCoveragePercent.Select(p => string.Format("{0:0}" + "%", (p * 100))))));
            sb.Append("\t");

            // sequence coverage
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SequenceCoverageDisplayList)));
            sb.Append("\t");

            // sequence coverage with mods
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SequenceCoverageDisplayListWithMods)));
            sb.Append("\t");

            //Detailed mods information list
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ModsInfo)));
            sb.Append("\t");

            // MS1 intensity (retrieved from FlashLFQ in the SearchTask)
            if (IntensitiesByFile != null && FilesForQuantification != null)
            {
                foreach (var file in FilesForQuantification)
                {
                    if (IntensitiesByFile[file] > 0)
                    {
                        sb.Append(IntensitiesByFile[file]);
                    }
                    else
                    {
                        sb.Append("");
                    }
                    sb.Append("\t");
                }
            }

            // number of PSMs for listed peptides
            sb.Append("" + AllPsmsBelowOnePercentFDR.Count);
            sb.Append("\t");

            // isDecoy
            if (IsDecoy)
            {
                sb.Append("D");
            }
            else if (IsContaminant)
            {
                sb.Append("C");
            }
            else
            {
                sb.Append("T");
            }
            sb.Append("\t");

            // cumulative target
            sb.Append(CumulativeTarget);
            sb.Append("\t");

            // cumulative decoy
            sb.Append(CumulativeDecoy);
            sb.Append("\t");

            // q value
            sb.Append(QValue);
            sb.Append("\t");

            // best peptide score
            sb.Append(BestPeptideScore);
            sb.Append("\t");

            // best peptide q value
            sb.Append(BestPeptideQValue);
            sb.Append("\t");

            return(sb.ToString());
        }
Ejemplo n.º 16
0
        public string ToString(IReadOnlyDictionary <string, int> ModstoWritePruned)
        {
            var sb = new StringBuilder();

            sb.Append(Path.GetFileNameWithoutExtension(FullFilePath));
            sb.Append('\t' + ScanNumber.ToString(CultureInfo.InvariantCulture));
            sb.Append('\t' + ScanRetentionTime.ToString("F5", CultureInfo.InvariantCulture));
            sb.Append('\t' + ScanExperimentalPeaks.ToString("F5", CultureInfo.InvariantCulture));
            sb.Append('\t' + TotalIonCurrent.ToString("F5", CultureInfo.InvariantCulture));
            sb.Append('\t' + (PrecursorScanNumber.HasValue ? PrecursorScanNumber.Value.ToString(CultureInfo.InvariantCulture) : "unknown"));
            sb.Append('\t' + ScanPrecursorCharge.ToString("F5", CultureInfo.InvariantCulture));
            sb.Append('\t' + ScanPrecursorMonoisotopicPeakMz.ToString("F5", CultureInfo.InvariantCulture));
            sb.Append('\t' + ScanPrecursorMass.ToString("F5", CultureInfo.InvariantCulture));
            sb.Append('\t' + Score.ToString("F3", CultureInfo.InvariantCulture));
            sb.Append("\t" + Resolve(compactPeptides.Select(b => b.Value.Item1)).Item1); // Notch
            sb.Append('\t' + NumDifferentCompactPeptides.ToString("F5", CultureInfo.InvariantCulture));

            if (compactPeptides.First().Value.Item2 != null)
            {
                sb.Append("\t" + GlobalVariables.CheckLengthOfOutput(string.Join("|", compactPeptides.Select(b => b.Value.Item2.Count.ToString(CultureInfo.InvariantCulture)))));

                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.BaseSequence)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.Sequence)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.EssentialSequence(ModstoWritePruned))).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.allModsOneIsNterminus)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => string.Join("|", b.allModsOneIsNterminus.OrderBy(c => c.Key).Where(c => c.Value is ModificationWithMassAndCf).Select(c => (c.Value as ModificationWithMassAndCf).chemicalFormula.Formula)))).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.allModsOneIsNterminus.Select(c => (c.Value as ModificationWithMassAndCf)))).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.NumVariableMods)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.MissedCleavages.HasValue ? b.MissedCleavages.Value.ToString(CultureInfo.InvariantCulture) : "unknown")).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.MonoisotopicMass)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => ScanPrecursorMass - b.MonoisotopicMass)).Item1);
                sb.Append('\t' + ResolveF2(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => ((ScanPrecursorMass - b.MonoisotopicMass) / b.MonoisotopicMass * 1e6))).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.Protein.Accession)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.Protein.FullName)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => string.Join(", ", b.Protein.GeneNames.Select(d => d.Item1 + ":" + d.Item2)))).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.Protein.Organism)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.Protein.IsContaminant ? "Y" : "N")).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.Protein.IsDecoy ? "Y" : "N")).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.PeptideDescription)).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => ("[" + b.OneBasedStartResidueInProtein.ToString(CultureInfo.InvariantCulture) + " to " + b.OneBasedEndResidueInProtein.ToString(CultureInfo.InvariantCulture) + "]"))).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.PreviousAminoAcid.ToString())).Item1);
                sb.Append('\t' + Resolve(compactPeptides.SelectMany(b => b.Value.Item2).Select(b => b.NextAminoAcid.ToString())).Item1);
                if (FdrInfo != null && FdrInfo.CalculateEValue)
                {
                    int theoreticalsSearched = AllScores[0];
                    sb.Append('\t' + AllScores[0].ToString());
                    for (int i = 1; i < AllScores.Count; i++)
                    {
                        sb.Append("_" + AllScores[i]);
                        theoreticalsSearched += AllScores[i];
                    }
                    sb.Append('\t' + theoreticalsSearched.ToString());
                }
                else
                {
                    sb.Append('\t' + " " + '\t' + " ");
                }
                // Unambiguous
                if (IsDecoy)
                {
                    sb.Append("\t" + "D");
                }
                else if (compactPeptides.Any(b => b.Value.Item2.Any(c => c.Protein.IsContaminant)))
                {
                    sb.Append("\t" + "C");
                }
                else
                {
                    sb.Append("\t" + "T");
                }
            }
            else
            {
                sb.Append('\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " ");
            }

            if (MatchedIonDictOnlyMatches.Any())
            {
                //Count
                sb.Append('\t' + string.Join(";", MatchedIonDictOnlyMatches.Select(b => b.Value.Count(c => c > 0))));
                //Masses
                sb.Append('\t' + "[");
                StringBuilder sbTemp = new StringBuilder();
                foreach (var kvp in MatchedIonDictOnlyMatches)
                {
                    sbTemp.Append("[" + string.Join(",", kvp.Value.Select(b => b.ToString("F5", CultureInfo.InvariantCulture))) + "];");
                }
                sb.Append(GlobalVariables.CheckLengthOfOutput(sbTemp.ToString()));
                sb.Append("]");

                //Mass error Da
                sb.Append('\t' + "[");
                sbTemp.Clear();
                foreach (var kvp in ProductMassErrorDa)
                {
                    sbTemp.Append("[" + string.Join(",", kvp.Value.Select(b => b.ToString("F5", CultureInfo.InvariantCulture))) + "];");
                }
                sb.Append(GlobalVariables.CheckLengthOfOutput(sbTemp.ToString()));
                sb.Append("]");

                //Mass error ppm
                sb.Append('\t' + "[");
                sbTemp.Clear();
                foreach (var kvp in ProductMassErrorPpm)
                {
                    sbTemp.Append("[" + string.Join(",", kvp.Value.Select(b => b.ToString("F2", CultureInfo.InvariantCulture))) + "];");
                }
                sb.Append(GlobalVariables.CheckLengthOfOutput(sbTemp.ToString()));
                sb.Append("]");
            }
            else
            {
                sb.Append('\t' + " " + '\t' + " " + '\t' + " " + '\t' + " ");
            }

            if (LocalizedScores != null)
            {
                sb.Append('\t' + GlobalVariables.CheckLengthOfOutput(("[" + string.Join(",", LocalizedScores.Select(b => b.ToString("F3", CultureInfo.InvariantCulture))) + "]")));
                sb.Append('\t' + (LocalizedScores.Max() - Score).ToString("F3", CultureInfo.InvariantCulture));
            }
            else
            {
                sb.Append('\t' + " " + '\t' + " ");
            }

            if (FdrInfo != null)
            {
                sb.Append('\t' + FdrInfo.CumulativeTarget.ToString(CultureInfo.InvariantCulture));
                sb.Append('\t' + FdrInfo.CumulativeDecoy.ToString(CultureInfo.InvariantCulture));
                sb.Append('\t' + FdrInfo.QValue.ToString("F6", CultureInfo.InvariantCulture));
                sb.Append('\t' + FdrInfo.CumulativeTargetNotch.ToString(CultureInfo.InvariantCulture));
                sb.Append('\t' + FdrInfo.CumulativeDecoyNotch.ToString(CultureInfo.InvariantCulture));
                sb.Append('\t' + FdrInfo.QValueNotch.ToString("F6", CultureInfo.InvariantCulture));

                if (FdrInfo.CalculateEValue)
                {
                    sb.Append("\t" + FdrInfo.EValue.ToString("F6", CultureInfo.InvariantCulture));
                    sb.Append("\t" + FdrInfo.EScore.ToString("F6", CultureInfo.InvariantCulture));
                }
                else
                {
                    sb.Append('\t' + " " + '\t' + " ");
                }
            }
            else
            {
                sb.Append('\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " " + '\t' + " ");
            }

            return(sb.ToString());
        }
Ejemplo n.º 17
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            // list of protein accession numbers
            sb.Append(ProteinGroupName);
            sb.Append("\t");

            // genes
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ListOfProteinsOrderedByAccession.Select(p => p.GeneNames.Select(x => x.Item2).FirstOrDefault()))));
            sb.Append("\t");

            // organisms
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ListOfProteinsOrderedByAccession.Select(p => p.Organism).Distinct())));
            sb.Append("\t");

            // list of protein names
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ListOfProteinsOrderedByAccession.Select(p => p.FullName).Distinct())));
            sb.Append("\t");

            // list of masses
            var           sequences = ListOfProteinsOrderedByAccession.Select(p => p.BaseSequence).Distinct();
            List <double> masses    = new List <double>();

            foreach (var sequence in sequences)
            {
                try
                {
                    masses.Add(new Proteomics.AminoAcidPolymer.Peptide(sequence).MonoisotopicMass);
                }
                catch (System.Exception)
                {
                    masses.Add(double.NaN);
                }
            }
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", masses)));
            sb.Append("\t");

            // number of proteins in group
            sb.Append("" + Proteins.Count);
            sb.Append("\t");

            // list of unique peptides
            if (UniquePeptidesOutput != null)
            {
                sb.Append(GlobalVariables.CheckLengthOfOutput(UniquePeptidesOutput));
            }
            sb.Append("\t");

            // list of shared peptides
            if (SharedPeptidesOutput != null)
            {
                sb.Append(GlobalVariables.CheckLengthOfOutput(SharedPeptidesOutput));
            }
            sb.Append("\t");

            // number of peptides
            if (!DisplayModsOnPeptides)
            {
                sb.Append("" + AllPeptides.Select(p => p.BaseSequence).Distinct().Count());
            }
            else
            {
                sb.Append("" + AllPeptides.Select(p => p.FullSequence).Distinct().Count());
            }
            sb.Append("\t");

            // number of unique peptides
            if (!DisplayModsOnPeptides)
            {
                sb.Append("" + UniquePeptides.Select(p => p.BaseSequence).Distinct().Count());
            }
            else
            {
                sb.Append("" + UniquePeptides.Select(p => p.FullSequence).Distinct().Count());
            }
            sb.Append("\t");

            // sequence coverage percent
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SequenceCoverageFraction.Select(p => string.Format("{0:0.#####}", p)))));
            sb.Append("\t");

            // sequence coverage
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SequenceCoverageDisplayList)));
            sb.Append("\t");

            // sequence coverage with mods
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", SequenceCoverageDisplayListWithMods)));
            sb.Append("\t");

            //Detailed mods information list
            sb.Append(GlobalVariables.CheckLengthOfOutput(string.Join("|", ModsInfo)));
            sb.Append("\t");

            // MS1 intensity (retrieved from FlashLFQ in the SearchTask)
            if (IntensitiesByFile != null && FilesForQuantification != null)
            {
                foreach (var sampleGroup in FilesForQuantification.GroupBy(p => p.Condition))
                {
                    foreach (var sample in sampleGroup.GroupBy(p => p.BiologicalReplicate).OrderBy(p => p.Key))
                    {
                        // if the samples are fractionated, the protein will only have 1 intensity in the first fraction
                        // and the other fractions will be zero. we could find the first/only fraction with an intensity,
                        // but simply summing the fractions is easier than finding the single non-zero value
                        double summedIntensity = sample.Sum(file => IntensitiesByFile[file]);

                        if (summedIntensity > 0)
                        {
                            sb.Append(summedIntensity);
                        }

                        sb.Append("\t");
                    }
                }
            }

            // number of PSMs for listed peptides
            sb.Append("" + AllPsmsBelowOnePercentFDR.Count);
            sb.Append("\t");

            // isDecoy
            if (IsDecoy)
            {
                sb.Append("D");
            }
            else if (IsContaminant)
            {
                sb.Append("C");
            }
            else
            {
                sb.Append("T");
            }
            sb.Append("\t");

            // cumulative target
            sb.Append(CumulativeTarget);
            sb.Append("\t");

            // cumulative decoy
            sb.Append(CumulativeDecoy);
            sb.Append("\t");

            // q value
            sb.Append(QValue);
            sb.Append("\t");

            // best peptide score
            sb.Append(BestPeptideScore);
            sb.Append("\t");

            // best peptide q value
            sb.Append(BestPeptideQValue);
            sb.Append("\t");

            return(sb.ToString());
        }