void AddCodonsToExtension(Extension e, XmlElement el) { foreach (object o in el.ChildNodes) { if (!(o is XmlElement)) { continue; } XmlElement curEl = (XmlElement)o; switch (curEl.Name) { default: //默认为一个代码子节点如:<MenuItem>,<Pad>,等等 //先创佳一个代码子对象 ICodon codon = AddInTreeSingleton.AddInTree.CodonFactory.CreateCodon(this, curEl); //为一个代码子对象中的所有字段赋值,值从Xml节点CurEl中读取 AutoInitializeAttributes(codon, curEl); if (codon.InsertAfter == null && codon.InsertBefore == null && e.CodonCollection.Count > 0) { codon.InsertAfter = new string[] { ((ICodon)e.CodonCollection[e.CodonCollection.Count - 1]).ID }; } //最后将当前代码子对象添加到代码子集合中 e.CodonCollection.Add(codon); //下面是,如果当前节点有子节点(如<MenuItem>节点中有子<MenuItem>节点),则对子节点进行递归操作 if (curEl.ChildNodes.Count > 0) { Extension newExtension = new Extension(e.Path + '/' + codon.ID); AddCodonsToExtension(newExtension, curEl); extensions.Add(newExtension); } break; } } }
/// <summary> /// Converts the specified ICodon to a signed integer with a max value of the specified maxValue. /// </summary> /// <param name="codon"></param> /// <param name="maxValue"></param> /// <returns></returns> protected IConvertedCodon ConvertCodonToSignedInteger(ICodon codon, int maxValue) { // Don't process the first INucleotide because we will use it as our // "signed" position to indicate whether the int is positive or negative var value = 0; var actualNucleotidePosition = 1; for (var digitPlace = codon.Count - 2; digitPlace >= 0; digitPlace--) { var baseValueAtDigitPlace = GetBaseValueAtDigitPlace(digitPlace, this.Parent.Nucleotides.Count); var nucleotideValue = this.GetValueOfNucleotide(codon[actualNucleotidePosition]); value += baseValueAtDigitPlace * nucleotideValue; actualNucleotidePosition++; } // Determine if the int is positive or negative based on the "signed" place var signedValue = this.GetValueOfNucleotide(codon[0]); var isNegative = signedValue < (this.Parent.Nucleotides.Count / 2); value = value > maxValue ? value % maxValue : value; return new ConvertedCodon(isNegative ? -value : value); }
/// <summary> /// Converts the given ICodon to an IConvertedCodon. /// </summary> /// <param name="codon"></param> /// <returns></returns> public abstract IConvertedCodon ConvertCodon(ICodon codon);
void AddCodonsToExtension(Extension e, XmlElement el, ConditionCollection conditions) { foreach (object o in el.ChildNodes) { if (!(o is XmlElement)) { continue; } XmlElement curEl = (XmlElement)o; switch (curEl.Name) { case "And": // these nodes are silently ignored. case "Or": case "Not": case "Condition": break; case "Conditional": ICondition condition = null; // 若当前条件结点的属性个数为零或者(个数为1并且包含action属性), //则说明当前条件结点为一个复合逻辑条件(即该条件由一些and,or等条件组成) if (curEl.Attributes.Count == 0 || (curEl.Attributes.Count == 1 && curEl.Attributes["FailedAction"] != null)) { condition = BuildComplexCondition(curEl); // set condition action manually if (curEl.Attributes["FailedAction"] != null) { condition.FailedAction = (ConditionFailedAction)Enum.Parse(typeof(ConditionFailedAction), curEl.Attributes["FailedAction"].InnerText); } if (condition == null) { throw new AddInTreeFormatException("empty conditional, but no condition definition found."); } } else { //当前条件结点为一个简单条件结点,该条件结点不会包含<Or>,<And>等子结点 condition = AddInTreeSingleton.AddInTree.ConditionFactory.CreateCondition(this, curEl); AutoInitializeAttributes(condition, curEl); } // put the condition at the end of the condition 'stack' conditions.Add(condition); // traverse the subtree AddCodonsToExtension(e, curEl, conditions); // now we are back to the old level, remove the condition // that was applied to the subtree. conditions.RemoveAt(conditions.Count - 1); break; default: ICodon codon = AddInTreeSingleton.AddInTree.CodonFactory.CreateCodon(this, curEl); AutoInitializeAttributes(codon, curEl); // Ensure that the codon is inserted after the codon which is defined // before in the add-in definition. // The codons get topologically sorted and if I don't set the InsertAfter they may // change it's sorting order. e.Conditions[codon.ID] = new ConditionCollection(conditions); if (codon.InsertAfter == null && codon.InsertBefore == null && e.CodonCollection.Count > 0) { codon.InsertAfter = new string[] { ((ICodon)e.CodonCollection[e.CodonCollection.Count - 1]).ID }; } e.CodonCollection.Add(codon); if (curEl.ChildNodes.Count > 0) { Extension newExtension = new Extension(e.Path + '/' + codon.ID); AddCodonsToExtension(newExtension, curEl, conditions); extensions.Add(newExtension); } break; } } }
internal static object ParseCommandId(ICodon codon) { string id = codon.ID; if (id.StartsWith ("@")) return id.Substring (1); Type enumType = null; string typeName = id; int i = id.LastIndexOf ("."); if (i != -1) typeName = id.Substring (0,i); enumType = codon.AddIn.GetType (typeName); if (enumType == null) enumType = Type.GetType (typeName); if (enumType == null) enumType = typeof(Command).Assembly.GetType (typeName); if (enumType == null || !enumType.IsEnum) throw new InvalidOperationException ("Could not find an enum type for the command '" + id + "'."); try { return Enum.Parse (enumType, id.Substring (i+1)); } catch { throw new InvalidOperationException ("Could not find an enum value for the command '" + id + "'."); } }
protected AminoAcidBase(ICodon codon) { this.Codon = codon; }
public override void AddCodon(ICodon codon) { this.AddCodon((IGEPCodon) codon); }
/// <summary> /// Converts an ICodon to a signed 5-bit integer (max value of 31) /// </summary> /// <param name="codon"></param> /// <returns></returns> public override IConvertedCodon ConvertCodon(ICodon codon) { return base.ConvertCodonToSignedInteger(codon: codon, maxValue: 31); }
/// <summary> /// Converts the specified ICodon using the specified ICodonConverterIdentifier. /// </summary> /// <param name="codon"></param> /// <param name="codonConverterIdentifier"></param> /// <returns></returns> public IConvertedCodon ConvertCodon(ICodon codon, ICodonConverterIdentifier codonConverterIdentifier) { return this.CodonConverters[codonConverterIdentifier].ConvertCodon(codon); }
/// <summary> /// Adds the specified ICodon to the IGeneticCode. /// </summary> /// <param name="codon"></param> public abstract void AddCodon(ICodon codon);
/// <summary> /// Converts the specified ICodon to a signed float with a max value of the specified maxValue and can have a /// maximum of "wholeNumberDigits" digits to the left of the decimal point. /// </summary> /// <param name="codon"></param> /// <param name="maxValue">The maximum value of the resulting signed float.</param> /// <param name="wholeNumberDigits">The number of digits to the left of the decimal place that the resulting float can potentially have.</param> /// <returns></returns> protected IConvertedCodon ConvertCodonToSignedFloat(ICodon codon, int maxValue, int wholeNumberDigits) { // We will add 1 digit to account for the "signed" position at the start of the ICodon. // The rest of the digit places will be beyond the decimal point. var nucleotidesBeforeDecimalPoint = wholeNumberDigits + 1; var minimumCodonLength = nucleotidesBeforeDecimalPoint + 1; if (this.Parent.CodonLength < minimumCodonLength) throw new CodonConverterException("The current CodonNumberConverterBase requires that the parent IGeneticCode have ICodons with a minimum length of " + minimumCodonLength + " INucleotides."); var value = 0f; // Process the "whole" numbers that are after the "signed" place var actualNucleotidePosition = 1; for (var digitPlace = nucleotidesBeforeDecimalPoint - (this.Parent.CodonLength - nucleotidesBeforeDecimalPoint); digitPlace >= 0; digitPlace--) { var baseValueAtDigitPlace = GetBaseValueAtDigitPlace(digitPlace, this.Parent.Nucleotides.Count); var nucleotideValue = this.GetValueOfNucleotide(codon[actualNucleotidePosition]); value += baseValueAtDigitPlace * nucleotideValue; actualNucleotidePosition++; } // Process the "decimal" numbers that are after the decimal point. for (var digitPlace = 1; digitPlace <= this.Parent.CodonLength - nucleotidesBeforeDecimalPoint; digitPlace++) { var baseValueAtDigitPlace = 1f / GetBaseValueAtDigitPlace(digitPlace, this.Parent.Nucleotides.Count); var nucleotideValue = this.GetValueOfNucleotide(codon[actualNucleotidePosition]); value += baseValueAtDigitPlace * nucleotideValue; actualNucleotidePosition++; } // Determine if the float is positive or negative based on the "signed" place var signedValue = this.GetValueOfNucleotide(codon[0]); var isNegative = signedValue < (this.Parent.Nucleotides.Count / 2); //value = value > float.MaxValue ? float.MaxValue : value; value = value > maxValue ? value % maxValue : value; return new ConvertedCodon(isNegative ? -value : value); }
public bool Equals(ICodon other) { return this.CodonIdentifier.Equals(other.CodonIdentifier); }
public int CompareTo(ICodon other) { return this.CodonIdentifier.CompareTo(other.CodonIdentifier); }