Exemplo n.º 1
0
        public string ToParsimonyProteins(ExperimentGroup exp, bool duplexQuant = false, bool useOnlyCompleteSets = false)
        {
            StringBuilder sb = new StringBuilder(512);

            sb.AppendFormat("{0},{1},{2},{3:G4},{4:G4},{5:G4},{6},{7},{8},{9},", Name, Description, LongestProteinLen, SequenceCoverage, RepresentativeProtein.CalculateSequenceCoverage(Peptides.Where(pep => !pep.IsShared)), SequenceRedundacy, Count, UniquePeptides, Peptides.Count, Peptides.Count(pep => pep.IsShared));
            if (exp != null)
            {
                int psms;
                HashSet <Peptide> uniquepeps;
                UniquePeptidesPerGroup.TryGetValue(exp, out uniquepeps);
                PsmsPerGroup.TryGetValue(exp, out psms);
                sb.Append(psms);
                sb.Append(',');
                if (uniquepeps != null)
                {
                    sb.Append(uniquepeps.Count);
                }
                sb.Append(',');
                sb.Append(uniquepeps.Count(pep => pep.IsShared));
                sb.Append(',');
            }
            sb.Append(PScore.ToString(CultureInfo.InvariantCulture));
            if (exp != null && exp.UseQuant)
            {
                Quantitation quant;
                if (Quantitation.TryGetValue(exp.Name, out quant))
                {
                    sb.Append(',');
                    sb.Append(quant.PSMs);
                    sb.Append(',');
                    sb.Append(quant.UniquePeptides.Count);
                    sb.Append(',');
                    sb.Append(quant.ToOutput(duplexQuant, exp.MeidanLog2Ratio, useOnlyCompleteSets));
                }
                else
                {
                    sb.Append(",0,0");
                    for (int i = 0; i < exp.QuantPlex * 4; i++)
                    {
                        sb.Append(",-");
                    }

                    if (duplexQuant)
                    {
                        sb.Append(",N/A,N/A");
                    }
                }
            }

            if (ProteinHoarder.AnnotationType != AnnotationType.None)
            {
                sb.Append(',');
                sb.Append(ProteinIdsString());
                sb.Append(',');
                sb.Append(GeneNamesString());
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        public bool TryGetLog2Ratio(ExperimentGroup exp, out double log2, bool useOnlyCompleteSets = false)
        {
            log2 = 0;
            Quantitation quant;

            if (Quantitation.TryGetValue(exp.Name, out quant))
            {
                double[] data;
                log2 = quant.GetLog2Ratio(useOnlyCompleteSets, out data);
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        /*
        /// <summary>
        /// Maps the peptide to all the protein groups that it is apart of
        /// </summary>
        /// <param name="proteinGroups">a list of Protein Groups to map too</param>
        /// <returns>a Dictionary of peptides isMapped to a List of Protein Groups</returns>
        private void MappedPeptidesToProteinGroups(List<ProteinGroup> proteinGroups)
        {
            // Clear all the mappings first
            //foreach (ProteinGroup proteinGroup in proteinGroups)
            //{
            //    // Go over each peptide of that protein group
            //    foreach (Peptide peptide in proteinGroup.Peptides)
            //    {
            //        //peptide.ClearProteinGroups();
            //    }
            //}
            // Go over each protein group
            foreach (ProteinGroup proteinGroup in proteinGroups)
            {
                // Go over each peptide of that protein group
                foreach (Peptide peptide in proteinGroup.Peptides)
                {
                    // Add to that peptide that group
                    peptide.AddProteinGroup(proteinGroup);
                }
            }
        }
        */
        private Dictionary<string, ExperimentGroup> GroupExperiments(IEnumerable<CsvFile> csvFiles, bool useQuant)
        {
            Dictionary<string, ExperimentGroup> uniqueNames = new Dictionary<string, ExperimentGroup>();
            foreach (CsvFile file in csvFiles)
            {
                ExperimentGroup experiment;
                if (string.IsNullOrEmpty(file.ExperimentName))
                {
                    file.ExperimentName = "";
                }
                if(uniqueNames.TryGetValue(file.ExperimentName, out experiment))
                {
                    experiment.CsvFiles.Add(file);
                }
                else
                {
                    experiment = new ExperimentGroup(file.ExperimentName);
                    experiment.CsvFiles.Add(file);
                    uniqueNames.Add(file.ExperimentName, experiment);
                    using (CsvReader reader = new CsvReader(new StreamReader(file.FilePath), true))
                    {
                        // write the header only once to the two outputs
                        string[] headers = reader.GetFieldHeaders();
                        experiment.Header = string.Join(",", headers);

                        if (!useQuant) continue;

                        int headerCount = headers.Length;

                        experiment.TQStart = -1;
                        experiment.TQStop = headerCount - 2;
                        for (int i = 0; i < headerCount; i++)
                        {
                            string header = headers[i];
                            if (!header.Contains("NL)"))
                                continue;
                            experiment.TQStart = i;
                            break;
                        }

                        if (experiment.TQStart < 0)
                        {
                            Log("[WARNING] No quantification data found in {0} for experiment {1}", file, experiment.Name);
                            experiment.UseQuant = false;
                            break;
                        }
                        experiment.UseQuant = true;

                        // Get the experimental Quant headers
                        StringBuilder sb = new StringBuilder();
                        for (int i = experiment.TQStart; i <= experiment.TQStop; i++)
                        {
                            sb.Append(headers[i]);
                            sb.Append(',');
                        }
                        sb.Remove(sb.Length - 1, 1);
                        experiment.QuantHeader = sb.ToString();
                    }
                }

            }

            return uniqueNames;

            //Dictionary<char, ExperimentGroup> expgroups = new Dictionary<char, ExperimentGroup>();
            //foreach (CsvFile csvfile in csvFiles)
            //{
            //    ExperimentGroup exp;
            //    if (expgroups.TryGetValue(csvfile.ExperimentGroup, out exp))
            //    {
            //        exp.CsvFiles.Add(csvfile);
            //    }
            //    else
            //    {
            //        exp = new ExperimentGroup(csvfile.ExperimentGroup, csvfile.ExperimentName);
            //        exp.CsvFiles.Add(csvfile);
            //        expgroups.Add(csvfile.ExperimentGroup, exp);
            //        using (CsvReader reader = new CsvReader(new StreamReader(csvfile.FilePath), true))
            //        {
            //            // write the header only once to the two outputs
            //            string[] headers = reader.GetFieldHeaders();
            //            exp.Header = string.Join(",", headers);

            //            if (!useQuant) continue;

            //            int headerCount = headers.Length;

            //            exp.TQStart = -1;
            //            exp.TQStop = headerCount - 2;
            //            for (int i = 0; i < headerCount; i++)
            //            {
            //                string header = headers[i];
            //                if (!header.Contains("NL)"))
            //                    continue;
            //                exp.TQStart = i;
            //                break;
            //            }

            //            if (exp.TQStart < 0)
            //            {
            //                Log("[WARNING] No quantification data found in {0} for experiment {1}", csvfile, exp.Name);
            //                exp.UseQuant = false;
            //                break;
            //            }
            //            exp.UseQuant = true;

            //            // Get the experimental Quant headers
            //            StringBuilder sb = new StringBuilder();
            //            for (int i = exp.TQStart; i <= exp.TQStop; i++)
            //            {
            //                sb.Append(headers[i]);
            //                sb.Append(',');
            //            }
            //            sb.Remove(sb.Length - 1, 1);
            //            exp.QuantHeader = sb.ToString();
            //        }
            //    }
            //}
            //return expgroups;
        }