/// <summary>
        ///     Validate BED Operations(Merge,Intersect)..
        /// </summary>
        /// <param name="nodeName">Xml Node name for different inputs.</param>
        /// <param name="operationPam">Different Bed operations.</param>
        /// <param name="overlappingBasePair">overlapping base pair</param>
        /// <param name="isParentSeqRangeRequired">Is Parent Sequence Range required?</param>
        private void ValidateBedOperations(string nodeName,
                                           BedOperationsParameters operationPam,
                                           bool overlappingBasePair, bool isParentSeqRangeRequired)
        {
            // Get values from xml.
            string expectedRangeIDs   = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.IDNode);
            string expectedStartIndex = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.StartNode);
            string expectedEndIndex   = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EndNode);
            string referenceFilePath  = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir();
            string queryFilePath      = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.QueryFilePath).TestDir();
            string minimalOverlap     = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.OverlapValue);

            SequenceRangeGrouping operationResult = null;

            // Parse a BED file.
            var parserObj = new BedParser();
            SequenceRangeGrouping referenceGroup = parserObj.ParseRangeGrouping(referenceFilePath);
            SequenceRangeGrouping queryGroup     = parserObj.ParseRangeGrouping(queryFilePath);

            var intersectOutputType = IntersectOutputType.OverlappingIntervals;

            if (overlappingBasePair)
            {
                intersectOutputType = IntersectOutputType.OverlappingPiecesOfIntervals;
            }

            var subtractOutputType = SubtractOutputType.NonOverlappingPiecesOfIntervals;

            if (overlappingBasePair)
            {
                subtractOutputType = SubtractOutputType.IntervalsWithNoOverlap;
            }

            switch (operationPam)
            {
            case BedOperationsParameters.Merge:
                operationResult = referenceGroup.MergeOverlaps();
                break;

            case BedOperationsParameters.MergeWithPam:
                operationResult = referenceGroup.MergeOverlaps(queryGroup,
                                                               0, isParentSeqRangeRequired);
                break;

            case BedOperationsParameters.Intersect:

                operationResult = referenceGroup.Intersect(queryGroup,
                                                           long.Parse(minimalOverlap, null), intersectOutputType,
                                                           isParentSeqRangeRequired);
                break;

            case BedOperationsParameters.MergeQueryWithReference:
                operationResult = queryGroup.MergeOverlaps(referenceGroup,
                                                           0, isParentSeqRangeRequired);
                break;

            case BedOperationsParameters.Subtract:
                operationResult = referenceGroup.Subtract(queryGroup,
                                                          long.Parse(minimalOverlap, null), subtractOutputType,
                                                          isParentSeqRangeRequired);
                break;

            default:
                break;
            }

            // Get a result SequenceGroup Id.
            IEnumerable <string> groupId = operationResult.GroupIDs;

            string[] expectedRangeIdsArray   = expectedRangeIDs.Split(',');
            string[] expectedStartIndexArray = expectedStartIndex.Split(',');
            string[] expectedEndIndexArray   = expectedEndIndex.Split(',');
            int      i = 0;

            foreach (string grpId in groupId)
            {
                string rangeId = grpId;

                List <ISequenceRange> rangeList = operationResult.GetGroup(rangeId);

                // Validate result sequence range.
                foreach (ISequenceRange range in rangeList)
                {
                    Assert.AreEqual(expectedRangeIdsArray[i], range.ID);
                    Assert.AreEqual(expectedStartIndexArray[i], range.Start.ToString((IFormatProvider)null));
                    Assert.AreEqual(expectedEndIndexArray[i], range.End.ToString((IFormatProvider)null));
                    i++;
                }
            }

            // Validate ParentSeqRange.
            bool result = ValidateParentSeqRange(operationResult, referenceGroup, queryGroup, isParentSeqRangeRequired);

            Assert.IsTrue(result);

            ApplicationLog.WriteLine("Bed Operations BVT: Successfully validated the BED SequenceID, Start and End Ranges");
        }
