Example #1
0
        public static string GetTab(RegionState state)
        {
            switch (state)
            {
            case RegionState.LevelHeader:
            case RegionState.LevelFooter:
            case RegionState.ModelsLoader:
                return("");

            case RegionState.AreaHeader:
            case RegionState.AreaData:
            case RegionState.AreaFooter:
                return("\t");

            case RegionState.GeoLayout:
                return("\t\t");

            case RegionState.Collision:
            case RegionState.DisplayList:
                return("\t\t\t");

            case RegionState.TextureInfo:
            case RegionState.VertexInfo:
            case RegionState.LightData:
            case RegionState.GraphicsData:
                return("\t\t\t\t");
            }

            return("");
        }
Example #2
0
        public void AddAndGetAlleleCounts()
        {
            var testRegion = new RegionState(1000, 2000);

            for (var i = 0; i < 5; i++)
            {
                testRegion.AddAlleleCount(1001, AlleleType.A, DirectionType.Forward);
            }
            for (var i = 0; i < 2; i++)
            {
                testRegion.AddAlleleCount(1001, AlleleType.C, DirectionType.Forward);
            }
            for (var i = 0; i < 12; i++)
            {
                testRegion.AddAlleleCount(1001, AlleleType.C, DirectionType.Reverse);
            }
            for (var i = 0; i < 15; i++)
            {
                testRegion.AddAlleleCount(2000, AlleleType.A, DirectionType.Stitched);
            }

            Assert.Equal(testRegion.GetAlleleCount(1001, AlleleType.A, DirectionType.Forward), 5);
            Assert.Equal(testRegion.GetAlleleCount(1001, AlleleType.C, DirectionType.Forward), 2);
            Assert.Equal(testRegion.GetAlleleCount(1001, AlleleType.C, DirectionType.Reverse), 12);
            Assert.Equal(testRegion.GetAlleleCount(2000, AlleleType.A, DirectionType.Stitched), 15);
            Assert.Equal(testRegion.GetAlleleCount(1000, AlleleType.A, DirectionType.Stitched), 0);
            Assert.Equal(testRegion.GetAlleleCount(1500, AlleleType.A, DirectionType.Forward), 0);
        }
Example #3
0
        public async Task <TypedResult <StateDTO> > Update(UpdateRegionState regionState)
        {
            try
            {
                if (regionState.Id.Equals(Guid.Empty))
                {
                    throw new InvalidOperationException(ErrorMessages.ID_IS_REQUIRED);
                }
                RegionState existsRecord = await regionStateRepo.FindById(regionState.Id);

                if (existsRecord == null)
                {
                    throw new InvalidOperationException(ErrorMessages.THIS_RECORD_DOES_NOT_EXISTS);
                }

                existsRecord.RegionCountryId = regionState.CountryId;
                existsRecord.Title           = regionState.Title;
                RegionState result = await regionStateRepo.Update(existsRecord);

                return(new TypedResult <StateDTO>(_mapper.Map <StateDTO>(result)));
            }
            catch (Exception ex)
            {
                return(new TypedResult <StateDTO>(ex));
            }
        }
Example #4
0
        private IAlleleSource CreateMockStateManager(List <AlleleCount> states, int refCounts = 0)
        {
            var mockAlleleCountSource = new Mock <IAlleleSource>();

            var numAnchorTypes = 5;
            var regionState    = new RegionState(1, 1000, numAnchorTypes);


            foreach (var state in states)
            {
                for (var directionIndex = 0; directionIndex < Constants.NumDirectionTypes; directionIndex++)
                {
                    for (var anchorIndex = 0; anchorIndex < numAnchorTypes * 2 + 1; anchorIndex++)
                    {
                        for (var i = 0; i < state.DirectionCoverage[directionIndex, anchorIndex]; i++)
                        {
                            regionState.AddAlleleCount(state.Coordinate, state.AlleleType, (DirectionType)directionIndex, anchorIndex);
                        }
                    }
                }
                mockAlleleCountSource.Setup(
                    s => s.GetAlleleCount(state.Coordinate,
                                          state.AlleleType,
                                          It.IsAny <DirectionType>(), It.IsAny <int>(), It.IsAny <int?>(), It.IsAny <bool>(), It.IsAny <bool>()))
                .Returns((int c, AlleleType a, DirectionType d, int minAnchor, int?maxAnchor, bool fromEnd, bool symm) =>
                {
                    return(regionState.GetAlleleCount(c, a, d, minAnchor, maxAnchor, fromEnd, symm));
                }
                         );
            }

            mockAlleleCountSource.Setup(c => c.GetGappedMnvRefCount(It.IsAny <int>())).Returns(refCounts);

            return(mockAlleleCountSource.Object);
        }
