Exemplo n.º 1
0
        private List <IIdentifiedSpectrum> DuplicateSpectrum(List <IIdentifiedSpectrum> spectra, string detailDir)
        {
            List <IIdentifiedSpectrum> result = new List <IIdentifiedSpectrum>();

            Dictionary <string, List <string> > rawmap = new Dictionary <string, List <string> >();

            foreach (var raws in rawpairs.Values)
            {
                foreach (var raw in raws)
                {
                    rawmap[raw] = raws;
                }
            }

            var format = new MascotPeptideTextFormat();

            foreach (var spectrum in spectra)
            {
                if (spectrum.HasRatio())
                {
                    var silacFile    = spectrum.GetRatioFile(detailDir);
                    var silacResult  = new SilacQuantificationSummaryItemXmlFormat().ReadFromFile(silacFile);
                    var maxIntensity = silacResult.ObservedEnvelopes.Max(m => Math.Max(m.LightIntensity, m.HeavyIntensity));
                    var scan         = silacResult.ObservedEnvelopes.Find(m => m.LightIntensity == maxIntensity || m.HeavyIntensity == maxIntensity).Scan;

                    var str    = format.PeptideFormat.GetString(spectrum);
                    var oldraw = spectrum.Query.FileScan.Experimental;
                    var lst    = rawmap[oldraw];
                    foreach (var otherraw in lst)
                    {
                        if (otherraw.Equals(oldraw))
                        {
                            continue;
                        }

                        var newspectrum = format.PeptideFormat.ParseString(str);
                        newspectrum.Query.FileScan.Experimental = otherraw;
                        newspectrum.Query.FileScan.FirstScan    = scan;
                        newspectrum.Query.FileScan.LastScan     = scan;
                        newspectrum.SetExtendedIdentification(true);

                        result.Add(newspectrum);
                        spectrum.AddDuplicatedSpectrum(newspectrum);
                    }
                }
            }

            return(result);
        }
        public override void Update(object sender, UpdateQuantificationItemEventArgs e)
        {
            IQuantificationSummaryOption option = e.Option as IQuantificationSummaryOption;

            panel.InitGraphPane(this.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 SilacQuantificationSummaryItemXmlFormat();

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

                        var item = format.ReadFromFile(ratioFile);

                        Func <SilacPeakListPair, double> getSamIntensity;
                        Func <SilacPeakListPair, double> getRefIntensity;

                        if (item.SampleIsLight)
                        {
                            getSamIntensity = m => m.LightIntensity;
                            getRefIntensity = m => m.HeavyIntensity;
                        }
                        else
                        {
                            getSamIntensity = m => m.HeavyIntensity;
                            getRefIntensity = m => m.LightIntensity;
                        }

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

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

                            double refIntensity    = getRefIntensity(envelope);
                            double sampleIntensity = getSamIntensity(envelope);

                            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           lr      = pplTotal.GetRegression();
                    var           lr_text = MyConvert.Format("Ratio={0:0.00}, Correl={1:0.00}, FValue={2:0.00}, FProb={3:E4}", lr.Ratio, lr.RSquare, lr.TValue, lr.PValue);
                    PointPairList line    = pplTotal.GetRegressionLine();

                    var lineItem = this.panel.AddCurve(lr_text, line, RegressionLineColor, SymbolType.None);
                    lineItem.Label.FontSpec = new FontSpec()
                    {
                        Size = 15, Border = new Border()
                        {
                            IsVisible = false
                        }
                    };
                }
            }
            finally
            {
                ZedGraphicExtension.UpdateGraph(this.zgcGraph);
            }
        }