コード例 #1
0
        public override void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            base.ReadXml(reader);
            Fragment = reader.GetAttribute(ATTR.cut);
            if (IsFragment)
            {
                Restrict          = reader.GetAttribute(ATTR.no_cut);
                Terminus          = reader.GetAttribute(ATTR.sense, ToSeqTerminus);
                MinFragmentLength = reader.GetNullableIntAttribute(ATTR.min_length) ??
                                    DEFAULT_MIN_FRAGMENT_LENGTH;
            }
            else
            {
                var charges = TextUtil.ParseInts(reader.GetAttribute(ATTR.charges)); // Old version?
                if (charges.Length > 1)
                {
                    throw new InvalidDataException(Resources.MeasuredIon_ReadXml_Multiple_charge_states_for_custom_ions_are_no_longer_supported_);
                }
                var    parsedIon = CustomIon.Deserialize(reader);
                Adduct adduct;
                if (charges.Any())  // Old style - fix it up a little for our revised ideas about custom ion ionization
                {
                    adduct = Adduct.FromChargeNoMass(charges[0]);
                    if (string.IsNullOrEmpty(parsedIon.NeutralFormula)) // Adjust the user-supplied masses
                    {
                        SettingsCustomIon = new SettingsCustomIon(parsedIon.NeutralFormula, adduct,
                                                                  Math.Round(parsedIon.MonoisotopicMass + charges[0] * BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.H), SequenceMassCalc.MassPrecision), // Assume user provided neutral mass.  Round new value easiest XML roundtripping.
                                                                  Math.Round(parsedIon.AverageMass + charges[0] * BioMassCalc.AVERAGE.GetMass(BioMassCalc.H), SequenceMassCalc.MassPrecision),           // Assume user provided neutral mass.  Round new value easiest XML roundtripping.
                                                                  parsedIon.Name);
                    }
                    else // Adjust the formula to include ion atoms
                    {
                        if (charges[0] > 1) // XML deserializer will have added an H already
                        {
                            var adductProtonated = Adduct.FromChargeProtonated(charges[0] - 1);
                            var formula          = adductProtonated.ApplyToFormula(parsedIon.NeutralFormula);
                            parsedIon = new CustomIon(formula, adduct, parsedIon.MonoisotopicMass, parsedIon.AverageMass, Name);
                        }
                    }
                }
                else
                {
                    adduct = Adduct.FromStringAssumeChargeOnly(reader.GetAttribute(ATTR.charge)); // Ionization mass is already in formula
                }
                if (SettingsCustomIon == null)
                {
                    SettingsCustomIon = new SettingsCustomIon(parsedIon.NeutralFormula, adduct,
                                                              parsedIon.MonoisotopicMass,
                                                              parsedIon.AverageMass,
                                                              parsedIon.Name);
                }
                IsOptional = reader.GetBoolAttribute(ATTR.optional);
            }
            // Consume tag
            reader.Read();

            Validate();
        }
コード例 #2
0
 /// <summary>
 /// Constructor for a reporter ion
 /// </summary>
 /// <param name="name">The name by which it is stored in the settings list</param>
 /// <param name="formula">Chemical formula of the ion</param>
 /// <param name="monoisotopicMass">Constant monoisotopic mass of the ion, if formula is not given</param>
 /// <param name="averageMass">Constant average mass of the ion, if formula is not given</param>
 /// <param name="adduct">The charge for this custom ion</param>
 /// <param name="isOptional">Whether or not the reporter ion will automatically be added to all proteins</param>
 public MeasuredIon(string name,
                    string formula,
                    double?monoisotopicMass,
                    double?averageMass,
                    Adduct adduct,
                    bool isOptional = false)
     : base(name)
 {
     SettingsCustomIon = new SettingsCustomIon(formula, adduct, monoisotopicMass, averageMass, name);
     IsOptional        = isOptional;
     Validate();
 }
コード例 #3
0
 /// <summary>
 /// Constructor for a reporter ion
 /// </summary>
 /// <param name="name">The name by which it is stored in the settings list</param>
 /// <param name="formula">Chemical formula of the ion</param>
 /// <param name="monoisotopicMass">Constant monoisotopic mass of the ion, if formula is not given</param>
 /// <param name="averageMass">Constant average mass of the ion, if formula is not given</param>
 /// <param name="charge">The charge for this custom ion</param>
 /// <param name="isOptional">Whether or not the reporter ion will automatically be added to all proteins</param>
 public MeasuredIon(string name,
                    string formula,
                    double?monoisotopicMass,
                    double?averageMass,
                    int charge,
                    bool isOptional = false)
     : base(name)
 {
     SettingsCustomIon = new SettingsCustomIon(formula, monoisotopicMass, averageMass, name); // Like a custom ion, but returns false for IsEditableInstance
     Charge            = charge;
     IsOptional        = isOptional;
     Validate();
 }
コード例 #4
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = base.GetHashCode();
         result = (result * 397) ^ (Fragment != null ? Fragment.GetHashCode() : 0);
         result = (result * 397) ^ (Restrict != null ? Restrict.GetHashCode() : 0);
         result = (result * 397) ^ (Terminus.HasValue ? Terminus.Value.GetHashCode() : 0);
         result = (result * 397) ^ (MinFragmentLength.HasValue ? MinFragmentLength.Value : 0);
         result = (result * 397) ^ (SettingsCustomIon != null ? SettingsCustomIon.GetHashCode() : 0);
         result = (result * 397) ^ Charge;
         result = (result * 397) ^ IsOptional.GetHashCode();
         return(result);
     }
 }
