private void WriteSpectra(PhosphoRSOutput output)
        {
            _writer.WriteStartElement("Spectra");

            output.Spectra.ForEach(spectrum =>
            {
                _writer.WriteStartElement("Spectrum");
                _writer.WriteAttributeString("ID", spectrum.ID.ToString());
                _writer.WriteAttributeString("Name", spectrum.Name?.ToString());
                _writer.WriteAttributeString("PrecursorCharge", spectrum.PrecursorCharge.ToString());
                _writer.WriteAttributeString("ActivationType", spectrum.ActivationType.ToString());

                _writer.WriteStartElement("Peptides");
                spectrum.Peptides.ForEach(peptide =>
                {
                    _writer.WriteStartElement("Peptide");
                    _writer.WriteAttributeString("ID", peptide.ID.ToString());

                    _writer.WriteStartElement("SitePrediction");
                    peptide.SitePrediction.ForEach(site =>
                    {
                        _writer.WriteStartElement("Site");
                        _writer.WriteAttributeString("SeqPos", site.Position.ToString());
                        _writer.WriteAttributeString("SiteProb", site.Probability.ToString());
                        _writer.WriteEndElement();
                    });
                    _writer.WriteEndElement();

                    _writer.WriteStartElement("Isoforms");
                    peptide.Isoforms.ForEach(isoform =>
                    {
                        _writer.WriteStartElement("Isoform");
                        _writer.WriteAttributeString("ID", isoform.ID.ToString());
                        _writer.WriteAttributeString("PepScore", isoform.Score.ToString());
                        _writer.WriteAttributeString("PepProb", isoform.Probability.ToString());

                        _writer.WriteStartElement("PhosphoSites");
                        isoform.Sites.ForEach(site =>
                        {
                            _writer.WriteStartElement("PhosphoSite");
                            _writer.WriteAttributeString("SeqPos", site.ToString());
                            _writer.WriteEndElement();
                        });
                        _writer.WriteEndElement();

                        _writer.WriteEndElement();
                    });
                    _writer.WriteEndElement();

                    _writer.WriteEndElement();
                });
                _writer.WriteEndElement();

                _writer.WriteEndElement();
            });

            _writer.WriteEndElement();
        }
        public void Write(PhosphoRSOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var s = JsonConvert.SerializeObject(output, Formatting.Indented);

            _writer.Write(s);
        }
        public void Write(PhosphoRSOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _writer.WriteRow(
                "Spectrum.ID",
                "Spectrum.Name",
                "Spectrum.PrecursorCharge",
                "Spectrum.ActivationType",
                "Peptide.ID",
                "Peptide.Sequence",
                "Peptide.SitePrediction",
                "Isoform.ID",
                "Isoform.Sites",
                "Isoform.Score",
                "Isoform.Probability"
                );

            string SitePredictionToString(Wrapper.PeptideResult peptide)
            {
                return(string.Join(
                           " ",
                           peptide.SitePrediction
                           .Select(site => $"{peptide.Sequence[site.Position - 1]}{site.Position}({site.Probability.ToString("0.###")})")
                           ));
            }

            output.Spectra.ForEach(spectrum =>
            {
                spectrum.Peptides.ForEach(peptide =>
                {
                    peptide.Isoforms.ForEach(isoform =>
                    {
                        _writer.WriteRow(new string[] {
                            spectrum.ID.ToString(),
                            spectrum.Name,
                            spectrum.PrecursorCharge.ToString(),
                            spectrum.ActivationType.ToString(),
                            peptide.ID.ToString(),
                            peptide.Sequence,
                            SitePredictionToString(peptide),
                            isoform.ID.ToString(),
                            string.Join(" ", isoform.Sites.Select(site => $"{peptide.Sequence[site - 1]}{site}")),
                            isoform.Score.ToString(),
                            isoform.Probability.ToString()
                        });
                    });
                });
            });
        }
        public void Write(PhosphoRSOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _writer.WriteStartDocument();
            _writer.WriteStartElement("PhosphoRS_Results");

            WriteGlobalParameters(output);

            WriteSpectra(output);

            _writer.WriteEndElement();
            _writer.WriteEndDocument();
        }
        private void WriteGlobalParameters(PhosphoRSOutput output)
        {
            _writer.WriteStartElement("GlobalParameters");

            _writer.WriteStartElement("MassTolerance");
            _writer.WriteAttributeString("Value", output.Options.MassTolerance.ToString());
            _writer.WriteEndElement();

            _writer.WriteStartElement("Modifications");
            output.Modifications.ForEach(modification =>
            {
                _writer.WriteStartElement("Modification");
                _writer.WriteAttributeString("ID", modification.Symbol.ToString());
                _writer.WriteAttributeString("Name", modification.Name.ToString());
                _writer.WriteAttributeString("MassDelta", modification.MassDelta.ToString());
                _writer.WriteEndElement();
            });
            _writer.WriteEndElement();

            _writer.WriteStartElement("Phosphorylation");
            _writer.WriteAttributeString("ID", output.Options.PhosphorylationSymbol.ToString());
            _writer.WriteEndElement();

            _writer.WriteStartElement("MaxIsoformCount");
            _writer.WriteAttributeString("Value", output.Options.MaxIsoformCount.ToString());
            _writer.WriteEndElement();

            _writer.WriteStartElement("MaxPTMCount");
            _writer.WriteAttributeString("Value", output.Options.MaxPTMCount.ToString());
            _writer.WriteEndElement();

            _writer.WriteStartElement("ScoreNeutralLoss");
            _writer.WriteAttributeString("Value", output.Options.ScoreNeutralLoss.ToString());
            _writer.WriteEndElement();

            _writer.WriteEndElement();
        }