public void ShouldReturnVariant2() { // Arrange var v1 = new VariantDefinition("a", 33, new Payload("string", "asd"), new Collection <VariantOverride>()); var v2 = new VariantDefinition("b", 33); var v3 = new VariantDefinition("c", 34); var toggle = new FeatureToggle( "test.variants", "release", true, new List <ActivationStrategy> { defaultStrategy }, new List <VariantDefinition> { v1, v2, v3 }); var context = new UnleashContext { UserId = "163", SessionId = "sessionId", RemoteAddress = "remoteAddress", Properties = new Dictionary <string, string>() }; // Act var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT); // Assert variant.Name.Should().Be(v2.Name); }
public IVariant[] CreateVariants(IChromosome chromosome, int start, int end, string refAllele, string[] altAlleles, IInfoData infoData, bool[] isDecomposed, bool isRecomposed, List <string>[] linkedVids, string globalMajorAllele) { string firstAltAllele = altAlleles[0]; bool isReference = globalMajorAllele != null; bool isSymbolicAllele = IsSymbolicAllele(firstAltAllele); var variantCategory = GetVariantCategory(firstAltAllele, isReference, isSymbolicAllele, infoData.SvType); if (isReference) { return new[] { GetVariant(chromosome, start, end, refAllele, firstAltAllele, infoData, variantCategory, isDecomposed[0], isRecomposed, linkedVids?[0]?.ToArray(), globalMajorAllele) } } ; _sequenceProvider.LoadChromosome(chromosome); var variants = new List <IVariant>(); for (var i = 0; i < altAlleles.Length; i++) { #if (!NI_ALLELE) if (VcfCommon.IsNonInformativeAltAllele(altAlleles[i])) { continue; } #endif bool isDecomposedVar = isDecomposed[i]; (int shiftedStart, string shiftedRef, string shiftedAlt) = VariantUtils.TrimAndLeftAlign(start, refAllele, altAlleles[i], _sequenceProvider.Sequence); variants.Add(GetVariant(chromosome, shiftedStart, end - (start - shiftedStart), shiftedRef, shiftedAlt, infoData, variantCategory, isDecomposedVar, isRecomposed, linkedVids?[i]?.ToArray(), null)); } return(variants.Count == 0 ? null : variants.ToArray()); }
/// <summary> /// Extracts a dbSNP item from the specified VCF line. /// </summary> /// <param name="vcfLine"></param> /// <returns></returns> public IEnumerable <DbSnpItem> ExtractItem(string vcfLine) { var splitLine = vcfLine.Split('\t', 6); if (splitLine.Length < 5) { yield break; } var chromosomeName = splitLine[VcfCommon.ChromIndex]; if (!_sequenceProvider.RefNameToChromosome.ContainsKey(chromosomeName)) { yield break; } var chromosome = _sequenceProvider.RefNameToChromosome[chromosomeName]; var position = int.Parse(splitLine[VcfCommon.PosIndex]); var dbSnpId = Convert.ToInt64(splitLine[VcfCommon.IdIndex].Substring(2)); var refAllele = splitLine[VcfCommon.RefIndex]; var altAlleles = splitLine[VcfCommon.AltIndex].OptimizedSplit(','); foreach (var altAllele in altAlleles) { var(shiftedPos, shiftedRef, shiftedAlt) = VariantUtils.TrimAndLeftAlign(position, refAllele, altAllele, _sequenceProvider.Sequence); yield return(new DbSnpItem(chromosome, shiftedPos, dbSnpId, shiftedRef, shiftedAlt)); } }
/// <summary> /// Attempts to parse a method call with format MethodId(Args) /// </summary> static public bool TryParse(StringSlice inData, out MethodCall outMethodCall) { int openParenIdx = inData.IndexOf('('); int closeParenIdx = inData.LastIndexOf(')'); if (openParenIdx <= 0 || closeParenIdx <= 0 || closeParenIdx <= openParenIdx) { outMethodCall = default(MethodCall); return(false); } StringSlice methodSlice = inData.Substring(0, openParenIdx).Trim(); if (!VariantUtils.IsValidIdentifier(methodSlice)) { outMethodCall = default(MethodCall); return(false); } StringSlice afterMethod = inData.Substring(closeParenIdx + 1); if (!afterMethod.IsWhitespace) { outMethodCall = default(MethodCall); return(false); } int argsLength = closeParenIdx - 1 - openParenIdx; outMethodCall.Id = methodSlice.Hash32(); outMethodCall.Args = inData.Substring(openParenIdx + 1, argsLength).Trim(); return(true); }
public void Recreate() { VariantUtils.SetDrawersForKnownTypes(); _drawerList = new ReorderableList ( Parameters, typeof(Parameter), true, false, true, true ); DrawerList.drawHeaderCallback += rect => { rect.x += ReorderableListOffset; rect.width -= ReorderableListOffset; var original = rect; rect.width *= 0.5f; GUI.Label(rect, "Name"); rect.x = original.x + rect.width; rect.width = VariantUtils.FieldWidth; GUI.Label(rect, "Value"); }; if (!CustomAdd) { DrawerList.onAddDropdownCallback += OnAddParameter; } DrawerList.drawElementCallback += OnDrawParameter; }
internal IEnumerable <OneKGenItem> ExtractItems(string vcfLine) { var splitLine = vcfLine.OptimizedSplit('\t');// we don't care about the many fields after info field if (splitLine.Length < 8) { yield break; } Clear(); var chromosomeName = splitLine[VcfCommon.ChromIndex]; if (!_refNameDictionary.ContainsKey(chromosomeName)) { yield break; } var chromosome = _refNameDictionary[chromosomeName]; var position = int.Parse(splitLine[VcfCommon.PosIndex]);//we have to get it from RSPOS in info var refAllele = splitLine[VcfCommon.RefIndex]; var altAlleles = splitLine[VcfCommon.AltIndex].OptimizedSplit(','); var infoFields = splitLine[VcfCommon.InfoIndex]; // parses the info fields and extract frequencies, ancestral allele, allele counts, etc. var hasSymbolicAllele = altAlleles.Any(x => x.OptimizedStartsWith('<') && x.OptimizedEndsWith('>')); if (hasSymbolicAllele) { yield break; } // ReSharper disable once ConditionIsAlwaysTrueOrFalse ParseInfoField(infoFields, hasSymbolicAllele); for (var i = 0; i < altAlleles.Length; i++) { var(shiftedPos, shiftedRef, shiftedAlt) = VariantUtils.TrimAndLeftAlign(position, refAllele, altAlleles[i], _sequenceProvider.Sequence); yield return(new OneKGenItem( chromosome, shiftedPos, shiftedRef, shiftedAlt, _ancestralAllele, GetAlleleCount(_allAlleleCounts, i), GetAlleleCount(_afrAlleleCounts, i), GetAlleleCount(_amrAlleleCounts, i), GetAlleleCount(_eurAlleleCounts, i), GetAlleleCount(_easAlleleCounts, i), GetAlleleCount(_sasAlleleCounts, i), _allAlleleNumber, _afrAlleleNumber, _amrAlleleNumber, _eurAlleleNumber, _easAlleleNumber, _sasAlleleNumber )); } }
public void Left_align_insertion(int position, string altAllele, int rotatedPos, string rotatedAlt) { var reference = new SimpleSequence(new string('A', VariantUtils.MaxUpstreamLength) + "ATGTGTTGTTATTCTGTGTGCAT"); var rotatedVariant = VariantUtils.TrimAndLeftAlign(position, "", altAllele, reference); Assert.Equal(rotatedPos, rotatedVariant.start); Assert.Equal(rotatedAlt, rotatedVariant.altAllele); }
public void Left_align_multiple_padding_bases() { var reference = new SimpleSequence(new string('A', VariantUtils.MaxUpstreamLength) + "ATGTGTTGTTATTCTGTGTGCAT"); var rotatedVariant = VariantUtils.TrimAndLeftAlign(501, "AT", "ATT", reference); Assert.Equal(502, rotatedVariant.start); Assert.Equal("T", rotatedVariant.altAllele); }
private void OnDrawParameter(Rect rect, int index, bool active, bool focused) { var parameter = TreeAsset.Parameters[index]; rect.height = VariantUtils.FieldHeight; rect.y += 2; VariantUtils.DrawParameter(rect, parameter.Value); }
private Variant GetVariant(string toggleName, UnleashContext context, Variant defaultValue) { var toggle = GetToggle(toggleName); var enabled = CheckIsEnabled(toggleName, context, false); var variant = enabled ? VariantUtils.SelectVariant(toggle, context, defaultValue) : defaultValue; RegisterVariant(toggleName, variant); return(variant); }
private void ParameterDraw(Rect rect, SerializedProperty element, GUIContent label, int index, bool selected, bool focused) { var param = element.GetAs <Framework.Parameter>(); if (param != null) { VariantUtils.DrawParameter(rect, param.Value); } else { GUI.Label(rect, "Unable to render as Parameter!"); } }
private void GenericParameterDrawer(Rect rect, SerializedProperty element, GUIContent label, int index, bool selected, bool focused) { var param = element.GetAs <Variant>(); if (param != null) { VariantUtils.DrawParameter(rect, param); } else { GUI.Label(rect, "Unable to render as Variant!"); } }
private List <AlleleFrequencyItem> ExtractItems(string vcfLine) { var splitLine = vcfLine.Split(new[] { '\t' }, 9);// we don't care about the many fields after info field if (splitLine.Length < 8) { return(null); } Clear(); var chromosomeName = splitLine[VcfCommon.ChromIndex]; if (!_refNameDictionary.ContainsKey(chromosomeName)) { return(null); } var chromosome = _refNameDictionary[chromosomeName]; var position = int.Parse(splitLine[VcfCommon.PosIndex]);//we have to get it from RSPOS in info var refAllele = splitLine[VcfCommon.RefIndex]; var altAlleles = splitLine[VcfCommon.AltIndex].OptimizedSplit(','); var infoFields = splitLine[VcfCommon.InfoIndex]; // parses the info fields and extract frequencies, ancestral allele, allele counts, etc. ParseInfoField(infoFields); if (_allAlleleNumber == null) { return(null); } var items = new List <AlleleFrequencyItem>(); for (var i = 0; i < altAlleles.Length; i++) { var alleleCount = GetAlleleCount(_allAlleleCounts, i); if (alleleCount == null || alleleCount == 0) { continue; } var frequency = 1.0 * alleleCount.Value / _allAlleleNumber.Value; var(shiftedPos, shiftedRef, shiftedAlt) = VariantUtils.TrimAndLeftAlign(position, refAllele, altAlleles[i], _sequenceProvider.Sequence); items.Add(new AlleleFrequencyItem(chromosome, shiftedPos, shiftedRef, shiftedAlt, frequency)); } return(items.Count > 0? items: null); }
private TopMedItem ExtractItems(string vcfLine) { if (vcfLine == null) { return(null); } var splitLine = vcfLine.OptimizedSplit('\t'); if (splitLine.Length < 8) { return(null); } Clear(); // chr1 10169 TOPMed_freeze_5?chr1:10,169 T C 255 SVM VRT=1;NS=62784;AN=125568;AC=20;AF=0.000159276;Het=20;Hom=0 NA:FRQ 125568:0.000159276 var chromosome = splitLine[VcfCommon.ChromIndex]; if (!_refChromDict.ContainsKey(chromosome)) { return(null); } var chrom = _refChromDict[chromosome]; var position = int.Parse(splitLine[VcfCommon.PosIndex]);//we have to get it from RSPOS in info var refAllele = splitLine[VcfCommon.RefIndex]; var altAllele = splitLine[VcfCommon.AltIndex]; var filters = splitLine[VcfCommon.FilterIndex]; var infoFields = splitLine[VcfCommon.InfoIndex]; if (altAllele.Contains(",")) { Console.WriteLine(vcfLine); throw new InvalidDataException("het site found!!"); } var failedFilter = !(filters.Equals("PASS") || filters.Equals(".")); ParseInfoField(infoFields); if (_alleleNum == 0) { return(null); } var(shiftedPos, shiftedRef, shiftedAlt) = VariantUtils.TrimAndLeftAlign(position, refAllele, altAllele, _sequenceProvider.Sequence); return(new TopMedItem(chrom, shiftedPos, shiftedRef, shiftedAlt, _alleleNum, _alleleCount, _homCount, failedFilter)); }
/// <summary> /// Extracts a splice AI item from the specified VCF line. /// </summary> /// <param name="vcfLine"></param> /// <returns></returns> private SpliceAiItem ExtractItem(string vcfLine) { var splitLine = vcfLine.Split('\t'); if (splitLine.Length < VcfCommon.InfoIndex + 1) { return(null); } var chromosomeName = splitLine[VcfCommon.ChromIndex]; if (!_sequenceProvider.RefNameToChromosome.ContainsKey(chromosomeName)) { return(null); } var chromosome = _sequenceProvider.RefNameToChromosome[chromosomeName]; var position = int.Parse(splitLine[VcfCommon.PosIndex]); var refAllele = splitLine[VcfCommon.RefIndex]; var altAllele = splitLine[VcfCommon.AltIndex]; if (altAllele.Contains(',')) { throw new DataException($"multiple alt allele present for {chromosome}-{position}"); } var start = position; //skipping insertions/deletions that were shifted if (VariantUtils.IsLeftShiftPossible(refAllele, altAllele)) { return(null); } (start, refAllele, altAllele) = BiDirectionalTrimmer.Trim(start, refAllele, altAllele); var end = start + refAllele.Length - 1; var isSpliceAdjacent = _spliceIntervals[chromosome.Index].OverlapsAny(start, end); ParseInfoField(splitLine[VcfCommon.InfoIndex]); if (!HasSignificantScore() && !isSpliceAdjacent) { return(null); } Count++; return(new SpliceAiItem(chromosome, start, refAllele, altAllele, _geneSymbol, _acceptorGainScore, _acceptorLossScore, _donorGainScore, _donorLossScore, _acceptorGainPosition, _acceptorLossPosition, _donorGainPosition, _donorLossPosition, isSpliceAdjacent)); }
private List <ClinVarItem> GetValidItems(List <ClinVarItem> clinVarItems) { var shiftedItems = new List <ClinVarItem>(); foreach (var item in clinVarItems) { _sequenceProvider.LoadChromosome(item.Chromosome); if (!ValidateRefAllele(item)) { continue; } string refAllele = item.RefAllele, altAllele = item.AltAllele; if (string.IsNullOrEmpty(item.RefAllele) && item.VariantType == "Deletion") { refAllele = GetReferenceAllele(item, _sequenceProvider.Sequence); } if (string.IsNullOrEmpty(item.RefAllele) && item.VariantType == "Indel" && !string.IsNullOrEmpty(item.AltAllele)) { refAllele = GetReferenceAllele(item, _sequenceProvider.Sequence); } if (string.IsNullOrEmpty(item.AltAllele) && item.VariantType == "Duplication") { altAllele = GetAltAllele(item, _sequenceProvider.Sequence); } if (string.IsNullOrEmpty(refAllele) && string.IsNullOrEmpty(altAllele)) { continue; } int start; (start, refAllele, altAllele) = VariantUtils.TrimAndLeftAlign(item.Position, refAllele, altAllele, _sequenceProvider.Sequence); shiftedItems.Add(new ClinVarItem(item.Chromosome, start, item.Stop, refAllele, altAllele, item.JsonSchema, item.AlleleOrigins, item.VariantType, item.Id, item.VariationId, item.ReviewStatus, item.MedGenIds, item.OmimIds, item.OrphanetIds, item.Phenotypes, item.Significances, item.PubmedIds, item.LastUpdatedDate)); } shiftedItems.Sort(); return(shiftedItems); }
void HandleBindValue(Rect rect, ParamBinding binding) { if (binding == null) { return; } var fieldRect = rect; fieldRect.y += 2; fieldRect.height = EditorGUIUtility.singleLineHeight; VariantUtils.DrawParameter(fieldRect, binding.DefaultValue, false); }
void RecreateDrawer() { VariantUtils.SetDrawersForKnownTypes(); ProxyList = new List <int>(Node.Inputs.Count); DrawerList = new UnityEditorInternal.ReorderableList ( ProxyList, typeof(ActionSelector.EntryPoint), true, false, true, true ); DrawerList.drawHeaderCallback += rect => { rect.x += ParamListDrawer.ReorderableListOffset; rect.width -= ParamListDrawer.ReorderableListOffset; var original = rect; rect.width *= 0.5f; GUI.Label(rect, "Name"); rect.x = original.x + VariantUtils.LabelWidth * 1.35f; rect.width = VariantUtils.FieldWidth; GUI.Label(rect, "Input value"); }; DrawerList.onAddCallback += OnAddInput; DrawerList.drawElementCallback += OnDrawParameter; DrawerList.onCanAddCallback += list => Node.InputType != null && Node.InputType.Type != null; DrawerList.onRemoveCallback += list => { OnRemoveInputAtIndex(list.index); }; DrawerList.onReorderCallbackWithDetails += (list, index, newIndex) => { float pos = Positions[index]; _positions.RemoveAt(index); _positions.Insert(newIndex, pos); OnReorderInputAtIndex(index, newIndex); }; }
void RecreateDrawer() { VariantUtils.SetDrawersForKnownTypes(); /*ProxyList = new List<int>(Graph.Inputs.Count); * * DrawerList = new UnityEditorInternal.ReorderableList * ( * ProxyList, typeof(ActionGraph.EntryPoint), * true, false, true, true * ); * * DrawerList.drawHeaderCallback += rect => * { * rect.x += ParamListDrawer.ReorderableListOffset; * rect.width -= ParamListDrawer.ReorderableListOffset; * * var original = rect; * * rect.width *= 0.5f; * GUI.Label(rect, "Name"); * * * rect.x = original.x + VariantUtils.LabelWidth * 1.35f; * rect.width = VariantUtils.FieldWidth; * GUI.Label(rect, "Input value"); * }; * * DrawerList.onAddCallback += OnAddInput; * * DrawerList.drawElementCallback += OnDrawParameter; * * DrawerList.onCanAddCallback += list => Graph.InputType != null && Graph.InputType.Type != null; * DrawerList.onRemoveCallback += list => * { * Presenter.OnRemoveInputAtIndex(list.index); * }; * * DrawerList.onReorderCallbackWithDetails += (list, index, newIndex) => * { * float pos = Positions[index]; * * _positions.RemoveAt(index); * _positions.Insert(newIndex, pos); * * Presenter.OnReorderInputAtIndex(index, newIndex); * };*/ }
private void OnDrawParameter(Rect rect, int index, bool active, bool focused) { var parameter = Node.Inputs[index]; if (index == 0) { FirstPos = rect.y; } Positions[index] = rect.y - FirstPos; rect.height = VariantUtils.FieldHeight; rect.y += 2; VariantUtils.DrawParameter(rect, parameter.Input); }
private void OnDrawParameter(Rect rect, int index, bool active, bool focused) { var parameter = Parameters[index]; if (index == 0) { FirstPos = rect.y; } Positions.Resize(index + 1); Positions[index] = rect.y - FirstPos; rect.height = VariantUtils.FieldHeight; rect.y += 2; VariantUtils.DrawParameter(rect, parameter.Value); }
private List <AncestralAlleleItem> ExtractItems(string vcfLine) { var splitLine = vcfLine.Split(new[] { '\t' }, 9);// we don't care about the many fields after info field if (splitLine.Length < 8) { return(null); } Clear(); var chromosomeName = splitLine[VcfCommon.ChromIndex]; if (!_refNameDictionary.ContainsKey(chromosomeName)) { return(null); } var chromosome = _refNameDictionary[chromosomeName]; var position = int.Parse(splitLine[VcfCommon.PosIndex]);//we have to get it from RSPOS in info var refAllele = splitLine[VcfCommon.RefIndex]; var altAlleles = splitLine[VcfCommon.AltIndex].OptimizedSplit(','); var infoFields = splitLine[VcfCommon.InfoIndex]; // parses the info fields and extract frequencies, ancestral allele, allele counts, etc. var hasSymbolicAllele = altAlleles.Any(x => x.OptimizedStartsWith('<') && x.OptimizedEndsWith('>')); if (hasSymbolicAllele) { return(null); } // ReSharper disable once ConditionIsAlwaysTrueOrFalse ParseInfoField(infoFields); var ancestralAlleleItems = new List <AncestralAlleleItem>(); foreach (string altAllele in altAlleles) { var(shiftedPos, shiftedRef, shiftedAlt) = VariantUtils.TrimAndLeftAlign(position, refAllele, altAllele, _sequenceProvider.Sequence); ancestralAlleleItems.Add(new AncestralAlleleItem(chromosome, shiftedPos, shiftedRef, shiftedAlt, _ancestralAllele)); } return(ancestralAlleleItems); }
public static void UpdateChromToPositions(Dictionary <IChromosome, List <int> > chromPositions, IChromosome chromosome, int position, string refAllele, string altAllele, ISequence refSequence) { if (!chromPositions.ContainsKey(chromosome)) { chromPositions.Add(chromosome, new List <int>(16 * 1024)); } foreach (string allele in altAllele.OptimizedSplit(',')) { if (allele.OptimizedStartsWith('<') || allele.Contains('[') || altAllele.Contains(']')) { continue; } (int shiftedPos, string _, string _) = VariantUtils.TrimAndLeftAlign(position, refAllele, allele, refSequence); chromPositions[chromosome].Add(shiftedPos); } }
public IVariant[] CreateVariants(IChromosome chromosome, int start, int end, string refAllele, string[] altAlleles, IInfoData infoData, bool[] isDecomposedByAllele, bool isRecomposed, List <string>[] linkedVids, string globalMajorAllele) { bool isReference = globalMajorAllele != null; if (isReference) { return(ReferenceVariantCreator.Create(_vidCreator, _sequence, chromosome, start, end, refAllele, altAlleles[0], globalMajorAllele)); } var variantCategory = GetVariantCategory(altAlleles[0], infoData.SvType); var variants = new List <IVariant>(altAlleles.Length); for (var i = 0; i < altAlleles.Length; i++) { #if (!NI_ALLELE) if (VcfCommon.IsNonInformativeAltAllele(altAlleles[i])) { continue; } #endif string altAllele = altAlleles[i]; bool isDecomposed = isDecomposedByAllele[i]; if (isDecomposed && isRecomposed) { throw new InvalidDataException("A variant can't be both decomposed and recomposed"); } (int shiftedStart, string shiftedRef, string shiftedAlt) = VariantUtils.TrimAndLeftAlign(start, refAllele, altAllele, _sequence); if (variantCategory == VariantCategory.SmallVariant || variantCategory == VariantCategory.Reference) { end = shiftedStart + shiftedRef.Length - 1; } variants.Add(GetVariant(chromosome, shiftedStart, end, shiftedRef, shiftedAlt, infoData, variantCategory, isDecomposed, isRecomposed, linkedVids?[i]?.ToArray())); } return(variants.Count == 0 ? null : variants.ToArray()); }
internal List <CosmicItem> ExtractCosmicItems(string vcfLine) { var splitLine = vcfLine.Split(new[] { '\t' }, 8); //skipping large variants if (splitLine[VcfCommon.RefIndex].Length > MaxVariantLength || splitLine[VcfCommon.AltIndex].Length > MaxVariantLength) { return(null); } string chromosomeName = splitLine[VcfCommon.ChromIndex]; if (!_refChromDict.ContainsKey(chromosomeName)) { return(null); } var chromosome = _refChromDict[chromosomeName]; int position = int.Parse(splitLine[VcfCommon.PosIndex]); string cosmicId = splitLine[VcfCommon.IdIndex]; string refAllele = splitLine[VcfCommon.RefIndex]; var altAlleles = splitLine[VcfCommon.AltIndex].OptimizedSplit(','); string infoField = splitLine[VcfCommon.InfoIndex]; Clear(); ParseInfoField(infoField); var cosmicItems = new List <CosmicItem>(); foreach (string altAllele in altAlleles) { var(shiftedPos, shiftedRef, shiftedAlt) = VariantUtils.TrimAndLeftAlign(position, refAllele, altAllele, _sequenceProvider.Sequence); cosmicItems.Add(_studies.TryGetValue(cosmicId, out var studies) ? new CosmicItem(chromosome, shiftedPos, cosmicId, shiftedRef, shiftedAlt, _geneName, studies, _sampleCount) : new CosmicItem(chromosome, shiftedPos, cosmicId, shiftedRef, shiftedAlt, _geneName, null, _sampleCount)); } return(cosmicItems); }
protected override void DrawContent() { if (Node.Anim) { GUI.Box(drawRect, GUIContent.none, EditorStyles.helpBox); var controller = AssetDatabase.LoadAssetAtPath <AnimatorController>(AssetDatabase.GetAssetPath(Node.Anim)); if (controller == null) { Debug.LogErrorFormat("AnimatorController must not be null."); return; } int index = -1; var paramList = controller.parameters.ToList(); var param = paramList.FirstOrDefault(p => p.name == Node.AnimParam.Name); if (param != null) { index = paramList.IndexOf(param); } drawRect.x += ContentMargin; drawRect.width = drawRect.width - ContentMargin * 2; drawRect.height = VariantUtils.FieldHeight; int newIndex = EditorGUI.Popup(drawRect, index, paramList.Select(p => p.name).ToArray()); if (newIndex != index) { SetNewParam(paramList[newIndex]); } if (string.IsNullOrWhiteSpace(Node.AnimParam?.HoldType?.Metadata)) { drawRect.y += drawRect.height; VariantUtils.DrawParameter(drawRect, Node.AnimParam, false); } } else { EditorGUI.HelpBox(drawRect, "AnimController is required!", MessageType.Error); } }
public void ShouldReturnDefaultVariantWhenToggleHasNoVariants() { // Arrange var toggle = new FeatureToggle("test.variants", "release", true, new List <ActivationStrategy> { defaultStrategy }); var context = new UnleashContext { UserId = "userA", SessionId = "sessionId", RemoteAddress = "remoteAddress", Properties = new Dictionary <string, string>() }; // Act var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT); // Assert variant.Should().BeSameAs(Variant.DISABLED_VARIANT); }
public void ShouldReturnVariantOverrideOnSessionId() { // Arrange var sessionId = "122221"; var v1 = new VariantDefinition("a", 33); var override_env = new VariantOverride("env", "dev"); var override_session = new VariantOverride("sessionId", sessionId); var v2 = new VariantDefinition("b", 33, null, new List <VariantOverride> { override_env, override_session }); var v3 = new VariantDefinition("c", 34); var toggle = new FeatureToggle( "test.variants", "release", true, new List <ActivationStrategy> { defaultStrategy }, new List <VariantDefinition> { v1, v2, v3 }); var context = new UnleashContext { UserId = "11", SessionId = sessionId, RemoteAddress = "remoteAddress", Properties = new Dictionary <string, string> { { "env", "prod" } } }; // Act var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT); // Assert variant.Name.Should().Be(v2.Name); }
private void RecreateParameterList() { if (!TreeAsset) { return; } VariantUtils.SetDrawersForKnownTypes(); ParameterList = new UnityEditorInternal.ReorderableList ( TreeAsset.Parameters, typeof(Variant), true, false, true, true ); ParameterList.drawHeaderCallback += rect => { rect.x += ReorderableListOffset; rect.width -= ReorderableListOffset; var original = rect; rect.width *= 0.5f; GUI.Label(rect, "Name"); rect.x = original.x + VariantUtils.LabelWidth * 1.35f; rect.width = VariantUtils.FieldWidth; GUI.Label(rect, "Default value"); }; ParameterList.onAddDropdownCallback += OnAddParameter; ParameterList.drawElementCallback += OnDrawParameter; ParameterList.onChangedCallback += list => { Undo.RecordObject(TreeAsset, "Modified Parameters"); EditorUtility.SetDirty(TreeAsset); }; }
public void Custom_Stickiness_CustomField_112_Yields_Yellow() { // Arrange var sessionId = "122221"; var val1Payload = new Payload("string", "val1"); var blue = new VariantDefinition("blue", 25, val1Payload, null, "customField"); var red = new VariantDefinition("red", 25, val1Payload, null, "customField"); var green = new VariantDefinition("green", 25, val1Payload, null, "customField"); var yellow = new VariantDefinition("yellow", 25, val1Payload, null, "customField"); var toggle = new FeatureToggle( "Feature.flexible.rollout.custom.stickiness_100", "release", true, new List <ActivationStrategy> { defaultStrategy }, new List <VariantDefinition> { blue, red, green, yellow }); var context = new UnleashContext { UserId = "13", SessionId = sessionId, RemoteAddress = "remoteAddress", Properties = new Dictionary <string, string> { { "env", "prod" }, { "customField", "112" } } }; // Act var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT); // Assert variant.Name.Should().Be(yellow.Name); }