protected void UpdateProteinEntries(IIdentifiedProteinGroup group)
        {
            try
            {
                this.lvProteins.BeginUpdate();

                var items = new List <ListViewItem>();
                foreach (ListViewItem item in this.lvProteins.Items)
                {
                    if (item.Tag == group)
                    {
                        items.Add(item);
                    }
                }

                for (int i = 0; i < group.Count && i < items.Count; i++)
                {
                    UpdateProteinEntry(items[i], group, i);
                }
            }
            finally
            {
                this.lvProteins.EndUpdate();
            }
        }
        private void UpdateProteinEntry(ListViewItem item, IIdentifiedProteinGroup mpg, int index)
        {
            item.ImageIndex = index;
            IIdentifiedProtein mp = mpg[index];
            var parts             = new List <string>(this.format.ProteinFormat.GetString(mp).Split(new[] { '\t' }));

            if (item.SubItems.Count != this.proteinColumnIndecies.Count)
            {
                item.SubItems.Clear();
                item.Text = MyConvert.Format("${0}-{1}", mpg.Index, index + 1);
                for (int i = 0; i < proteinColumnIndecies.Count; i++)
                {
                    item.SubItems.Add(parts[proteinColumnIndecies[i]]);
                }
            }
            else
            {
                for (int i = 0; i < proteinColumnIndecies.Count; i++)
                {
                    item.SubItems[i].Text = parts[proteinColumnIndecies[i]];
                }
            }
            item.Checked = option.IsProteinRatioValid(mpg[0]) && !option.IsProteinOutlier(mpg[0]);

            item.Tag = mpg;

            UpdateProteinColor(mpg[index], item);
        }
Пример #3
0
        public void Calculate(IIdentifiedProteinGroup proteinGroup, Func <IIdentifiedSpectrum, bool> validFunc)
        {
            List <IIdentifiedSpectrum> spectra = (from s in proteinGroup[0].GetSpectra()
                                                  where s.GetRatioEnabled() && validFunc(s)
                                                  select s).ToList();

            QuantificationItem item;

            if (spectra.Count == 1)
            {
                item = spectra[0].GetQuantificationItem();
            }
            else if (spectra.Count > 1)
            {
                var sampleIntensities = new List <double>();
                var refIntensities    = new List <double>();

                spectra.ForEach(m =>
                {
                    sampleIntensities.Add(m.GetQuantificationItem().SampleIntensity);
                    refIntensities.Add(m.GetQuantificationItem().ReferenceIntensity);
                });

                var intensities = new double[2][];
                intensities[0] = refIntensities.ToArray();
                intensities[1] = sampleIntensities.ToArray();
                LinearRegressionRatioResult lrrr = LinearRegressionRatioCalculator.CalculateRatio(intensities);

                item             = new QuantificationItem();
                item.Ratio       = lrrr.Ratio;
                item.Correlation = lrrr.RSquare;

                double sampleIntensity, refIntensity;
                if (lrrr.Ratio > 1)
                {
                    sampleIntensity = sampleIntensities.Max();
                    refIntensity    = sampleIntensity / lrrr.Ratio;
                }
                else
                {
                    refIntensity    = refIntensities.Max();
                    sampleIntensity = refIntensity * lrrr.Ratio;
                }

                item.SampleIntensity    = sampleIntensity;
                item.ReferenceIntensity = refIntensity;
                item.Enabled            = true;
            }
            else
            {
                item         = new QuantificationItem();
                item.Enabled = false;
            }

            foreach (IIdentifiedProtein protein in proteinGroup)
            {
                protein.SetQuantificationItem(item);
            }
        }
 private void CalculateProteinRatio(IIdentifiedProteinGroup group, Func <IsobaricItem, double> getSample, string dsName, string channelName, HashSet <string> expNames)
 {
     ratioCalc.GetSample   = getSample;
     ratioCalc.DatasetName = dsName;
     ratioCalc.ChannelName = channelName;
     ratioCalc.Filter      = m => expNames.Contains(m.Query.FileScan.Experimental);
     ratioCalc.Calculate(group);
 }
 public void WriteToStream(StreamWriter sw, IIdentifiedProteinGroup mpg)
 {
     for (int proteinIndex = 0; proteinIndex < mpg.Count; proteinIndex++)
     {
         IIdentifiedProtein mpro = mpg[proteinIndex];
         sw.WriteLine("${0}-{1}{2}",
                      mpg.Index,
                      proteinIndex + 1,
                      ProteinFormat.GetString(mpro));
     }
 }
Пример #6
0
 public void SetUp()
 {
     group = new IdentifiedProteinGroup();
     group.Add(new IdentifiedProtein("SHORT")
     {
         Sequence = shortSeq
     });
     group.Add(new IdentifiedProtein("LONG")
     {
         Sequence = longSeq
     });
 }
