Exemplo n.º 1
0
        public void ValidateCompoundNucleotideAminoAcid()
        {
            ISequenceItem        seqItem1    = new Sequence(Alphabets.DNA, "AGCT")[0];
            ISequenceItem        seqItem2    = new Sequence(Alphabets.Protein, "KEI")[0];
            List <ISequenceItem> seqItemList = new List <ISequenceItem>();

            seqItemList.Add(seqItem1);
            seqItemList.Add(seqItem2);
            double        weightItem1 = 35;
            double        weightItem2 = 33;
            List <double> weightList  = new List <double>();

            weightList.Add(weightItem1);
            weightList.Add(weightItem2);

            try
            {
                ICompoundSequenceItem seqItemObj =
                    new CompoundNucleotide('B', "CompoundSeq'", seqItemList, weightList);
                Assert.IsTrue(null != seqItemObj);
            }
            catch (ArgumentException)
            {
                ApplicationLog.WriteLine(
                    "CompoundSequenceP2TestCases : Successfully validated the Amino Acid for Nucleotide exception");
                Console.WriteLine(
                    "CompoundSequenceP2TestCases : Successfully validated the Amino Acid for Nucleotide exception");
            }
        }
Exemplo n.º 2
0
        public void SparseSequenceClone()
        {
            SparseSequence sparseSeq = new SparseSequence(Alphabets.DNA);

            sparseSeq.Count = 50;
            sparseSeq[0]    = Alphabets.DNA.C;
            sparseSeq[5]    = Alphabets.DNA.G;
            sparseSeq[30]   = Alphabets.DNA.C;
            sparseSeq[44]   = Alphabets.DNA.A;
            sparseSeq[45]   = new Nucleotide('A', "Nucleotide A");
            CompoundNucleotide cn = new CompoundNucleotide('M', "Compound");

            cn.Add(new Nucleotide('A', "Item A"), 30);
            cn.Add(new Nucleotide('C', "Item C"), 20);
            sparseSeq[46] = cn;

            Assert.AreEqual(sparseSeq.Count, 50);
            Assert.AreEqual(sparseSeq.Alphabet, Alphabets.DNA);
            Assert.AreSame(sparseSeq[0], Alphabets.DNA.C);
            Assert.AreSame(sparseSeq[5], Alphabets.DNA.G);
            Assert.AreSame(sparseSeq[30], Alphabets.DNA.C);
            Assert.AreSame(sparseSeq[44], Alphabets.DNA.A);
            Assert.AreEqual(sparseSeq[45].Symbol, 'A');
            Assert.AreSame(sparseSeq[46], cn);
            Assert.AreNotSame(sparseSeq[46], Alphabets.DNA.AC);
            for (int i = 0; i < sparseSeq.Count; i++)
            {
                if (i != 0 && i != 5 && i != 30 && i != 44 && i != 45 && i != 46)
                {
                    Assert.IsNull(sparseSeq[i]);
                }
            }

            SparseSequence sparseSeqClone = sparseSeq.Clone();

            Assert.AreEqual(sparseSeqClone.Count, 50);
            Assert.AreEqual(sparseSeqClone.Alphabet, Alphabets.DNA);
            Assert.AreSame(sparseSeqClone[0], Alphabets.DNA.C);
            Assert.AreSame(sparseSeqClone[5], Alphabets.DNA.G);
            Assert.AreSame(sparseSeqClone[30], Alphabets.DNA.C);
            Assert.AreSame(sparseSeqClone[44], Alphabets.DNA.A);
            Assert.AreNotSame(sparseSeqClone[46], cn);
            Assert.AreNotSame(sparseSeqClone[46], Alphabets.DNA.AC);
            Assert.AreEqual(sparseSeqClone[46].Symbol, 'M');
            cn = sparseSeqClone[46] as CompoundNucleotide;
            IList <ISequenceItem> sequenceItems = cn.SequenceItems;

            Assert.AreEqual(sequenceItems.Count, 2);
            Assert.IsTrue(sequenceItems.First(I => I.Symbol == 'A') != null);
            Assert.IsTrue(sequenceItems.First(I => I.Symbol == 'C') != null);

            for (int i = 0; i < sparseSeqClone.Count; i++)
            {
                if (i != 0 && i != 5 && i != 30 && i != 44 && i != 45 && i != 46)
                {
                    Assert.IsNull(sparseSeqClone[i]);
                }
            }
        }
