Example #1
0
        public void VirtualSequenceClone()
        {
            VirtualSequence virtualSeq = new VirtualSequence(Alphabets.DNA);
            string          id         = Guid.NewGuid().ToString(String.Empty);

            virtualSeq.ID           = id;
            virtualSeq.DisplayID    = "Id to display";
            virtualSeq.MoleculeType = MoleculeType.DNA;

            // Test cloning of data in Metadata property.
            virtualSeq.Metadata.Add("NotCloneable", Alphabets.DNA);
            Sequence seqCloneable = new Sequence(Alphabets.RNA);

            virtualSeq.Metadata.Add("CloneableValue", seqCloneable);

            VirtualSequence cloneCopy1 = virtualSeq.Clone();

            Assert.AreNotSame(cloneCopy1, virtualSeq);
            Assert.AreEqual(virtualSeq.ID, cloneCopy1.ID);
            Assert.AreEqual(virtualSeq.DisplayID, cloneCopy1.DisplayID);
            Assert.AreEqual(virtualSeq.MoleculeType, cloneCopy1.MoleculeType);
            Assert.AreNotSame(virtualSeq.Metadata, cloneCopy1.Metadata);
            Assert.AreSame(virtualSeq.Metadata["NotCloneable"], cloneCopy1.Metadata["NotCloneable"]);
            Assert.AreNotSame(virtualSeq.Metadata["CloneableValue"], cloneCopy1.Metadata["CloneableValue"]);
        }
Example #2
0
 /// <summary>
 /// Validate VirtualSeq Contains method exception
 /// </summary>
 /// <param name="virtualSeq">Virtual seq</param>
 static void VirtualSeqContainsValidation(VirtualSequence virtualSeq)
 {
     foreach (Nucleotide nucleotide in Alphabets.DNA)
     {
         Assert.IsFalse(virtualSeq.Contains(nucleotide));
     }
 }
Example #3
0
        public void ValidateVirtualSequenceGetObjectData()
        {
            ISequence virSeq =
                new VirtualSequence(Alphabets.DNA);

            SerializationInfo info =
                new SerializationInfo(typeof(Sequence),
                                      new FormatterConverter());
            StreamingContext context =
                new StreamingContext(StreamingContextStates.All);

            // Serialize the target object
            virSeq.GetObjectData(info, context);

            Assert.IsNull(info.GetValue(
                              string.Format("{0}:{1}",
                                            Constants.VirtualSequence, Constants.Documentation),
                              typeof(object)));
            Assert.IsNotNull(info.GetValue(
                                 string.Format("{0}:{1}",
                                               Constants.VirtualSequence, Constants.SeqInfo),
                                 typeof(BasicSequenceInfo)));
            Assert.IsNotNull(info.GetValue(
                                 string.Format("{0}:{1}",
                                               Constants.VirtualSequence, Constants.MoleculeType),
                                 typeof(MoleculeType)));
            Assert.AreEqual(null, info.GetValue(
                                string.Format("{0}:{1}",
                                              Constants.VirtualSequence, Constants.Documentation),
                                typeof(object)));
            Assert.AreEqual(
                Constants.MBFBasicSequenceInfo,
                info.GetValue(
                    string.Format("{0}:{1}",
                                  Constants.VirtualSequence, Constants.SeqInfo),
                    typeof(BasicSequenceInfo)).ToString());
            Assert.AreEqual(MoleculeType.Invalid,
                            info.GetValue(
                                string.Format("{0}:{1}",
                                              Constants.VirtualSequence, Constants.MoleculeType),
                                typeof(MoleculeType)));

            // Create a copy of Virtual Sequence
            object seqClone = virSeq.Clone();

            Assert.IsNotNull(seqClone);
            Assert.IsNotNull(seqClone);
            Assert.AreEqual(
                ((MBF.VirtualSequence)(seqClone)).Alphabet, Alphabets.DNA);
            Assert.AreEqual(
                ((MBF.VirtualSequence)(seqClone)).Documentation, null);
            Assert.AreEqual(
                ((MBF.VirtualSequence)(seqClone)).IsReadOnly, true);
            Assert.AreEqual(
                ((MBF.VirtualSequence)(seqClone)).MoleculeType, MoleculeType.Invalid);
            Assert.AreEqual(
                ((MBF.VirtualSequence)(seqClone)).UseEncoding, false);
        }
