public override object ReadRatioFile(string file)
 {
     return(format.ReadFromFile(file));
 }
        public void WriteToStream(System.IO.StreamWriter sw, IIdentifiedSpectrum peptide)
        {
            string detailFile = this.detailDirectory + "\\" + peptide.GetQuantificationItem().Filename;

            if (File.Exists(detailFile))
            {
                SilacQuantificationSummaryItem item = format.ReadFromFile(detailFile);

                Func <SilacPeakListPair, double> SampleIntensityFunc;
                Func <SilacPeakListPair, double> ReferenceIntensityFunc;

                if (item.SampleIsLight)
                {
                    SampleIntensityFunc    = m => m.LightIntensity;
                    ReferenceIntensityFunc = m => m.HeavyIntensity;
                }
                else
                {
                    SampleIntensityFunc    = m => m.HeavyIntensity;
                    ReferenceIntensityFunc = m => m.LightIntensity;
                }

                var valueFuncs = new List <Func <SilacPeakListPair, string> >();
                foreach (var header in headers)
                {
                    switch (header)
                    {
                    case "Scan": valueFuncs.Add(m => string.Format("{0}", m.Scan));
                        break;

                    case "Retentiontime": valueFuncs.Add(m => string.Format("{0:0.00}", m.Light.ScanTimes[0].RetentionTime));
                        break;

                    case "Identified": valueFuncs.Add(m => m.IsIdentified.ToString());
                        break;

                    case QuantificationItem.KEY_REFERENCE_INTENSITY: valueFuncs.Add(m => string.Format("{0:0.0}", ReferenceIntensityFunc(m)));
                        break;

                    case QuantificationItem.KEY_SAMPLE_INTENSITY: valueFuncs.Add(m => string.Format("{0:0.0}", SampleIntensityFunc(m)));
                        break;

                    case QuantificationItem.KEY_RATIO: valueFuncs.Add(m => string.Format("{0:0.0000}", SampleIntensityFunc(m) / ReferenceIntensityFunc(m)));
                        break;

                    case "Protein": valueFuncs.Add(m => peptide.GetProteins("/"));
                        break;
                    }
                    ;
                }

                foreach (var scan in item.ObservedEnvelopes)
                {
                    if (scan.Enabled)
                    {
                        var ri = ReferenceIntensityFunc(scan);
                        var si = SampleIntensityFunc(scan);
                        if (ri == 0.0 || si == 0.0)
                        {
                            continue;
                        }

                        sw.Write("\t");
                        foreach (var func in valueFuncs)
                        {
                            sw.Write("\t{0}", func(scan));
                        }
                        sw.WriteLine();
                    }
                }
            }
        }
        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);
            }
        }