Пример #7
0
        public bool Accept(IIdentifiedProteinGroup t)
        {
            foreach (IIdentifiedProteinGroupFilter filter in filters)
            {
                if (!filter.Accept(t))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #8
0
        private void WriteProteinOneLine(StreamWriter sw, IIdentifiedProteinGroup mpg, IdentifiedProteinTextWriter proteinWriter)
        {
            //find user-defined protein
            IIdentifiedProtein filtered = null;

            foreach (Regex reg in this.perferAccessNumberRegexs)
            {
                foreach (IIdentifiedProtein mp in mpg)
                {
                    if (reg.Match(mp.Name).Success)
                    {
                        filtered = mp;
                        break;
                    }
                }
                if (filtered != null)
                {
                    break;
                }
            }

            string name;
            string reference;

            if (filtered != null)
            {
                name      = filtered.Name;
                reference = filtered.Description;
                filtered.UniquePeptideCount = mpg[0].UniquePeptideCount;
            }
            else
            {
                var names = new StringBuilder();
                var refs  = new StringBuilder();
                for (int proteinIndex = 0; proteinIndex < mpg.Count; proteinIndex++)
                {
                    names.Append(" ! ").Append(mpg[proteinIndex].Name);
                    refs.Append(" ! ").Append(mpg[proteinIndex].Description);
                    IIdentifiedProtein mpro = mpg[proteinIndex];
                    mpro.UniquePeptideCount = mpg[0].UniquePeptideCount;
                }

                filtered  = mpg[0];
                name      = names.ToString().Substring(3);
                reference = refs.ToString().Substring(3);
            }

            sw.WriteLine("${0}-1\t{1}\t{2}{3}",
                         mpg.Index,
                         name,
                         reference,
                         proteinWriter.GetString(filtered));
        }
Пример #9
0
        public bool Accept(IIdentifiedProteinGroup t)
        {
            foreach (var p in t)
            {
                var ac = acParser.GetValue(p.Name);
                if (conMap.Contains(ac))
                {
                    return(true);
                }
            }

            return(false);
        }
        public int CompareTo(IIdentifiedProteinGroup other)
        {
            if (this.Count == 0)
            {
                return(1);
            }

            if (other.Count == 0)
            {
                return(-1);
            }
            return(this[0].CompareTo(other[0]));
        }
Пример #11
0
        private IIdentifiedProteinGroup GetGroupContainClassifiedPeptideHitOnly(string keptClassifiedName, IIdentifiedProteinGroup group)
        {
            IIdentifiedProteinGroup result = (IIdentifiedProteinGroup)group.Clone();

            foreach (IIdentifiedProtein protein in result)
            {
                protein.Peptides.RemoveAll(m => !sphc.GetClassification(m).Equals(keptClassifiedName));
                protein.InitUniquePeptideCount();
                protein.CalculateCoverage();
            }

            return(result);
        }
Пример #12
0
 private bool Accept(List <string> acNumbers, IIdentifiedProteinGroup group)
 {
     foreach (var protein in group)
     {
         foreach (var ac in acNumbers)
         {
             if (protein.Name.Contains(ac))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #13
0
 private void WriteProteinMultipleLines(StreamWriter sw, IIdentifiedProteinGroup mpg, IdentifiedProteinTextWriter proteinWriter)
 {
     for (int proteinIndex = 0; proteinIndex < mpg.Count; proteinIndex++)
     {
         IIdentifiedProtein mpro = mpg[proteinIndex];
         mpro.UniquePeptideCount = mpg[0].UniquePeptideCount;
         sw.WriteLine("${0}-{1}\t{2}\t{3}\t{4}",
                      mpg.Index,
                      proteinIndex + 1,
                      mpro.Name,
                      mpro.Description,
                      proteinWriter.GetString(mpro));
     }
 }
Пример #14
0
        protected override void PrintItem(StreamWriter pw, CalculationItem calculationItem)
        {
            IIdentifiedProteinGroup progroup = (IIdentifiedProteinGroup)calculationItem.Key;

            pw.Write(StringUtils.Merge(
                         from p in progroup select parser.GetValue(p.Name),
                         " ! "));

            pw.Write("\t");

            pw.Write(StringUtils.Merge(
                         from p in progroup select p.Description,
                         " ! "));

            PrintClassifiedPeptideCount(pw, calculationItem);
        }
Пример #15
0
        /// <summary>
        /// 输出每次条件下,每个fraction的protein group文件
        /// </summary>
        protected override void ExportIndividualFractionFile()
        {
            DirectoryInfo individualDir = new DirectoryInfo(resultDir.FullName + "\\individual");
            FileInfo      sourceFile    = new FileInfo(option.SourceFileName);

            SequestResultTextFormat writeFormat = GetWriteFormat();

            for (int iMinCount = option.FilterFrom; iMinCount <= option.FilterTo; iMinCount += option.FilterStep)
            {
                List <CalculationItem> currentItems = GetFilteredItems(iMinCount);

                if (!individualDir.Exists)
                {
                    individualDir.Create();
                }

                foreach (string keptClassifiedName in option.GetClassifiedNames())
                {
                    string result_file = MyConvert.Format(@"{0}\{1}.{2}.{3}{4}",
                                                          individualDir.FullName,
                                                          FileUtils.ChangeExtension(sourceFile.Name, ""),
                                                          GetOptionCondition(iMinCount),
                                                          keptClassifiedName,
                                                          sourceFile.Extension);

                    List <IIdentifiedProteinGroup> groups = new List <IIdentifiedProteinGroup>();
                    foreach (var item in currentItems)
                    {
                        if (item.GetClassifiedCount(keptClassifiedName) >= iMinCount)
                        {
                            IIdentifiedProteinGroup group = (IIdentifiedProteinGroup)item.Key;

                            IIdentifiedProteinGroup clonedGroup = GetGroupContainClassifiedPeptideHitOnly(keptClassifiedName, group);

                            groups.Add(clonedGroup);
                        }
                    }

                    IdentifiedResult curResult = new IdentifiedResult();
                    curResult.AddRange(groups);
                    curResult.Sort();

                    writeFormat.WriteToFile(result_file, curResult);
                }
            }
        }
Пример #16
0
        public void WriteToStream(StreamWriter sw, IIdentifiedProteinGroup mpg)
        {
            //find user-defined protein
            foreach (Regex reg in perferAccessNumberRegexs)
            {
                foreach (IIdentifiedProtein mp in mpg)
                {
                    if (reg.Match(mp.Name).Success)
                    {
                        sw.WriteLine("${0}-1{1}", mpg.Index, ProteinFormat.GetString(mp));
                        return;
                    }
                }
            }

            StringBuilder names = new StringBuilder();
            StringBuilder refs  = new StringBuilder();

            for (int proteinIndex = 0; proteinIndex < mpg.Count; proteinIndex++)
            {
                if (proteinIndex != 0)
                {
                    names.Append(" ! ");
                    refs.Append(" ! ");
                }

                names.Append(mpg[proteinIndex].Name);
                refs.Append(mpg[proteinIndex].Description);
            }

            string oldName      = mpg[0].Name;
            string oldReference = mpg[0].Description;

            mpg[0].Name        = names.ToString();
            mpg[0].Description = refs.ToString();
            try
            {
                sw.WriteLine("${0}-1{1}", mpg.Index, ProteinFormat.GetString(mpg[0]));
            }
            finally
            {
                mpg[0].Name        = oldName;
                mpg[0].Description = oldReference;
            }
        }
        public bool Accept(IIdentifiedProteinGroup t)
        {
            var decoy = (from p in t[0].Peptides
                         where p.Spectrum.FromDecoy
                         select p.Spectrum.Query.FileScan.LongFileName).Distinct().Count();
            var target = (from p in t[0].Peptides
                          where !p.Spectrum.FromDecoy
                          select p.Spectrum.Query.FileScan.LongFileName).Distinct().Count();

            if (decoy == 0)
            {
                return(false);
            }

            var tdratio = target * 1.0 / decoy;

            return(tdratio < this.minTargetDecoyRatio);
        }
        public override IEnumerable <string> Process(string fileName)
        {
            var format = new SequestResultTextFormat();

            format.Progress = this.Progress;

            Progress.SetMessage("Reading identified result from " + fileName + " ...");
            IIdentifiedResult ir = format.ReadFromFile(fileName);

            Progress.SetMessage("Removing duplicated peptide ...");
            Progress.SetRange(0, ir.Count);
            for (int i = 0; i < ir.Count; i++)
            {
                Progress.SetPosition(i);
                IIdentifiedProteinGroup    group = ir[i];
                List <IIdentifiedSpectrum> peps  = UniquePeptideDistiller.KeepMaxScorePeptideOnly(group.GetPeptides());
                foreach (var protein in group)
                {
                    protein.Peptides.RemoveAll(m => !peps.Contains(m.Spectrum));
                }
            }

            string resultFileName = fileName + ".unique";

            Progress.SetMessage("Saving proteins to " + resultFileName + " ...");
            format.WriteToFile(resultFileName, ir);

            List <IIdentifiedSpectrum> spectra = ir.GetSpectra();
            var    peptideFormat   = new SequestPeptideTextFormat(format.PeptideFormat.GetHeader());
            string peptideFileName = fileName + ".unique.peptides";

            Progress.SetMessage("Saving peptides to " + peptideFileName + " ...");
            peptideFormat.WriteToFile(peptideFileName, spectra);

            Progress.SetMessage("Finished.");
            return(new[] { resultFileName, peptideFileName });
        }
Пример #19
0
        public override IEnumerable <string> Process(string filename)
        {
            string resultFile = FileUtils.ChangeExtension(filename, "peptides");

            using (IdentifiedProteinGroupEnumerator iter = new IdentifiedProteinGroupEnumerator(filename, true))
            {
                using (StreamWriter sw = new StreamWriter(resultFile))
                {
                    sw.WriteLine(iter.PeptideFormat.GetHeader());
                    HashSet <string> saved          = new HashSet <string>();
                    HashSet <string> uniquepeptides = new HashSet <string>();
                    while (iter.MoveNext())
                    {
                        IIdentifiedProteinGroup    group   = iter.Current;
                        List <IIdentifiedSpectrum> spectra = group[0].GetSpectra();
                        spectra.ForEach(delegate(IIdentifiedSpectrum spectrum)
                        {
                            string dta = spectrum.Query.FileScan.LongFileName;
                            if (!saved.Contains(dta))
                            {
                                saved.Add(dta);
                                uniquepeptides.Add(spectrum.Peptide.PureSequence);
                                sw.WriteLine(iter.PeptideFormat.GetString(spectrum));
                            }
                        });
                    }

                    sw.WriteLine();

                    sw.WriteLine("----- summary -----");
                    sw.WriteLine("Total peptides: {0}", saved.Count);
                    sw.WriteLine("Unique peptides: {0}", uniquepeptides.Count);
                }
            }

            return(new [] { resultFile });
        }
 public static void CalcRatioSignificanceProteinGroups(SilacType type, ICombinedData combinedData, RawFileInfo fileInfo)
 {
     if (type == SilacType.Doublets)
     {
         {
             List <double> lNormRatio = new List <double>();
             List <double> lRatio     = new List <double>();
             List <double> lIntensity = new List <double>();
             List <int>    indices    = new List <int>();
             for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                 double ratio;
                 double normalizedRatio;
                 int    count;
                 double dev;
                 int    nOutliers;
                 double pval;
                 group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval);
                 double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData);
                 if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                 {
                     lNormRatio.Add(Math.Log(normalizedRatio));
                     lRatio.Add(Math.Log(ratio));
                     lIntensity.Add(Math.Log(intensity));
                     indices.Add(i);
                 }
             }
             double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lNormRatio.ToArray(), lIntensity.ToArray(), 1);
             double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lNormRatio.ToArray(), lIntensity.ToArray(), -1);
             for (int i = 0; i < indices.Count; i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                 group.RatioSignificanceA10 = ratioSignificanceA[i];
                 group.RatioSignificanceB10 = ratioSignificanceB[i];
             }
         }
         if (fileInfo.HasExperiment)
         {
             string[] exps = fileInfo.GetAllExperimentValues();
             foreach (string exp in exps)
             {
                 List <double> lratio     = new List <double>();
                 List <double> lIntensity = new List <double>();
                 List <int>    indices    = new List <int>();
                 for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                     double ratio;
                     double normalizedRatio;
                     int    count;
                     double dev;
                     int    nOutliers;
                     double pval;
                     group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers,
                                      fileInfo.GetRawFileIndicesFromExperiment(exp), out pval);
                     double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData);
                     if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                     {
                         lratio.Add(Math.Log(normalizedRatio));
                         lIntensity.Add(Math.Log(intensity));
                         indices.Add(i);
                     }
                 }
                 double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1);
                 double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1);
                 for (int i = 0; i < indices.Count; i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                     group.AddRatioSignificanceA10(exp, ratioSignificanceA[i]);
                     group.AddRatioSignificanceB10(exp, ratioSignificanceB[i]);
                 }
             }
         }
     }
     if (type == SilacType.Triplets)
     {
         {
             List <double> lratio     = new List <double>();
             List <double> lIntensity = new List <double>();
             List <int>    indices    = new List <int>();
             for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                 double ratio;
                 double normalizedRatio;
                 int    count;
                 double dev;
                 int    nOutliers;
                 double pval;
                 group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval);
                 double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) +
                                    group.GetIntensity2(combinedData);
                 if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                 {
                     lratio.Add(Math.Log(normalizedRatio));
                     lIntensity.Add(Math.Log(intensity));
                     indices.Add(i);
                 }
             }
             double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1);
             double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1);
             for (int i = 0; i < indices.Count; i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                 group.RatioSignificanceA10 = ratioSignificanceA[i];
                 group.RatioSignificanceB10 = ratioSignificanceB[i];
             }
         }
         if (fileInfo.HasExperiment)
         {
             string[] exps = fileInfo.GetAllExperimentValues();
             foreach (string exp in exps)
             {
                 List <double> lratio     = new List <double>();
                 List <double> lIntensity = new List <double>();
                 List <int>    indices    = new List <int>();
                 for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                     double ratio;
                     double normalizedRatio;
                     int    count;
                     double dev;
                     int    nOutliers;
                     double pval;
                     group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers,
                                      fileInfo.GetRawFileIndicesFromExperiment(exp), out pval);
                     double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) +
                                        group.GetIntensity2(combinedData);
                     if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                     {
                         lratio.Add(Math.Log(normalizedRatio));
                         lIntensity.Add(Math.Log(intensity));
                         indices.Add(i);
                     }
                 }
                 double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1);
                 double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1);
                 for (int i = 0; i < indices.Count; i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                     group.AddRatioSignificanceA10(exp, ratioSignificanceA[i]);
                     group.AddRatioSignificanceB10(exp, ratioSignificanceB[i]);
                 }
             }
         }
         {
             List <double> lratio     = new List <double>();
             List <double> lIntensity = new List <double>();
             List <int>    indices    = new List <int>();
             for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                 double ratio;
                 double normalizedRatio;
                 int    count;
                 double dev;
                 int    nOutliers;
                 double pval;
                 group.GetRatio20(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval);
                 double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) +
                                    group.GetIntensity2(combinedData);
                 if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                 {
                     lratio.Add(Math.Log(normalizedRatio));
                     lIntensity.Add(Math.Log(intensity));
                     indices.Add(i);
                 }
             }
             double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1);
             double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1);
             for (int i = 0; i < indices.Count; i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                 group.RatioSignificanceA20 = ratioSignificanceA[i];
                 group.RatioSignificanceB20 = ratioSignificanceB[i];
             }
         }
         if (fileInfo.HasExperiment)
         {
             string[] exps = fileInfo.GetAllExperimentValues();
             foreach (string exp in exps)
             {
                 List <double> lratio     = new List <double>();
                 List <double> lIntensity = new List <double>();
                 List <int>    indices    = new List <int>();
                 for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                     double ratio;
                     double normalizedRatio;
                     int    count;
                     double dev;
                     int    nOutliers;
                     double pval;
                     group.GetRatio20(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers,
                                      fileInfo.GetRawFileIndicesFromExperiment(exp), out pval);
                     double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) +
                                        group.GetIntensity2(combinedData);
                     if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                     {
                         lratio.Add(Math.Log(normalizedRatio));
                         lIntensity.Add(Math.Log(intensity));
                         indices.Add(i);
                     }
                 }
                 double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1);
                 double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1);
                 for (int i = 0; i < indices.Count; i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                     group.AddRatioSignificanceA20(exp, ratioSignificanceA[i]);
                     group.AddRatioSignificanceB20(exp, ratioSignificanceB[i]);
                 }
             }
         }
         {
             List <double> lratio     = new List <double>();
             List <double> lIntensity = new List <double>();
             List <int>    indices    = new List <int>();
             for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                 double ratio;
                 double normalizedRatio;
                 int    count;
                 double dev;
                 int    nOutliers;
                 double pval;
                 group.GetRatio21(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval);
                 double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) +
                                    group.GetIntensity2(combinedData);
                 if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                 {
                     lratio.Add(Math.Log(normalizedRatio));
                     lIntensity.Add(Math.Log(intensity));
                     indices.Add(i);
                 }
             }
             double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1);
             double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1);
             for (int i = 0; i < indices.Count; i++)
             {
                 IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                 group.RatioSignificanceA21 = ratioSignificanceA[i];
                 group.RatioSignificanceB21 = ratioSignificanceB[i];
             }
         }
         if (fileInfo.HasExperiment)
         {
             string[] exps = fileInfo.GetAllExperimentValues();
             foreach (string exp in exps)
             {
                 List <double> lratio     = new List <double>();
                 List <double> lIntensity = new List <double>();
                 List <int>    indices    = new List <int>();
                 for (int i = 0; i < combinedData.GetProteinGroupCount(); i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i);
                     double ratio;
                     double normalizedRatio;
                     int    count;
                     double dev;
                     int    nOutliers;
                     double pval;
                     group.GetRatio21(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers,
                                      fileInfo.GetRawFileIndicesFromExperiment(exp), out pval);
                     double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) +
                                        group.GetIntensity2(combinedData);
                     if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0)
                     {
                         lratio.Add(Math.Log(normalizedRatio));
                         lIntensity.Add(Math.Log(intensity));
                         indices.Add(i);
                     }
                 }
                 double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1);
                 double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1);
                 for (int i = 0; i < indices.Count; i++)
                 {
                     IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]);
                     group.AddRatioSignificanceA21(exp, ratioSignificanceA[i]);
                     group.AddRatioSignificanceB21(exp, ratioSignificanceB[i]);
                 }
             }
         }
     }
 }