Example #4
0
 /// <summary>
 /// Validate VirtualSeq IndexOf method exception
 /// </summary>
 /// <param name="virtualSeq">Virtual seq</param>
 static void VirtualSeqIndexOfValidation(VirtualSequence virtualSeq,
                                         string expectedValue)
 {
     foreach (Nucleotide nucleotide in Alphabets.RNA)
     {
         Assert.AreEqual(virtualSeq.IndexOf(nucleotide).ToString((IFormatProvider)null),
                         expectedValue);
     }
 }
Example #5
0
        /// <summary>
        /// General method to validate creation of clone virtual seqeunce.
        /// <param name="nodeName">xml node name.</param>
        /// </summary>
        void ValidateGeneralVirtualSequenceCloning(
            string nodeName)
        {
            // Gets alphabet and properties from the Xml
            string alphabet = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string id = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.Id);
            string diplayId = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.DisplayId);
            string expectedDocumentaion = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.Documentaion);

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Virtual Sequence P1: Sequence {0} is expected.", alphabet));

            // Create virtual seqeunce for an alphabet.
            VirtualSequence virtualSeq = new VirtualSequence(
                Utility.GetAlphabet(alphabet));

            // Set the value to virtual sequences.
            virtualSeq.ID            = id;
            virtualSeq.DisplayID     = diplayId;
            virtualSeq.Documentation = expectedDocumentaion;

            // Create a copy of virtual seqeunce.
            VirtualSequence cloneVirtualSeq = virtualSeq.Clone();

            // Validate the created clone virtual Sequence
            Assert.AreEqual(virtualSeq.DisplayID, cloneVirtualSeq.DisplayID);
            Assert.AreEqual(virtualSeq.ID, cloneVirtualSeq.ID);
            Assert.AreEqual(virtualSeq.Documentation, cloneVirtualSeq.Documentation);
            Assert.AreNotSame(virtualSeq, cloneVirtualSeq);
            Assert.AreEqual(virtualSeq.Alphabet, cloneVirtualSeq.Alphabet);
            Assert.AreEqual(virtualSeq.Count, cloneVirtualSeq.Count);
            Assert.AreEqual(virtualSeq.Statistics, cloneVirtualSeq.Statistics);

            // Logs to the NUnit GUI (Console.Out) window
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence P1: Clone Virtual Sequence ID {0} is as expected.",
                                            cloneVirtualSeq.ID.ToString((IFormatProvider)null)));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence P1: Clone Virtual Sequence Display ID {0} is as expected.",
                                            cloneVirtualSeq.DisplayID.ToString((IFormatProvider)null)));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence P1:Clone Virtual Sequence count {0} is as expected.",
                                            cloneVirtualSeq.Count.ToString((IFormatProvider)null)));

            // Logs to the NUnit GUI (Console.Out) window
            Console.WriteLine(
                "Virtual Sequence P1:Clone Virtual Sequence validation is completed successfully.");
        }
