Exemplo n.º 1
0
        public void ValidateFVQSPProperties()
        {
            IVirtualSequenceParser parserObj = new FastQParser();

            try
            {
                FileVirtualQualitativeSequenceProvider provObj =
                    new FileVirtualQualitativeSequenceProvider(parserObj, GetSequencePointer());
                provObj.BlockSize               = 5;
                provObj.IsReadOnly              = false;
                provObj.MaxNumberOfBlocks       = 10;
                provObj.SequencePointerInstance = GetSequencePointer();
                SequencePointer seqPoint = GetSequencePointer();
                Assert.AreEqual(5, provObj.BlockSize);
                Assert.AreEqual(10, provObj.MaxNumberOfBlocks);
                Assert.IsFalse(provObj.IsReadOnly);
                Assert.AreEqual(seqPoint.AlphabetName, provObj.SequencePointerInstance.AlphabetName);
                Assert.AreEqual(26, provObj.Count);

                ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated all the properties");
                Console.WriteLine(@"FVQSP Bvt : Successfully validated all the properties");
            }
            finally
            {
                (parserObj as FastQParser).Dispose();
            }
        }
Exemplo n.º 2
0
        public void ValidateFVQSPGetScores()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            byte[] byteArrayObj = provObj.GetScores();

            Assert.AreEqual(25, byteArrayObj.Length);

            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the GetScores() method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the GetScores() method");
        }
Exemplo n.º 3
0
        public void ValidateFVQSPClear()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            // Clear
            provObj.Clear();

            Assert.AreEqual(0, provObj.Count);
            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the Clear() method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the Clear() method");
        }
Exemplo n.º 4
0
        public void ValidateFVQSPAdd()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "AGGCT");

            provObj.Add(seqObj[0]);

            Assert.AreEqual(seqObj[0].Name, provObj.GetISequenceItem(provObj.Count - 1).Name);
            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the Add() method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the Add() method");
        }
Exemplo n.º 5
0
        public void ValidateFVQSPInsertSeqItem()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "A");

            provObj.Insert(0, seqObj[0]);
            Assert.AreEqual((byte)seqObj[0].Symbol, provObj[0]);

            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the Insert(int, seqItem) method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the Insert(int, seqItem) method");
        }
Exemplo n.º 6
0
        public void ValidateFVQSPVirtualSeqParserSeqPointerConstructor()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            SequencePointer seqPointerObj = GetSequencePointer();

            Assert.AreEqual(26, provObj.Count);
            Assert.AreEqual(seqPointerObj.Id, provObj.SequencePointerInstance.Id);

            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the constructor 
                FileVirtualQualitativeSequenceProvider(IVirtualSequenceParser, SequencePointer)");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the constructor 
                FileVirtualQualitativeSequenceProvider(IVirtualSequenceParser, SequencePointer)");
        }
Exemplo n.º 7
0
        public void ValidateFVQSPContains()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "AGGCT");

            provObj.Add(seqObj[0]);
            provObj.Add(seqObj[1]);
            Assert.IsTrue(provObj.Contains(seqObj[0]));

            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the Contains() method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the Contains() method");
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the VirtualSequenceProvider
        /// </summary>
        /// <returns>Virtual Sequence Provider</returns>
        static FileVirtualQualitativeSequenceProvider GetVirtualSequenceProvider()
        {
            string filePath = Utility._xmlUtil.GetTextValue(
                Constants.SingleSequenceSangerFastQNode, Constants.FilePathNode);

            FastQParser parserObj = new FastQParser();

            parserObj.Parse(filePath);

            FileVirtualQualitativeSequenceProvider provObj =
                new FileVirtualQualitativeSequenceProvider(parserObj,
                                                           GetSequencePointer());

            return(provObj);
        }
Exemplo n.º 9
0
        public void ValidateFVQSPCopyToByteArray()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "AGGCT");

            provObj.Add(seqObj[0]);
            byte[] byteArray = new byte[provObj.Count];
            provObj.CopyTo(byteArray, 0);

            Assert.AreEqual("A", seqObj[0].Symbol.ToString());

            ApplicationLog.WriteLine("FVQSP Bvt : Successfully validated the CopyTo() method");
            Console.WriteLine("FVQSP Bvt : Successfully validated the CopyTo() method");
        }
