示例#1
0
        public void ValidateDerivedSequenceConvertToString()
        {
            string seqLargeStr = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                      Constants.seqLargeStringNode);
            ISequence seqLarge       = new Sequence(Alphabets.DNA, seqLargeStr);
            ISequence DeriveSeqLarge = new DerivedSequence(seqLarge, false, true);

            string ActualLargeString = DeriveSeqLarge.ToString();
            string seqLargeExpected  = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                            Constants.seqLargeExpectedNode);
            string expectedLargeString = string.Format(CultureInfo.CurrentCulture,
                                                       seqLargeExpected,
                                                       (seqLarge.Count - Helper.AlphabetsToShowInToString));

            Assert.AreEqual(expectedLargeString, ActualLargeString);

            // Get input and expected values from xml
            string expectedSequence = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.AlphabetNameNode);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            ISequence seq         = new Sequence(alphabet, expectedSequence);
            var       derSequence = new DerivedSequence(seq, false, false);

            Assert.AreEqual(expectedSequence.Substring(2, 5), derSequence.ConvertToString(2, 5));
        }
示例#2
0
        public void ValidateDnaDerivedSequenceIndexOfNonGap()
        {
            // Get input and expected values from xml
            string expectedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.AlphabetNameNode);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence);

            try
            {
                derSequence.IndexOfNonGap();
                Assert.Fail("The method is now implemented");
            }
            catch (NotImplementedException)
            {
                Console.WriteLine(
                    "DerivedSequenceBvtTestCases:Validation of IndexOfNonGap() method of derived sequence completed successfully");
                ApplicationLog.WriteLine(
                    "DerivedSequenceBvtTestCases:Validation of IndexOfNonGap() method of derived sequence completed successfully");
            }
        }
示例#3
0
        public void ValidateDnaDerivedSequenceGetSubSequence()
        {
            // Get input and expected values from xml
            string expectedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.AlphabetNameNode);
            string rangeObj = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.Range);
            string expSubSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.RangeSequence);
            string derivedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.DerivedSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence);

            string[] ranges = rangeObj.Split(',');

            // Validate IndexOf() derived Sequence.
            Assert.AreEqual(derivedSequence, new string(derSequence.Select(a => (char)a).ToArray()));
            Assert.AreEqual(expSubSequence, new string(derSequence.GetSubSequence(long.Parse(ranges[0],
                                                                                             (IFormatProvider)null), long.Parse(ranges[1], (IFormatProvider)null)).Select(a => (char)a).ToArray()));

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetSubSequence() method of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetSubSequence() method of derived sequence completed successfully");
        }
示例#4
0
        public void InValidateReplaceDerivedSequenceItems()
        {
            // Pass protein sequences
            ISequence       seqObj     = new Sequence(Alphabets.DNA, "AAGGTT");
            DerivedSequence deriSeqObj = new DerivedSequence(seqObj);

            // Pass invalid index value and get the exception required
            try
            {
                deriSeqObj.Replace(-1, deriSeqObj[0]);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for ReplaceRange() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for ReplaceRange() method");
            }

            // Pass invalid sequence and get the exception required
            try
            {
                deriSeqObj.Replace(1, null);
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for ReplaceRange() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for ReplaceRange() method");
            }
        }
示例#5
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Validates expected items are present in derived sequence using Contains() method.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceContains(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string removeRange = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveRange);
            string addSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.DerivedSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence, addSequence, removeRange);

            // Validate Contains() derived Sequence.
            Assert.AreEqual(derivedSequence, derSequence.ToString());
            Sequence sequence = new Sequence(alphabet, addSequence);

            foreach (ISequenceItem item in sequence)
            {
                Assert.IsTrue(derSequence.Contains(item));
            }

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Contains() method of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Contains() method of derived sequence completed successfully");
        }
示例#6
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Clear the derived sequence changes and validated that it matches against oroginal sequence.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceClear(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string removeRange = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveRange);
            string addSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence, addSequence, removeRange);

            // clear the changes.
            derSequence.Clear();

            // Validate derived Sequence changes are cleared
            // It matches now with source sequence.
            Assert.AreEqual(expectedSequence, derSequence.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Clear() method of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Clear() method of derived sequence completed successfully");
        }