Example #6
0
 /// <summary>
 /// Validate VirtualSeq Complement method exception
 /// </summary>
 /// <param name="virtualSeq">Virtual seq</param>
 /// <param name="exThrown">true if an exception</param>
 /// <param name="expectedException">exception message</param>
 static void VirtualSeqComplementValidation(VirtualSequence virtualSeq,
                                            bool exThrown, string expectedException)
 {
     try
     {
         ISequence complSeq = virtualSeq.Complement;
         // Below line is the dummy code
         // for fixing FxCop error "RemoveUnusedLocals".
         Assert.AreEqual(complSeq, null);
     }
     catch (NotSupportedException e)
     {
         exThrown = true;
         Assert.AreEqual(expectedException, e.Message);
         Console.WriteLine(string.Format((IFormatProvider)null,
                                         " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
     }
     // Validate an exception.
     Assert.IsTrue(exThrown);
     try
     {
         ISequence rev = virtualSeq.Reverse;
         // Below line is the dummy code
         // for fixing FxCop error "RemoveUnusedLocals".
         Assert.AreEqual(rev, null);
     }
     catch (NotSupportedException e)
     {
         exThrown = true;
         Assert.AreEqual(expectedException, e.Message);
         Console.WriteLine(string.Format((IFormatProvider)null,
                                         " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
     }
     // Validate an exception.
     Assert.IsTrue(exThrown);
     try
     {
         ISequence complSeq = virtualSeq.ReverseComplement;
     }
     catch (NotSupportedException e)
     {
         exThrown = true;
         Assert.IsTrue(exThrown);
         Assert.AreEqual(expectedException, e.Message);
         Console.WriteLine(string.Format((IFormatProvider)null,
                                         " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
     }
 }
Example #7
0
 public void ValidateVirtualSequenceNull()
 {
     try
     {
         // Create virtual seqeunce with null value
         VirtualSequence virtualSeq = new VirtualSequence(null);
         Assert.IsTrue(null != virtualSeq);
     }
     catch (ArgumentNullException)
     {
         ApplicationLog.WriteLine(
             "Virtual Sequence P2: Sequence exception validated successfully.");
         Console.WriteLine(
             "Virtual Sequence P2: Sequence exception validated successfully.");
     }
 }
Example #8
0
 /// <summary>
 /// Validate VirtualSeq Remove method exception
 /// </summary>
 /// <param name="virtualSeq">Virtual seq</param>
 /// <param name="exThrown">true if an exception</param>
 /// <param name="expectedException">exception message</param>
 static void VirtualSeqRemoveValidation(VirtualSequence virtualSeq,
                                        bool exThrown, string expectedException)
 {
     try
     {
         virtualSeq.Remove(virtualSeq[0]);
     }
     catch (NotSupportedException e)
     {
         exThrown = true;
         Assert.IsTrue(exThrown);
         Assert.AreEqual(expectedException, e.Message);
         Console.WriteLine(string.Format((IFormatProvider)null,
                                         " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
     }
 }
Example #9
0
 public void ValidateVirtualSequenceToString()
 {
     try
     {
         // Create virtual seqeunce with null value
         VirtualSequence virtualSeq = new VirtualSequence(Alphabets.Protein);
         virtualSeq.ToString();
         Assert.Fail();
     }
     catch (NotSupportedException)
     {
         ApplicationLog.WriteLine(
             "Virtual Sequence P2: Sequence exception validated successfully.");
         Console.WriteLine(
             "Virtual Sequence P2: Sequence exception validated successfully.");
     }
 }
Example #10
0
 /// <summary>
 /// Validate VirtualSeq CopyTo method exception
 /// </summary>
 /// <param name="virtualSeq">Virtual seq</param>
 /// <param name="exThrown">true if an exception</param>
 /// <param name="expectedException">exception message</param>
 static void VirtualSeqCopyToValidation(VirtualSequence virtualSeq,
                                        bool exThrown, string expectedException)
 {
     try
     {
         ISequenceItem[] iseqItems = new ISequenceItem[20];
         virtualSeq.CopyTo(iseqItems, 0);
     }
     catch (NotSupportedException e)
     {
         exThrown = true;
         Assert.IsTrue(exThrown);
         Assert.AreEqual(expectedException, e.Message);
         Console.WriteLine(string.Format((IFormatProvider)null,
                                         " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
     }
 }
Example #11
0
        /// <summary>
        /// Validate virtual seqeunce methods general exception.
        /// <param name="methodName">Virtual seqeunce method parameters</param>
        /// </summary>
        static void ValidateGeneralVirtualSequenceException(
            VirtualSequenceParameters methodName)
        {
            // Gets the alphabet from the Xml
            string alphabet = Utility._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.AlphabetNameNode);
            string expectedException = Utility._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.ExceptionMessage);
            string expectedValue = Utility._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.IndexValue);
            bool exThrown = false;

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format(null,
                                                   "Virtual Sequence P1: Sequence {0} is expected.", alphabet));

            // create virtual seqeunce for an alphabet.
            VirtualSequence virtualSeq = new VirtualSequence(
                Utility.GetAlphabet(alphabet));

            switch (methodName)
            {
            case VirtualSequenceParameters.Add:
                try
                {
                    virtualSeq.Add(Alphabets.DNA.A);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }

                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.Clear:
                try
                {
                    virtualSeq.Clear();
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.CopyTo:
                try
                {
                    ISequenceItem[] iseqItems = new ISequenceItem[20];
                    virtualSeq.CopyTo(iseqItems, 0);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.Remove:
                try
                {
                    virtualSeq.Remove(virtualSeq[0]);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.GetEnumerator:
                try
                {
                    virtualSeq.GetEnumerator();
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.Insert:
                try
                {
                    virtualSeq.Insert(0, 'G');
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.Range:
                try
                {
                    virtualSeq.Range(0, 5);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.InsertRange:
                try
                {
                    virtualSeq.InsertRange(0, "GCCAAAATTTAGGCAGAGA");
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.RemoveAt:
                try
                {
                    virtualSeq.RemoveAt(0);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.RemoveRange:
                try
                {
                    virtualSeq.RemoveRange(0, 1);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.ReplaceRange:
                try
                {
                    virtualSeq.ReplaceRange(0, "AUGAUGAUGAG");
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.ReplaceChar:
                try
                {
                    virtualSeq.Replace(0, Alphabets.DNA.A.Symbol);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                break;

            case VirtualSequenceParameters.ReplaceSeqItem:
                try
                {
                    virtualSeq.Replace(0, virtualSeq[0]);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.ToString:
                try
                {
                    virtualSeq.ToString();
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                break;

            case VirtualSequenceParameters.Complement:
                try
                {
                    ISequence complSeq = virtualSeq.Complement;
                    // Below line is the dummy code
                    // for fixing FxCop error "RemoveUnusedLocals".
                    Assert.AreEqual(complSeq, null);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                try
                {
                    ISequence rev = virtualSeq.Reverse;
                    // Below line is the dummy code
                    // for fixing FxCop error "RemoveUnusedLocals".
                    Assert.AreEqual(rev, null);
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                try
                {
                    ISequence complSeq = virtualSeq.ReverseComplement;
                }
                catch (NotSupportedException e)
                {
                    exThrown = true;
                    Assert.AreEqual(expectedException, e.Message);
                    Console.WriteLine(string.Format(null,
                                                    " VirtualSequence P1: Virtual seqeunce item to virtual seqeunce was {0}", e.Message));
                }
                // Validate an exception.
                Assert.IsTrue(exThrown);
                break;

            case VirtualSequenceParameters.IndexOf:
                foreach (Nucleotide nucleotide in Alphabets.RNA)
                {
                    Assert.AreEqual(virtualSeq.IndexOf(nucleotide).ToString((IFormatProvider)null),
                                    expectedValue);
                }
                break;

            case VirtualSequenceParameters.Contains:
                foreach (Nucleotide nucleotide in Alphabets.DNA)
                {
                    Assert.IsFalse(virtualSeq.Contains(nucleotide));
                }
                break;

            default:
                break;
            }
        }
Example #12
0
        /// <summary>
        /// General method to validate VirtualSequence
        /// <param name="method"> Method name to be validate </param>
        /// </summary>
        static void ValidateVirtualSequence(VirtualSequenceMethod method)
        {
            try
            {
                ISequence virSeq = new VirtualSequence(Alphabets.DNA);

                switch (method)
                {
                case VirtualSequenceMethod.Gap:
                    virSeq.IndexOfNonGap();
                    break;

                case VirtualSequenceMethod.GapPosition:
                    virSeq.IndexOfNonGap(0);
                    break;

                case VirtualSequenceMethod.LastGap:
                    virSeq.LastIndexOfNonGap();
                    break;

                case VirtualSequenceMethod.LastGapPosition:
                    virSeq.LastIndexOfNonGap(0);
                    break;

                case VirtualSequenceMethod.Remove:
                    virSeq.Remove(null);
                    break;

                case VirtualSequenceMethod.Replace:
                    virSeq.Replace(0, null);
                    break;

                case VirtualSequenceMethod.GetEnum:
                    virSeq.GetEnumerator();
                    break;

                case VirtualSequenceMethod.Insert:
                    virSeq.Insert(0, null);
                    break;

                case VirtualSequenceMethod.GetObjData:
                    virSeq.GetObjectData(null as SerializationInfo,
                                         new StreamingContext());
                    break;
                }

                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                ApplicationLog.WriteLine(
                    "Virtual Sequence P2: Method exception validated successfully.");
                Console.WriteLine(
                    "Virtual Sequence P2: Method exception validated successfully.");
            }
            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine(
                    "Virtual Sequence P2: Method exception validated successfully.");
                Console.WriteLine(
                    "Virtual Sequence P2: Method exception validated successfully.");
            }
        }
Example #13
0
        public void TestVirtualSequence()
        {
            VirtualSequence virtualSeq = new VirtualSequence(Alphabets.DNA);
            string          id         = Guid.NewGuid().ToString(string.Empty);

            virtualSeq.ID = id;
            Assert.AreEqual(virtualSeq.Alphabet, Alphabets.DNA);
            Assert.AreEqual(virtualSeq.Count, 0);
            Assert.AreEqual(virtualSeq.ID, id);

            // By default Displayid should show value of id.
            Assert.AreEqual(virtualSeq.DisplayID, virtualSeq.ID);

            virtualSeq.DisplayID = "VirtualSeq1";
            Assert.AreEqual(virtualSeq.DisplayID, "VirtualSeq1");
            Assert.AreNotEqual(virtualSeq.DisplayID, virtualSeq.ID);
            Assert.AreEqual(virtualSeq.IsReadOnly, true);
            Assert.AreEqual(virtualSeq.IndexOf(Alphabets.DNA.A), -1);

            foreach (Nucleotide nucleotide in Alphabets.DNA)
            {
                Assert.AreEqual(virtualSeq.IndexOf(nucleotide), -1);
                Assert.IsFalse(virtualSeq.Contains(nucleotide));
            }

            // Verify the above test using ISequence interface.
            ISequence seq = virtualSeq as ISequence;

            Assert.AreEqual(seq.Alphabet, Alphabets.DNA);
            Assert.AreEqual(seq.Count, 0);
            Assert.AreEqual(seq.ID, id);
            Assert.AreNotEqual(seq.DisplayID, virtualSeq.ID);
            Assert.AreEqual(seq.DisplayID, "VirtualSeq1");
            Assert.AreEqual(seq.IsReadOnly, true);

            foreach (Nucleotide nucleotide in Alphabets.DNA)
            {
                Assert.AreEqual(seq.IndexOf(nucleotide), -1);
                Assert.IsFalse(seq.Contains(nucleotide));
            }

            #region Test not supported members

            try
            {
                seq.Add(Alphabets.DNA.A);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.Count, 0);
            }
            try
            {
                seq.Clear();
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.Count, 0);
            }

            ISequence tmpSeq = null;

            try
            {
                tmpSeq = seq.Complement;
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.IsNull(tmpSeq);
            }

            try
            {
                ISequenceItem[] seqItems = new ISequenceItem[10];
                seq.CopyTo(seqItems, 0);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                seq.Insert(0, 'A');
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.Count, 0);
            }

            try
            {
                seq.InsertRange(0, "ACG");
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.Count, 0);
            }

            try
            {
                tmpSeq = seq.Range(0, 1);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.IsNull(tmpSeq);
            }

            try
            {
                seq.Remove(Alphabets.DNA.A);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.IsNull(tmpSeq);
            }

            try
            {
                seq.RemoveAt(0);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.Count, 0);
            }

            try
            {
                seq.RemoveRange(0, 1);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.Count, 0);
            }

            try
            {
                seq.Replace(0, Alphabets.DNA.A.Symbol);
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.IndexOf(Alphabets.DNA.A), -1);
            }

            try
            {
                seq.ReplaceRange(0, "GA");
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.AreEqual(seq.Count, 0);
            }

            try
            {
                tmpSeq = seq.Reverse;
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.IsNull(tmpSeq);
            }

            try
            {
                tmpSeq = seq.ReverseComplement;
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.IsNull(tmpSeq);
            }

            string sequence = string.Empty;
            try
            {
                sequence = seq.ToString();
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.IsTrue(string.IsNullOrEmpty(sequence));
            }

            ISequenceItem seqItem = null;
            try
            {
                seqItem = seq[0];
                Assert.Fail();
            }
            catch (NotSupportedException)
            {
                Assert.IsNull(seqItem);
            }
            #endregion Test not supported members
        }
Example #14
0
        /// <summary>
        /// Validate virtual seqeunce methods general exception.
        /// <param name="methodName">Virtual seqeunce method parameters</param>
        /// </summary>
        void ValidateGeneralVirtualSequenceException(
            VirtualSequenceParameters methodName)
        {
            // Gets the alphabet from the Xml
            string alphabet = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.AlphabetNameNode);
            string expectedException = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.ExceptionMessage);
            string expectedValue = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.IndexValue);
            bool exThrown = false;

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Virtual Sequence P1: Sequence {0} is expected.", alphabet));

            // create virtual seqeunce for an alphabet.
            VirtualSequence virtualSeq = new VirtualSequence(
                Utility.GetAlphabet(alphabet));

            switch (methodName)
            {
            case VirtualSequenceParameters.Add:
                VirtualSeqAddValidation(virtualSeq,
                                        exThrown, expectedException);
                break;

            case VirtualSequenceParameters.Clear:
                VirtualSeqClearValidation(virtualSeq,
                                          exThrown, expectedException);
                break;

            case VirtualSequenceParameters.CopyTo:
                VirtualSeqCopyToValidation(virtualSeq,
                                           exThrown, expectedException);
                break;

            case VirtualSequenceParameters.Remove:
                VirtualSeqRemoveValidation(virtualSeq,
                                           exThrown, expectedException);
                break;

            case VirtualSequenceParameters.GetEnumerator:
                VirtualSeqGetEnumeratorValidation(virtualSeq, exThrown,
                                                  expectedException);
                break;

            case VirtualSequenceParameters.Insert:
                VirtualSeqInsertValidation(virtualSeq, exThrown,
                                           expectedException);
                break;

            case VirtualSequenceParameters.Range:
                VirtualSeqRangeValidation(virtualSeq, exThrown,
                                          expectedException);
                break;

            case VirtualSequenceParameters.InsertRange:
                VirtualSeqInsertRangeValidation(virtualSeq, exThrown,
                                                expectedException);
                break;

            case VirtualSequenceParameters.RemoveAt:
                VirtualSeqRemoveAtValidation(virtualSeq, exThrown,
                                             expectedException);
                break;

            case VirtualSequenceParameters.RemoveRange:
                VirtualSeqRemoveRangeValidation(virtualSeq, exThrown,
                                                expectedException);
                break;

            case VirtualSequenceParameters.ReplaceRange:
                VirtualSeqReplaceRangeValidation(virtualSeq, exThrown,
                                                 expectedException);
                break;

            case VirtualSequenceParameters.ReplaceChar:
                VirtualSeqReplaceCharValidation(virtualSeq, exThrown,
                                                expectedException);
                break;

            case VirtualSequenceParameters.ReplaceSeqItem:
                VirtualSeqSeqItemValidation(virtualSeq, exThrown,
                                            expectedException);
                break;

            case VirtualSequenceParameters.ToString:
                VirtualSeqToStringValidation(virtualSeq, exThrown,
                                             expectedException);
                break;

            case VirtualSequenceParameters.Complement:
                VirtualSeqComplementValidation(virtualSeq,
                                               exThrown, expectedException);
                break;

            case VirtualSequenceParameters.IndexOf:
                VirtualSeqIndexOfValidation(virtualSeq, expectedValue);
                break;

            case VirtualSequenceParameters.Contains:
                VirtualSeqContainsValidation(virtualSeq);
                break;

            default:
                break;
            }
        }
Example #15
0
        /// <summary>
        /// General method to validate creation of virtual seqeunce.
        /// <param name="nodeName">xml node name.</param>
        /// <param name="alphabetName">alphabet name.</param>
        /// </summary>
        void ValidateGeneralVirtualSequence(
            string nodeName, AlphabetNameParameter alphabetName)
        {
            // Gets the alphabet from the Xml
            string alphabet = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string expectedSeqCount = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.ExpectedVSeqCount);
            string id = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.Id);
            string diplayId = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.DisplayId);
            string expectedValue = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.IndexValue);
            string expectedDocumentaion = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.Documentaion);

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Virtual Sequence BVT: Sequence {0} is expected.", alphabet));

            // create virtual seqeunce for an alphabet.
            VirtualSequence virtualSeq = new VirtualSequence(
                Utility.GetAlphabet(alphabet));

            // Set value to virtual sequences.
            virtualSeq.ID            = id;
            virtualSeq.DisplayID     = diplayId;
            virtualSeq.Documentation = expectedDocumentaion;

            // Validate the created virtual Sequence
            Assert.AreEqual(virtualSeq.DisplayID, diplayId);
            Assert.AreEqual(virtualSeq.ID, id);
            Assert.AreEqual(virtualSeq.IsReadOnly, true);
            Assert.AreEqual(virtualSeq.Count.ToString(
                                (IFormatProvider)null), expectedSeqCount);
            Assert.AreEqual(virtualSeq.Statistics, null);

            switch (alphabetName)
            {
            case AlphabetNameParameter.DNA:
                virtualSeq.MoleculeType = MoleculeType.DNA;
                foreach (Nucleotide nucleo in Alphabets.DNA)
                {
                    Assert.AreEqual(virtualSeq.IndexOf(nucleo).ToString(
                                        (IFormatProvider)null), expectedValue);
                }
                Assert.AreEqual(virtualSeq.MoleculeType, MoleculeType.DNA);
                break;

            case AlphabetNameParameter.RNA:
                virtualSeq.MoleculeType = MoleculeType.RNA;
                foreach (Nucleotide nucleo in Alphabets.RNA)
                {
                    Assert.AreEqual(virtualSeq.IndexOf(nucleo).ToString(
                                        (IFormatProvider)null), expectedValue);
                }
                Assert.AreEqual(virtualSeq.MoleculeType, MoleculeType.RNA);
                break;

            case AlphabetNameParameter.PROTEIN:
                virtualSeq.MoleculeType = MoleculeType.Protein;
                foreach (AminoAcid aminoacid in Alphabets.Protein)
                {
                    Assert.AreEqual(virtualSeq.IndexOf(aminoacid).ToString(
                                        (IFormatProvider)null), expectedValue);
                }
                Assert.AreEqual(virtualSeq.MoleculeType, MoleculeType.Protein);
                break;

            default:
                break;
            }

            // Logs to the NUnit GUI (Console.Out) window
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence BVT: Virtual Sequence ID {0} is as expected.",
                                            virtualSeq.ID.ToString((IFormatProvider)null)));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence BVT: Virtual Sequence Display ID {0} is as expected.",
                                            virtualSeq.DisplayID.ToString((IFormatProvider)null)));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence BVT: Virtual Sequence count {0} is as expected.",
                                            virtualSeq.Count.ToString((IFormatProvider)null)));

            // Logs to the NUnit GUI (Console.Out) window
            ApplicationLog.WriteLine(
                "Virtual Sequence BVT: Virtual Sequence validation is completed successfully.");
        }