Exemplo n.º 3
0
        public void ValidateCompoundNucleotideNegWeight()
        {
            ICompoundSequenceItem seqItem = new CompoundNucleotide('B', "NegativeWeight");

            seqItem.Add(new Sequence(Alphabets.DNA, "AGCT")[0], -35);
            Assert.AreEqual("Adenine", seqItem.SequenceItems[0].Name);
            ApplicationLog.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the negative weight expression");
            Console.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the negative weight expression");
        }
Exemplo n.º 4
0
        public void ValidateCompoundNucleotideNonAmbiguous()
        {
            ICompoundSequenceItem seqItemObj =
                new CompoundNucleotide('X', "CompoundSeq", false, false);

            Assert.IsFalse(seqItemObj.IsAmbiguous);

            ApplicationLog.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the Ambiguous property");
            Console.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the Ambiguous property");
        }
Exemplo n.º 5
0
 public void ValidateCompoundNucleotideInValidSymbol()
 {
     try
     {
         ICompoundSequenceItem seqItemObj = new CompoundNucleotide('Ñ', "CompoundSeq");
         ISequence             seq        = new Sequence(Alphabets.DNA);
         seq.Add(seqItemObj);
     }
     catch (ArgumentException)
     {
         ApplicationLog.WriteLine(
             "CompoundSequenceP2TestCases : Successfully validated the invalid sequence Symbol");
         Console.WriteLine(
             "CompoundSequenceP2TestCases : Successfully validated the invalid sequence Symbol");
     }
 }
Exemplo n.º 6
0
        public void ValidateCompoundNucleotideInValidRemove()
        {
            List <ISequenceItem> seqItemList = null;
            List <double>        weightList  = null;

            GetSequenceItemWithWeight(out seqItemList, out weightList, true);

            ICompoundSequenceItem seqItem =
                new CompoundNucleotide('B', "CompoundSeq", seqItemList, weightList);

            seqItem.Remove(new Sequence(Alphabets.DNA, "T")[0]);
            Assert.AreEqual(2, seqItem.SequenceItems.Count);

            ApplicationLog.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the invalid remove");
            Console.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the invalid remove");
        }
Exemplo n.º 7
0
        public void ValidateCompoundNucleotideDuplicateSequence()
        {
            List <ISequenceItem> seqItemList = null;
            List <double>        weightList  = null;

            GetSequenceItemWithWeight(out seqItemList, out weightList, true);

            ICompoundSequenceItem seqItemObj1 =
                new CompoundNucleotide('B', "CompoundSeq", seqItemList, weightList);
            ICompoundSequenceItem seqItemObj2 =
                new CompoundNucleotide('B', "CompoundSeq", seqItemList, weightList);

            Assert.AreEqual(seqItemObj1, seqItemObj2);

            ApplicationLog.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the duplicate item");
            Console.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the duplicate item");
        }
Exemplo n.º 8
0
        public void ValidateCompoundNucleotideSequenceListNull()
        {
            List <ISequenceItem> seqItemList = null;
            List <double>        weightList  = null;

            GetSequenceItemWithWeight(out seqItemList, out weightList, true);

            try
            {
                ICompoundSequenceItem seqItemObj =
                    new CompoundNucleotide('B', "CompoundSeq", null, weightList);
                Assert.IsTrue(null != seqItemObj);
            }
            catch (ArgumentException)
            {
                ApplicationLog.WriteLine(
                    "CompoundSequenceP2TestCases : Successfully validated the sequence list null exception");
                Console.WriteLine(
                    "CompoundSequenceP2TestCases : Successfully validated the sequence list null exception");
            }
        }
Exemplo n.º 9
0
        public void ValidateCompoundNucleotideDuplicateSequenceItemSymbol()
        {
            List <ISequenceItem> seqItemList = null;
            List <double>        weightList  = null;

            GetSequenceItemWithWeight(out seqItemList, out weightList, true);

            ICompoundSequenceItem seqItemObj1 =
                new CompoundNucleotide('B', "CompoundSeq", seqItemList, weightList);
            ICompoundSequenceItem seqItemObj2 =
                new CompoundNucleotide('B', "CompoundSeq", seqItemList, weightList);

            Sequence originalSeq = new Sequence(Alphabets.DNA);

            originalSeq.Add(seqItemObj1);
            originalSeq.Add(seqItemObj2);

            Assert.AreEqual("BB", originalSeq.ToString());

            ApplicationLog.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the duplicate item & symbol");
            Console.WriteLine(
                "CompoundSequenceP2TestCases : Successfully validated the duplicate item & symbol");
        }