Example #5
0
 public void SetRegionState(int id, RegionState value)
 {
     SubVirtualRegion region;
     if (subRegions.TryGetValue(id, out region))
     {
         region.SetState(value);
     }
 }
Example #6
0
 public LevelScriptRegion(string dirname, RegionState state, int area = -1, int model = -1) : base(dirname, state, area, model)
 {
     if (state != RegionState.LevelFooter && state != RegionState.LevelHeader && state != RegionState.ModelsLoader &&
         state != RegionState.AreaFooter && state != RegionState.AreaHeader && state != RegionState.AreaData &&
         state != RegionState.AreaScrolls)
     {
         throw new Exception("Level Script Region was used with bad state");
     }
 }
Example #7
0
 public LevelScriptRegion(int start, int length, RegionState state) : base(start, length, state)
 {
     if (state != RegionState.LevelFooter && state != RegionState.LevelHeader && state != RegionState.ModelsLoader &&
         state != RegionState.AreaFooter && state != RegionState.AreaHeader && state != RegionState.AreaData &&
         state != RegionState.AreaScrolls)
     {
         throw new Exception("Level Script Region was used with bad state");
     }
 }
Example #8
0
 public DynamicRegion(string dirname, RegionState state, int area = -1, int model = -1) : base(dirname, state, area, model)
 {
     if (state == RegionState.LevelFooter || state == RegionState.LevelHeader || state == RegionState.ModelsLoader ||
         state == RegionState.AreaFooter || state == RegionState.AreaHeader || state == RegionState.AreaData ||
         state == RegionState.GeoLayout || state == RegionState.DisplayList)
     {
         throw new ArgumentException("Using DynamicRegion with given state is not allowed");
     }
 }
Example #9
0
 // TODO: Bullshit, make like bunch of classes or something
 public DynamicRegion(int start, int length, RegionState state) : base(start, length, state)
 {
     if (state == RegionState.LevelFooter || state == RegionState.LevelHeader || state == RegionState.ModelsLoader ||
         state == RegionState.AreaFooter || state == RegionState.AreaHeader || state == RegionState.AreaData ||
         state == RegionState.GeoLayout || state == RegionState.DisplayList)
     {
         throw new ArgumentException("Using DynamicRegion with given state is not allowed");
     }
 }
Example #10
0
        public void SetRegionState(int id, RegionState value)
        {
            SubVirtualRegion region;

            if (subRegions.TryGetValue(id, out region))
            {
                region.SetState(value);
            }
        }
Example #11
0
        public void AddAndGetCandidates_Errors()
        {
            var testRegion = new RegionState(1000, 2000);

            Assert.Throws <ArgumentException>(
                () => testRegion.AddCandidate(new CandidateAllele("chr1", 999, "A", "T", AlleleCategory.Snv)));

            Assert.Throws <ArgumentException>(
                () => testRegion.GetAlleleCount(2001, AlleleType.A, DirectionType.Forward));
        }
Example #12
0
        public void Create_P1Armies17_AreEqual()
        {
            var act = RegionState.Create(17, PlayerType.player1);

            var expOwner  = PlayerType.player1;
            var expArmies = 17;

            Assert.AreEqual(expOwner, act.Owner, "Owner");
            Assert.AreEqual(expArmies, act.Armies, "Armies");
        }
Example #13
0
        // Read from dirname init
        public Region(string dirname, RegionState state, int area = -1, int model = -1, int number = -1)
        {
            string levelHeaderPath = PathComposer.ComposeName(dirname, state, area, model, number);

            this.data   = File.ReadAllBytes(levelHeaderPath);
            this.length = data.Length;

            this.area   = area;
            this.model  = model;
            this.number = number;
        }