示例#7
0
        /// <summary>
        /// Creates a dna derived sequence after removing few items using RemoveAt() from original sequence.
        /// Validates it against expected sequence.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceRemoveAt(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string removeRange = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveRange1);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveDerivedSequence2);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence.
            Sequence        seq         = new Sequence(alphabet, expectedSequence);
            DerivedSequence derSequence = new DerivedSequence(seq);

            string[] removals = removeRange.Split(',');
            int      position = int.Parse(removals[0], null);
            int      length   = int.Parse(removals[1], null);

            // Remove items
            for (int index = position; index <= length; index++)
            {
                derSequence.RemoveAt(index);
            }

            // Validate Derived Sequence
            Assert.AreEqual(derivedSequence, derSequence.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of RemoveAt() of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of RemoveAt() of derived sequence completed successfully");
        }
示例#8
0
        public void ValidateCopyTo()
        {
            // Get input and expected values from xml
            string expectedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.AlphabetNameNode);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence seqObj = CreateDerivedSequence(
                alphabet, expectedSequence);

            byte[] array = new byte[expectedSequence.Length];
            seqObj.CopyTo(array, 0, expectedSequence.Length);
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < expectedSequence.Length; i++)
            {
                builder.Append((char)array[i]);
            }
            string actualValue = builder.ToString();

            Assert.AreEqual(expectedSequence, actualValue);

            //check with a part of the expected seq only
            seqObj.CopyTo(array, 0, 5);
            builder = new StringBuilder();
            for (int i = 0; i < 5; i++)
            {
                builder.Append((char)array[i]);
            }
            actualValue = builder.ToString();
            Assert.AreEqual(expectedSequence.Substring(0, 5), actualValue);
        }
示例#9
0
        /// <summary>
        /// Creates a dna derived sequence after inserting few items using Insert(pos,item) from original sequence.
        /// Validates it against expected sequence.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceInsertWithSequenceItem(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.InsertDerivedSequence);
            string insertSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence.
            Sequence        seq         = new Sequence(alphabet, expectedSequence);
            DerivedSequence derSequence = new DerivedSequence(seq);
            int             position    = 1;

            // Insert sequence item
            Sequence insertSeq = new Sequence(alphabet, insertSequence);

            foreach (ISequenceItem item in insertSeq)
            {
                derSequence.Insert(position, item);
            }

            // Validate Derived Sequence
            Assert.AreEqual(derivedSequence, derSequence.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Insert() by passing item of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Insert() by passing item of derived sequence completed successfully");
        }
示例#10
0
        /// <summary>
        /// Creates a dna derived sequence after adding few items using Add() from original sequence.
        /// Validates it against expected sequence.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceAdd(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddDerivedSequence);
            string addSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence.
            Sequence        seq         = new Sequence(alphabet, expectedSequence);
            DerivedSequence derSequence = new DerivedSequence(seq);

            // Add sequence item
            Sequence addSeq = new Sequence(alphabet, addSequence);

            foreach (ISequenceItem item in addSeq)
            {
                derSequence.Add(item);
            }

            // Validate Derived Sequence
            Assert.AreEqual(derivedSequence, derSequence.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Add() of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Add() of derived sequence completed successfully");
        }
示例#11
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Create a copy of derived sequence and validates it against expected sequence.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceClone(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string removeRange = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveRange);
            string addSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.DerivedSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence, addSequence, removeRange);
            DerivedSequence derSequenceCopy = derSequence.Clone();


            // Validate copy of derived Sequence.
            Assert.AreEqual(derSequence.ToString(), derSequenceCopy.ToString());
            Assert.AreEqual(derivedSequence, derSequenceCopy.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Clone() of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Clone() of derived sequence completed successfully");
        }
示例#12
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Replace few items by passing char using Replace() and validates it against expected sequence.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceReplaceWithChar(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string derivedSequence = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.ReplaceSequence);
            string replaceSequence = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.ReplaceRangeSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence.
            Sequence        seq         = new Sequence(alphabet, expectedSequence);
            DerivedSequence derSequence = new DerivedSequence(seq);
            int             position    = 0;

            // Replace sequence with char.
            Sequence replaceSeq = new Sequence(alphabet, replaceSequence);

            foreach (ISequenceItem item in replaceSeq)
            {
                derSequence.Replace(position, item.Symbol);
                position++;
            }

            // Validate Derived Sequence
            Assert.AreEqual(derivedSequence, derSequence.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Replace() by passing char of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Replace() by passing char of derived sequence completed successfully");
        }
示例#13
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Get a sub sequence using Range() and validates it against expected sequence.
        /// </summary>
        /// <param name="nodeName"></param>
        private void ValidateDerivedSequenceRange(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string removeRange = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveRange);
            string addSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            string rangeSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RangeSequence);
            string    range    = _utilityObj._xmlUtil.GetTextValue(nodeName, Constants.Range);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence, addSequence, removeRange);

            string[] ranges   = range.Split(',');
            int      position = int.Parse(ranges[0], null);
            int      length   = int.Parse(ranges[1], null);

            ISequence sequence = derSequence.Range(position, length);

            // Validate range Sequence.
            Assert.AreEqual(rangeSequence, sequence.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Range() of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of Range() of derived sequence completed successfully");
        }
