Exemplo n.º 1
0
        /// <summary>
        /// Serializes the contents of a single <see cref="TransitionGroupDocNode"/>
        /// to XML.
        /// </summary>
        /// <param name="writer">The XML writer</param>
        /// <param name="nodePep">The parent peptide document node</param>
        /// <param name="node">The transition group document node</param>
        private void WriteTransitionGroupXml(XmlWriter writer, PeptideDocNode nodePep, TransitionGroupDocNode node)
        {
            TransitionGroup group       = node.TransitionGroup;
            var             isCustomIon = nodePep.Peptide.IsCustomMolecule;

            writer.WriteAttribute(ATTR.charge, group.PrecursorAdduct.AdductCharge);
            if (!group.LabelType.IsLight)
            {
                writer.WriteAttribute(ATTR.isotope_label, group.LabelType);
            }
            if (!isCustomIon)
            {
                writer.WriteAttribute(ATTR.calc_neutral_mass, node.GetPrecursorIonPersistentNeutralMass());
            }
            writer.WriteAttribute(ATTR.precursor_mz, SequenceMassCalc.PersistentMZ(node.PrecursorMz));
            WriteExplicitTransitionGroupValuesAttributes(writer, node.ExplicitValues);

            writer.WriteAttribute(ATTR.auto_manage_children, node.AutoManageChildren, true);
            writer.WriteAttributeNullable(ATTR.decoy_mass_shift, group.DecoyMassShift);
            writer.WriteAttributeNullable(ATTR.precursor_concentration, node.PrecursorConcentration);


            TransitionPrediction predict = Settings.TransitionSettings.Prediction;
            double regressionMz          = Settings.GetRegressionMz(nodePep, node);
            var    ce = predict.CollisionEnergy.GetCollisionEnergy(node.TransitionGroup.PrecursorAdduct, regressionMz);

            writer.WriteAttribute(ATTR.collision_energy, ce);

            var dpRegression = predict.DeclusteringPotential;

            if (dpRegression != null)
            {
                var dp = dpRegression.GetDeclustringPotential(regressionMz);
                writer.WriteAttribute(ATTR.declustering_potential, dp);
            }

            if (!isCustomIon)
            {
                // modified sequence
                var calcPre = Settings.GetPrecursorCalc(node.TransitionGroup.LabelType, nodePep.ExplicitMods);
                var seq     = node.TransitionGroup.Peptide.Target;
                writer.WriteAttribute(ATTR.modified_sequence, calcPre.GetModifiedSequence(seq,
                                                                                          false)); // formatNarrow = false; We want InvariantCulture, not the local format
                Assume.IsTrue(group.PrecursorAdduct.IsProteomic);
            }
            else
            {
                // Custom ion
                node.CustomMolecule.WriteXml(writer, group.PrecursorAdduct);
            }
            // Write child elements
            WriteAnnotations(writer, node.Annotations);
            if (node.HasLibInfo)
            {
                var helpers = PeptideLibraries.SpectrumHeaderXmlHelpers;
                writer.WriteElements(new[] { node.LibInfo }, helpers);
            }

            if (node.HasResults)
            {
                WriteResults(writer, Settings, node.Results,
                             EL.precursor_results, EL.precursor_peak, WriteTransitionGroupChromInfo);
            }

            if (UseCompactFormat())
            {
                writer.WriteStartElement(EL.transition_data);
                var transitionData = new SkylineDocumentProto.Types.TransitionData();
                transitionData.Transitions.AddRange(node.Transitions.Select(transition => transition.ToTransitionProto(Settings)));
                byte[] bytes = transitionData.ToByteArray();
                writer.WriteBase64(bytes, 0, bytes.Length);
                writer.WriteEndElement();
                if (WroteTransitions != null)
                {
                    WroteTransitions(node.TransitionCount);
                }
            }
            else
            {
                foreach (TransitionDocNode nodeTransition in node.Children)
                {
                    writer.WriteStartElement(EL.transition);
                    WriteTransitionXml(writer, nodePep, node, nodeTransition);
                    writer.WriteEndElement();
                }
            }
        }