Пример #21
0
        public override void Update(object sender, UpdateQuantificationItemEventArgs e)
        {
            IQuantificationSummaryOption option = e.Option as IQuantificationSummaryOption;

            panel.InitGraphPane(title, option.Func.ReferenceKey, option.Func.SampleKey, true, 0.0);

            IIdentifiedProteinGroup group = e.Item as IIdentifiedProteinGroup;

            try
            {
                var pplNormal   = new PointPairList();
                var pplSelected = new PointPairList();
                var pplOutlier  = new PointPairList();

                var spectra = group.GetPeptides();

                foreach (var pep in spectra)
                {
                    if (option.IsPeptideRatioValid(pep))
                    {
                        PointPairList ppl;
                        if (pep.Selected)
                        {
                            ppl = pplSelected;
                        }
                        else if (option.IsPeptideOutlier(pep))
                        {
                            ppl = pplOutlier;
                        }
                        else
                        {
                            ppl = pplNormal;
                        }

                        double sampleIntensity = option.Func.GetSampleIntensity(pep);
                        double refIntensity    = option.Func.GetReferenceIntensity(pep);
                        ppl.Add(refIntensity, sampleIntensity);
                        ppl[ppl.Count - 1].Tag = pep;

                        Debug.Assert(ppl[ppl.Count - 1].Tag == pep);
                    }
                }

                this.panel.ClearData();

                this.panel.AddPoints(pplSelected, SelectedColor);

                this.panel.AddPoints(pplNormal, NormalColor);

                this.panel.AddPoints(pplOutlier, OutlierColor);

                var pplTotal = new PointPairList();
                pplTotal.AddRange(pplSelected);
                pplTotal.AddRange(pplNormal);
                pplTotal.AddRange(pplOutlier);

                if (pplTotal.Count > 0)
                {
                    var maxValue = (from p in pplTotal
                                    select Math.Max(p.X, p.Y)).Max() * 1.1;

                    this.panel.XAxis.Scale.Max = maxValue;
                    this.panel.YAxis.Scale.Max = maxValue;

                    var ratio = option.GetProteinRatio(group[0]);

                    PointPairList line = pplTotal.GetRegressionLine(ratio);

                    var lineItem = this.panel.AddCurve(option.GetProteinRatioDescription(group[0]), line, RegressionLineColor, SymbolType.None);
                    lineItem.Label.FontSpec = new FontSpec()
                    {
                        Size = 15, Border = new Border()
                        {
                            IsVisible = false
                        }
                    };
                }
            }
            finally
            {
                ZedGraphicExtension.UpdateGraph(this.zgcGraph);
            }
        }