Example #16
0
        public void ValidateVirtualSequenceGetObjectDataDocument()
        {
            ISequence virSeq =
                new VirtualSequence(Alphabets.DNA);

            virSeq.Documentation = Constants.Documentation;

            SerializationInfo info =
                new SerializationInfo(typeof(VirtualSequence),
                                      new FormatterConverter());
            StreamingContext context =
                new StreamingContext(StreamingContextStates.All);

            // Serialize the target object
            virSeq.GetObjectData(info, context);

            Assert.IsNotNull(info.GetValue(
                                 string.Format((IFormatProvider)null, "{0}:{1}",
                                               Constants.VirtualSequence, Constants.Documentation),
                                 typeof(object)));
            Assert.IsNotNull(info.GetValue(
                                 string.Format((IFormatProvider)null, "{0}:{1}",
                                               Constants.VirtualSequence, Constants.SeqInfo),
                                 typeof(BasicSequenceInfo)));
            Assert.IsNotNull(info.GetValue(
                                 string.Format((IFormatProvider)null, "{0}:{1}",
                                               Constants.VirtualSequence, Constants.MoleculeType),
                                 typeof(MoleculeType)));
            Assert.AreEqual
                (Constants.Documentation,
                info.GetValue(
                    string.Format((IFormatProvider)null, "{0}:{1}",
                                  Constants.VirtualSequence, Constants.Documentation),
                    typeof(object)).ToString());
            Assert.AreEqual(
                Constants.MBFBasicSequenceInfo,
                info.GetValue(
                    string.Format((IFormatProvider)null, "{0}:{1}",
                                  Constants.VirtualSequence, Constants.SeqInfo),
                    typeof(BasicSequenceInfo)).ToString());
            Assert.AreEqual(
                MoleculeType.Invalid,
                info.GetValue(
                    string.Format((IFormatProvider)null, "{0}:{1}",
                                  Constants.VirtualSequence, Constants.MoleculeType),
                    typeof(MoleculeType)));

            ICloneable iClone = virSeq;
            object     clone  = null;

            // Create a copy of Virtual Sequence
            clone = iClone.Clone();
            VirtualSequence cloneVSeq = ((MBF.VirtualSequence)(clone));

            Assert.IsNotNull(clone);
            Assert.AreEqual(cloneVSeq.Alphabet, Alphabets.DNA);
            Assert.AreEqual(cloneVSeq.Documentation,
                            Constants.Documentation);
            Assert.AreEqual(cloneVSeq.IsReadOnly, true);
            Assert.AreEqual(cloneVSeq.MoleculeType,
                            MoleculeType.Invalid);
            Assert.AreEqual(cloneVSeq.UseEncoding, false);
        }