Esempio n. 2
0
        public void SubtractTest()
        {
            string                refSeqRangefile   = @"testdata\BED\Subtract\Subtract_ref.BED";
            string                querySeqRangefile = @"testdata\BED\Subtract\Subtract_query.BED";
            string                resultfilepath    = "tmp_mergeresult.bed";
            BedParser             parser            = new BedParser();
            BedFormatter          formatter         = new BedFormatter();
            SequenceRangeGrouping result            = null;
            bool resultvalue = false;

            SequenceRangeGrouping refSeqRange   = parser.ParseRangeGrouping(refSeqRangefile);
            SequenceRangeGrouping querySeqRange = parser.ParseRangeGrouping(querySeqRangefile);

            string expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap1.BED";

            result = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.IntervalsWithNoOverlap);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 1, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap0.BED";
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.IntervalsWithNoOverlap);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap1.BED";
            result             = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.IntervalsWithNoOverlap, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 1, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap0.BED";
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.IntervalsWithNoOverlap, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, true);
            Assert.IsTrue(resultvalue);


            expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap1.BED";
            result             = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.IntervalsWithNoOverlap, false);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 1, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap0.BED";
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.IntervalsWithNoOverlap, false);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap0_NOnOverlappingPieces.BED";
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.NonOverlappingPiecesOfIntervals, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Subtract\Result_Subtract_minoverlap1_NOnOverlappingPieces.BED";
            result             = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.NonOverlappingPiecesOfIntervals, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 1, true);
            Assert.IsTrue(resultvalue);
        }
Esempio n. 3
0
        /// <summary>
        /// Validate Subtract SequenceRangeGrouping.
        /// </summary>
        /// <param name="nodeName">Xml Node name for different inputs.</param>
        /// <param name="overlappingBasePair">Value of overlappingBasePair</param>
        /// <param name="IsParentSeqRangesRequired">Is Parent Sequence Range required?</param>
        void SubtractSequenceRange(string nodeName,
                                   bool overlappingBasePair, bool IsParentSeqRangeRequired)
        {
            // Get values from xml.
            string[] expectedRangeIDs = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.IDNode).Split(',');
            string[] expectedStartIndex = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.StartNode).Split(',');
            string[] expectedEndIndex = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.EndNode).Split(',');
            string referenceFilePath = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string queryFilePath = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.QueryFilePath);
            string minimalOverlap = _utilityObj._xmlUtil.GetTextValue(
                nodeName, Constants.OverlapValue);
            string rangeID = string.Empty;
            bool   result  = false;

            List <ISequenceRange> rangeList = null;

            // Parse a BED file.
            BedParser             parserObj      = new BedParser();
            SequenceRangeGrouping referenceGroup = parserObj.ParseRangeGrouping(referenceFilePath);
            SequenceRangeGrouping queryGroup     = parserObj.ParseRangeGrouping(queryFilePath);

            SubtractOutputType subtractOutputType = SubtractOutputType.NonOverlappingPiecesOfIntervals;

            if (overlappingBasePair)
            {
                subtractOutputType = SubtractOutputType.IntervalsWithNoOverlap;
            }

            // Subtract a SequenceRangeGroup.
            SequenceRangeGrouping subtractGroup = referenceGroup.Subtract(queryGroup,
                                                                          long.Parse(minimalOverlap, (IFormatProvider)null), subtractOutputType, IsParentSeqRangeRequired);

            // Get a intersect SequenceGroup Id.
            IEnumerable <string> groupIds = subtractGroup.GroupIDs;

            int j = 0;

            foreach (string grpID in groupIds)
            {
                rangeID = grpID;

                rangeList = subtractGroup.GetGroup(rangeID);

                // Validate intersect sequence range.
                foreach (ISequenceRange range in rangeList)
                {
                    Assert.AreEqual(expectedStartIndex[j], range.Start.ToString((IFormatProvider)null));
                    Assert.AreEqual(expectedEndIndex[j], range.End.ToString((IFormatProvider)null));
                    Assert.AreEqual(expectedRangeIDs[j], range.ID.ToString((IFormatProvider)null));
                    j++;
                }
            }

            // Validate ParentSeqRanges.
            result = ValidateParentSeqRange(
                subtractGroup, referenceGroup, queryGroup, IsParentSeqRangeRequired);
            Assert.IsTrue(result);

            ApplicationLog.WriteLine(
                "Bed Parser BVT: Successfully validated the subtract SequeID, Start and End Ranges");
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "Bed Parser BVT: Successfully validated the subtracted SequeID, Start and End Ranges"));
        }