示例#14
0
        public void ValidateDnaDerivedSequenceGetComplemented()
        {
            // Get input and expected values from xml
            string expectedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.AlphabetNameNode);
            string complementObj = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.Complement);
            string derivedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.DerivedSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence);

            // Validate IndexOf() derived Sequence.
            Assert.AreEqual(derivedSequence, new string(derSequence.Select(a => (char)a).ToArray()));
            Assert.AreEqual(complementObj, new string(derSequence.GetComplementedSequence().Select(a => (char)a).ToArray()));

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetComplementedSequence() method of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetComplementedSequence() method of derived sequence completed successfully");
        }
示例#15
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Validates items of derived sequence using GeEnumerator()
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceGetEnumerator(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string removeRange = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveRange);
            string addSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.DerivedSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence, addSequence, removeRange);

            // Validate GetEnumerator() derived Sequence.
            Assert.AreEqual(derivedSequence, derSequence.ToString());
            IEnumerator <ISequenceItem> list = derSequence.GetEnumerator();
            int index = 0;

            while (list.MoveNext())
            {
                Assert.AreEqual(list.Current.Symbol, derivedSequence[index]);
                index++;
            }

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetEnumerator() method of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetEnumerator() method of derived sequence completed successfully");
        }
示例#16
0
        public void ValidateDnaDerivedSequenceProperties()
        {
            // Get input and expected values from xml
            string expectedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.AlphabetNameNode);
            string derivedSequence = utilityObj.xmlUtil.GetTextValue(
                Constants.DnaDerivedSequenceNode, Constants.DerivedSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence);

            // Validate properties of derived Sequence.
            Assert.AreEqual(derivedSequence, new string(derSequence.Select(a => (char)a).ToArray()));
            Assert.AreEqual(alphabet, derSequence.Alphabet);
            Assert.IsNotNull(derSequence.Metadata);

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of properties of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of properties of derived sequence completed successfully");
        }
示例#17
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Replace few items using ReplaceRange() and validates it against expected sequence.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceReplaceRange(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ReplaceSequence);
            string replaceSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ReplaceRangeSequence);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence.
            Sequence        seq         = new Sequence(alphabet, expectedSequence);
            DerivedSequence derSequence = new DerivedSequence(seq);
            int             position    = 0;

            // Replace range of sequence.
            derSequence.ReplaceRange(position, replaceSequence);

            // Validate Derived Sequence
            Assert.AreEqual(derivedSequence, derSequence.ToString());

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of ReplaceRange() of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of ReplaceRange() of derived sequence completed successfully");
        }
示例#18
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// </summary>
        /// <param name="alphabet">Alphabet</param>
        /// <param name="source">source sequence</param>
        private static DerivedSequence CreateDerivedSequence(
            IAlphabet alphabet, string source)
        {
            ISequence       seq         = new Sequence(alphabet, source);
            DerivedSequence derSequence = new DerivedSequence(seq, false, false);

            return(derSequence);
        }
示例#19
0
 public void TestDerivedSequenceConvertToString()
 {
     Sequence baseSeq = new Sequence(Alphabets.DNA, "ATCGATCGGATCGATCGGCTACTAATATCGATCGGCTACGATCGGCTAATCGATCGATCGGCTAATCGATCGATCGGCTAGCTA");
     DerivedSequence seq = new DerivedSequence(baseSeq, false, false);
     const string expectedValue = "TCGATCGGCT";
     string actualValue = seq.ConvertToString(10, 10);
     Assert.AreEqual(expectedValue, actualValue);
 }
示例#20
0
 public void TestGetReverseComplementedSequence()
 {
     const string sequence = "ATGCC";
     const string expectedSequence = "GGCAT";
     ISequence orignalSequence = new Sequence(Alphabets.DNA, sequence);
     DerivedSequence deriveSequence = new DerivedSequence(orignalSequence, false, false);
     string actualSequence = new string(deriveSequence.GetReverseComplementedSequence().Select(a => (char)a).ToArray());
     Assert.AreEqual(expectedSequence, actualSequence);
 }
