Example #1
0
        public void ReadXml(XmlReader reader)
        {
            // Read start tag attributes
            ExcludeNTermAAs = reader.GetIntAttribute(ATTR.start);
            MinPeptideLength = reader.GetIntAttribute(ATTR.min_length);
            MaxPeptideLength = reader.GetIntAttribute(ATTR.max_length);
            AutoSelect = reader.GetBoolAttribute(ATTR.auto_select);

            var list = new List<PeptideExcludeRegex>();

            // Consume tag
            if (reader.IsEmptyElement)
                reader.Read();
            else
            {
                reader.ReadStartElement();
                // Read child elements
                reader.ReadElementList(EL.peptide_exclusions, list);
                reader.ReadEndElement();
            }

            Exclusions = list;

            DoValidate();
        }
Example #2
0
        public void ReadXml(XmlReader reader)
        {
            var list = new List<TypedModifications>();
            var internalStandardTypes = new[] {IsotopeLabelType.heavy};

            MaxVariableMods = reader.GetIntAttribute(ATTR.max_variable_mods, DEFAULT_MAX_VARIABLE_MODS);
            MaxNeutralLosses = reader.GetIntAttribute(ATTR.max_neutral_losses, DEFAULT_MAX_NEUTRAL_LOSSES);

            // Consume tag
            if (reader.IsEmptyElement)
            {
                list.Add(new TypedModifications(IsotopeLabelType.light, new StaticMod[0]));
                reader.Read();
            }
            else
            {
                var internalStandardNames = new List<string>();
                string internalStandardName = reader.GetAttribute(ATTR.internal_standard);

                reader.ReadStartElement();

                if (internalStandardName != null)
                {
                    if (internalStandardName == IsotopeLabelType.NONE_NAME)
                        internalStandardTypes = new IsotopeLabelType[0];
                    else
                        internalStandardNames.Add(internalStandardName);
                }
                else
                {
                    while (reader.IsStartElement(EL.internal_standard))
                    {
                        internalStandardNames.Add(reader.GetAttribute(ATTR.name));
                        reader.Read();
                    }
                }

                if (internalStandardNames.Count > 0)
                    internalStandardTypes = new IsotopeLabelType[internalStandardNames.Count];

                SetInternalStandardType(IsotopeLabelType.light, internalStandardNames, internalStandardTypes);

                // Read child elements
                var listMods = new List<StaticMod>();
                reader.ReadElementList(EL.static_modifications, listMods);
                list.Add(new TypedModifications(IsotopeLabelType.light, listMods));
                int typeOrder = IsotopeLabelType.FirstHeavy;
                while (reader.IsStartElement(EL.heavy_modifications))
                {
                    // If first heavy tag has no isotope_label attribute, use the default heavy type
                    var labelType = IsotopeLabelType.heavy;
                    string typeName = reader.GetAttribute(ATTR.isotope_label);
                    if (!string.IsNullOrEmpty(typeName))
                    {
                        labelType = new IsotopeLabelType(typeName, typeOrder);
                        if (Equals(labelType, IsotopeLabelType.heavy))
                            labelType = IsotopeLabelType.heavy;
                        // If the created label type is going to be used and there are serialization
                        // context modifications, try to use the label types from the context.
                        else if (_serializationContext != null)
                        {
                            var modsContext = _serializationContext.GetModificationsByName(typeName);
                            if (modsContext != null)
                            {
                                // CONSIDER: Should this require full equality, including order?
                                labelType = modsContext.LabelType;
                            }
                        }
                    }
                    else if (typeOrder > IsotopeLabelType.FirstHeavy)
                    {
                        throw new InvalidDataException(
                            string.Format(Resources.PeptideModifications_ReadXml_Heavy_modifications_found_without__0__attribute,
                                          ATTR.isotope_label));
                    }
                    typeOrder++;

                    SetInternalStandardType(labelType, internalStandardNames, internalStandardTypes);

                    // If no internal standard type was given, use the first heavy type.
                    if (internalStandardNames.Count == 0 && internalStandardTypes.Length != 0)
                    {
                        internalStandardNames.Add(labelType.Name);
                        internalStandardTypes = new[] {labelType};
                    }
                    listMods = new List<StaticMod>();
                    reader.ReadElementList(EL.heavy_modifications, listMods);

                    list.Add(new TypedModifications(labelType, listMods));
                }
                int iMissingType = internalStandardTypes.IndexOf(labelType => labelType == null);
                if (iMissingType != -1)
                {
                    throw new InvalidDataException(string.Format(Resources.PeptideModifications_ReadXml_Internal_standard_type__0__not_found,
                                                                 internalStandardNames[iMissingType]));
                }
                reader.ReadEndElement();
            }

            if (list.Count < 2)
                list.Add(new TypedModifications(IsotopeLabelType.heavy, new StaticMod[0]));

            _modifications = MakeReadOnly(list.ToArray());
            InternalStandardTypes = internalStandardTypes;

            DoValidate();
        }