Exemplo n.º 10
0
        public void TestSparseSequenceWithBinaryFormatter()
        {
            Stream stream = null;

            try
            {
                SparseSequence seq = new SparseSequence(Alphabets.DNA);
                seq.Count = 50;
                seq.Insert(2, Alphabets.DNA.A);
                seq.Insert(8, Alphabets.DNA.T);
                seq.Insert(9, Alphabets.DNA.T);
                seq.Insert(10, Alphabets.DNA.A);
                seq.Insert(21, Alphabets.DNA.G);
                seq.Insert(45, Alphabets.DNA.C);
                CompoundNucleotide cn = new CompoundNucleotide('M', "Compound");
                cn.Add(new Nucleotide('A', "Item A"), 30);
                cn.Add(new Nucleotide('C', "Item C"), 20);
                seq[46] = cn;
                seq.Add(new Nucleotide('A', "Question"));
                stream = File.Open("SparseSequence.data", FileMode.Create);
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, seq);

                stream.Seek(0, SeekOrigin.Begin);
                SparseSequence deserializedSeq = (SparseSequence)formatter.Deserialize(stream);

                Assert.AreNotSame(seq, deserializedSeq);
                Assert.AreSame(seq.Alphabet, deserializedSeq.Alphabet);

                Assert.AreEqual(seq.Count, deserializedSeq.Count);
                Assert.AreEqual(seq.DisplayID, deserializedSeq.DisplayID);
                Assert.AreEqual(seq.ID, deserializedSeq.ID);
                Assert.AreEqual(seq.IsReadOnly, deserializedSeq.IsReadOnly);
                Assert.AreEqual(seq.MoleculeType, deserializedSeq.MoleculeType);

                Assert.AreSame(seq[0], deserializedSeq[0]);
                Assert.AreSame(seq[2], deserializedSeq[2]);
                Assert.AreSame(seq[8], deserializedSeq[8]);
                Assert.AreSame(seq[9], deserializedSeq[9]);
                Assert.AreSame(seq[10], deserializedSeq[10]);
                Assert.AreSame(seq[21], deserializedSeq[21]);
                Assert.AreSame(seq[45], deserializedSeq[45]);
                Assert.AreNotSame(seq[46], deserializedSeq[46]);
                cn = deserializedSeq[46] as CompoundNucleotide;
                IList <ISequenceItem> sequenceItems = cn.SequenceItems;
                Assert.AreEqual(sequenceItems.Count, 2);
                Assert.IsTrue(sequenceItems.First(I => I.Symbol == 'A') != null);
                Assert.IsTrue(sequenceItems.First(I => I.Symbol == 'C') != null);
                Assert.AreEqual(seq[46].Symbol, 'M');

                Assert.AreNotSame(seq[seq.Count - 1], deserializedSeq[deserializedSeq.Count - 1]);
                Assert.AreEqual(seq.Statistics.GetCount('A'), deserializedSeq.Statistics.GetCount('A'));
                stream.Close();
                stream    = null;
                seq       = new SparseSequence(Alphabets.DNA);
                stream    = File.Open("SparseSequence.data", FileMode.Create);
                formatter = new BinaryFormatter();
                formatter.Serialize(stream, seq);

                stream.Seek(0, SeekOrigin.Begin);
                deserializedSeq = (SparseSequence)formatter.Deserialize(stream);

                Assert.AreNotSame(seq, deserializedSeq);
                Assert.AreSame(seq.Alphabet, deserializedSeq.Alphabet);

                Assert.AreEqual(seq.Count, deserializedSeq.Count);
                Assert.AreEqual(seq.DisplayID, deserializedSeq.DisplayID);
                Assert.AreEqual(seq.ID, deserializedSeq.ID);
                Assert.AreEqual(seq.IsReadOnly, deserializedSeq.IsReadOnly);
                Assert.AreEqual(seq.MoleculeType, deserializedSeq.MoleculeType);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                    stream = null;
                }
            }
        }
