コード例 #1
0
 public void ValidateDnaSparseSequenceConstAlpIndex()
 {
     var sparseSeq = new SparseSequence(Alphabets.DNA, 0);
     Assert.IsNotNull(sparseSeq);
     Assert.AreEqual(0, sparseSeq.Count);
     Assert.IsNotNull(sparseSeq.Statistics);
     ApplicationLog.WriteLine("SparseSequence BVT: Validation of SparseSequence(alp, index) constructor is completed");
 }
コード例 #2
0
        public void ValidateRnaSparseSequenceConstAlp()
        {
            var sparseSeq = new SparseSequence(Alphabets.RNA);
            Assert.IsNotNull(sparseSeq);
            Assert.AreEqual(0, sparseSeq.Count);
            Assert.IsNotNull(sparseSeq.Statistics);

            ApplicationLog.WriteLine("SparseSequence P1: Validation of SparseSequence(alp) constructor is completed");
        }
コード例 #3
0
 public void ValidateDnaSparseSequenceConstAlpIndexByte()
 {
     byte[] byteArrayObj = Encoding.ASCII.GetBytes("AGCT");
     var sparseSeq = new SparseSequence(Alphabets.DNA, 1, byteArrayObj[0]);
     Assert.IsNotNull(sparseSeq);
     Assert.IsNotNull(sparseSeq.Statistics);
     SequenceStatistics seqStatObj = sparseSeq.Statistics;
     Assert.AreEqual(1, seqStatObj.GetCount('A'));
     ApplicationLog.WriteLine("SparseSequence BVT: Validation of SparseSequence(alp, index, byte) constructor is completed");
 }
コード例 #4
0
 public void TestSparseSequenceCopyTo()
 {
     IEnumerable<byte> seqItems = new List<Byte>() { 65, 65, 67, 67 };
     SparseSequence sparseSeq = new SparseSequence(Alphabets.DNA, 0, seqItems);
     byte[] array = new byte[2];
     sparseSeq.CopyTo(array, 1, 2);
     string expectedValue = "AC";
     StringBuilder b = new StringBuilder();
     b.Append((char)array[0]);
     b.Append((char)array[1]);
     string actualValue = b.ToString();
     Assert.AreEqual(expectedValue, actualValue);
 }
コード例 #5
0
        public void ValidateSparseSequenceGetObjectData()
        {
            SerializationInfo info = new SerializationInfo(typeof(SparseSequence),
                                                           new FormatterConverter());
            StreamingContext context = new StreamingContext(StreamingContextStates.All);

            SparseSequence sparseSeqObj = CreateSparseSequence(Alphabets.DNA, 0);

            sparseSeqObj.GetObjectData(info, context);

            // Validate if there are no exceptions from the public method.
            Assert.IsNotNull(sparseSeqObj);
            Console.WriteLine(
                "SparseSequenceBVT: Validation of GetObjectData() is completed");
            ApplicationLog.WriteLine(
                "SparseSequenceBVT:  Validation of GetObjectData() is completed");
        }
コード例 #6
0
 /// <summary>
 /// Invalidate Sparse sequence IndexOfNonGap
 /// </summary>
 /// <param name="sparseSeq">Sparse Sequence</param>
 private static void InvalidateSparseSequenceIndexOfNonGap(SparseSequence sparseSeq)
 {
     sparseSeq.Count = 1000;
     sparseSeq[9]    = null;
     sparseSeq[10]   = Alphabets.DNA.Gap;
     sparseSeq[20]   = Alphabets.DNA.GA;
     sparseSeq[501]  = Alphabets.DNA.A;
     sparseSeq[905]  = Alphabets.DNA.Gap;
     sparseSeq[906]  = null;
     Assert.AreEqual(20, sparseSeq.IndexOfNonGap());
     Assert.AreEqual(20, sparseSeq.IndexOfNonGap(10));
     Assert.AreEqual(20, sparseSeq.IndexOfNonGap(20));
     Assert.AreEqual(501, sparseSeq.LastIndexOfNonGap());
     Assert.AreEqual(501, sparseSeq.LastIndexOfNonGap(910));
     Assert.AreEqual(501, sparseSeq.LastIndexOfNonGap(905));
     Assert.AreEqual(501, sparseSeq.LastIndexOfNonGap(501));
 }
コード例 #7
0
        /// <summary>
        /// Invalidate Sparse sequence Add()
        /// </summary>
        /// <param name="sparseSeq">Sparse Sequence</param>
        private static void InvalidateSparseSequenceAdd(SparseSequence sparseSeq)
        {
            sparseSeq.Add(Alphabets.DNA.G);
            Assert.AreEqual(sparseSeq.Count, 2);
            Assert.AreSame(sparseSeq[0], Alphabets.DNA.A);
            Assert.AreSame(sparseSeq[1], Alphabets.DNA.G);

            try
            {
                sparseSeq.Add(Alphabets.RNA.U);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                Assert.AreEqual(sparseSeq.Count, 2);
            }
        }
コード例 #8
0
        /// <summary>
        /// The common ParseOne method called for parsing sequences from Xsv files.
        /// This assumes that that the first line has been read into the XsvSparseReader
        /// (i.e. GoToNextLine() has been called). This adds the offset position present in
        /// the sequence start line to each position value in the sequence item.
        /// e.g. the following returns a sparse sequence with ID 'Test sequence' of length 100
        /// with A at position 32 (25+7) and G at position 57 (50+7).
        /// # 7, 100, Test sequence
        /// 25,A
        /// 50,G
        /// </summary>
        /// <param name="sparseReader">The Xsv sparse reader that can read the sparse sequences.
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>The first sequence present starting from the
        /// current position in the reader as a SparseSequence. The sparse sequence has the ID present in the
        /// sequence start line, and its length equals the count present in that line.
        /// Null if EOF has been reached. Throws an exception if the current position did
        /// not have the sequence start line with the sequence prefix ID character.
        /// </returns>
        protected ISequence ParseOne(XsvSparseReader sparseReader)
        {
            // Check input arguments
            if (sparseReader == null)
            {
                throw new ArgumentNullException("sparseReader");
            }

            if (!sparseReader.HasLines)
            {
                return(null);
            }

            if (sparseReader.SkipCommentLines || !sparseReader.HasCommentLine)
            {
                throw new InvalidDataException(Properties.Resource.XsvOffsetNotFound);
            }

            // create a new sparse sequence
            SparseSequence sequence = new SparseSequence(Alphabet);

            // read the sequence ID, count and offset
            sequence.ID = sparseReader.GetSequenceId();
            long offset = sparseReader.GetSequenceOffset();

            sequence.Count = sparseReader.GetSequenceCount() + offset;

            sequence.Metadata.Add(MetadataOffsetKey, offset);
            // go to first sequence item
            sparseReader.GoToNextLine();

            while (sparseReader.HasLines && !sparseReader.HasCommentLine)
            {
                // add offset to position
                long position = long.Parse(sparseReader.Fields[0], CultureInfo.InvariantCulture) + offset;
                char symbol   = sparseReader.Fields[1][0];
                if (sequence.Count <= position)
                {
                    sequence.Count = position + 1;
                }
                sequence[position] = (byte)symbol;
                sparseReader.GoToNextLine();
            }

            return(sequence);
        }