Пример #22
0
        protected override IEnumerable <string> DoProcess(string filename, List <string> result, Dictionary <IFilter <IIdentifiedSpectrum>, SpectrumEntry> map)
        {
            string database = filename + ".fasta";

            if (!File.Exists(database))
            {
                throw new Exception("Fasta file not exists : " + database);
            }

            IAccessNumberParser           acParser = AccessNumberParserFactory.GuessParser(database);
            Dictionary <string, Sequence> seqMap   = DatabaseUtils.GetAccessNumberMap(database, acParser);

            try
            {
                using (IdentifiedProteinGroupEnumerator iter = new IdentifiedProteinGroupEnumerator(filename))
                {
                    foreach (IFilter <IIdentifiedSpectrum> filter in map.Keys)
                    {
                        SpectrumEntry entry = map[filter];
                        entry.ResultWriter.WriteLine(iter.ProteinFormat.GetHeader());
                        entry.ResultWriter.WriteLine(iter.PeptideFormat.GetHeader());
                    }

                    while (iter.MoveNext())
                    {
                        IIdentifiedProteinGroup group = iter.Current;

                        List <IIdentifiedSpectrum> spectra = group[0].GetSpectra();

                        foreach (IFilter <IIdentifiedSpectrum> filter in map.Keys)
                        {
                            SpectrumEntry entry = map[filter];
                            entry.Spectra.Clear();

                            foreach (IIdentifiedSpectrum spectrum in spectra)
                            {
                                if (filter.Accept(spectrum))
                                {
                                    entry.Spectra.Add(spectrum);
                                }
                            }

                            if (entry.Spectra.Count > 0)
                            {
                                for (int i = 0; i < group.Count; i++)
                                {
                                    entry.ResultWriter.WriteLine("${0}-{1}{2}", group.Index, i + 1, iter.ProteinFormat.GetString(group[i]));

                                    string   ac  = acParser.GetValue(group[i].Name);
                                    Sequence seq = seqMap[ac];
                                    entry.FastaWriter.WriteLine(">" + seq.Reference);
                                    entry.FastaWriter.WriteLine(seq.SeqString);
                                }

                                foreach (IIdentifiedSpectrum spectrum in entry.Spectra)
                                {
                                    entry.ResultWriter.WriteLine(iter.PeptideFormat.GetString(spectrum));
                                }
                            }
                        }
                    }

                    return(result);
                }
            }
            finally
            {
                foreach (SpectrumEntry entry in map.Values)
                {
                    entry.Dispose();
                }
            }
        }