Exemplo n.º 10
0
        public void ValidateFVQSPRemove()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "AGGCT");

            provObj.Add(seqObj[0]);
            provObj.Add(seqObj[1]);
            provObj.Add(seqObj[2]);
            provObj.Remove(provObj[1]);

            Assert.AreEqual((byte)seqObj[2].Symbol, provObj[2]);

            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the Remove() method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the Remove() method");
        }
Exemplo n.º 11
0
        public void ValidateFVQSPReplaceRange()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "AGGC");

            provObj.Add(seqObj[0]);
            provObj.Add(seqObj[1]);
            provObj.ReplaceRange(provObj.Count - 2, "GC");

            Assert.AreEqual(seqObj[2].Name, provObj[provObj.Count - 2].Name);
            Assert.AreEqual(seqObj[3].Name, provObj[provObj.Count - 1].Name);

            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the ReplaceRange() method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the ReplaceRange() method");
        }
Exemplo n.º 12
0
        public void ValidateFVQSPInsertRange()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "AGGCT");

            provObj.InsertRange(0, "AGGCT");

            Assert.AreEqual(seqObj[0], provObj[0]);
            Assert.AreEqual(seqObj[1], provObj[1]);
            Assert.AreEqual(seqObj[2], provObj[2]);
            Assert.AreEqual(seqObj[3], provObj[3]);
            Assert.AreEqual(seqObj[4], provObj[4]);

            ApplicationLog.WriteLine(@"FVQSP Bvt : Successfully validated the InsertRange() method");
            Console.WriteLine(@"FVQSP Bvt : Successfully validated the InsertRange() method");
        }
Exemplo n.º 13
0
        public void ValidateFVQSPReplaceSeqItem()
        {
            FileVirtualQualitativeSequenceProvider provObj =
                GetVirtualSequenceProvider();

            IQualitativeSequence seqObj =
                new QualitativeSequence(Alphabets.DNA, FastQFormatType.Illumina, "AGGCT");

            provObj.Add(seqObj[0]);
            provObj.Add(seqObj[1]);
            provObj.Add(seqObj[2]);
            provObj.Add(seqObj[3]);
            provObj.Replace(0, seqObj[3]);

            Assert.AreEqual(seqObj[3], provObj.GetISequenceItem(0));

            ApplicationLog.WriteLine(
                "FVQSP Bvt : Successfully validated the Replace(int, seqItem) method");
            Console.WriteLine(
                "FVQSP Bvt : Successfully validated the Replace(int, seqItem) method");
        }