示例#21
0
        public void TestDerivedSequenceConvertToString()
        {
            Sequence        baseSeq       = new Sequence(Alphabets.DNA, "ATCGATCGGATCGATCGGCTACTAATATCGATCGGCTACGATCGGCTAATCGATCGATCGGCTAATCGATCGATCGGCTAGCTA");
            DerivedSequence seq           = new DerivedSequence(baseSeq, false, false);
            const string    expectedValue = "TCGATCGGCT";
            string          actualValue   = seq.ConvertToString(10, 10);

            Assert.AreEqual(expectedValue, actualValue);
        }
示例#22
0
        public void TestGetReverseComplementedSequence()
        {
            const string    sequence         = "ATGCC";
            const string    expectedSequence = "GGCAT";
            ISequence       orignalSequence  = new Sequence(Alphabets.DNA, sequence);
            DerivedSequence deriveSequence   = new DerivedSequence(orignalSequence, false, false);
            string          actualSequence   = new string(deriveSequence.GetReverseComplementedSequence().Select(a => (char)a).ToArray());

            Assert.AreEqual(expectedSequence, actualSequence);
        }
示例#23
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// Validates its updated items against expected updated items.
        /// </summary>
        /// <param name="nodeName">alphabet xml node.</param>
        private void ValidateDerivedSequenceGetUpdatedItems(string nodeName)
        {
            // Get input and expected values from xml
            string expectedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedSequence);
            string alphabetName = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string removeRange = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.RemoveRange);
            string addSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AddSequence);
            string derivedSequence = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.DerivedSequence);
            string updatedItems = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.UpdatedItemList);
            string updatedIndices = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.UpdatedItemsIndex);
            string updatedTypes = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.UpdatedTypeList);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            DerivedSequence derSequence = CreateDerivedSequence(
                alphabet, expectedSequence, addSequence, removeRange);

            string[] updatedIndexList = updatedIndices.Split(',');
            string[] updatedTypesList = updatedTypes.Split(',');
            Assert.AreEqual(updatedTypesList.Length, updatedIndexList.Length);

            // Validate derived Sequence.
            Assert.AreEqual(derivedSequence, derSequence.ToString());

            // Validate GetUpdatedItems
            IList <IndexedItem <UpdatedSequenceItem> > actualUpdatedItemList =
                derSequence.GetUpdatedItems();

            Assert.AreEqual(updatedIndexList.Length, actualUpdatedItemList.Count);
            for (int index = 0; index < actualUpdatedItemList.Count; index++)
            {
                Assert.AreEqual(updatedIndexList[index],
                                actualUpdatedItemList[index].Index.ToString((IFormatProvider)null));
                Assert.AreEqual(updatedItems[index].ToString(),
                                actualUpdatedItemList[index].Item.SequenceItem.Symbol.ToString((IFormatProvider)null));
                Assert.AreEqual(updatedTypesList[index],
                                actualUpdatedItemList[index].Item.Type.ToString());
            }

            Console.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetUpdatedItems() of derived sequence completed successfully");
            ApplicationLog.WriteLine(
                "DerivedSequenceBvtTestCases:Validation of GetUpdatedItems() of derived sequence completed successfully");
        }
示例#24
0
 public void TestDeriveSequenceCopyTo()
 {
     ISequence seq = new Sequence(Alphabets.DNA, "ATCG");
     DerivedSequence derSeq = new DerivedSequence(seq, false, true);
     byte[] array = new byte[2];
     derSeq.CopyTo(array, 1, 2);
     string expectedValue = "AG";
     StringBuilder b = new StringBuilder();
     b.Append((char)array[0]);
     b.Append((char)array[1]);
     string actualValue = b.ToString();
     Assert.AreEqual(expectedValue, actualValue);
 }
示例#25
0
        public void ValidateDerivedContainsNullSeqItem()
        {
            // Pass protein sequences
            ISequence       seqObj  = new Sequence(Alphabets.Protein, "EEE");
            DerivedSequence deriSeq = new DerivedSequence(seqObj);

            // Validate null sequence item in the derived sequence object
            Assert.IsFalse(deriSeq.Contains(null));
            ApplicationLog.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated the Contains method for null sequence item");
            Console.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated the Contains method for null sequence item");
        }
示例#26
0
        public void ValidateDerivedIndexOfNull()
        {
            Sequence seqObj = new Sequence(Alphabets.Protein, "KIE");

            // Valid index of validation
            DerivedSequence deriSeq = new DerivedSequence(seqObj);

            Assert.AreEqual(-1, deriSeq.IndexOf(null));
            ApplicationLog.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated IndexOf() method with null values");
            Console.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated the IndexOf() method with null values");
        }