Example #14
0
        private List <int> GetAllRefCounts(RegionState testRegion)
        {
            var refCounts = new List <int>();

            for (int position = testRegion.StartPosition; position <= testRegion.EndPosition; position++)
            {
                refCounts.Add(testRegion.GetGappedMnvRefCount(position));
            }

            return(refCounts);
        }
Example #15
0
        // Empty region init
        public Region(int start, int length, RegionState state)
        {
            this.romStart = start;
            this.length   = length;
            this.state    = state;

            if (start == 0)
            {
                throw new ArgumentNullException("ROM Region Start is 0, bug?");
            }
        }
Example #16
0
        public void Contains()
        {
            var region = new RegionState(1, 5);

            for (var i = 1; i <= 5; i++)
            {
                Assert.True(region.ContainsPosition(i));
            }

            Assert.False(region.ContainsPosition(0));
            Assert.False(region.ContainsPosition(6));
        }
Example #17
0
        public void BeginRegion()
        {
            if (!_atLineStart)
            {
                Line();
            }

            _regionStateStack.Push(_regionState);
            _regionState = new RegionState()
            {
                AtStart = true
            };
        }
Example #18
0
        //see wiki.warlight.net/index.php/Combat_Basics
        private SimulationOutcome SimulateAttack(RegionState source, RegionState target, int armies)
        {
            //int attackers, int defenders, out int attackersDestroyed, out int defendersDestroyed

            int attackingArmies = armies;
            int defendingArmies = target.Armies;

            var attackersDestroyed = 0;
            var defendersDestroyed = 0;

            for (int t = 1; t <= attackingArmies; t++)             //calculate how much defending armies are destroyed
            {
                double rand = Rnd.NextDouble();

                //60% chance to destroy one defending army
                if (rand < AttackFactor)
                {
                    defendersDestroyed++;
                }
            }
            for (int t = 1; t <= defendingArmies; t++)             //calculate how much attacking armies are destroyed
            {
                double rand = Rnd.NextDouble();
                //70% chance to destroy one attacking army
                if (rand < DefendFactor)
                {
                    attackersDestroyed++;
                }
            }

            if (attackersDestroyed >= attackingArmies)
            {
                if (defendersDestroyed >= defendingArmies)
                {
                    defendersDestroyed = defendingArmies - 1;
                }
                attackersDestroyed = attackingArmies;
            }

            //process result of attack
            if (defendersDestroyed >= defendingArmies)             //attack success
            {
                var survivors = attackingArmies - attackersDestroyed;
                return(new SimulationOutcome(source.Leave(armies), RegionState.Create(survivors, source.Owner)));
            }
            else             //attack fail
            {
                return(new SimulationOutcome(source.Leave(attackersDestroyed), target.Leave(defendersDestroyed)));
            }
        }
Example #19
0
 private void ToggleRegion(RegionState state)
 {
     if (state == RegionState.DropDownList)
     {
         lblRegion.CssClass = "dnnFormRequired";
         txtRegion.Visible  = false;
         cboRegion.Visible  = true;
         rfvRegion.Enabled  = true;
     }
     else
     {
         lblRegion.CssClass = string.Empty;
         txtRegion.Visible  = true;
         cboRegion.Visible  = false;
         rfvRegion.Enabled  = false;
     }
 }
Example #20
0
        public void Equality()
        {
            // happy path
            var testRegion  = new RegionState(1500, 7002);
            var otherRegion = new RegionState(1500, 7002);

            Assert.True(testRegion.Equals(otherRegion));
            Assert.True(otherRegion.Equals(testRegion));

            // error conditions
            otherRegion = new RegionState(1501, 7002); // diff start
            Assert.False(testRegion.Equals(otherRegion));
            otherRegion = new RegionState(1500, 7001); // diff end
            Assert.False(testRegion.Equals(otherRegion));

            Assert.False(testRegion.Equals("otherobject"));
        }