Example #17
0
        public void TestVirtualSequenceWithBinaryFormatter()
        {
            Stream stream = null;

            try
            {
                string id = Guid.NewGuid().ToString();

                VirtualSequence seq = new VirtualSequence(Alphabets.RNA);
                seq.Metadata.Add("string", "Value1");
                seq.Metadata.Add("int", 2);
                seq.Metadata.Add("float", 4.5);

                // Add non serializable object.
                seq.Metadata.Add("Nucleotide", new Nucleotide('A', "A", false, false));
                seq.Documentation = "document";
                seq.ID            = id;
                seq.DisplayID     = "displayid";
                seq.MoleculeType  = MoleculeType.mRNA;
                stream            = File.Open("VirtualSequence.data", FileMode.Create);
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, seq);

                stream.Seek(0, SeekOrigin.Begin);
                VirtualSequence deserializedSeq = (VirtualSequence)formatter.Deserialize(stream);
                Assert.AreNotSame(seq, deserializedSeq);
                Assert.AreSame(seq.Alphabet, deserializedSeq.Alphabet);
                Assert.AreEqual(seq.ID, deserializedSeq.ID);
                Assert.AreEqual(seq.IsReadOnly, deserializedSeq.IsReadOnly);
                Assert.AreEqual(seq.MoleculeType, deserializedSeq.MoleculeType);
                Assert.AreEqual(seq.Count, deserializedSeq.Count);
                Assert.AreEqual(seq.DisplayID, deserializedSeq.DisplayID);
                Assert.AreEqual(seq.Documentation, deserializedSeq.Documentation);

                if (deserializedSeq.Metadata != null && deserializedSeq.Metadata.Count > 0)
                {
                    foreach (string key in seq.Metadata.Keys)
                    {
                        if (deserializedSeq.Metadata.ContainsKey(key))
                        {
                            if (key.Equals("Nucleotide"))
                            {
                                Assert.IsNotNull(deserializedSeq.Metadata[key]);
                            }
                            else
                            {
                                Assert.AreEqual(seq.Metadata[key], deserializedSeq.Metadata[key]);
                            }
                        }
                        else
                        {
                            Assert.Fail();
                        }
                    }
                }
                else
                {
                    Assert.Fail();
                }
            }
            catch (Exception)
            {
                Assert.Fail();
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream = null;
                }
            }
        }
