The complex chain.
Inheritance: LibiadaCore.Core.Chain
 public void ClearAtTest()
 {
     var secondComplexChain = new ComplexChain("AGTC");
     var firstComplexChain = new ComplexChain("ATC");
     secondComplexChain.ClearAt(1);
     Assert.True(firstComplexChain.Equals(secondComplexChain));
 }
 /// <summary>
 /// The calculate std.
 /// </summary>
 /// <param name="convoluted">
 /// The convoluted.
 /// </param>
 /// <param name="pbalance">
 /// The pbalance.
 /// </param>
 /// <param name="windowLen">
 /// The window len.
 /// </param>
 /// <param name="length">
 /// The length.
 /// </param>
 /// <param name="criteriaCalculator">
 /// The criteria calculator.
 /// </param>
 public void CalculateStd(
     ComplexChain convoluted,
     double pbalance,
     int windowLen,
     int length,
     CriterionMethod criteriaCalculator)
 {
     foreach (KeyValuePair<List<string>, List<int>> accord in fullEntry.Entry())
     {
         PositionFilter.Filtrate(accord.Value, windowLen);
         double frequency = criteriaCalculator.Frequency(accord.Value, length, windowLen);
         double design = criteriaCalculator.DesignExpected(
             accord.Key,
             length,
             windowLen,
             minusOneEntry,
             minusTwoEntry);
         double interval = criteriaCalculator.IntervalEstimate(
             accord.Value,
             length,
             windowLen,
             convoluted.Anchor);
         double std = Math.Abs((pbalance * interval) + ((1 - pbalance) * frequency) - design) / Math.Sqrt(design);
         if (!wordPriority.ContainsKey(std))
         {
             wordPriority.Add(std, accord);
         }
     }
 }
        /// <summary>
        /// The distortion.
        /// </summary>
        /// <param name="chain">
        /// The chain.
        /// </param>
        /// <param name="alphabet">
        /// The alphabet.
        /// </param>
        /// <returns>
        /// The <see cref="double"/>.
        /// </returns>
        public override double Distortion(ComplexChain chain, FrequencyDictionary alphabet)
        {
            double maxFrequency = MaxFrequency(alphabet);
            double power = alphabet.Count;

            double greaterToSmaller = power / maxFrequency;
            double sumToGreater = (power + maxFrequency) / power;

            return Math.Abs(greaterToSmaller - sumToGreater);
        }
        public void ConcatTwoTest()
        {
            int start = 0;
            int end = chain.GetLength();

            var firstComplexChain = new ComplexChain(chain.Substring(start, end - 1));
            var secondComplexChain = new ComplexChain(chain.Substring(end - 1, end));
            ComplexChain concatChain = firstComplexChain.Concat(secondComplexChain.ToString());
            Assert.True(concatChain.Equals(chain));
        }
        /// <summary>
        /// The state.
        /// </summary>
        /// <param name="chain">
        /// The chain.
        /// </param>
        /// <param name="alphabet">
        /// The alphabet.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public override bool State(ComplexChain chain, FrequencyDictionary alphabet)
        {
            double currentDistortion = depth.Calculate(chain, chain.Anchor); // - calculate(gamutDeep, chain);
            if (Math.Abs(currentDistortion) > Value)
            {
                this.chain = chain.Clone();
                this.alphabet = alphabet.Clone();
                ThresholdToStop.SaveBest();
                Value = currentDistortion;
            }

            return ThresholdToStop.Distance > ThresholdVariator.Precision;
        }
        /// <summary>
        /// The state.
        /// </summary>
        /// <param name="chain">
        /// The chain.
        /// </param>
        /// <param name="alphabet">
        /// The alphabet.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public override bool State(ComplexChain chain, FrequencyDictionary alphabet)
        {
            double distortion = Distortion(chain, alphabet);
            if (Math.Abs(Value) > Math.Abs(distortion))
            {
                this.chain = chain.Clone();
                this.alphabet = alphabet.Clone();
                Value = distortion;
                ThresholdToStop.SaveBest();
            }

            return ThresholdToStop.Distance > ThresholdVariator.Precision;
        }
        /// <summary>
        /// The state.
        /// </summary>
        /// <param name="chain">
        /// The chain.
        /// </param>
        /// <param name="alphabet">
        /// The alphabet.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public override bool State(ComplexChain chain, FrequencyDictionary alphabet)
        {
            double current = Distortion(chain, alphabet);
            if (Value > current)
            {
                Value = current;
                this.chain = chain.Clone();
                this.alphabet = alphabet.Clone();
                ThresholdToStop.SaveBest();
            }

            return ThresholdToStop.Distance > ThresholdVariator.Precision;
        }
        public void ReplaceTest()
        {
            var chain = new ComplexChain(list);
            var filter = new Filter(chain);
            int hits = filter.Replace(str2, "-");

            var sb = new StringBuilder();
            foreach (string s in list)
            {
                sb.Append(s);
            }

            string result = filter.GetChain().ToString();
            string buf = chain.ToString();
            Assert.True(buf.Length - result.Length == hits);
        }
        /// <summary>
        /// Calculate std method.
        /// </summary>
        /// <param name="convoluted">
        /// The convoluted.
        /// </param>
        /// <param name="windowLen">
        /// The window len.
        /// </param>
        public void CalculateStd(ComplexChain convoluted, int windowLen)
        {
            var geometricMean = new GeometricMean();
            var arithmeticMean = new ArithmeticMean();

            foreach (KeyValuePair<List<string>, List<int>> accord in fullEntry.Entry())
            {
                PositionFilter.Filtrate(accord.Value, windowLen);
                var temp = new ComplexChain(accord.Value);
                double geometric = geometricMean.Calculate(temp, convoluted.Anchor);
                double arithmetic = arithmeticMean.Calculate(temp, convoluted.Anchor);
                double std = 1 - (1 / Math.Abs(arithmetic - geometric));
                if (!wordPriority.ContainsKey(std))
                {
                    wordPriority.Add(std, accord);
                }
            }
        }
        public void FilteroutTest()
        {
            var chain = new ComplexChain(list);
            var filter = new Filter(chain);
            int hits = filter.FilterOut(str1);

            var sb = new StringBuilder();
            foreach (string s in list)
            {
                sb.Append(s);
            }

            string result = filter.GetChain().ToString();
            string buf = chain.ToString();
            Assert.True(buf.Length - result.Length == hits);

            filter = new Filter(chain);
            hits = filter.FilterOut(str2);

            filter.GetChain().ToString();
            chain.ToString();
            Assert.True(hits == 3);
        }
        /// <summary>
        /// The initialize method.
        /// </summary>
        /// <param name="chain">
        /// The chain.
        /// </param>
        /// <param name="windowLength">
        /// The window length.
        /// </param>
        /// <param name="step">
        /// The step.
        /// </param>
        private void Initialize(ComplexChain chain, int windowLength, int step)
        {
            try
            {
                int chainLength = chain.GetLength();

                if ((chainLength < windowLength) || (windowLength == 0) || ((step < 1) || (step > chainLength)))
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
            }

            this.chain = chain.Clone();
            this.windowLength = windowLength;
            this.step = step;
            CursorPosition = -step;
            CalculateMaxShifts();
        }
 /// <summary>
 /// The update.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 private void Update(ComplexChain chain, FrequencyDictionary alphabet)
 {
     double dist = TheoryVolume(chain, alphabet) - alphabet.Count;
     if (Math.Abs(Value) > Math.Abs(dist))
     {
         this.alphabet = alphabet.Clone();
         this.chain = chain.Clone();
         Value = dist;
         ThresholdToStop.SaveBest();
     }
 }
 /// <summary>
 /// The distortion.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public override sealed double Distortion(ComplexChain chain, FrequencyDictionary alphabet)
 {
     return TheoryVolume(chain, alphabet) - alphabet.Count;
 }
 /// <summary>
 /// The state.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public override bool State(ComplexChain chain, FrequencyDictionary alphabet)
 {
     Update(chain, alphabet);
     return (ThresholdToStop.Distance > ThresholdVariator.Precision)
            && (Math.Abs(Distortion(chain, alphabet)) > precisionOfDifference);
 }
        /// <summary>
        /// Calculates the theoretical volume the alphabet for a chain.
        /// </summary>
        /// <param name="chain">
        /// An estimated chain.
        /// </param>
        /// <param name="alphabet">
        /// Current alphabet.
        /// </param>
        /// <returns>
        /// The theoretical volume the alphabet.
        /// </returns>
        public double TheoryVolume(ComplexChain chain, FrequencyDictionary alphabet)
        {
            double f = 0;
            List<string> wordsList = alphabet.GetWords();
            foreach (string word in wordsList)
            {
                double freq = Frequency(chain, word);
                if (freq > f)
                {
                    f = freq;
                }
            }

            double z = chain.GetLength();
            double k = 1 / Math.Log(f * z);
            double b = (k / f) - 1;
            double v = (k * z) - b;
            return v;
        }
 public void SetUp()
 {
     complexChain = new ComplexChain("AACAGGTGCCCCTTATTT");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StartIterator" /> class.
 /// </summary>
 /// <param name="chain">
 /// An iterable sequence
 /// </param>
 /// <param name="windowLength">
 /// Length of a word (window of cutting)
 /// </param>
 /// <param name="step">
 /// The number of elements through which the pointer will jump at the next iteration
 /// </param>
 public StartIterator(ComplexChain chain, int windowLength, int step)
     : base(chain, windowLength, step)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EndIterator"/> class.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="length">
 /// Length of a word (window of cutting)
 /// </param>
 /// <param name="step">
 /// The number of elements through which the pointer will jump at the next iteration
 /// </param>
 public EndIterator(ComplexChain chain, int length, int step)
     : base(chain, length, step)
 {
     CursorPosition = chain.GetLength() - windowLength + 1;
 }
 /// <summary>
 /// The distortion.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public override double Distortion(ComplexChain chain, FrequencyDictionary alphabet)
 {
     return depth.Calculate(chain.Original(), chain.Anchor); // - gamutDeep.Calculate(chain);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FrequencyDictionary"/> class.
 /// </summary>
 /// <param name="sequence">
 /// The sequence.
 /// </param>
 public FrequencyDictionary(ComplexChain sequence)
 {
     Fill(sequence);
 }
 /// <summary>
 /// Extracts new words and their places of occurrence from a current word sequence
 /// </summary>
 /// <param name="sequence">the current word sequence</param>
 public void Fill(ComplexChain sequence)
 {
     Clear();
     for (int index = 0; index < sequence.GetLength(); index++)
     {
         Put(sequence[index].ToString(), index);
     }
 }
 /// <summary>
 /// The distortion.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public override double Distortion(ComplexChain chain, FrequencyDictionary alphabet)
 {
     return (remoteness.Calculate(chain, chain.Anchor) / remoteness.Calculate(chain.Original(), chain.Anchor)) - wordAverageLength.Calculate(chain, chain.Anchor);
 }
 /// <summary>
 /// The state.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public override bool State(ComplexChain chain, FrequencyDictionary alphabet)
 {
     return false;
 }
 /// <summary>
 /// The distortion.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public override double Distortion(ComplexChain chain, FrequencyDictionary alphabet)
 {
     return 0;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseIterator"/> class.
 /// </summary>
 /// <param name="chain">
 /// An iterated sequence.
 /// </param>
 /// <param name="length">
 /// Length of a word (window of cutting).
 /// </param>
 /// <param name="step">
 /// The number of elements through which the pointer will jump at the next iteration.
 /// </param>
 public BaseIterator(ComplexChain chain, int length, int step)
 {
     CursorPosition = -1;
     Initialize(chain, length, step);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SequenceCleaner"/> class.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 public SequenceCleaner(ComplexChain chain)
     : base(chain)
 {
 }
        public void ResetTest()
        {
            int lengthCut = 2;
            int step = 1;
            int index = 0;
            int position = 6;
            var list1 = new List<string>
                {
                    "ABABAB",
                    "ABATAT",
                    "TABABAB",
                    "ABTABAB",
                    "ABABAB",
                    "ABABAB",
                    "ABABAB"
                };
            var chain = new ComplexChain(list1);
            var iterator = new EndIterator(chain, lengthCut, step);
            while (iterator.HasNext())
            {
                iterator.Next();
                index = index + 1;
            }

            iterator.Reset();

            Assert.True(iterator.Position() == position);
        }
 /// <summary>
 /// The frequency.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="word">
 /// The word.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public double Frequency(ComplexChain chain, string word)
 {
     var temp = new List<object>(chain.Substring(0, chain.GetLength()));
     return Frequency(temp, word) / (double)chain.GetLength();
 }
 public void MoveTest()
 {
     int len = 2;
     int step = 1;
     int from = 1, to = 3;
     var list1 = new List<string>
         {
             "ABABAB",
             "ABATAT",
             "TABABAB",
             "ABTABAB",
             "ABABAB",
             "ABABAB",
             "ABABAB"
         };
     List<string> list = list1.GetRange(@from, to - @from);
     var chain = new ComplexChain(list1);
     var iterator = new EndIterator(chain, len, step);
     iterator.Move(2);
     List<string> result = iterator.Next();
     for (int i = 0; i < list.Count; i++)
     {
         Assert.True(list[i].Equals(result[i]));
     }
 }
 /// <summary>
 /// The distortion.
 /// </summary>
 /// <param name="chain">
 /// The chain.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public override double Distortion(ComplexChain chain, FrequencyDictionary alphabet)
 {
     return regularity.Calculate(chain, chain.Anchor);
 }