Example #21
0
        public SimulationDistribution Simulate(RegionState source, RegionState target, int armies, int simulations = 1000)
        {
            if (source.Owner == target.Owner)
            {
                var outcome = new SimulationOutcome(source.Leave(armies), target.Arive(armies));
                return(null);
            }

            var success = new Dictionary <RegionState, int>();
            var failure = new Dictionary <SimulationOutcome, int>();

            for (var simulation = 0; simulation < simulations; simulation++)
            {
                var outcome = SimulateAttack(source, target, armies);

                if (outcome.HaveSameOwner)
                {
                    if (!success.ContainsKey(outcome.Target))
                    {
                        success[outcome.Target] = 1;
                    }
                    else
                    {
                        success[outcome.Target]++;
                    }
                }
                else
                {
                    if (!failure.ContainsKey(outcome))
                    {
                        failure[outcome] = 1;
                    }
                    else
                    {
                        failure[outcome]++;
                    }
                }
            }
            return(new SimulationDistribution()
            {
                Source = source.Leave(armies),
                Success = success,
                Failure = failure,
            });
        }
Example #22
0
        public void Constructor()
        {
            // happy path
            var testRegion = new RegionState(1, 6000);

            Assert.Equal(testRegion.StartPosition, 1);
            Assert.Equal(testRegion.EndPosition, 6000);
            Assert.Equal(6000, testRegion.Size);

            // error conditions
            // start position
            Assert.Throws <ArgumentException>(() => new RegionState(0, 6000));    // zero
            Assert.Throws <ArgumentException>(() => new RegionState(-100, 6000)); // negative
            // end position
            Assert.Throws <ArgumentException>(() => new RegionState(1, 0));       // zero
            Assert.Throws <ArgumentException>(() => new RegionState(1, -100));    // negative
            Assert.Throws <ArgumentException>(() => new RegionState(1, 1));       // equal start
            Assert.Throws <ArgumentException>(() => new RegionState(6, 1));       // less than start
        }
Example #23
0
        public async Task <TypedResult <bool> > Remove(Guid Id)
        {
            try
            {
                RegionState existsRecord = await regionStateRepo.FindById(Id);

                if (existsRecord == null)
                {
                    throw new InvalidOperationException(ErrorMessages.THIS_RECORD_DOES_NOT_EXISTS);
                }
                Boolean result = await regionStateRepo.Delete(Id);

                return(new TypedResult <Boolean>(result));
            }
            catch (Exception ex)
            {
                return(new TypedResult <Boolean>(ex));
            }
        }
Example #24
0
        public void Simulate_20Vs11_10000Runs()
        {
            var source = RegionState.Create(20, PlayerType.player1);
            var target = RegionState.Create(11, PlayerType.player2);

            var rnd       = new MT19937Generator(17);
            var simulator = new Simulator(rnd);

            var sw = new Stopwatch();

            sw.Start();

            var act = simulator.Simulate(source, target, 19, 10000);

            sw.Stop();

            Console.WriteLine(sw.Elapsed.TotalMilliseconds);

            Console.WriteLine("success: {0}, failure: {1}", act.SuccessCount, act.FailureCount);
        }
Example #25
0
        public void AddAndGetGappedMnvReferenceCounts_Errors()
        {
            var testRegion = new RegionState(50, 150);

            testRegion.AddGappedMnvRefCount(150, 10);

            var refCountsBefore = GetAllRefCounts(testRegion);

            // -----------------------------------------------
            // adding at an invalid position should do nothing
            // -----------------------------------------------
            testRegion.AddGappedMnvRefCount(151, 1);
            var refCountsAfter = GetAllRefCounts(testRegion);

            Assert.True(refCountsAfter.SequenceEqual(refCountsBefore));

            // -----------------------------------------------
            // getting at an invalid position should throw exception
            // -----------------------------------------------
            Assert.Throws <ArgumentException>(() => testRegion.GetGappedMnvRefCount(151));
        }
Example #26
0
        public void AddAndGetGappedMnvReferenceCounts()
        {
            var testRegion = new RegionState(50, 150);

            // -----------------------------------------------
            // happy path - add a couple of counts,
            // getting them should return the same
            // -----------------------------------------------
            testRegion.AddGappedMnvRefCount(75, 1);
            testRegion.AddGappedMnvRefCount(76, 10);
            Assert.Equal(1, testRegion.GetGappedMnvRefCount(75));
            Assert.Equal(10, testRegion.GetGappedMnvRefCount(76));

            // -----------------------------------------------
            // happy path - add a couple of counts to existing ref,
            // it should be incremented but others should be unchanged
            // -----------------------------------------------
            testRegion.AddGappedMnvRefCount(76, 3);
            Assert.Equal(1, testRegion.GetGappedMnvRefCount(75));
            Assert.Equal(13, testRegion.GetGappedMnvRefCount(76));
        }