示例#27
0
        public void ValidateDerivedInvalidRemove()
        {
            // Pass protein sequences
            ISequence       seqObj     = new Sequence(Alphabets.DNA, "AAGGTT");
            DerivedSequence deriSeqObj = new DerivedSequence(seqObj);

            ISequence tempSeq = new Sequence(Alphabets.DNA, "C");

            Assert.IsFalse(deriSeqObj.Remove(tempSeq[0]));

            ApplicationLog.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveAt() method");
            Console.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveAt() method");
        }
示例#28
0
        public void TestDerivedSequenceToString()
        {
            ISequence seqSmall       = new Sequence(Alphabets.DNA, "ATCG");
            ISequence seqLarge       = new Sequence(Alphabets.DNA, "ATCGGGGGGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGTTTTTTTTTTTTTTT");
            ISequence DeriveSeqSmall = new DerivedSequence(seqSmall, false, true);
            ISequence DeriveSeqLarge = new DerivedSequence(seqLarge, false, true);

            string ActualSmallString   = DeriveSeqSmall.ToString();
            string ActualLargeString   = DeriveSeqLarge.ToString();
            string ExpectedSmallString = "TAGC";
            string expectedLargeString = string.Format(CultureInfo.CurrentCulture, "TAGCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGCCCCCCCCCCAAAAA... +[{0}]", (seqLarge.Count - Helper.AlphabetsToShowInToString));

            Assert.AreEqual(ExpectedSmallString, ActualSmallString);
            Assert.AreEqual(expectedLargeString, ActualLargeString);
        }
示例#29
0
        public void ValidateDerivedSeqInvalidRange()
        {
            // Pass protein sequences
            ISequence       seqObj     = new Sequence(Alphabets.DNA, "AAGGTT");
            DerivedSequence deriSeqObj = new DerivedSequence(seqObj);

            // Pass invalid index value and get the exception required
            try
            {
                deriSeqObj.Range(-1, -1);
                Assert.IsTrue(false);
            }
            catch (ArgumentOutOfRangeException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for Range() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for Range() method");
            }

            // Pass length value lesser than zero.
            try
            {
                deriSeqObj.Range(1, -21);
                Assert.IsTrue(false);
            }
            catch (ArgumentOutOfRangeException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for Range() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for Range() method");
            }

            // Pass invalid length and startPos value.
            try
            {
                deriSeqObj.Range(2, 6);
                Assert.IsTrue(false);
            }
            catch (ArgumentException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for Range() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for Range() method");
            }
        }
示例#30
0
        public void ValidateDerivedInvalidRemoveRange()
        {
            // Pass protein sequences
            ISequence       seqObj     = new Sequence(Alphabets.DNA, "AAGGTT");
            DerivedSequence deriSeqObj = new DerivedSequence(seqObj);

            // Pass invalid index value and get the exception required
            try
            {
                deriSeqObj.RemoveRange(-1, 0);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveRange() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveRange() method");
            }

            // Pass invalid length value and get the exception required
            try
            {
                deriSeqObj.RemoveRange(3, -1);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveRange() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveRange() method");
            }

            // Pass invalid length, index value and get the exception required
            try
            {
                deriSeqObj.RemoveRange(1, 10);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                ApplicationLog.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveRange() method");
                Console.WriteLine(
                    "DerivedSequenceP2TestCases : Successfully validated the exception for RemoveRange() method");
            }
        }
示例#31
0
        public void ValidateDerivedContainsDnaRnaSeqItem()
        {
            // Pass protein sequences
            ISequence     seqObj     = new Sequence(Alphabets.DNA, "GCT");
            ISequence     tempObj    = new Sequence(Alphabets.RNA, "UUU");
            ISequenceItem seqItemObj = tempObj[0];

            DerivedSequence deriSeq = new DerivedSequence(seqObj);

            // Validate in valid sequence item in the derived sequence object
            Assert.IsFalse(deriSeq.Contains(seqItemObj));
            ApplicationLog.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated the Contains method for Rna sequence item");
            Console.WriteLine(
                "DerivedSequenceP2TestCases : Successfully validated the Contains method for Rna sequence item");
        }
示例#32
0
        public void TestDeriveSequenceCopyTo()
        {
            ISequence       seq    = new Sequence(Alphabets.DNA, "ATCG");
            DerivedSequence derSeq = new DerivedSequence(seq, false, true);

            byte[] array = new byte[2];
            derSeq.CopyTo(array, 1, 2);
            string        expectedValue = "AG";
            StringBuilder b             = new StringBuilder();

            b.Append((char)array[0]);
            b.Append((char)array[1]);
            string actualValue = b.ToString();

            Assert.AreEqual(expectedValue, actualValue);
        }
