示例#1
0
        public static Tuple <long, long> Fill <TPayload>(Sorting sorting, Overlapping overlapping, TPayload filler, MappedInterval <TPayload>[] output)
        {
            var count    = output.Length;
            var start    = 0L;
            var duration = 10L;
            var step     = overlapping == Overlapping.Yes ? duration >> 1 : duration << 1;

            var min = long.MaxValue;
            var max = long.MinValue;

            switch (sorting)
            {
            case Sorting.Ascending:
            case Sorting.Descending:
            {
                var from  = sorting == Sorting.Ascending ? 0 : count - 1;
                var to    = sorting == Sorting.Ascending ? count : 0;
                var delta = sorting == Sorting.Ascending ? 1 : -1;

                while (from != to)
                {
                    min = Math.Min(min, start);
                    max = Math.Max(max, start + duration);

                    output[from] = new MappedInterval <TPayload>(start, start + duration, filler);
                    start       += step;
                    from        += delta;
                }

                break;
            }

            case Sorting.Random:
            {
                var durationFrom = (int)(duration - duration * 0.2);
                var durationTo   = (int)(duration + duration * 0.2);
                var r            = new Random(0xDEAD);
                for (var i = 0; i < count; ++i)
                {
                    var s = r.Next(0, int.MaxValue);
                    var d = r.Next(durationFrom, durationTo);
                    min       = Math.Min(min, s);
                    max       = Math.Max(max, s + d);
                    output[i] = new MappedInterval <TPayload>(s, s + d, filler);
                }

                break;
            }
            }

            return(Tuple.Create(min, max));
        }
示例#2
0
 /// <summary>
 /// Cut the last nucleotide of.
 /// </summary>
 /// <param name="minLen">Minimum primer length.</param>
 /// <returns>Last nucleotide or 255 if oligo too short to pop.</returns>
 public byte Pop(int minLen)
 {
     if (IsPopAllowed(minLen))
     {
         byte item = this.GeneSpecific[0];
         this.GeneSpecific      = this.GeneSpecific.GetSubSequence(0, this.GeneSpecific.Count - 1);
         this.Sequence          = new Sequence(Alphabets.DNA, Overlapping.ToString() + GeneSpecific.ToString());
         this.PrimerTemperature = GetSimpleMeltingTemperature(GeneSpecific);
         return(item);
     }
     else
     {
         return(255);
     }
 }
示例#3
0
 /// <summary>
 /// Cut the first nucleotide off.
 /// </summary>
 /// <param name="minLen">Minimum overlap length.</param>
 /// <returns>First nucleotide or 255 if oligo too short to dequeue.</returns>
 public byte Dequeue(int minLen)
 {
     if (IsDequeAllowed(minLen))
     {
         byte item = this.Overlapping[this.Overlapping.Count - 1];
         this.Overlapping = this.Overlapping.GetSubSequence(1, this.Overlapping.Count - 1);
         this.Sequence    = new Sequence(Alphabets.DNA, Overlapping.ToString() + GeneSpecific.ToString());
         this.Temperature = GetSimpleMeltingTemperature(Overlapping);
         return(item);
     }
     else
     {
         return(255);
     }
 }
        private void OnPlace()
        {
            if (CanPlace.Invoke(StrokeCount))
            {
                for (int i = 0; i < HiddenPieces.Count; i++)
                {
                    HiddenPieces [i].gameObject.SetActive(true);
                }
                HiddenPieces.Clear();

                Dictionary <Vector4, ModularPlacableObject> NewlyPlaced = new Dictionary <Vector4, ModularPlacableObject> ();
                ForEachStrokePoint((Vector4 Position, StrokeType Type, Quaternion Rotation) => {
                    if (PlacableFilter(Position))
                    {
                        NewlyPlaced.Add(Position, PlaceObjectAt(Position, Rotation, Type));
                    }
                    StrokeStartPos = Position;                     // set Stroke start pos to be last
                }, (GameObject Overlapping) => {
                    var ModularPlacable = Overlapping.GetComponent <ModularPlacableObject>();
                    if (ModularPlacable != null)
                    {
                        OnDeleted.Invoke(Overlapping.GetComponent <ModularPlacableObject>());
                    }                     // invoke on deleted callback
                    ModularPlacable.gameObject.SetActive(false);
                    ModularPlacable.Destroy();
                }, (Vector4 Position, StrokeType Type, Quaternion Rotation) => {            // for each newly placed item
                    if (NewlyPlaced.ContainsKey(Position))
                    {
                        OnPlaced.Invoke(NewlyPlaced[Position]);
                    }
                });

                foreach (var Placed in NewlyPlaced)
                {
                    Placed.Value.OnPlaced();
                }                                                                               // on placed event
            }
        }
示例#5
0
        public void Intervals()
        {
            List <int[]> result = Overlapping.Intervals(new int[][] {
                new int[] { 1, 3 },
                new int[] { 2, 4 },
                new int[] { 5, 7 },
                new int[] { 6, 8 },
            });

            Assert.Equal(1, result[0][0]);
            Assert.Equal(4, result[0][1]);
            Assert.Equal(5, result[1][0]);
            Assert.Equal(8, result[1][1]);

            result = Overlapping.Intervals(new int[][] {
                new int[] { 6, 8 },
                new int[] { 1, 9 },
                new int[] { 2, 4 },
                new int[] { 4, 7 },
            });

            Assert.Equal(1, result[0][0]);
            Assert.Equal(9, result[0][1]);
        }