Example #27
0
        public async Task <TypedResult <StateDTO> > Add(InsertRegionState regionState)
        {
            try
            {
                ICollection <RegionState> existsRecords = await regionStateRepo
                                                          .GetList(condition : x => x.RegionCountryId == regionState.CountryId && x.Title.Equals(regionState.Title));

                if (existsRecords.Any())
                {
                    throw new InvalidOperationException(ErrorMessages.THIS_RECORD_ALREADY_EXISTS);
                }

                RegionState entity = _mapper.Map <RegionState>(regionState);
                RegionState result = await regionStateRepo.Add(entity);

                return(new TypedResult <StateDTO>(_mapper.Map <StateDTO>(result)));
            }
            catch (Exception ex)
            {
                return(new TypedResult <StateDTO>(ex));
            }
        }
Example #28
0
        public void ExecuteTest_GetCandidates(bool withReference, bool withIntervals)
        {
            var testRegion   = new RegionState(1, 50);
            var chrReference = new ChrReference()
            {
                Name     = "chr1",
                Sequence = string.Concat(Enumerable.Repeat("A", 50))
            };
            var snv1 = new CandidateAllele("chr1", 5, "A", "T", AlleleCategory.Snv)
            {
                SupportByDirection = new [] { 10, 5, 0 }
            };
            var snv2 = new CandidateAllele("chr1", 15, "A", "T", AlleleCategory.Snv)
            {
                SupportByDirection = new[] { 10, 5, 0 }
            };

            testRegion.AddCandidate(snv1);
            testRegion.AddCandidate(snv2);

            for (var i = 0; i < 5; i++)
            {
                testRegion.AddAlleleCount(5, AlleleType.A, DirectionType.Stitched);  // ref @ variant position
                testRegion.AddAlleleCount(6, AlleleType.A, DirectionType.Stitched);  // ref by itself
                testRegion.AddAlleleCount(10, AlleleType.C, DirectionType.Stitched); // nonref by itself (no ref)
                testRegion.AddAlleleCount(15, AlleleType.A, DirectionType.Reverse);  // ref (multiple directions) + nonref
                testRegion.AddAlleleCount(15, AlleleType.A, DirectionType.Forward);
                testRegion.AddAlleleCount(15, AlleleType.T, DirectionType.Reverse);
            }

            ChrIntervalSet intervals = null;

            if (withIntervals)
            {
                intervals = new ChrIntervalSet(new List <CallSomaticVariants.Logic.RegionState.Region>()
                {
                    new CallSomaticVariants.Logic.RegionState.Region(3, 6),
                    new CallSomaticVariants.Logic.RegionState.Region(16, 16)
                }, "chr1");
            }
            var expectedList = new List <CandidateAllele>();

            expectedList.Add(snv1);
            expectedList.Add(snv2);

            if (withReference)
            {
                expectedList.Add(new CandidateAllele("chr1", 5, "A", "A", AlleleCategory.Reference)
                {
                    SupportByDirection = new[] { 0, 0, 5 }
                });
                expectedList.Add(new CandidateAllele("chr1", 6, "A", "A", AlleleCategory.Reference)
                {
                    SupportByDirection = new[] { 0, 0, 5 }
                });
                expectedList.Add(new CandidateAllele("chr1", 10, "A", "A", AlleleCategory.Reference)
                {
                    SupportByDirection = new[] { 0, 0, 0 }
                });
                expectedList.Add(new CandidateAllele("chr1", 15, "A", "A", AlleleCategory.Reference)
                {
                    SupportByDirection = new[] { 5, 5, 0 }
                });
            }

            if (withIntervals)
            {
                expectedList = expectedList.Where(c => c.Coordinate == 5 || c.Coordinate == 6 || c.Type != AlleleCategory.Reference).ToList();
                if (withReference)
                {
                    expectedList.Add(new CandidateAllele("chr1", 3, "A", "A", AlleleCategory.Reference)
                    {
                        SupportByDirection = new[] { 0, 0, 0 }
                    });
                    expectedList.Add(new CandidateAllele("chr1", 4, "A", "A", AlleleCategory.Reference)
                    {
                        SupportByDirection = new[] { 0, 0, 0 }
                    });
                    expectedList.Add(new CandidateAllele("chr1", 16, "A", "A", AlleleCategory.Reference)
                    {
                        SupportByDirection = new[] { 0, 0, 0 }
                    });
                }
            }
            var allCandidates = testRegion.GetAllCandidates(withReference, chrReference, intervals);

            VerifyCandidates(expectedList, allCandidates);
        }