示例#33
0
        public void ValidateDerivedSequenceToString()
        {
            ISequence seqSmall    = new Sequence(Alphabets.DNA, "ATCG");
            string    seqLargeStr = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                         Constants.seqLargeStringNode);
            ISequence seqLarge       = new Sequence(Alphabets.DNA, seqLargeStr);
            ISequence DeriveSeqSmall = new DerivedSequence(seqSmall, false, true);
            ISequence DeriveSeqLarge = new DerivedSequence(seqLarge, false, true);

            string ActualSmallString   = DeriveSeqSmall.ToString();
            string ActualLargeString   = DeriveSeqLarge.ToString();
            string ExpectedSmallString = "TAGC";
            string seqLargeExpected    = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                              Constants.seqLargeExpectedNode);
            string expectedLargeString = string.Format(CultureInfo.CurrentCulture,
                                                       seqLargeExpected,
                                                       (seqLarge.Count - Helper.AlphabetsToShowInToString));

            Assert.AreEqual(ExpectedSmallString, ActualSmallString);
            Assert.AreEqual(expectedLargeString, ActualLargeString);

            //read sequences from file
            // Get input and expected values from xml
            string expectedSequence = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.AlphabetNameNode);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            ISequence seq         = new Sequence(alphabet, expectedSequence);
            var       derSequence = new DerivedSequence(seq, false, false);

            string actualDerivedSeqStr = derSequence.ToString();

            if (actualDerivedSeqStr.Length > Helper.AlphabetsToShowInToString)
            {
                //check if the whole sequence string contains the string retrieved from ToString
                Assert.IsTrue(
                    expectedSequence.Contains(derSequence.ToString().Substring(0, Helper.AlphabetsToShowInToString)));
                Assert.IsTrue(derSequence.ToString().Contains("... +["));
            }
            else
            {
                Assert.AreEqual(expectedSequence, derSequence.ToString());
            }
        }
示例#34
0
        public void ValidateDerivedSequenceConvertToString()
        {
            string seqLargeStr = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                 Constants.seqLargeStringNode);
            ISequence seqLarge = new Sequence(Alphabets.DNA, seqLargeStr);
            ISequence DeriveSeqLarge = new DerivedSequence(seqLarge, false, true);

            string ActualLargeString = DeriveSeqLarge.ToString();
            string seqLargeExpected = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                      Constants.seqLargeExpectedNode);
            string expectedLargeString = string.Format(CultureInfo.CurrentCulture,
                                                       seqLargeExpected,
                                                       (seqLarge.Count - Helper.AlphabetsToShowInToString));

            Assert.AreEqual(expectedLargeString, ActualLargeString);

            // Get input and expected values from xml
            string expectedSequence = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.AlphabetNameNode);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            ISequence seq = new Sequence(alphabet, expectedSequence);
            var derSequence = new DerivedSequence(seq, false, false);

            Assert.AreEqual(expectedSequence.Substring(2, 5), derSequence.ConvertToString(2, 5));
        }
示例#35
0
        public void InvalidateDerivedSequenceConvertToString()
        {
            try
            {
                //check with blank sequene
                var baseSeq = new Sequence(Alphabets.DNA, "");
                var seq = new DerivedSequence(baseSeq, false, false);
                string seqStr = seq.ConvertToString(0, 3);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException aorex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentOutOfRangeException : " + aorex.Message);
            }

            try
            {
                //check with length greater than actual length
                var baseSeq = new Sequence(Alphabets.DNA, "ATGCCCC");
                var seq = new DerivedSequence(baseSeq, false, false);
                string seqStr = seq.ConvertToString(0, 30);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException aorex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentOutOfRangeException : " + aorex.Message);
            }

            try
            {
                //check with length < 0
                var baseSeq = new Sequence(Alphabets.DNA, "ATGCCCC");
                var seq = new DerivedSequence(baseSeq, false, false);
                string seqStr = seq.ConvertToString(0, -30);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException aorex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentOutOfRangeException : " + aorex.Message);
            }

            try
            {
                //check with start index < 0
                var baseSeq = new Sequence(Alphabets.DNA, "ATGCCCC");
                var seq = new DerivedSequence(baseSeq, false, false);
                string seqStr = seq.ConvertToString(-10, 3);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException aorex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentOutOfRangeException : " + aorex.Message);
            }

            try
            {
                //check with start index greater than actual length
                var baseSeq = new Sequence(Alphabets.DNA, "ATGCCCC");
                var seq = new DerivedSequence(baseSeq, false, false);
                string seqStr = seq.ConvertToString(30, 3);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException aorex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentOutOfRangeException : " + aorex.Message);
            }

            try
            {
                //check with null sequence
                Sequence baseSeq = null;
                var seq = new DerivedSequence(baseSeq, false, false);
                string seqStr = seq.ConvertToString(0, 3);
                Assert.Fail();
            }
            catch (NullReferenceException nre)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentOutOfRangeException : " + nre.Message);
            }
        }