Пример #23
0
 public bool Accept(IIdentifiedProteinGroup t)
 {
     return(t[0].UniquePeptideCount > 1 || t[0].Peptides.Count >= peptideCount);
 }
Пример #24
0
        public QuantificationItem Calculate(IIdentifiedProteinGroup proteinGroup, Func <IIdentifiedSpectrum, bool> validFunc)
        {
            List <IIdentifiedSpectrum> spectra = (from s in proteinGroup[0].GetSpectra()
                                                  where s.IsEnabled(true) && validFunc(s)
                                                  select s).ToList();

            if (spectra.Count == 1)
            {
                var item = spectra[0].GetQuantificationItem();
                return(new QuantificationItem()
                {
                    Enabled = true,
                    Ratio = item.Ratio,
                    Correlation = item.Correlation,
                    SampleIntensity = item.SampleIntensity,
                    ReferenceIntensity = item.ReferenceIntensity
                });
            }

            if (spectra.Count > 1)
            {
                var sampleIntensities = new List <double>();
                var refIntensities    = new List <double>();

                spectra.ForEach(m =>
                {
                    sampleIntensities.Add(m.GetQuantificationItem().SampleIntensity);
                    refIntensities.Add(m.GetQuantificationItem().ReferenceIntensity);
                });

                var intensities = new double[2][];
                intensities[0] = refIntensities.ToArray();
                intensities[1] = sampleIntensities.ToArray();
                LinearRegressionRatioResult lrrr = LinearRegressionRatioCalculator.CalculateRatio(intensities);

                double sampleIntensity, refIntensity;
                if (lrrr.Ratio > 1)
                {
                    sampleIntensities.Sort();
                    sampleIntensity = sampleIntensities[sampleIntensities.Count - 1];
                    refIntensity    = sampleIntensity / lrrr.Ratio;
                }
                else
                {
                    refIntensities.Sort();
                    refIntensity    = refIntensities[refIntensities.Count - 1];
                    sampleIntensity = refIntensity * lrrr.Ratio;
                }

                return(new QuantificationItem()
                {
                    Enabled = true,
                    Ratio = lrrr.Ratio,
                    Correlation = lrrr.RSquare,
                    SampleIntensity = sampleIntensity,
                    ReferenceIntensity = refIntensity
                });
            }

            return(new QuantificationItem()
            {
                Enabled = false
            });
        }
 public void Calculate(IIdentifiedProteinGroup proteinGroup, Func <IIdentifiedSpectrum, bool> validFunc)
 {
     DoCalculate(proteinGroup, validFunc, true);
 }
        public override void Update(object sender, UpdateQuantificationItemEventArgs e)
        {
            IExtendQuantificationSummaryOption option = e.Option as IExtendQuantificationSummaryOption;
            string xTitle = string.Format("Log({0})", option.Func.ReferenceKey);
            string yTitle = string.Format("Log({0})", option.Func.SampleKey);

            panel.InitGraphPane(title, xTitle, yTitle, true, 0.0);

            IIdentifiedProteinGroup group = e.Item as IIdentifiedProteinGroup;

            try
            {
                Dictionary <string, List <PointPairList> > pplMap = new Dictionary <string, List <PointPairList> >();

                var pplNormal   = new PointPairList();
                var pplSelected = new PointPairList();
                var pplOutlier  = new PointPairList();

                var spectra = group.GetPeptides();

                foreach (var pep in spectra)
                {
                    if (pep.IsEnabled(true) && option.IsPeptideRatioValid(pep))
                    {
                        var key = option.GetPeptideClassification(pep);

                        if (!pplMap.ContainsKey(key))
                        {
                            var lst = new List <PointPairList>();
                            pplMap[key] = lst;
                            lst.Add(new PointPairList()); //selected
                            lst.Add(new PointPairList()); //outlier
                            lst.Add(new PointPairList()); //normal
                        }

                        var ppls = pplMap[key];

                        PointPairList ppl;
                        if (pep.Selected)
                        {
                            ppl = ppls[0];
                        }
                        else if (option.IsPeptideOutlier(pep))
                        {
                            ppl = ppls[1];
                        }
                        else
                        {
                            ppl = ppls[2];
                        }

                        double refIntensity    = option.Func.GetReferenceIntensity(pep);
                        double sampleIntensity = option.Func.GetSampleIntensity(pep);
                        ppl.Add(refIntensity, sampleIntensity);
                        ppl[ppl.Count - 1].Tag = pep;

                        Debug.Assert(ppl[ppl.Count - 1].Tag == pep);
                    }
                }

                this.panel.ClearData();

                foreach (var key in pplMap.Keys)
                {
                    var ppls = pplMap[key];
                    this.panel.AddPoints(ppls[0], SelectedColor);

                    this.panel.AddPoints(ppls[1], NormalColor);

                    this.panel.AddPoints(ppls[2], OutlierColor);

                    var pplTotal = new PointPairList();
                    pplTotal.AddRange(ppls[0]);
                    pplTotal.AddRange(ppls[1]);
                    pplTotal.AddRange(ppls[2]);

                    if (pplTotal.Count > 0)
                    {
                        PointPairList line = ZedGraphicExtension.GetRegressionLine(pplTotal, option.GetProteinRatio(group[0], key));

                        var lineItem = this.panel.AddCurve(option.GetProteinRatioDescription(group[0], key), line, RegressionLineColor, SymbolType.None);
                        lineItem.Label.FontSpec = new FontSpec()
                        {
                            Size = 15, Border = new Border()
                            {
                                IsVisible = false
                            }
                        };
                    }
                }
            }
            finally
            {
                ZedGraphicExtension.UpdateGraph(this.zgcGraph);
            }
        }