Example #29
0
        public void AddAndGetCandidates()
        {
            // -----------------------------------------------
            // simple test case adding candidate to empty region
            // -----------------------------------------------
            var testRegion = new RegionState(1000, 2000);
            var snv1       = new CandidateAllele("chr1", 1500, "A", "T", AlleleCategory.Snv)
            {
                SupportByDirection = new[] { 10, 0, 0 }
            };

            testRegion.AddCandidate(snv1);

            var allCandidates = testRegion.GetAllCandidates(false, null);

            Assert.Equal(allCandidates.Count, 1);

            var fetchedCandidate = allCandidates[0];

            Assert.True(fetchedCandidate.Equals(snv1));

            // -----------------------------------------------
            // add same type of candidate but at different position
            // -----------------------------------------------
            var snv2 = new CandidateAllele("chr1", 1501, "A", "T", AlleleCategory.Snv)
            {
                SupportByDirection = new[] { 5, 0, 0 }
            };

            testRegion.AddCandidate(snv2);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 2);

            // make sure coverage is preserved
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv1));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 10);
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv2));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 5);

            // -----------------------------------------------
            // add a different type of candidate at same position
            // -----------------------------------------------
            var deletion1 = new CandidateAllele("chr1", 1500, "AT", "A", AlleleCategory.Deletion)
            {
                SupportByDirection = new[] { 15, 0, 0 }
            };

            testRegion.AddCandidate(deletion1);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 3);

            // make sure coverage is preserved
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv1));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 10);
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv2));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 5);
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(deletion1));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 15);

            // -----------------------------------------------
            // add same variant, but more coverage
            // -----------------------------------------------
            var moreSnv1 = new CandidateAllele("chr1", 1500, "A", "T", AlleleCategory.Snv)
            {
                SupportByDirection = new[] { 2, 0, 0 }
            };

            testRegion.AddCandidate(moreSnv1);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 3);

            // make sure coverage is incremented
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv1));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 12);

            // make sure coverage is preserved
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv2));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 5);
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(deletion1));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 15);

            var moreDeletion1 = new CandidateAllele("chr1", 1500, "AT", "A", AlleleCategory.Deletion)
            {
                SupportByDirection = new[] { 0, 18, 0 }
            };

            testRegion.AddCandidate(moreDeletion1);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 3);

            // make sure coverage is incremented
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(deletion1));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 33);

            // make sure coverage is preserved
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv1));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 12);
            fetchedCandidate = allCandidates.FirstOrDefault(c => c.Equals(snv2));
            Assert.True(fetchedCandidate != null && fetchedCandidate.Support == 5);

            // -----------------------------------------------
            // add insertion that goes off block
            // -----------------------------------------------
            var edgeInsertion = new CandidateAllele("chr1", 2000, "A", "TCG", AlleleCategory.Insertion)
            {
                SupportByDirection = new[] { 5, 0, 0 }
            };

            testRegion.AddCandidate(edgeInsertion);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 4);
            Assert.Equal(2001, testRegion.MaxAlleleEndpoint);

            // -----------------------------------------------
            // add mnv that goes off block
            // -----------------------------------------------
            var edgeMnv = new CandidateAllele("chr1", 1999, "ATCC", "TCGG", AlleleCategory.Mnv)
            {
                SupportByDirection = new[] { 5, 0, 0 }
            };

            testRegion.AddCandidate(edgeMnv);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 5);
            Assert.Equal(2002, testRegion.MaxAlleleEndpoint);

            // -----------------------------------------------
            // add deletion that goes off block
            // -----------------------------------------------
            var edgeDeletion = new CandidateAllele("chr1", 1999, "A" + new string('T', 25), "A", AlleleCategory.Deletion)
            {
                SupportByDirection = new[] { 5, 0, 0 }
            };

            testRegion.AddCandidate(edgeDeletion);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 6);
            Assert.Equal(2025, testRegion.MaxAlleleEndpoint);

            // -----------------------------------------------
            // add variant that goes off block but not as far as the deletion did - max endpoint should stay the same
            // -----------------------------------------------
            var edgeMnv2 = new CandidateAllele("chr1", 1999, "ATCGA", "TCGCT", AlleleCategory.Mnv)
            {
                SupportByDirection = new[] { 5, 0, 0 }
            };

            testRegion.AddCandidate(edgeMnv2);

            allCandidates = testRegion.GetAllCandidates(false, null);
            Assert.Equal(allCandidates.Count, 7);
            Assert.Equal(2025, testRegion.MaxAlleleEndpoint);
        }