Esempio n. 4
0
        /// <summary>
        /// Validate BED Operations(Merge,Intersect)..
        /// </summary>
        /// <param name="nodeName">Xml Node name for different inputs.</param>
        /// <param name="operationPam">Different Bed operations.</param>
        /// <param name="overlappingBasePair">overlapping base pair</param>
        /// <param name="IsParentSeqRangeRequired">Is Parent Sequence Range required?</param>
        static void ValidateBedOperations(string nodeName,
                                          BedOperationsParameters operationPam,
                                          bool overlappingBasePair, bool IsParentSeqRangeRequired)
        {
            // Get values from xml.
            string expectedRangeIDs = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.IDNode);
            string expectedStartIndex = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.StartNode);
            string expectedEndIndex = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.EndNode);
            string referenceFilePath = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);
            string queryFilePath = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.QueryFilePath);
            string minimalOverlap = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.OverlapValue);
            string rangeID      = string.Empty;
            string actualStarts = string.Empty;
            string actualEnds   = string.Empty;
            string actualIDs    = string.Empty;
            bool   result       = false;

            List <ISequenceRange> rangeList       = null;
            SequenceRangeGrouping operationResult = null;

            // Parse a BED file.
            BedParser             parserObj      = new BedParser();
            SequenceRangeGrouping referenceGroup = parserObj.ParseRangeGrouping(referenceFilePath);
            SequenceRangeGrouping queryGroup     = parserObj.ParseRangeGrouping(queryFilePath);

            IntersectOutputType intersectOutputType = IntersectOutputType.OverlappingIntervals;

            if (overlappingBasePair)
            {
                intersectOutputType = IntersectOutputType.OverlappingPiecesOfIntervals;
            }

            SubtractOutputType subtractOutputType = SubtractOutputType.NonOverlappingPiecesOfIntervals;

            if (overlappingBasePair)
            {
                subtractOutputType = SubtractOutputType.IntervalsWithNoOverlap;
            }

            switch (operationPam)
            {
            case BedOperationsParameters.Merge:
                operationResult = referenceGroup.MergeOverlaps();
                break;

            case BedOperationsParameters.MergeWithPam:
                operationResult = referenceGroup.MergeOverlaps(queryGroup,
                                                               0, IsParentSeqRangeRequired);
                break;

            case BedOperationsParameters.Intersect:

                operationResult = referenceGroup.Intersect(queryGroup,
                                                           long.Parse(minimalOverlap), intersectOutputType, IsParentSeqRangeRequired);
                break;

            case BedOperationsParameters.MergeQueryWithReference:
                operationResult = queryGroup.MergeOverlaps(referenceGroup,
                                                           0, IsParentSeqRangeRequired);
                break;

            case BedOperationsParameters.Subtract:
                operationResult = referenceGroup.Subtract(queryGroup,
                                                          long.Parse(minimalOverlap), subtractOutputType, IsParentSeqRangeRequired);
                break;

            default:
                break;
            }

            // Get a result SequenceGroup Id.
            IEnumerable <string> groupId = operationResult.GroupIDs;

            foreach (string grpID in groupId)
            {
                rangeID = grpID;

                rangeList = operationResult.GetGroup(rangeID);

                // Validate result sequence range.
                foreach (ISequenceRange range in rangeList)
                {
                    actualStarts = string.Concat(actualStarts, range.Start.ToString(), ",");
                    actualEnds   = string.Concat(actualEnds, range.End.ToString(), ",");
                    actualIDs    = string.Concat(actualIDs, range.ID.ToString(), ",");
                }
            }

            Assert.AreEqual(expectedRangeIDs, actualIDs.Substring(0, actualIDs.Length - 1));
            Assert.AreEqual(expectedStartIndex, actualStarts.Substring(0, actualStarts.Length - 1));
            Assert.AreEqual(expectedEndIndex, actualEnds.Substring(0, actualEnds.Length - 1));

            // Validate ParentSeqRange.
            result = ValidateParentSeqRange(operationResult, referenceGroup,
                                            queryGroup, IsParentSeqRangeRequired);
            Assert.IsTrue(result);

            ApplicationLog.WriteLine(
                "Bed Parser BVT: Successfully validated the BED SequenceID, Start and End Ranges");
        }