コード例 #9
0
        public void ValidateSparseSequenceFindMatches()
        {
            ISequence      seq   = new Sequence(Alphabets.DNA, "ACCGGTT");
            SparseSequence ssObj =
                new SparseSequence(Alphabets.DNA, 0, seq[0]);

            IList <string> patterns = new List <string>();

            patterns.Add("A");
            IDictionary <string, IList <int> > actual = ssObj.FindMatches(patterns, 0, false);

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(0, actual["A"][0]);

            Console.WriteLine("Segmented Sequence : Successfully validated FindMatches() method.");
            ApplicationLog.WriteLine("Segmented Sequence : Successfully validated FindMatches() method.");
        }
コード例 #10
0
        public void ValidateSparseSequenceInvalidIndex()
        {
            SparseSequence sparseSeq = null;

            // Try Creating sparse sequence by passing invalid index.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, -1, null);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #11
0
        public void ValidateExceptionByPassingInvalidStartIndex()
        {
            //Create a sparse sequence.
            SparseSequence sparseSeq = new SparseSequence(Alphabets.DNA);

            // Try to add RNA Sequence Item to DNA sparse sequence.
            try
            {
                sparseSeq.GetSubSequence(10, 0);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                Console.WriteLine(
                    "SparseSequence P2: SparseSequence Exception was validated successfully");
            }
        }
コード例 #12
0
ファイル: SparseSequenceTests.cs プロジェクト: sjmercer65/bio
        public void TestSparseSequenceGetKnownSequenceItems()
        {
            ISequence seq       = new Sequence(Alphabets.DNA, "ATGC");
            var       sparseSeq = new SparseSequence(Alphabets.DNA, 0, seq);

            var knownItems = sparseSeq.GetKnownSequenceItems();

            Assert.AreEqual(knownItems.Count, 4);
            Assert.AreEqual(0, knownItems[0].Index);
            Assert.AreEqual(Alphabets.DNA.A, knownItems[0].Item);
            Assert.AreEqual(1, knownItems[1].Index);
            Assert.AreEqual(Alphabets.DNA.T, knownItems[1].Item);
            Assert.AreEqual(2, knownItems[2].Index);
            Assert.AreEqual(Alphabets.DNA.G, knownItems[2].Item);
            Assert.AreEqual(3, knownItems[3].Index);
            Assert.AreEqual(Alphabets.DNA.C, knownItems[3].Item);
        }
コード例 #13
0
        public void ValidateSparseSequenceInvalidSeqItem()
        {
            SparseSequence sparseSeq = null;

            // Try Creating sparse sequence by passing invalid sequence item.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, 0, null);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #14
0
        /// <summary>
        /// The common ParseOne method called for parsing sequences from Xsv files.
        /// This assumes that that the first line has been read into the XsvSparseReader
        /// (i.e. GoToNextLine() has been called). This adds the offset position present in
        /// the sequence start line to each position value in the sequence item.
        /// e.g. the following returns a sparse sequence with ID 'Test sequence' of length 100
        /// with A at position 32 (25+7) and G at position 57 (50+7).
        /// # 7, 100, Test sequence
        /// 25,A
        /// 50,G
        ///
        /// </summary>
        /// <param name="sparseReader">The Xsv sparse reader that can read the sparse sequences.</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>The first sequence present starting from the
        /// current position in the reader as a SparseSequence. The sparse sequence has the ID present in the
        /// sequence start line, and its length equals the count present in that line.
        /// Null if EOF has been reached. Throws an exception if the current position did
        /// not have the sequence start line with the sequence prefix ID character.
        /// </returns>
        protected ISequence ParseOne(XsvSparseReader sparseReader, bool isReadOnly)
        {
            // Check input arguments
            if (sparseReader == null)
            {
                throw new ArgumentNullException("sparseReader", "Sparse reader to read sequence from cannot be null");
            }

            if (!sparseReader.HasLines)
            {
                return(null);
            }

            if (sparseReader.SkipCommentLines || !sparseReader.HasCommentLine)
            {
                throw new InvalidDataException(Properties.Resource.XsvOffsetNotFound);
            }

            // create a new sparse sequence
            SparseSequence sequence = new SparseSequence(Alphabet);

            // read the sequence ID, count and offset
            sequence.ID    = sparseReader.GetSequenceId();
            sequence.Count = sparseReader.GetSequenceCount();
            int offset = sparseReader.GetSequenceOffset();

            // go to first sequence item
            sparseReader.GoToNextLine();

            while (sparseReader.HasLines && !sparseReader.HasCommentLine)
            {
                // add offset to position
                int  position = int.Parse(sparseReader.Fields[0], CultureInfo.InvariantCulture) + offset;
                char symbol   = sparseReader.Fields[1][0];
                if (sequence.Count <= position)
                {
                    sequence.Count = position + 1;
                }
                sequence[position] = Alphabet.LookupBySymbol(symbol);
                sparseReader.GoToNextLine();
            }

            sequence.IsReadOnly = isReadOnly;
            return(sequence);
        }
コード例 #15
0
        /// <summary>
        /// Creates a sparse sequence and inserts sequence items of alphabet.
        /// Delete all sequence items using Clear() method and
        /// validates if all items are deleted from sparse sequence object.
        /// </summary>
        /// <param name="alphabet">alphabet instance.</param>
        private void ValidateSparseSequenceClear(IAlphabet alphabet)
        {
            SparseSequence sparseSeq = CreateSparseSequence(alphabet, 10);

            sparseSeq.IsReadOnly = false;

            // Validate if sparse sequence conatins all sequence items.
            Assert.AreEqual(alphabet.Count + 10, sparseSeq.Count);

            // Clear the sparse sequence.
            sparseSeq.Clear();

            // Validate if all sequence items are deleted.
            Assert.AreEqual(0, sparseSeq.Count);

            Console.WriteLine("SparseSequenceP1: Validation of Clear() method is completed");
            ApplicationLog.WriteLine("SparseSequenceP1: Validation of Clear() method is completed");
        }
コード例 #16
0
        /// <summary>
        /// The ParseOne method called for parsing sequences from Xsv files,
        /// and returning the offset separately. This can be used by aligned/assembled
        /// sparse sequences.
        /// This assumes that that the first line has been read into the XsvSparseReader
        /// (i.e. GoToNextLine() has been called). This does NOT add the offset position
        /// present in the sequence start line to each position value in the sequence item.
        /// Instead, it returns the offset in the out parameter.
        /// e.g. the following returns a sparse sequence with ID 'Test sequence' of length 100
        /// with A at position 25 and G at position 50,
        /// and the out offset value as 7.
        /// # 7, 100, Test sequence
        /// 25,A
        /// 50,G
        ///
        /// </summary>
        /// <param name="sparseReader">The Xsv sparse reader that can read the sparse sequences.</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>The first sequence present starting from the
        /// current position in the reader, as a SparseSequence. The sparse sequence has the ID present in the
        /// sequence start line, and its length equals the count present in that line.
        /// Throws an exception if EOF has been reached or the current position did
        /// not have the sequence start line with the sequence prefix ID character.
        /// Also returns the offset value present in the sequence start line.
        /// </returns>
        protected Tuple <ISequence, int> ParseOneWithOffset(XsvSparseReader sparseReader, bool isReadOnly)
        {
            if (sparseReader == null)
            {
                throw new ArgumentNullException("sparseReader");
            }

            int offset = -1;

            if (!sparseReader.HasLines)
            {
                return(null);
            }

            if (sparseReader.SkipCommentLines || !sparseReader.HasCommentLine)
            {
                throw new InvalidDataException(Properties.Resource.XsvOffsetNotFound);
            }

            // create a new sparse sequence
            SparseSequence sequence = new SparseSequence(Alphabet);

            // read the sequence ID and offset
            sequence.ID    = sparseReader.GetSequenceId();
            sequence.Count = sparseReader.GetSequenceCount();
            offset         = sparseReader.GetSequenceOffset();
            sparseReader.GoToNextLine();

            while (sparseReader.HasLines && !sparseReader.HasCommentLine)
            {
                int  position = int.Parse(sparseReader.Fields[0], CultureInfo.InvariantCulture);
                char symbol   = sparseReader.Fields[1][0];
                if (sequence.Count <= position)
                {
                    sequence.Count = position + 1;
                }
                sequence[position] = Alphabet.LookupBySymbol(symbol);
                sparseReader.GoToNextLine();
            }

            sequence.IsReadOnly = isReadOnly;
            return(Tuple.Create((ISequence)sequence, offset));
        }
コード例 #17
0
        /// <summary>
        /// Creates a sparse sequence and inserts sequence items of alphabet
        /// and removes few sequence items using RemoveRange()
        /// Validates ifexpected number of items are removed.
        /// </summary>
        /// <param name="alphabet">alphabet instance.</param>
        private void ValidateSparseSequenceRemoveRange(IAlphabet alphabet)
        {
            SparseSequence sparseSequence = CreateSparseSequence(alphabet, 10);

            sparseSequence.IsReadOnly = false;

            // Remove all sequence items
            Assert.AreEqual(alphabet.Count + 10, sparseSequence.Count);

            sparseSequence.RemoveRange(10, 10);

            // Validate if 10 items are removed using RemoveRange
            Assert.AreEqual(alphabet.Count, sparseSequence.Count);

            Console.WriteLine(
                "SparseSequenceP1: Validation of RemoveRange() method by passing position and length is completed");
            ApplicationLog.WriteLine(
                "SparseSequenceP1: Validation of RemoveRange() method by passing position and length is completed");
        }
コード例 #18
0
        public void ValidateSparseSequenceGetReversedComplementedSequence()
        {
            byte[] byteArrayObj = Encoding.ASCII.GetBytes("ACGT");

            IEnumerable <byte> seqItems =
                new List <Byte> {
                byteArrayObj[0], byteArrayObj[1], byteArrayObj[2], byteArrayObj[3]
            };

            var       sparseSeqObj = new SparseSequence(Alphabets.DNA, 0, seqItems);
            ISequence revSeqObj    = sparseSeqObj.GetReverseComplementedSequence();

            for (int i = 0; i < byteArrayObj.Length; i++)
            {
                Assert.AreEqual(byteArrayObj[i], revSeqObj[i]);
            }

            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of GetReverseComplementedSequence() method successfully completed");
        }
コード例 #19
0
        public void ValidateRnaSparseSequenceConstAlpIndexByteList()
        {
            byte[] byteArrayObj = Encoding.ASCII.GetBytes("AGCU");

            IEnumerable<byte> seqItems =
                new List<Byte> {byteArrayObj[0], byteArrayObj[1], byteArrayObj[2], byteArrayObj[3]};

            var sparseSeq = new SparseSequence(Alphabets.RNA, 4, seqItems);
            Assert.IsNotNull(sparseSeq);
            Assert.IsNotNull(sparseSeq.Statistics);
            Assert.AreEqual(8, sparseSeq.Count);
            SequenceStatistics seqStatObj = sparseSeq.Statistics;
            Assert.AreEqual(1, seqStatObj.GetCount('A'));
            Assert.AreEqual(1, seqStatObj.GetCount('G'));
            Assert.AreEqual(1, seqStatObj.GetCount('C'));
            Assert.AreEqual(1, seqStatObj.GetCount('U'));

            ApplicationLog.WriteLine("SparseSequence P1: Validation of SparseSequence(alp, index, seq items) constructor is completed");
        }
コード例 #20
0
        /// <summary>
        /// Invalidate Sparse sequence Remove
        /// </summary>
        /// <param name="sparseSeq">Sparse Sequence</param>
        private static void ValidateSparseSequenceRemove(SparseSequence sparseSeq)
        {
            Assert.IsTrue(sparseSeq.Remove(Alphabets.DNA.A));
            Assert.AreEqual(sparseSeq.Count, 9);
            Assert.AreSame(sparseSeq[0], Alphabets.DNA.C);
            Assert.AreSame(sparseSeq[1], Alphabets.DNA.G);
            Assert.IsNull(sparseSeq[2]);
            Assert.IsNull(sparseSeq[3]);
            Assert.AreSame(sparseSeq[4], Alphabets.DNA.A);
            Assert.AreSame(sparseSeq[5], Alphabets.DNA.G);
            Assert.AreSame(sparseSeq[6], Alphabets.DNA.C);
            Assert.IsNull(sparseSeq[7]);
            Assert.IsNull(sparseSeq[8]);

            Assert.IsFalse(sparseSeq.Remove(Alphabets.DNA.T));

            Assert.IsFalse(sparseSeq.Remove(Alphabets.RNA.U));
            Assert.AreEqual(sparseSeq.Count, 9);
        }
コード例 #21
0
        public void TestSparseSequenceCopyTo()
        {
            IEnumerable <byte> seqItems = new List <Byte>()
            {
                65, 65, 67, 67
            };
            SparseSequence sparseSeq = new SparseSequence(Alphabets.DNA, 0, seqItems);

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

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

            Assert.AreEqual(expectedValue, actualValue);
        }
コード例 #22
0
        public void ValidateSparseSequenceInvalidAlphabet()
        {
            SparseSequence sparseSeq = null;
            var            seq       = new Sequence(Alphabets.RNA, "U");
            byte           seqItem   = seq[0];

            // Try Creating sparse sequence by passing invalid alphabet.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, 0, seqItem);
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #23
0
        /// <summary>
        /// The common ParseOne method called for parsing SNPs
        /// NOTE: The snpReader.MoveNext must have already been called and
        /// the ISnpReader.Current have the first SnpItem to parse into the sequence
        /// </summary>
        /// <param name="snpReader">The ISnpReader to read a Snp chromosome sequence from</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous
        /// chromosome number read from the snp reader.</returns>
        protected ISequence ParseOne(ISnpReader snpReader, bool isReadOnly)
        {
            // Check input arguments
            if (snpReader == null)
            {
                throw new ArgumentNullException("snpReader", "SNP Reader to read SNP sequences from cannot be null");
            }

            if (snpReader.Current == null)
            {
                return new SparseSequence(Alphabet)
                       {
                           ID = "Empty"
                       }
            }
            ;

            int            sequenceChromosome = snpReader.Current.Chromosome;
            SparseSequence sequence           = new SparseSequence(Alphabet);

            sequence.ID = ("Chr" + sequenceChromosome);

            do
            {
                SnpItem snp = snpReader.Current;

                // increase the size of the sparse sequence
                if (sequence.Count <= snp.Position)
                {
                    sequence.Count = snp.Position + 1;
                }
                sequence[snp.Position] = ParseAlleleOne
                                             ? Alphabet.LookupBySymbol(snp.AlleleOne)
                                             : Alphabet.LookupBySymbol(snp.AlleleTwo);
            } while (snpReader.MoveNext() && snpReader.Current.Chromosome == sequenceChromosome);

            sequence.IsReadOnly = isReadOnly;
            return(sequence);
        }

        #endregion Protected Methods of SnpParser
    }
コード例 #24
0
        public void ValidateSparseSequenceIndexOfNonGap()
        {
            SparseSequence sparseSeqObj = new SparseSequence(Alphabets.DNA);

            sparseSeqObj.Count = 1000;
            sparseSeqObj[9]    = null;
            sparseSeqObj[10]   = Alphabets.DNA.Gap;
            sparseSeqObj[20]   = Alphabets.DNA.GA;
            sparseSeqObj[501]  = Alphabets.DNA.A;
            sparseSeqObj[905]  = Alphabets.DNA.Gap;
            sparseSeqObj[906]  = null;
            Assert.AreEqual(20, sparseSeqObj.IndexOfNonGap());
            Assert.AreEqual(20, sparseSeqObj.IndexOfNonGap(10));
            Assert.AreEqual(20, sparseSeqObj.IndexOfNonGap(20));

            Console.WriteLine(
                "SparseSequenceBVT: Validation of IndexOfNonGap() method successfully completed");
            ApplicationLog.WriteLine(
                "SparseSequenceBVT: Validation of IndexOfNonGap() method successfully completed");
        }
コード例 #25
0
        /// <summary>
        /// Invalidate Sparse sequence Comp & ReverseComplement
        /// </summary>
        /// <param name="sparseSeq">Sparse Sequence</param>
        private static void InvalidateSparseSequenceReverseComplement(SparseSequence sparseSeq)
        {
            SparseSequence tempSeq = new SparseSequence(sparseSeq.Alphabet, 1, sparseSeq);

            Assert.AreEqual(tempSeq.Count, 6);
            Assert.IsNull(tempSeq[0]);
            Assert.AreSame(tempSeq[1], Alphabets.DNA.A);
            Assert.IsNull(tempSeq[2]);
            Assert.AreSame(tempSeq[3], Alphabets.DNA.T);
            Assert.AreSame(tempSeq[4], Alphabets.DNA.G);
            Assert.AreSame(tempSeq[5], Alphabets.DNA.C);

            #region Test - Complement
            ISequence compSeq = sparseSeq.Complement;

            Assert.AreEqual(compSeq.Count, 5);
            Assert.AreSame(compSeq[0], Alphabets.DNA.T);
            Assert.IsNull(compSeq[1]);
            Assert.AreSame(compSeq[2], Alphabets.DNA.A);
            Assert.AreSame(compSeq[3], Alphabets.DNA.C);
            Assert.AreSame(compSeq[4], Alphabets.DNA.G);
            #endregion Test - Complement

            #region Test - Reverse
            compSeq = sparseSeq.Reverse;
            Assert.AreEqual(compSeq.Count, 5);
            Assert.AreSame(compSeq[4], Alphabets.DNA.A);
            Assert.IsNull(compSeq[3]);
            Assert.AreSame(compSeq[2], Alphabets.DNA.T);
            Assert.AreSame(compSeq[1], Alphabets.DNA.G);
            Assert.AreSame(compSeq[0], Alphabets.DNA.C);
            #endregion Test - Reverse

            compSeq = sparseSeq.ReverseComplement;
            Assert.AreEqual(compSeq.Count, 5);
            Assert.AreSame(compSeq[4], Alphabets.DNA.T);
            Assert.IsNull(compSeq[3]);
            Assert.AreSame(compSeq[2], Alphabets.DNA.A);
            Assert.AreSame(compSeq[1], Alphabets.DNA.C);
            Assert.AreSame(compSeq[0], Alphabets.DNA.G);
        }
コード例 #26
0
        /// <summary>
        /// The common ParseOne method called for parsing SNPs
        /// NOTE: The snpReader.MoveNext must have already been called and
        /// the ISnpReader.Current have the first SnpItem to parse into the sequence
        /// </summary>
        /// <param name="snpReader">The ISnpReader to read a Snp chromosome sequence from</param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous
        /// chromosome number read from the snp reader.</returns>
        protected ISequence ParseOne(ISnpReader snpReader)
        {
            // Check input arguments
            if (snpReader == null)
            {
                throw new ArgumentNullException("snpReader", Properties.Resource.snpTextReaderNull);
            }

            if (snpReader.Current == null)
            {
                return new SparseSequence(Alphabet)
                       {
                           ID = "Empty"
                       }
            }
            ;

            int            sequenceChromosome = snpReader.Current.Chromosome;
            SparseSequence sequence           = new SparseSequence(Alphabet);

            sequence.ID = ("Chr" + sequenceChromosome);

            do
            {
                SnpItem snp = snpReader.Current;

                // increase the size of the sparse sequence
                if (sequence.Count <= snp.Position)
                {
                    sequence.Count = snp.Position + 1;
                }
                sequence[snp.Position] = ParseAlleleOne
                             ? (byte)snp.AlleleOne
                             : (byte)snp.AlleleTwo;
            } while (snpReader.MoveNext() && snpReader.Current.Chromosome == sequenceChromosome);

            return(sequence);
        }

        #endregion Protected Methods of SnpParser
    }
コード例 #27
0
        /// <summary>
        /// Creates a sparse sequence and inserts sequence items at even position of alphabet
        /// and replace the sequence item with sequence item symbol present at odd position.
        /// Validates if item is replaced.
        /// </summary>
        /// <param name="alphabet">alphabet instance.</param>
        private void ValidateSparseSequenceReplaceWithChar(IAlphabet alphabet)
        {
            // Create sequence item array
            ISequenceItem[] sequenceItemArray = new ISequenceItem[alphabet.Count];
            int             index             = 0;

            foreach (ISequenceItem item in alphabet)
            {
                sequenceItemArray[index] = item;
                index++;
            }

            /// Validate the Replace method with char
            /// Add even sequence items from sequence item array at random position
            /// and replace with odd sequence item symbol from array.
            int replaceIndex = 1;

            int[] randomNumbers = Utility.RandomNumberGenerator(1502, alphabet.Count);
            index = 0;
            for (int addIndex = 0; addIndex < alphabet.Count; addIndex = addIndex + 2)
            {
                SparseSequence sparseSeq =
                    new SparseSequence(alphabet, randomNumbers[index], sequenceItemArray[addIndex]);
                sparseSeq.IsReadOnly = false;
                sparseSeq.Replace(randomNumbers[index], sequenceItemArray[replaceIndex].Symbol);

                // Validate if item is replaced as expected.
                Assert.AreEqual(sparseSeq[randomNumbers[index]].Symbol,
                                sequenceItemArray[replaceIndex].Symbol);
                Assert.AreEqual(sparseSeq[randomNumbers[index]],
                                sequenceItemArray[replaceIndex]);

                replaceIndex = replaceIndex + 2;
                index++;
            }

            Console.WriteLine(
                "SparseSequenceBVT: Validation of Replace() method by passing char is completed");
            ApplicationLog.WriteLine(
                "SparseSequenceBVT: Validation of Replace() method by passing char is completed");
        }
コード例 #28
0
        /// <summary>
        /// Creates a sparse sequence and inserts sequence items of alphabet
        /// and removes all sequence items.
        /// Validates if items are getting removed.
        /// </summary>
        /// <param name="alphabet">alphabet instance.</param>
        private void ValidateSparseSequenceRemove(IAlphabet alphabet)
        {
            SparseSequence sparseSequence = CreateSparseSequence(alphabet, 0);

            sparseSequence.IsReadOnly = false;

            // Remove all sequence items
            Assert.AreEqual(alphabet.Count, sparseSequence.Count);
            foreach (ISequenceItem item in alphabet)
            {
                sparseSequence.Remove(item);
            }

            // Validate if all items are removed.
            Assert.AreEqual(0, sparseSequence.Count);

            Console.WriteLine(
                "SparseSequenceBVT: Validation of Replace() method by passing char is completed");
            ApplicationLog.WriteLine(
                "SparseSequenceBVT: Validation of Replace() method by passing char is completed");
        }
コード例 #29
0
        public void ValidateSparseSequenceListInvalidIndex()
        {
            SparseSequence sparseSeq   = null;
            var            seq         = new Sequence(Alphabets.DNA, "G");
            var            seqItemList = new List <byte> {
                seq[0]
            };

            // Try Creating sparse sequence by passing invalid index.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, -1, seqItemList);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #30
0
        /// <summary>
        /// Test Sparse sequence constructor using alphabet
        /// </summary>
        /// <param name="sparseSeq">Sparse Sequence</param>
        private static void InvalidateSparseSequenceCtorUsingAlphabet(SparseSequence sparseSeq)
        {
            Assert.IsFalse(sparseSeq.IsReadOnly);
            sparseSeq.Insert(0, 'C');
            Assert.AreEqual(sparseSeq.Count, 1);
            Assert.AreSame(sparseSeq[0], Alphabets.DNA.C);

            sparseSeq = new SparseSequence(Alphabets.DNA, 0, Alphabets.DNA.A);

            string id = Guid.NewGuid().ToString(string.Empty);

            sparseSeq.ID        = id;
            sparseSeq.DisplayID = "SparseSeq1";

            Assert.AreSame(Alphabets.DNA, sparseSeq.Alphabet);
            Assert.IsTrue(sparseSeq.IsReadOnly);
            Assert.AreSame(sparseSeq.Complement[0], Alphabets.DNA.T);
            Assert.AreEqual(sparseSeq.Count, 1);
            Assert.AreEqual(sparseSeq.DisplayID, "SparseSeq1");
            Assert.AreEqual(sparseSeq.ID, id);
        }
コード例 #31
0
        public void ValidateSparseSequenceSetIndexer()
        {
            IAlphabet alphabet = Alphabets.DNA;

            // Create sequence item list
            var sequenceList = new List <byte>();

            foreach (byte item in alphabet)
            {
                sequenceList.Add(item);
            }

            // Store sequence item in sparse sequence object using list of sequence items
            var  sparseSeq = new SparseSequence(alphabet, 0, sequenceList);
            byte seqItem   = new Sequence(Alphabets.DNA, "AGCT")[0];

            sparseSeq[0] = seqItem;
            Assert.AreEqual(65, sparseSeq[0]);

            ApplicationLog.WriteLine("SparseSequence BVT: Validation of Indexer successfully completed");
        }
コード例 #32
0
        public void ValidateSparseSequenceListInvalidAlphabet()
        {
            SparseSequence sparseSeq   = null;
            Sequence       seq         = new Sequence(Alphabets.RNA, "U");
            List <byte>    seqItemList = new List <byte>();

            seqItemList.Add(seq[0]);

            // Try Creating sparse sequence by passing Invalid alphabet
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, 0, seqItemList);
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #33
0
        public void ValidateSparseSequenceGetKnownSequenceItems()
        {
            byte[] byteArrayObj = Encoding.ASCII.GetBytes("ACGT");

            IEnumerable <byte> seqItems =
                new List <Byte> {
                byteArrayObj[0], byteArrayObj[1], byteArrayObj[2], byteArrayObj[3]
            };

            var sparseSeqObj = new SparseSequence(Alphabets.DNA, 0, seqItems);
            IList <IndexedItem <byte> > revSeqObj = sparseSeqObj.GetKnownSequenceItems();
            long i = 0;

            foreach (var by in revSeqObj)
            {
                Assert.AreEqual(i, by.Index);
                Assert.AreEqual(byteArrayObj[i], by.Item);
                i++;
            }

            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of GetKnownSequenceItems() method successfully completed");
        }
コード例 #34
0
        /// <summary>
        /// Creates sparse sequence object using seq item list overload.
        /// Validates if all items are present in sparse sequence instance.
        /// </summary>
        /// <param name="alphabet">alphabet instance.</param>
        private void ValidateSparseSequenceWithSeqItemList(IAlphabet alphabet)
        {
            SparseSequence sparseSeq = CreateSparseSequence(alphabet, 20);

            // Retrieve all stored sequence items and validate Sparse Sequence
            int retrieveIndex = 20;

            foreach (ISequenceItem item in alphabet)
            {
                // Validate new added items
                Assert.IsTrue(sparseSeq.Contains(item));
                Assert.AreEqual(sparseSeq.IndexOf(item), retrieveIndex);
                Assert.AreEqual(item, sparseSeq[retrieveIndex]);
                Assert.AreEqual(item.Symbol, sparseSeq[retrieveIndex].Symbol);
                retrieveIndex++;
            }

            Console.WriteLine(
                "SparseSequenceP1: Validation of Sparse Sequence constructor with Sequence item list is completed");
            ApplicationLog.WriteLine(
                "SparseSequenceP1: Validation of Sparse Sequence constructor with Sequence item list is completed");
        }
コード例 #35
0
        public void ValidateDnaSparseSequenceProperties()
        {
            IAlphabet alphabet = Alphabets.DNA;

            // Create sparse sequence object
            const int insertPosition = 0;
            // Create sequence item list
            IList <byte> sequenceList = alphabet.ToList();

            // Store sequence item in sparse sequence object using list of sequence items
            var sparseSequence = new SparseSequence(alphabet, insertPosition, sequenceList);

            //Validate all properties
            Assert.AreEqual(alphabet.Count + insertPosition, sparseSequence.Count);
            Assert.AreEqual(alphabet, sparseSequence.Alphabet);
            Assert.IsTrue(string.IsNullOrEmpty(sparseSequence.ID));
            Assert.IsNotNull(sparseSequence.Metadata);
            Assert.IsNotNull(sparseSequence.Statistics);
            Assert.IsNotNull(sparseSequence.GetKnownSequenceItems());

            ApplicationLog.WriteLine("SparseSequence BVT: Validation of all properties of sparse sequence instance is completed");
        }
コード例 #36
0
        public void ValidateSparseSeqNegativeIndexException()
        {
            string expectedErrorMessage = this.GetErrorMessage(Constants.NegativeIndexErrorMessage);
            string actualError = string.Empty;
            SparseSequence sparseSeq = null;

            // Try Creating sparse sequence by passing null value.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, -5, Alphabets.DNA.A);
            }
            catch (ArgumentException e)
            {
                actualError = e.Message;
            }

            string updatedActualError = Regex.Replace(actualError, "[\r\n\t]", "");
            Assert.AreEqual(expectedErrorMessage.ToUpperInvariant(), updatedActualError.ToUpperInvariant());
            Assert.IsNull(sparseSeq);

            // Log to GUI.
            ApplicationLog.WriteLine(string.Format(null, "SparseSequence P2: SparseSequence Exception was validated successfully {0}",
                                            updatedActualError));
        }
コード例 #37
0
        public void ValidateSparseSequenceIndexOfNonGap()
        {
            var sparseSeqObj = new SparseSequence(Alphabets.DNA, 10);
            sparseSeqObj[8] = Alphabets.DNA.Gap;
            sparseSeqObj[9] = Alphabets.DNA.A;

            Assert.AreEqual(9, sparseSeqObj.IndexOfNonGap(8));
            Assert.AreEqual(9, sparseSeqObj.IndexOfNonGap(9));

            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of IndexOfNonGap(startPos) method successfully completed");
        }
コード例 #38
0
        public void ValidateSparseSequenceGetSubSequence()
        {
            var byteList = new List<byte>
            {
                Alphabets.DNA.Gap,
                Alphabets.DNA.G,
                Alphabets.DNA.A,
                Alphabets.DNA.Gap,
                Alphabets.DNA.T,
                Alphabets.DNA.C,
                Alphabets.DNA.Gap,
                Alphabets.DNA.Gap
            };

            var sparseSeq = new SparseSequence(Alphabets.DNA, 0, byteList);

            ISequence result = sparseSeq.GetSubSequence(0, 3);
            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(Alphabets.DNA.Gap, result[0]);
            Assert.AreEqual(Alphabets.DNA.G, result[1]);
            Assert.AreEqual(Alphabets.DNA.A, result[2]);

            result = sparseSeq.GetSubSequence(0, 0);
            Assert.AreEqual(0, result.Count);

            result = sparseSeq.GetSubSequence(3, 2);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(Alphabets.DNA.Gap, result[0]);
            Assert.AreEqual(Alphabets.DNA.T, result[1]);

            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of GetSubSequence() method successfully completed");
        }
コード例 #39
0
        public void ValidateSparseSequenceGetComplementedSequence()
        {
            byte[] byteArrayObj = Encoding.ASCII.GetBytes("ACGT");

            IEnumerable<byte> seqItems =
                new List<Byte> {byteArrayObj[0], byteArrayObj[1], byteArrayObj[2], byteArrayObj[3]};

            var sparseSeqObj = new SparseSequence(Alphabets.DNA, 0, seqItems);
            ISequence revSeqObj = sparseSeqObj.GetComplementedSequence();

            byteArrayObj = Encoding.ASCII.GetBytes("TGCA");

            for (int i = 0; i < byteArrayObj.Length; i++)
            {
                Assert.AreEqual(byteArrayObj[i], revSeqObj[i]);
            }

            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of GetComplementedSequence() method successfully completed");
        }
コード例 #40
0
        public void ValidateExceptionByPassingInvalidLength()
        {
            //Create a sparse sequence.
            var sparseSeq = new SparseSequence(Alphabets.DNA, 5);

            try
            {
                sparseSeq.GetSubSequence(0, 10);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                // Log to GUI.
                ApplicationLog.WriteLine("SparseSequence P2: SparseSequence Exception was validated successfully");
            }
        }
コード例 #41
0
ファイル: SnpParser.cs プロジェクト: cpatmoore/bio
        /// <summary>
        /// The common ParseOne method called for parsing SNPs
        /// NOTE: The snpReader.MoveNext must have already been called and 
        /// the ISnpReader.Current have the first SnpItem to parse into the sequence
        /// </summary>
        /// <param name="snpReader">The ISnpReader to read a Snp chromosome sequence from</param>
        /// <returns>Returns a SparseSequence containing Snp items from the first contiguous 
        /// chromosome number read from the snp reader.</returns>
        protected ISequence ParseOne(ISnpReader snpReader)
        {
            // Check input arguments
            if (snpReader == null) 
            {
                throw new ArgumentNullException("snpReader",Properties.Resource.snpTextReaderNull);
            }

            if (snpReader.Current == null)
                return new SparseSequence(Alphabet)
                {
                    ID = "Empty"
                };

            int sequenceChromosome = snpReader.Current.Chromosome;
            SparseSequence sequence = new SparseSequence(Alphabet) { ID = "Chr" + sequenceChromosome };

            do
            {
                SnpItem snp = snpReader.Current;
                // increase the size of the sparse sequence
                if (sequence.Count <= snp.Position)
                    sequence.Count = snp.Position + 1;
                sequence[snp.Position] = ParseAlleleOne
                             ? (byte)snp.AlleleOne
                             : (byte)snp.AlleleTwo;
            } while (snpReader.MoveNext() && snpReader.Current.Chromosome == sequenceChromosome);

            return sequence;
        }
コード例 #42
0
ファイル: XsvSparseParser.cs プロジェクト: cpatmoore/bio
        /// <summary>
        /// The common ParseOne method called for parsing sequences from Xsv files. 
        /// This assumes that that the first line has been read into the XsvSparseReader 
        /// (i.e. GoToNextLine() has been called). This adds the offset position present in 
        /// the sequence start line to each position value in the sequence item.
        /// e.g. the following returns a sparse sequence with ID 'Test sequence' of length 100 
        /// with A at position 32 (25+7) and G at position 57 (50+7).
        /// # 7, 100, Test sequence
        /// 25,A
        /// 50,G
        /// </summary>
        /// <param name="sparseReader">The Xsv sparse reader that can read the sparse sequences.
        /// Flag to indicate whether the resulting sequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting sequence's isReadOnly property 
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>The first sequence present starting from the 
        /// current position in the reader as a SparseSequence. The sparse sequence has the ID present in the 
        /// sequence start line, and its length equals the count present in that line. 
        /// Null if EOF has been reached. Throws an exception if the current position did 
        /// not have the sequence start line with the sequence prefix ID character.
        /// </returns>
        protected ISequence ParseOne(XsvSparseReader sparseReader)
        {
            // Check input arguments
            if (sparseReader == null)
            {
                throw new ArgumentNullException("sparseReader");
            }

            if (!sparseReader.HasLines) return null;

            if (sparseReader.SkipCommentLines || !sparseReader.HasCommentLine)
                throw new InvalidDataException(Properties.Resource.XsvOffsetNotFound);

            // create a new sparse sequence
            SparseSequence sequence = new SparseSequence(Alphabet) { ID = sparseReader.GetSequenceId() };

            // read the sequence ID, count and offset
            long offset = sparseReader.GetSequenceOffset();
            sequence.Count = sparseReader.GetSequenceCount() + offset;
            sequence.Metadata.Add(MetadataOffsetKey, offset); 

            // go to first sequence item
            sparseReader.GoToNextLine();

            while (sparseReader.HasLines && !sparseReader.HasCommentLine)
            {
                // add offset to position
                long position = long.Parse(sparseReader.Fields[0], CultureInfo.InvariantCulture) + offset;
                char symbol = sparseReader.Fields[1][0];
                if (sequence.Count <= position)
                    sequence.Count = position + 1; 
                sequence[position] = (byte)symbol;
                sparseReader.GoToNextLine();
            }

            return sequence;
        }
コード例 #43
0
        public void ValidateSparseSequenceGetKnownSequenceItems()
        {
            byte[] byteArrayObj = Encoding.ASCII.GetBytes("ACGT");

            IEnumerable<byte> seqItems =
                new List<Byte> {byteArrayObj[0], byteArrayObj[1], byteArrayObj[2], byteArrayObj[3]};

            var sparseSeqObj = new SparseSequence(Alphabets.DNA, 0, seqItems);
            IReadOnlyList<IndexedItem<byte>> revSeqObj = sparseSeqObj.GetKnownSequenceItems();
            long i = 0;
            foreach (var by in revSeqObj)
            {
                Assert.AreEqual(i, by.Index);
                Assert.AreEqual(byteArrayObj[i], by.Item);
                i++;
            }

            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of GetKnownSequenceItems() method successfully completed");
        }
コード例 #44
0
        public void ValidateSparseSequenceInvalidSeqItem()
        {
            SparseSequence sparseSeq = null;

            // Try Creating sparse sequence by passing invalid sequence item.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, 0, null);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #45
0
        public void ValidateSparseSequenceInvalidIndex()
        {
            SparseSequence sparseSeq = null;

            // Try Creating sparse sequence by passing invalid index.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, -1, null);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #46
0
        public void ValidateIndexValueOfDifferentSeqItemOtherThanSparseSeqItem()
        {
            // Create a sparse sequence.
            var sparseSeq = new SparseSequence(Alphabets.DNA) {Count = 2000};

            // Store all sequence items in sparse sequence object
            int insertIndex = 0;
            int[] randomNumbers = Utility.RandomNumberGenerator(2000, Alphabets.DNA.Count);
            foreach (byte item in Alphabets.DNA)
            {
                sparseSeq[randomNumbers[insertIndex]] = item;
                insertIndex++;
            }

            foreach (byte bt in sparseSeq)
            {
                Assert.AreNotEqual(bt, Alphabets.RNA.U);
            }

            // Log to GUI.
            ApplicationLog.WriteLine("SparseSequence P2: SparseSequence Exception was validated successfully");
        }
コード例 #47
0
        public void ValidateExceptionByPassingSeqItemToInvalidSequenceItemPostion()
        {
            string expectedErrorMessage = this.GetErrorMessage(Constants.InvalidSequenceCountError);
            string actualError = string.Empty;
            var sparseSeq = new SparseSequence(Alphabets.DNA) {Count = 1000};

            // Try to store seq items at 1050 position greater than sparse
            // sequence count.
            try
            {
                sparseSeq[1050] = Alphabets.DNA.A;
            }
            catch (ArgumentOutOfRangeException e)
            {
                actualError = e.Message;
            }

            string updatedActualError = Regex.Replace(actualError, "[\r\n\t]", "");
            Assert.AreEqual(expectedErrorMessage.ToUpperInvariant(), updatedActualError.ToUpperInvariant());

            // Log to GUI.
            ApplicationLog.WriteLine(string.Format(null,
                                            "SparseSequence P2: SparseSequence Exception was validated successfully {0}",
                                            updatedActualError));
        }
コード例 #48
0
        public void ValidateSeqItemsByPassingProteinSeqItemToRnaSequence()
        {
            var sparseSeq = new SparseSequence(Alphabets.RNA) {Count = 2000};

            // Store all sequence items in sparse sequence object
            int insertIndex = 0;
            int[] randomNumbers = Utility.RandomNumberGenerator(2000, Alphabets.RNA.Count);
            foreach (byte item in Alphabets.RNA)
            {
                sparseSeq[randomNumbers[insertIndex]] = item;
                insertIndex++;
            }

            // Validate whether invalid sequence item contains in Sparse 
            // sequence or not.
            foreach (byte bt in sparseSeq)
            {
                Assert.AreNotEqual(bt, Alphabets.Protein.D);
            }

            ApplicationLog.WriteLine("SparseSequence P2: SparseSequence error was validated successfully.");
        }
コード例 #49
0
        public void TestSparseSequenceConstructorWithSequenceArgument()
        {
            IEnumerable<byte> seqItems = new List<Byte>() { 65, 65, 67, 67 };
            SparseSequence sparseSeq = new SparseSequence(Alphabets.DNA, 0, seqItems);
            ISequence seq = sparseSeq.GetSubSequence(0, sparseSeq.Count);
            SparseSequence newSparseSequence = new SparseSequence(seq);
            ISequence newSeq = newSparseSequence.GetSubSequence(0, newSparseSequence.Count);

            string expectedValue = "AACC";
            string actualValue = new string(newSeq.Select(x => (char)x).ToArray());
            Assert.AreEqual(expectedValue, actualValue);
        }
コード例 #50
0
        public void ValidateSparseSequenceGetEnumerator()
        {
            byte[] byteArrayObj = Encoding.ASCII.GetBytes("ACGT");

            IEnumerable<byte> seqItems =
                new List<Byte> {byteArrayObj[0], byteArrayObj[1], byteArrayObj[2], byteArrayObj[3]};

            var sparseSeqObj = new SparseSequence(Alphabets.DNA, 0, seqItems);
            IEnumerator<byte> seqObj = sparseSeqObj.GetEnumerator();
            int i = 0;
            while (seqObj.MoveNext())
            {
                Assert.AreEqual(byteArrayObj[i], seqObj.Current);
                i++;
            }
            i = 0;
            foreach (byte alp in sparseSeqObj)
            {
                Assert.AreEqual(byteArrayObj[i], alp);
                i++;
            }

            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of GetEnumerator() method successfully completed");
        }
コード例 #51
0
        public void ValidateDnaSparseSequenceProperties()
        {
            IAlphabet alphabet = Alphabets.DNA;

            // Create sparse sequence object
            const int insertPosition = 0;
            // Create sequence item list
            IList<byte> sequenceList = alphabet.ToList();

            // Store sequence item in sparse sequence object using list of sequence items
            var sparseSequence = new SparseSequence(alphabet, insertPosition, sequenceList);

            //Validate all properties
            Assert.AreEqual(alphabet.Count + insertPosition, sparseSequence.Count);
            Assert.AreEqual(alphabet, sparseSequence.Alphabet);
            Assert.IsTrue(string.IsNullOrEmpty(sparseSequence.ID));
            Assert.IsNotNull(sparseSequence.Metadata);
            Assert.IsNotNull(sparseSequence.Statistics);
            Assert.IsNotNull(sparseSequence.GetKnownSequenceItems());

            ApplicationLog.WriteLine("SparseSequence BVT: Validation of all properties of sparse sequence instance is completed");
        }
コード例 #52
0
        public void ValidateSparseSequenceSetIndexer()
        {
            IAlphabet alphabet = Alphabets.DNA;

            // Create sequence item list
            var sequenceList = new List<byte>();
            foreach (byte item in alphabet)
            {
                sequenceList.Add(item);
            }

            // Store sequence item in sparse sequence object using list of sequence items
            var sparseSeq = new SparseSequence(alphabet, 0, sequenceList);
            byte seqItem = new Sequence(Alphabets.DNA, "AGCT")[0];

            sparseSeq[0] = seqItem;
            Assert.AreEqual(65, sparseSeq[0]);

            ApplicationLog.WriteLine("SparseSequence BVT: Validation of Indexer successfully completed");
        }
コード例 #53
0
        public void InvalidateCopyTo()
        {
            var byteList = new List<byte>
            {
                Alphabets.DNA.Gap,
                Alphabets.DNA.G,
                Alphabets.DNA.A,
                Alphabets.DNA.Gap,
                Alphabets.DNA.T,
                Alphabets.DNA.C,
                Alphabets.DNA.Gap,
                Alphabets.DNA.Gap
            };

            ISequence iSeq = new SparseSequence(Alphabets.DNA, 0, byteList);
            var seqObj = new SparseSequence(iSeq);

            //check with null array
            byte[] array = null;
            try
            {
                seqObj.CopyTo(array, 10, 20);
                Assert.Fail();
            }
            catch (ArgumentNullException anex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentNullException : " + anex.Message);
            }

            //check with more than available length
            array = new byte[byteList.Count];
            try
            {
                seqObj.CopyTo(array, 0, byteList.Count + 100);
                Assert.Fail();
            }
            catch (ArgumentException aex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentException : " + aex.Message);
            }

            //check with negative start
            array = new byte[byteList.Count];
            try
            {
                seqObj.CopyTo(array, -5, byteList.Count);
                Assert.Fail();
            }
            catch (ArgumentException aex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentException : " + aex.Message);
            }

            //check with negative count
            array = new byte[byteList.Count];
            try
            {
                seqObj.CopyTo(array, 0, -5);
                Assert.Fail();
            }
            catch (ArgumentException aex)
            {
                ApplicationLog.WriteLine("Successfully caught ArgumentException : " + aex.Message);
            }
        }
コード例 #54
0
        /// <summary>
        ///     Create sparse sequence and insert all sequence items of alphabet.
        /// </summary>
        /// <param name="alphabet"></param>
        /// <param name="insertPosition"></param>
        /// <returns></returns>
        private static SparseSequence CreateSparseSequence(IAlphabet alphabet, int insertPosition)
        {
            // Create sequence item list
            var sequenceList = alphabet.ToList();

            // Store sequence item in sparse sequence object using list of sequence items
            var sparseSeq = new SparseSequence(alphabet, insertPosition, sequenceList);

            return sparseSeq;
        }
コード例 #55
0
        public void ValidateSparseSequenceLastIndexOfNonGapNull()
        {
            var sparseSeqObj = new SparseSequence(Alphabets.DNA, 2);
            sparseSeqObj[1] = Alphabets.DNA.Gap;
            sparseSeqObj[0] = Alphabets.DNA.A;

            Assert.AreEqual(0, sparseSeqObj.LastIndexOfNonGap());
            ApplicationLog.WriteLine("SparseSequenceBVT: Validation of LastIndexOfNonGap() method successfully completed");
        }
コード例 #56
0
        public void ValidateSparseSequenceListInvalidIndex()
        {
            SparseSequence sparseSeq = null;
            var seq = new Sequence(Alphabets.DNA, "G");
            var seqItemList = new List<byte> {seq[0]};

            // Try Creating sparse sequence by passing invalid index.
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, -1, seqItemList);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #57
0
        public void ValidateExceptionByPassingInvalidStartIndex()
        {
            //Create a sparse sequence.
            var sparseSeq = new SparseSequence(Alphabets.DNA);

            // Try to add RNA Sequence Item to DNA sparse sequence.
            try
            {
                sparseSeq.GetSubSequence(10, 0);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                ApplicationLog.WriteLine("SparseSequence P2: SparseSequence Exception was validated successfully");
            }
        }
コード例 #58
0
        public void ValidateSparseSequenceListInvalidAlphabet()
        {
            SparseSequence sparseSeq = null;
            var seq = new Sequence(Alphabets.RNA, "U");
            var seqItemList = new List<byte> {seq[0]};

            // Try Creating sparse sequence by passing Invalid alphabet
            try
            {
                sparseSeq = new SparseSequence(Alphabets.DNA, 0, seqItemList);
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                LogMessage(ex.Message);
            }

            Assert.IsNull(sparseSeq);
        }
コード例 #59
0
        public void ValidateCopyTo()
        {
            var byteList = new List<byte>
            {
                Alphabets.DNA.Gap,
                Alphabets.DNA.G,
                Alphabets.DNA.A,
                Alphabets.DNA.Gap,
                Alphabets.DNA.T,
                Alphabets.DNA.C,
                Alphabets.DNA.Gap,
                Alphabets.DNA.Gap
            };

            ISequence iSeq = new SparseSequence(Alphabets.DNA, 0, byteList);
            var sparseSeq = new SparseSequence(iSeq);

            var array = new byte[byteList.Count];
            sparseSeq.CopyTo(array, 0, byteList.Count);
            for (int i = 0; i < byteList.Count; i++)
            {
                Assert.AreEqual(byteList.ElementAt(i), array[i]);
            }

            //check for a part of the sequence
            array = new byte[5];
            sparseSeq.CopyTo(array, 0, 5);
            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(byteList.ElementAt(i), array[i]);
            }
        }