Пример #27
0
 public bool Accept(IIdentifiedProteinGroup t)
 {
     return(t.Any(m => conRegex.Match(m.Reference).Success));
 }
Пример #28
0
        public override void Update(object sender, UpdateQuantificationItemEventArgs e)
        {
            IQuantificationSummaryOption option = e.Option as IQuantificationSummaryOption;

            panel.InitGraphPane(title, option.Func.ReferenceKey, option.Func.SampleKey, true, 0.0);

            IIdentifiedProteinGroup group = e.Item as IIdentifiedProteinGroup;

            try
            {
                var pplNormal   = new PointPairList();
                var pplSelected = new PointPairList();

                var spectra = group.GetPeptides();

                var format = new O18QuantificationSummaryItemXmlFormat();

                foreach (var pep in spectra)
                {
                    if (pep.IsEnabled(true) && option.IsPeptideRatioValid(pep))
                    {
                        string ratioFile = GetRatioFile(option, pep);
                        if (ratioFile == null)
                        {
                            continue;
                        }

                        O18QuantificationSummaryItem item = new O18QuantificationSummaryItemXmlFormat().ReadFromFile(ratioFile);
                        item.CalculateIndividualAbundance();

                        PointPairList ppl;
                        if (pep.Selected)
                        {
                            ppl = pplSelected;
                        }
                        else
                        {
                            ppl = pplNormal;
                        }

                        foreach (var envelope in item.ObservedEnvelopes)
                        {
                            if (!envelope.Enabled)
                            {
                                continue;
                            }

                            double refIntensity    = envelope.SampleAbundance.O16;
                            double sampleIntensity = envelope.SampleAbundance.O18;

                            if (refIntensity == 0.0 || sampleIntensity == 0.0)
                            {
                                continue;
                            }

                            ppl.Add(refIntensity, sampleIntensity);
                            ppl[ppl.Count - 1].Tag = pep;

                            Debug.Assert(ppl[ppl.Count - 1].Tag == pep);
                        }
                    }
                }
                this.panel.ClearData();

                this.panel.AddPoints(pplSelected, SelectedColor);

                this.panel.AddPoints(pplNormal, NormalColor);

                var pplTotal = new PointPairList();
                pplTotal.AddRange(pplSelected);
                pplTotal.AddRange(pplNormal);

                if (pplTotal.Count > 0)
                {
                    var maxValue = (from p in pplTotal
                                    select Math.Max(p.X, p.Y)).Max() * 1.1;

                    this.panel.XAxis.Scale.Max = maxValue;
                    this.panel.YAxis.Scale.Max = maxValue;

                    var ratio = option.GetProteinRatio(group[0]);

                    PointPairList line = pplTotal.GetRegressionLine(ratio);

                    var lineItem = this.panel.AddCurve(option.GetProteinRatioDescription(group[0]), line, RegressionLineColor, SymbolType.None);
                    lineItem.Label.FontSpec = new FontSpec()
                    {
                        Size = 15, Border = new Border()
                        {
                            IsVisible = false
                        }
                    };
                }
            }
            finally
            {
                ZedGraphicExtension.UpdateGraph(this.zgcGraph);
            }
        }
 public void SetUp()
 {
   group = new IdentifiedProteinGroup();
   group.Add(new IdentifiedProtein("SHORT") { Sequence = shortSeq });
   group.Add(new IdentifiedProtein("LONG") { Sequence = longSeq });
 }
        private WaitingEntry DoCalculate(IIdentifiedProteinGroup proteinGroup, Func <IIdentifiedSpectrum, bool> validFunc, bool runRImmediately)
        {
            List <IIdentifiedSpectrum> spectra = (from s in proteinGroup[0].GetSpectra()
                                                  where validFunc(s) && s.IsEnabled(true) && HasPeptideRatio(s)
                                                  select s).ToList();

            if (spectra.Count == 1)
            {
                var r = CalculatePeptideRatio(spectra[0]);
                foreach (var protein in proteinGroup)
                {
                    protein.SetEnabled(true);

                    protein.Annotations[O18QuantificationConstants.O18_RATIO] = new LinearRegressionRatioResult(r, 0.0)
                    {
                        PointCount = 1, FCalculatedValue = 0, FProbability = 1
                    };
                    protein.Annotations[this.intensityFunc.ReferenceKey] = spectra[0].Annotations[this.intensityFunc.ReferenceKey];
                    protein.Annotations[this.intensityFunc.SampleKey]    = spectra[0].Annotations[this.intensityFunc.SampleKey];
                }
                return(null);
            }
            else if (spectra.Count > 1)
            {
                var intensities = this.intensityFunc.ConvertToArray(spectra);

                double maxSam = intensities[0].Max();
                double maxRef = intensities[1].Max();

                LinearRegressionRatioResult ratioResult;

                if (maxSam == 0.0)
                {
                    ratioResult = new LinearRegressionRatioResult(20, 0.0)
                    {
                        PointCount = intensities.Count(), FCalculatedValue = 0, FProbability = 0
                    };
                    maxSam = maxRef / ratioResult.Ratio;
                }
                else
                {
                    if (maxRef == 0.0)
                    {
                        ratioResult = new LinearRegressionRatioResult(0.05, 0.0)
                        {
                            PointCount = intensities.Count(), FCalculatedValue = 0, FProbability = 0
                        };
                    }
                    else
                    {
                        var dd       = this.SummaryFileDirectory + "/" + this.DetailDirectory + "/";
                        var filename = (dd + proteinGroup[0].Name.Replace("|", "_") + ".csv").Replace("\\", "/");

                        PrepareIntensityFile(spectra, filename);

                        if (!runRImmediately)
                        {
                            return(new WaitingEntry()
                            {
                                Group = proteinGroup,
                                IntensityFile = filename,
                                MaxReference = maxRef,
                                MaxSample = maxSam
                            });
                        }

                        var linearfile = filename + ".linear";
                        var rfile      = filename + ".r";
                        using (StreamWriter sw = new StreamWriter(rfile))
                        {
                            sw.WriteLine(string.Format(
                                             @"require(MASS)

data<-read.csv(""{0}"")
yxPCA<-PcaHubert(~0+SamIntensity+RefIntensity, data=data)
r<-yxPCA@loadings[1,1]/yxPCA@loadings[2,1]

df<-data.frame(Ratio=r)
colnames(df)<-c(""Ratio"")
write.csv(df,""{1}"")
", filename, linearfile));
                        }

                        new RProcessor(rExecute, rfile, linearfile).Process();

                        ratioResult = new LinearRegressionRatioResult();
                        var parts = File.ReadAllLines(linearfile).Skip(1).First().Split(',');
                        ratioResult.Ratio            = double.Parse(parts[1]);
                        ratioResult.RSquare          = 0;
                        ratioResult.FCalculatedValue = 0;
                        ratioResult.FProbability     = 0;
                    }
                    maxRef = maxSam * ratioResult.Ratio;
                }

                foreach (IIdentifiedProtein protein in proteinGroup)
                {
                    protein.SetEnabled(true);

                    protein.Annotations[O18QuantificationConstants.O18_RATIO] = ratioResult;
                    protein.Annotations[this.intensityFunc.ReferenceKey]      = maxRef;
                    protein.Annotations[this.intensityFunc.SampleKey]         = maxSam;
                }
            }
            else
            {
                foreach (IIdentifiedProtein protein in proteinGroup)
                {
                    protein.SetEnabled(false);
                    protein.Annotations.Remove(O18QuantificationConstants.O18_RATIO);
                    protein.Annotations.Remove(this.intensityFunc.ReferenceKey);
                    protein.Annotations.Remove(this.intensityFunc.SampleKey);
                }
            }
            return(null);
        }
Пример #31
0
 public bool Accept(IIdentifiedProteinGroup t)
 {
     return(acceptFunc(t));
 }