Example #30
0
        public static bool IsRegionFileExists(string dirname, RegionState state, int area = -1, int model = -1, int number = -1)
        {
            string path = ComposeName(dirname, state, area, model, number);

            return(File.Exists(path));
        }
Example #31
0
        public static string ComposeName(string dirname, RegionState state, int area = -1, int model = -1, int number = -1)
        {
            string regionPath = null;

            switch (state)
            {
            case RegionState.LevelHeader:
                regionPath = Path.Combine(dirname, "header");
                break;

            case RegionState.LevelFooter:
                regionPath = Path.Combine(dirname, "footer");
                break;

            case RegionState.ModelsLoader:
                regionPath = Path.Combine(dirname, "models", "loader");
                break;

            case RegionState.AreaHeader:
                if (area == -1)
                {
                    throw new ArgumentException("Orphan AreaHeader!");
                }
                regionPath = Path.Combine(dirname, "area" + area, "header");
                break;

            case RegionState.AreaData:
                if (area == -1)
                {
                    throw new ArgumentException("Orphan AreaData!");
                }
                regionPath = Path.Combine(dirname, "area" + area, "objects");
                break;

            case RegionState.AreaScrolls:
                if (area == -1)
                {
                    throw new ArgumentException("Orphan AreaScrolls!");
                }
                regionPath = Path.Combine(dirname, "area" + area, "scrolls");
                break;

            case RegionState.AreaFooter:
                if (area == -1)
                {
                    throw new ArgumentException("Orphan AreaFooter!");
                }
                regionPath = Path.Combine(dirname, "area" + area, "footer");
                break;

            case RegionState.GeoLayout:
                if (area != -1)
                {
                    regionPath = Path.Combine(dirname, "area" + area, "geolayout");
                }
                else if (model != -1)
                {
                    regionPath = Path.Combine(dirname, "models", "geolayout" + model);
                }
                else
                {
                    throw new ArgumentException("Orphan Geolayout!");
                }

                break;

            case RegionState.Collision:
                if (area == -1)
                {
                    throw new ArgumentException("Orphan Collision!");
                }
                regionPath = Path.Combine(dirname, "area" + area, "collision");
                break;

            case RegionState.DisplayList:
                if (area != -1)
                {
                    regionPath = Path.Combine(dirname, "area" + area, "graphics", "disp" + number);
                }
                else if (model != -1)
                {
                    regionPath = Path.Combine(dirname, "models", "graphics" + model, "disp" + number);
                }
                else
                {
                    throw new ArgumentException("Orphan DisplayList!");
                }
                break;

            case RegionState.GraphicsData:
                if (area != -1)
                {
                    regionPath = Path.Combine(dirname, "area" + area, "graphics", "data");
                }
                else if (model != -1)
                {
                    regionPath = Path.Combine(dirname, "models", "graphics" + model, "data");
                }
                else
                {
                    throw new ArgumentException("Orphan GraphicsData!");
                }
                break;
            }

            return(regionPath);
        }
Example #32
0
 private void ToggleRegion(RegionState state)
 {
     if (state == RegionState.DropDownList)
     {
         lblRegion.CssClass = "dnnFormRequired";
         txtRegion.Visible = false;
         cboRegion.Visible = true;
         rfvRegion.Enabled = true;
     }
     else
     {
         lblRegion.CssClass = string.Empty;
         txtRegion.Visible = true;
         cboRegion.Visible = false;
         rfvRegion.Enabled = false;
     }
 }