GetLength() public method

The length of chain.
public GetLength ( ) : int
return int
        /// <summary>
        /// Method that creates chain of "first occurrences of different elements".
        /// </summary>
        /// <param name="source">
        /// Source chain.
        /// </param>
        /// <returns>/
        /// Dissimilar chain.
        /// </returns>
        public static Chain Create(BaseChain source)
        {
            var result = new Chain(source.GetLength());
            Alphabet sourceAlphabet = source.Alphabet;
            var entries = new int[sourceAlphabet.Cardinality];

            for (int i = 0; i < source.GetLength(); i++)
            {
                int elementIndex = sourceAlphabet.IndexOf(source[i]);
                int entry = ++entries[elementIndex];
                result.Set(new ValueInt(entry), i);
            }

            return result;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TreeTop"/> class,
        /// representing root element of the tree.
        /// </summary>
        /// <param name="source">
        /// The input chain.
        /// </param>
        /// <param name="generator">
        /// The gen.
        /// </param>
        public TreeTop(BaseChain source, IGenerator generator)
        {
            table = new PhantomTable(source);
            this.generator = generator;
            StartPosition = 0;
            Volume = table[0].Volume;
            Level = -1;
            if ((table[1].Content[0] is ValueString) || (table[1].Content[0] is BaseChain))
            {
                isString = true;
            }

            if ((source != null) && (source.GetLength() != 0))
            {
                var temp = (ValuePhantom)source[0];
                for (int i = 0; i < temp.Cardinality; i++)
                {
                    Children.Add(new TreeNode(this, temp[i], table));
                }
            }
        }
        public void SortListTest()
        {
            var temp = new ChainsAlphabet();
            var a = new BaseChain(2);
            for (int i = 0; i < a.GetLength(); i++)
            {
                a.Set((ValueInt)i, i);
            }

            temp.Add(a);
            var b = new BaseChain(1);
            for (int i = 0; i < b.GetLength(); i++)
            {
                b.Set((ValueInt)i, i);
            }

            temp.Add(b);
            var c = new BaseChain(5);
            for (int i = 0; i < c.GetLength(); i++)
            {
                c.Set((ValueInt)i, i);
            }

            temp.Add(c);
            var d = new BaseChain(2);
            for (int i = 0; i < d.GetLength(); i++)
            {
                d.Set((ValueInt)(i + 1), i);
            }

            temp.Add(d);
            ArrayList list = temp.GetLengthList();
            Assert.AreEqual(5, list[2]);
            Assert.AreEqual(2, list[1]);
            Assert.AreEqual(1, list[0]);
        }
 public void ConstructorTest()
 {
     chain = new Chain(100);
     Assert.AreEqual(100, chain.GetLength());
 }
        public void AddLengthMoreThanChainRankTest()
        {
            alphabet.Add(a);
            alphabet.Add(b);
            alphabet.Add(c);
            alphabet.Add(d);

            baseChain = new BaseChain(3);

            baseChain.Set(a, 0);
            baseChain.Set(b, 1);
            baseChain.Set(b, 2);

            matrix = new Matrix(alphabet.Cardinality, 2);
            var arrayCh = new int[baseChain.GetLength()];
            arrayCh[0] = alphabet.IndexOf(baseChain[0]);
            arrayCh[1] = alphabet.IndexOf(baseChain[1]);
            arrayCh[2] = alphabet.IndexOf(baseChain[2]);
            Assert.Throws<ArgumentException>(() => matrix.Add(arrayCh));
        }
        public void LargerNTest()
        {
            alphabet.Add(a);
            alphabet.Add(b);
            alphabet.Add(c);
            alphabet.Add(d);

            baseChain = new BaseChain(2);
            baseChain.Set(f, 0);
            baseChain.Set(c, 1);

            matrix = new Matrix(alphabet.Cardinality, 2);
            var array = new int[baseChain.GetLength()];
            array[0] = alphabet.IndexOf(baseChain[0]);
            array[1] = alphabet.IndexOf(baseChain[1]);
            Assert.Throws<ArgumentOutOfRangeException>(() => matrix.FrequencyFromObject(array));
        }
        public ActionResult Index(long matterId, string[] file)
        {
            return Action(() =>
            {
                var myFile = Request.Files[0];

                if (myFile == null || myFile.ContentLength == 0)
                {
                    throw new ArgumentNullException("file", "Sequence file not found or empty.");
                }

                int fileLen = myFile.ContentLength;
                var input = new byte[fileLen];

                // Initialize the stream.
                var fileStream = myFile.InputStream;

                // Read the file into the byte array.
                fileStream.Read(input, 0, fileLen);

                // Copy the byte array into a string.
                string stringSequence = Encoding.ASCII.GetString(input);
                string[] tempString = stringSequence.Split('\n', '\r');

                var sequenceStringBuilder = new StringBuilder();
                string fastaHeader = tempString[0];

                for (int j = 1; j < tempString.Length; j++)
                {
                    sequenceStringBuilder.Append(tempString[j]);
                }

                string resultStringSequence = DataTransformers.CleanFastaFile(sequenceStringBuilder.ToString());

                var chain = new BaseChain(resultStringSequence);

                long sequenceId = db.CommonSequence.Single(c => c.MatterId == matterId).Id;

                string message;

                BaseChain dataBaseChain = commonSequenceRepository.ToLibiadaBaseChain(sequenceId);

                if (dataBaseChain.Equals(chain))
                {
                    message = "Sequence in db and in file are equal";
                }
                else
                {
                    if (chain.Alphabet.Cardinality != dataBaseChain.Alphabet.Cardinality)
                    {
                        message = "Alphabet sizes are not equal. In db - " + dataBaseChain.Alphabet.Cardinality + ". In file - " + chain.Alphabet.Cardinality;

                        return new Dictionary<string, object> { { "message", message } };
                    }

                    for (int i = 0; i < chain.Alphabet.Cardinality; i++)
                    {
                        if (!chain.Alphabet[i].ToString().Equals(dataBaseChain.Alphabet[i].ToString()))
                        {
                            message = i + "Elements in alphabet are not equal. In db - " + dataBaseChain.Alphabet[i] + ". In file - " + chain.Alphabet[i];

                            return new Dictionary<string, object> { { "message", message } };
                        }
                    }

                    if (chain.GetLength() != dataBaseChain.GetLength())
                    {
                        message = "Sequence length in db " + dataBaseChain.GetLength() + ", and sequence length from file" + chain.GetLength();

                        return new Dictionary<string, object> { { "message", message } };
                    }

                    int[] libiadaBuilding = chain.Building;
                    int[] dataBaseBuilding = dataBaseChain.Building;

                    for (int j = 0; j < chain.GetLength(); j++)
                    {
                        if (libiadaBuilding[j] != dataBaseBuilding[j])
                        {
                            message = j + "Sequences elements are not equal. In db " + dataBaseBuilding[j] + ". In file " + libiadaBuilding[j];

                            return new Dictionary<string, object> { { "message", message } };
                        }
                    }

                    message = "Sequences are equal and not equal at the same time.";
                }

                return new Dictionary<string, object> { { "message", message } };
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActualChain"/> class.
 /// </summary>
 /// <param name="source">
 /// The source chain.
 /// </param>
 public ActualChain(BaseChain source)
 {
     Source = (BaseChain)source.Clone();
     actualLength = 0;
     resultChain = new BaseChain(source.GetLength());
 }