示例#36
0
        public void ValidateDerivedSequenceToString()
        {
            ISequence seqSmall = new Sequence(Alphabets.DNA, "ATCG");
            string seqLargeStr = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                 Constants.seqLargeStringNode);
            ISequence seqLarge = new Sequence(Alphabets.DNA, seqLargeStr);
            ISequence DeriveSeqSmall = new DerivedSequence(seqSmall, false, true);
            ISequence DeriveSeqLarge = new DerivedSequence(seqLarge, false, true);

            string ActualSmallString = DeriveSeqSmall.ToString();
            string ActualLargeString = DeriveSeqLarge.ToString();
            string ExpectedSmallString = "TAGC";
            string seqLargeExpected = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                      Constants.seqLargeExpectedNode);
            string expectedLargeString = string.Format(CultureInfo.CurrentCulture,
                                                       seqLargeExpected,
                                                       (seqLarge.Count - Helper.AlphabetsToShowInToString));

            Assert.AreEqual(ExpectedSmallString, ActualSmallString);
            Assert.AreEqual(expectedLargeString, ActualLargeString);

            //read sequences from file
            // Get input and expected values from xml
            string expectedSequence = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.ExpectedSequence);
            string alphabetName = this.utilityObj.xmlUtil.GetTextValue(
                Constants.ProteinDerivedSequenceNode, Constants.AlphabetNameNode);
            IAlphabet alphabet = Utility.GetAlphabet(alphabetName);

            // Create derived Sequence
            ISequence seq = new Sequence(alphabet, expectedSequence);
            var derSequence = new DerivedSequence(seq, false, false);

            string actualDerivedSeqStr = derSequence.ToString();
            if (actualDerivedSeqStr.Length > Helper.AlphabetsToShowInToString)
            {
                //check if the whole sequence string contains the string retrieved from ToString
                Assert.IsTrue(
                    expectedSequence.Contains(derSequence.ToString().Substring(0, Helper.AlphabetsToShowInToString)));
                Assert.IsTrue(derSequence.ToString().Contains("... +["));
            }
            else
            {
                Assert.AreEqual(expectedSequence, derSequence.ToString());
            }
        }
示例#37
0
        /// <summary>
        /// Creates a dna derived sequence after adding and removing few items from original sequence.
        /// </summary>
        /// <param name="alphabet">Alphabet</param>
        /// <param name="source">source sequence</param>
        private static DerivedSequence CreateDerivedSequence(
            IAlphabet alphabet, string source)
        {
            ISequence seq = new Sequence(alphabet, source);
            DerivedSequence derSequence = new DerivedSequence(seq, false, false);

            return derSequence;
        }
示例#38
0
        public void TestDerivedSequenceToString()
        {
            ISequence seqSmall = new Sequence(Alphabets.DNA, "ATCG");
            ISequence seqLarge = new Sequence(Alphabets.DNA, "ATCGGGGGGGGGGGGGGGGGGGGGGGGCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGTTTTTTTTTTTTTTT");
            ISequence DeriveSeqSmall = new DerivedSequence(seqSmall, false, true);
            ISequence DeriveSeqLarge = new DerivedSequence(seqLarge, false, true);

            string ActualSmallString = DeriveSeqSmall.ToString();
            string ActualLargeString = DeriveSeqLarge.ToString();
            string ExpectedSmallString = "TAGC";
            string expectedLargeString = string.Format(CultureInfo.CurrentCulture, "TAGCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGCCCCCCCCCCAAAAA... +[{0}]", (seqLarge.Count - Helper.AlphabetsToShowInToString));

            Assert.AreEqual(ExpectedSmallString, ActualSmallString);
            Assert.AreEqual(expectedLargeString, ActualLargeString);
        }