Example #18
0
        public void ValidateAllProprtiesOfVirtualSequenceClass()
        {
            // Gets the alphabet from the Xml
            string alphabet = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.AlphabetNameNode);
            string expectedSeqCount = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.ExpectedVSeqCount);
            string id = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.Id);
            string diplayId = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.DisplayId);
            string expectedValue = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.IndexValue);
            string expectedDocumentaion = _utilityObj._xmlUtil.GetTextValue(
                Constants.DnaVirtualSeqNode, Constants.Documentaion);

            // Logs information to the log file
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "Virtual Sequence P1: Sequence {0} is expected.", alphabet));

            // create virtual seqeunce for an alphabet.
            VirtualSequence virtualSeq = new VirtualSequence(
                Utility.GetAlphabet(alphabet));

            // Set value to virtual sequences.
            virtualSeq.ID            = id;
            virtualSeq.DisplayID     = diplayId;
            virtualSeq.Documentation = expectedDocumentaion;
            virtualSeq.Metadata.Add("metaDataValue", Alphabets.DNA);

            // Validate the created virtual Sequence
            Assert.AreEqual(virtualSeq.DisplayID, diplayId);
            Assert.AreEqual(virtualSeq.ID, id);
            Assert.AreEqual(virtualSeq.IsReadOnly, true);
            Assert.AreEqual(virtualSeq.Count.ToString((IFormatProvider)null), expectedSeqCount);
            Assert.AreEqual(virtualSeq.Statistics, null);
            Assert.AreEqual(virtualSeq.Alphabet, Alphabets.DNA);
            Assert.AreEqual(virtualSeq.Documentation, expectedDocumentaion);

            virtualSeq.MoleculeType = MoleculeType.DNA;
            foreach (Nucleotide nucleo in Alphabets.DNA)
            {
                Assert.AreEqual(virtualSeq.IndexOf(nucleo).ToString((IFormatProvider)null), expectedValue);
            }
            Assert.AreEqual(virtualSeq.MoleculeType, MoleculeType.DNA);

            // Logs to the NUnit GUI (Console.Out) window
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence BVT: Virtual Sequence ID {0} is as expected.",
                                            virtualSeq.ID.ToString((IFormatProvider)null)));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence BVT: Virtual Sequence Display ID {0} is as expected.",
                                            virtualSeq.DisplayID.ToString((IFormatProvider)null)));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            " VirtualSequence BVT: Virtual Sequence count {0} is as expected.",
                                            virtualSeq.Count.ToString((IFormatProvider)null)));

            // Logs to the NUnit GUI (Console.Out) window
            ApplicationLog.WriteLine(
                "Virtual Sequence BVT: Virtual Sequence validation is completed successfully.");
        }