Exemplo n.º 14
0
        /// <summary>
        /// Parses a single FASTQ text from a reader into a QualitativeSequence.
        /// </summary>
        /// <param name="mbfReader">A reader for a biological sequence text.</param>
        /// <param name="isReadOnly">
        /// Flag to indicate whether the resulting QualitativeSequence should be in readonly mode or not.
        /// If this flag is set to true then the resulting QualitativeSequence's isReadOnly property
        /// will be set to true, otherwise it will be set to false.
        /// </param>
        /// <returns>A new QualitativeSequence instance containing parsed data.</returns>
        private IQualitativeSequence ParseOneWithFastQFormat(MBFStreamReader mbfReader, bool isReadOnly)
        {
            SequencePointer sequencePointer = new SequencePointer();

            string message;

            // Check for '@' symbol at the first line.
            if (!mbfReader.HasLines || !mbfReader.Line.StartsWith("@", StringComparison.Ordinal))
            {
                message = string.Format(CultureInfo.CurrentCulture, Resource.INVALID_INPUT_FILE, Name);
                Trace.Report(message);
                throw new FileFormatException(message);
            }

            // Process header line.
            string id = mbfReader.GetLineField(2).Trim();

            // save sequence starting index
            sequencePointer.IndexOffsets[0] = mbfReader.Position;

            // Go to second line.
            mbfReader.GoToNextLine();
            if (!mbfReader.HasLines || string.IsNullOrEmpty(mbfReader.Line))
            {
                string message1 = string.Format(CultureInfo.CurrentCulture, Resource.FastQ_InvalidSequenceLine, id);
                message = string.Format(CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name, message1);
                Trace.Report(message);
                throw new FileFormatException(message);
            }

            // Get sequence from second line.
            string sequenceLine = mbfReader.Line;

            //save sequence ending index
            sequencePointer.IndexOffsets[1] = sequencePointer.IndexOffsets[0] + mbfReader.Line.Length;

            // Goto third line.
            mbfReader.GoToNextLine();

            // Check for '+' symbol in the third line.
            if (!mbfReader.HasLines || !mbfReader.Line.StartsWith("+", StringComparison.Ordinal))
            {
                string message1 = string.Format(CultureInfo.CurrentCulture, Resource.FastQ_InvalidQualityScoreHeaderLine, id);
                message = string.Format(CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name, message1);
                Trace.Report(message);
                throw new FileFormatException(message);
            }

            string qualScoreId = mbfReader.GetLineField(2).Trim();

            if (!string.IsNullOrEmpty(qualScoreId) && !id.Equals(qualScoreId))
            {
                string message1 = string.Format(CultureInfo.CurrentCulture, Resource.FastQ_InvalidQualityScoreHeaderData, id);
                message = string.Format(CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name, message1);
                Trace.Report(message);
                throw new FileFormatException(message);
            }

            // Goto fourth line.
            mbfReader.GoToNextLine();
            if (!mbfReader.HasLines || string.IsNullOrEmpty(mbfReader.Line))
            {
                string message1 = string.Format(CultureInfo.CurrentCulture, Resource.FastQ_EmptyQualityScoreLine, id);
                message = string.Format(CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name, message1);
                Trace.Report(message);
                throw new FileFormatException(message);
            }

            // Get the quality scores from the fourth line.
            byte[] qualScores = ASCIIEncoding.ASCII.GetBytes(mbfReader.Line);

            // Check for sequence length and quality score length.
            if (sequenceLine.Length != mbfReader.Line.Length)
            {
                string message1 = string.Format(CultureInfo.CurrentCulture, Resource.FastQ_InvalidQualityScoresLength, id);
                message = string.Format(CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name, message1);
                Trace.Report(message);
                throw new FileFormatException(message);
            }

            mbfReader.GoToNextLine();

            IAlphabet alphabet = Alphabet;

            // Identify alphabet if it is not specified.
            if (alphabet == null)
            {
                alphabet = _commonSequenceParser.IdentifyAlphabet(alphabet, sequenceLine);

                if (alphabet == null)
                {
                    string message1 = string.Format(CultureInfo.CurrentCulture, Resource.InvalidSymbolInString, sequenceLine);
                    message = string.Format(CultureInfo.CurrentCulture, Resource.IOFormatErrorMessage, Name, message1);
                    Trace.Report(message);
                    throw new FileFormatException(message);
                }
            }

            FastQFormatType fastQType = FastqType;

            // Identify fastq format type if AutoDetectFastQFormat property is set to true.
            if (AutoDetectFastQFormat)
            {
                fastQType = IdentifyFastQFormatType(qualScores);
            }

            QualitativeSequence sequence = null;

            if (Encoding == null)
            {
                sequence = new QualitativeSequence(alphabet, fastQType, sequenceLine, qualScores);
            }
            else
            {
                sequence = new QualitativeSequence(alphabet, fastQType, Encoding, sequenceLine, qualScores);
            }

            sequence.ID         = id;
            sequence.IsReadOnly = isReadOnly;

            sequencePointer.AlphabetName = sequence.Alphabet.Name;
            sequencePointer.Id           = sequence.ID;
            _sequencePointers.Add(sequencePointer);

            FileVirtualQualitativeSequenceProvider dataProvider = new FileVirtualQualitativeSequenceProvider(this, sequencePointer)
            {
                BlockSize         = _blockSize,
                MaxNumberOfBlocks = _maxNumberOfBlocks
            };

            sequence.VirtualQualitativeSequenceProvider = dataProvider;
            return(sequence);
        }