示例#39
0
        /// <summary>
        /// Returns a sequence which contains bases from the specified sequence as specified by the location.
        /// If the location contains accession then the sequence from the referredSequences which matches the 
        /// accession of the location will be considered.
        /// 
        /// For example,
        /// if location is "join(100..200, J00089.1:10..50, J00090.2:30..40)"
        /// then bases from 100 to 200 will be considered from the sequence parameter and referredSequences will
        /// be searched for the J00089.1 and J00090.2 accession if found then those sequences will be considered 
        /// for constructing the output sequence.
        /// If the referred sequence is not found in the referredSequences then an exception will occur.
        /// </summary>
        /// <param name="location">Location instance.</param>
        /// <param name="sequence">Sequence instance from which the sub sequence has to be returned.</param>
        /// <param name="referredSequences">A dictionary containing Accession numbers as keys and Sequences as values, this will be used when
        /// the location or sub-locations contains accession.</param>
        public ISequence GetSubSequence(ILocation location, ISequence sequence, Dictionary<string, ISequence> referredSequences)
        {
            if (location == null)
            {
                throw new ArgumentNullException(Properties.Resource.ParameterNameLocation);
            }

            if (sequence == null)
            {
                throw new ArgumentNullException(Properties.Resource.ParameterNameSequence);
            }

            DerivedSequence basicDerSeq;

            if (location.Operator == LocationOperator.Complement)
            {
                if (location.SubLocations.Count > 1)
                {
                    throw new ArgumentException(Properties.Resource.ComplementWithMorethanOneSubLocs);
                }

                if (location.SubLocations.Count > 0)
                {
                    basicDerSeq = new DerivedSequence(location.SubLocations[0].GetSubSequence(sequence, referredSequences), false, true);
                }
                else
                {
                    basicDerSeq = new DerivedSequence(GetSubSequence(location.LocationStart, location.LocationEnd, location.Accession, location.Separator, sequence, referredSequences), false, true);
                }

                byte[] tempSeqData = new byte[basicDerSeq.Count];
                for (int i = 0; i < basicDerSeq.Count; i++)
                {
                    tempSeqData[i] = basicDerSeq[i];
                }

                return new Sequence(sequence.Alphabet, tempSeqData);
            }

            if (location.Operator == LocationOperator.Order)
            {
                List<ISequence> subSequences = new List<ISequence>();
                if (location.SubLocations.Count > 0)
                {
                    foreach (ILocation loc in location.SubLocations)
                    {
                        subSequences.Add(loc.GetSubSequence(sequence, referredSequences));
                    }
                }
                else
                {
                    basicDerSeq = new DerivedSequence(GetSubSequence(location.LocationStart, location.LocationEnd, location.Accession, location.Separator, sequence, referredSequences), false, false);
                    byte[] seqData = new byte[basicDerSeq.Count];
                    for (long i = 0; i < basicDerSeq.Count; i++)
                    {
                        seqData[i] = basicDerSeq[i];
                    }

                    subSequences.Add(new Sequence(sequence.Alphabet, seqData));
                }

                long totalSubSequenceLength = 0;
                long j = 0;
                foreach (ISequence seq in subSequences)
                {
                    totalSubSequenceLength += seq.Count;
                }
                byte[] tempSeqData = new byte[totalSubSequenceLength];
                totalSubSequenceLength = 0;
                IAlphabet alphabet = null;
                int m = 0;
                foreach (ISequence seq in subSequences)
                {
                    totalSubSequenceLength += seq.Count;
                    while (j < totalSubSequenceLength)
                    {
                        tempSeqData[j] = seq[m];
                        j++;
                        m++;
                    }
                    m = 0;
                    alphabet = seq.Alphabet;
                    
                }

                //return Segmented sequence.
                return new Sequence(alphabet, tempSeqData);
            }

            if (location.Operator == LocationOperator.Join || location.Operator == LocationOperator.Bond)
            {
                if (location.SubLocations.Count > 0)
                {
                    List<ISequence> subSequences = new List<ISequence>();
                    foreach (ILocation loc in location.SubLocations)
                    {
                        subSequences.Add(loc.GetSubSequence(sequence, referredSequences));
                    }


                    long i = 0;
                    long subSeqLength = 0;
                    foreach (ISequence subSeq in subSequences)
                    {
                        subSeqLength += subSeq.Count;
                    }
                    byte[] seqData = new byte[subSeqLength];
                    subSeqLength = 0;
                    int m = 0;
                    foreach (ISequence subSeq in subSequences)
                    {
                        subSeqLength += subSeq.Count;
                        while (i < subSeqLength)
                        {
                            seqData[i] = subSeq[m];
                            i++; 
                            m++;
                        }
                        m = 0;
                    }

                    Sequence seq = new Sequence(sequence.Alphabet,seqData);

                    return seq;
                }
                else
                {
                    return GetSubSequence(location.LocationStart, location.LocationEnd, location.Accession, location.Separator, sequence, referredSequences);
                }
            }

            if (location.SubLocations.Count > 0)
            {
                throw new ArgumentException(Properties.Resource.NoneWithSubLocs);
            }

            return GetSubSequence(location.LocationStart, location.LocationEnd, location.Accession, location.Separator, sequence, referredSequences);
        }