コード例 #5
0
        public override void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            base.ReadXml(reader);
            Fragment = reader.GetAttribute(ATTR.cut);
            if (IsFragment)
            {
                Restrict          = reader.GetAttribute(ATTR.no_cut);
                Terminus          = reader.GetAttribute(ATTR.sense, ToSeqTerminus);
                MinFragmentLength = reader.GetNullableIntAttribute(ATTR.min_length) ??
                                    DEFAULT_MIN_FRAGMENT_LENGTH;
            }
            else
            {
                var charges = TextUtil.ParseInts(reader.GetAttribute(ATTR.charges)); // Old version?
                if (charges.Count() > 1)
                {
                    throw new InvalidDataException(Resources.MeasuredIon_ReadXml_Multiple_charge_states_for_custom_ions_are_no_longer_supported_);
                }
                SettingsCustomIon = SettingsCustomIon.Deserialize(reader);
                if (charges.Any())  // Old style - fix it up a little for our revised ideas about custom ion ionization
                {
                    Charge = charges[0];
                    if (string.IsNullOrEmpty(SettingsCustomIon.Formula)) // Adjust the user-supplied masses
                    {
                        SettingsCustomIon = new SettingsCustomIon(SettingsCustomIon.Formula,
                                                                  Math.Round(SettingsCustomIon.MonoisotopicMass + BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.H), SequenceMassCalc.MassPrecision), // Assume user provided neutral mass.  Round new value easiest XML roundtripping.
                                                                  Math.Round(SettingsCustomIon.AverageMass + BioMassCalc.AVERAGE.GetMass(BioMassCalc.H), SequenceMassCalc.MassPrecision),           // Assume user provided neutral mass.  Round new value easiest XML roundtripping.
                                                                  SettingsCustomIon.Name);
                    }
                }
                else
                {
                    Charge = reader.GetIntAttribute(ATTR.charge);
                }
                IsOptional = reader.GetBoolAttribute(ATTR.optional);
            }
            // Consume tag
            reader.Read();

            Validate();
        }
コード例 #6
0
ファイル: MeasuredIon.cs プロジェクト: lgatto/proteowizard
        public override void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            base.ReadXml(reader);
            Fragment = reader.GetAttribute(ATTR.cut);
            if (IsFragment)
            {
                Restrict = reader.GetAttribute(ATTR.no_cut);
                Terminus = reader.GetAttribute(ATTR.sense, ToSeqTerminus);
                MinFragmentLength = reader.GetNullableIntAttribute(ATTR.min_length) ??
                    DEFAULT_MIN_FRAGMENT_LENGTH;
            }
            else
            {
                var charges = TextUtil.ParseInts(reader.GetAttribute(ATTR.charges)); // Old version?
                if (charges.Count() > 1)
                    throw new InvalidDataException(Resources.MeasuredIon_ReadXml_Multiple_charge_states_for_custom_ions_are_no_longer_supported_);
                SettingsCustomIon = SettingsCustomIon.Deserialize(reader);
                if (charges.Any())  // Old style - fix it up a little for our revised ideas about custom ion ionization
                {
                    Charge = charges[0];
                    if (string.IsNullOrEmpty(SettingsCustomIon.Formula)) // Adjust the user-supplied masses
                    {
                        SettingsCustomIon = new SettingsCustomIon(SettingsCustomIon.Formula,
                            Math.Round(SettingsCustomIon.MonoisotopicMass + BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.H), SequenceMassCalc.MassPrecision), // Assume user provided neutral mass.  Round new value easiest XML roundtripping.
                            Math.Round(SettingsCustomIon.AverageMass + BioMassCalc.AVERAGE.GetMass(BioMassCalc.H), SequenceMassCalc.MassPrecision), // Assume user provided neutral mass.  Round new value easiest XML roundtripping.
                            SettingsCustomIon.Name);
                    }
                }
                else
                {
                    Charge = reader.GetIntAttribute(ATTR.charge);
                }
                IsOptional = reader.GetBoolAttribute(ATTR.optional);
            }
            // Consume tag
            reader.Read();

            Validate();
        }
コード例 #7
0
ファイル: MeasuredIon.cs プロジェクト: lgatto/proteowizard
 /// <summary>
 /// Constructor for a reporter ion
 /// </summary>
 /// <param name="name">The name by which it is stored in the settings list</param>
 /// <param name="formula">Chemical formula of the ion</param>
 /// <param name="monoisotopicMass">Constant monoisotopic mass of the ion, if formula is not given</param>
 /// <param name="averageMass">Constant average mass of the ion, if formula is not given</param>
 /// <param name="charge">The charge for this custom ion</param>
 /// <param name="isOptional">Whether or not the reporter ion will automatically be added to all proteins</param>
 public MeasuredIon(string name,
     string formula,
     double? monoisotopicMass,
     double? averageMass,
     int charge,
     bool isOptional = false)
     : base(name)
 {
     SettingsCustomIon = new SettingsCustomIon(formula, monoisotopicMass, averageMass, name); // Like a custom ion, but returns false for IsEditableInstance
     Charge = charge;
     IsOptional = isOptional;
     Validate();
 }