Esempio n. 5
0
        public void SubtractTest()
        {
            var                   direc             = System.IO.Path.Combine("TestUtils", "BED", "Subtract");
            string                refSeqRangefile   = System.IO.Path.Combine(direc, "Subtract_ref.BED").TestDir();
            string                querySeqRangefile = System.IO.Path.Combine(direc, "Subtract_query.BED").TestDir();
            string                resultfilepath    = "tmp_mergeresult.bed";
            BedParser             parser            = new BedParser();
            BedFormatter          formatter         = new BedFormatter();
            SequenceRangeGrouping result            = null;
            bool                  resultvalue       = false;

            SequenceRangeGrouping refSeqRange   = parser.ParseRangeGrouping(refSeqRangefile);
            SequenceRangeGrouping querySeqRange = parser.ParseRangeGrouping(querySeqRangefile);

            const string MinOverlap1        = "Result_Subtract_minoverlap1.bed";
            string       expectedresultpath = System.IO.Path.Combine(direc, MinOverlap1).TestDir();

            result = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.IntervalsWithNoOverlap);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, true);
            Assert.IsTrue(resultvalue);

            const string MinOverlap0 = "Result_subtract_minoverlap0.bed";

            expectedresultpath = System.IO.Path.Combine(direc, MinOverlap0).TestDir();
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.IntervalsWithNoOverlap);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = System.IO.Path.Combine(direc, MinOverlap1).TestDir();
            result             = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.IntervalsWithNoOverlap, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = System.IO.Path.Combine(direc, MinOverlap0).TestDir();
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.IntervalsWithNoOverlap, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, true);
            Assert.IsTrue(resultvalue);


            expectedresultpath = System.IO.Path.Combine(direc, MinOverlap1).TestDir();
            result             = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.IntervalsWithNoOverlap, false);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = System.IO.Path.Combine(direc, MinOverlap0).TestDir();
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.IntervalsWithNoOverlap, false);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, false);
            Assert.IsTrue(resultvalue);

            const string MinNoOverlap0 = "Result_Subtract_minoverlap0_NOnOverlappingPieces.BED";

            expectedresultpath = System.IO.Path.Combine(direc, MinNoOverlap0).TestDir();
            result             = refSeqRange.Subtract(querySeqRange, 0, SubtractOutputType.NonOverlappingPiecesOfIntervals, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, true);
            Assert.IsTrue(resultvalue);

            const string MinNoOverlap1 = "Result_Subtract_minoverlap1_NOnOverlappingPieces.BED";

            expectedresultpath = System.IO.Path.Combine(direc, MinNoOverlap1).TestDir();
            result             = refSeqRange.Subtract(querySeqRange, 1, SubtractOutputType.NonOverlappingPiecesOfIntervals, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, true);
            Assert.IsTrue(resultvalue);
        }