Exemplo n.º 11
0
        public void TestDerivedSequence()
        {
            Sequence        seq    = new Sequence(Alphabets.RNA, "ACUGUA");
            DerivedSequence derSeq = new DerivedSequence(seq);

            derSeq.Insert(3, Alphabets.DNA.A);
            derSeq.RemoveAt(2);
            Assert.AreEqual(derSeq.ToString(), "ACAGUA");

            derSeq.Insert(3, Alphabets.DNA.A);
            Assert.AreEqual(derSeq.ToString(), "ACAAGUA");
            derSeq.RemoveAt(2);
            derSeq.RemoveAt(1);
            Assert.AreEqual(derSeq.ToString(), "AAGUA");
            derSeq.Insert(1, 'C');
            Assert.AreEqual(derSeq.ToString(), "ACAGUA");
            derSeq.Replace(0, 'C');
            Assert.AreEqual(derSeq.ToString(), "CCAGUA");
            derSeq.ReplaceRange(1, "UA");
            Assert.AreEqual(derSeq.ToString(), "CUAGUA");
            derSeq.InsertRange(derSeq.Count, "UUAA");
            Assert.AreEqual(derSeq.ToString(), "CUAGUAUUAA");
            derSeq.InsertRange(0, "UUAA");
            Assert.AreEqual(derSeq.ToString(), "UUAACUAGUAUUAA");

            seq    = new Sequence(Alphabets.DNA, "ACTGTA");
            derSeq = new DerivedSequence(seq);
            derSeq.RemoveAt(3);
            derSeq.Insert(3, Alphabets.DNA.A);
            Assert.AreEqual(derSeq.ToString(), "ACTATA");
            derSeq.InsertRange(derSeq.Count, "TTTT");
            derSeq.RemoveRange(6, 4);
            Assert.AreEqual(derSeq.ToString(), "ACTATA");
            derSeq.Insert(derSeq.Count, 'T');
            Assert.AreEqual(derSeq.ToString(), "ACTATAT");
            derSeq.Add(Alphabets.DNA.G);
            Assert.AreEqual(derSeq.ToString(), "ACTATATG");
            Assert.AreEqual(0, derSeq.IndexOf(Alphabets.DNA.A));
            Assert.IsTrue(derSeq.Contains(Alphabets.DNA.G));
            Assert.IsTrue(derSeq.Remove(Alphabets.DNA.C));
            Assert.AreEqual(derSeq.ToString(), "ATATATG");
            Assert.IsFalse(derSeq.Contains(Alphabets.DNA.C));
            Assert.IsFalse(derSeq.Remove(Alphabets.DNA.C));
            Assert.AreEqual(derSeq.Source.ToString(), "ACTGTA");
            derSeq.Clear();
            Assert.AreEqual(derSeq.Source.ToString(), derSeq.ToString());
            Assert.AreEqual(derSeq.Source.ToString(), "ACTGTA");

            seq    = new Sequence(Alphabets.DNA, "ACTGTA");
            derSeq = new DerivedSequence(seq);
            derSeq.RemoveAt(3);
            derSeq.Insert(3, Alphabets.DNA.A);
            IList <IndexedItem <UpdatedSequenceItem> > updatedItems = derSeq.GetUpdatedItems();

            Assert.AreEqual(updatedItems.Count, 2);
            Assert.AreEqual(updatedItems[0].Index, 3);
            Assert.AreEqual(updatedItems[0].Item.Type, UpdateType.Removed);
            Assert.AreEqual(updatedItems[1].Index, 4);
            Assert.AreEqual(updatedItems[1].Item.Type, UpdateType.Inserted);

            seq    = new Sequence(Alphabets.DNA, "ACGTATAT");
            derSeq = new DerivedSequence(seq);
            derSeq.RemoveAt(5);
            derSeq.RemoveAt(4);
            derSeq.RemoveAt(3);
            derSeq.RemoveAt(1);
            Assert.AreEqual(derSeq.ToString(), "AGAT");
            updatedItems = derSeq.GetUpdatedItems();
            Assert.AreEqual(updatedItems.Count, 4);
            Assert.AreEqual(updatedItems[0].Index, 1);
            Assert.AreEqual(updatedItems[0].Item.Type, UpdateType.Removed);
            Assert.AreSame(updatedItems[0].Item.SequenceItem, seq[1]);
            Assert.AreEqual(updatedItems[1].Index, 3);
            Assert.AreEqual(updatedItems[1].Item.Type, UpdateType.Removed);
            Assert.AreSame(updatedItems[1].Item.SequenceItem, seq[3]);
            Assert.AreEqual(updatedItems[2].Index, 4);
            Assert.AreEqual(updatedItems[2].Item.Type, UpdateType.Removed);
            Assert.AreSame(updatedItems[2].Item.SequenceItem, seq[4]);
            Assert.AreEqual(updatedItems[3].Index, 5);
            Assert.AreEqual(updatedItems[3].Item.Type, UpdateType.Removed);
            Assert.AreSame(updatedItems[3].Item.SequenceItem, seq[5]);

            seq    = new Sequence(Alphabets.DNA, "ACGTATAT");
            derSeq = new DerivedSequence(seq);
            derSeq.RemoveRange(1, 4);
            Assert.AreEqual(derSeq.ToString(), "ATAT");

            seq    = new Sequence(Alphabets.DNA, "ACGTATAT");
            derSeq = new DerivedSequence(seq);
            derSeq.RemoveAt(1);
            derSeq.RemoveAt(2);
            derSeq.RemoveAt(5);
            derSeq.Insert(3, 'A');
            updatedItems = derSeq.GetUpdatedItems();
            Assert.AreEqual(updatedItems.Count, 4);
            Assert.AreEqual(updatedItems.Where(R => R.Item.Type == UpdateType.Removed).Count(), 3);
            Assert.AreEqual(updatedItems.Where(R => R.Item.Type == UpdateType.Inserted).Count(), 1);

            #region Test - IndexOfNonGap and LastIndexOfNonGap
            seq    = new Sequence(Alphabets.RNA, "--ACUGUA-");
            derSeq = new DerivedSequence(seq);
            Assert.AreEqual(seq.IndexOfNonGap(), 2);
            Assert.AreEqual(seq.IndexOfNonGap(1), 2);
            Assert.AreEqual(seq.IndexOfNonGap(4), 4);
            Assert.AreEqual(seq.IndexOfNonGap(8), -1);
            Assert.AreEqual(seq.LastIndexOfNonGap(), 7);
            Assert.AreEqual(seq.LastIndexOfNonGap(seq.Count - 1), 7);
            Assert.AreEqual(seq.LastIndexOfNonGap(7), 7);
            Assert.AreEqual(seq.LastIndexOfNonGap(5), 5);

            Assert.AreEqual(seq.IndexOfNonGap(), derSeq.IndexOfNonGap());
            Assert.AreEqual(seq.IndexOfNonGap(1), derSeq.IndexOfNonGap(1));
            Assert.AreEqual(seq.IndexOfNonGap(4), derSeq.IndexOfNonGap(4));
            Assert.AreEqual(seq.IndexOfNonGap(8), derSeq.IndexOfNonGap(8));
            Assert.AreEqual(seq.LastIndexOfNonGap(), derSeq.LastIndexOfNonGap());
            Assert.AreEqual(seq.LastIndexOfNonGap(seq.Count - 1), derSeq.LastIndexOfNonGap(derSeq.Count - 1));
            Assert.AreEqual(seq.LastIndexOfNonGap(7), derSeq.LastIndexOfNonGap(7));
            Assert.AreEqual(seq.LastIndexOfNonGap(5), derSeq.LastIndexOfNonGap(5));
            #endregion Test - IndexOfNonGap and LastIndexOfNonGap

            seq    = new Sequence(Alphabets.RNA, "ACUGUA");
            derSeq = new DerivedSequence(seq);
            derSeq.Insert(3, new Nucleotide('A', "RNACHAR"));
            derSeq.RemoveAt(2);
            Assert.AreEqual(derSeq.ToString(), "ACAGUA");
            CompoundNucleotide cn = new CompoundNucleotide('M', "Compound");
            cn.Add(new Nucleotide('A', "Item A"), 30);
            cn.Add(new Nucleotide('C', "Item C"), 20);
            derSeq.Insert(3, cn);
            Assert.AreEqual(derSeq[2].Symbol, 'A');
            Assert.AreEqual(derSeq[2].Name, "RNACHAR");
            Assert.AreEqual(derSeq[3].Symbol, 'M');
        }