Ejemplo n.º 1
0
        /// <summary>
        /// Create a SequenceRangeGrouping by passing RangeID,Start and End Index.
        /// and validate created SequenceRange.
        /// </summary>
        /// <param name="nodeName">Xml Node name for different inputs.</param>
        static void CreateSequenceRangeGrouping(string nodeName)
        {
            // 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 expectedSequenceRangeCount = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.SequenceRangeCountNode);
            string actualRangeStarts = string.Empty;
            string actualRangeEnds   = string.Empty;
            string actualRangeIDs    = string.Empty;

            string[] rangeIDs    = expectedRangeIDs.Split(',');
            string[] rangeStarts = expectedStartIndex.Split(',');
            string[] rangeEnds   = expectedEndIndex.Split(',');
            SequenceRangeGrouping seqRangeGrouping = new SequenceRangeGrouping();
            List <ISequenceRange> rangeList        = null;

            // Create a SequenceRange and add to SequenceRangeList.
            for (int i = 0; i < rangeIDs.Length; i++)
            {
                SequenceRange seqRange = new SequenceRange(rangeIDs[i],
                                                           long.Parse(rangeStarts[i]), long.Parse(rangeEnds[i]));

                seqRangeGrouping.Add(seqRange);
            }

            IEnumerable <string> rangeGroupIds = seqRangeGrouping.GroupIDs;
            string rangeID = string.Empty;

            foreach (string groupID in rangeGroupIds)
            {
                rangeID = groupID;

                // Get SequenceRangeIds.
                rangeList = seqRangeGrouping.GetGroup(rangeID);

                // Validate created SequenceRanges.
                foreach (ISequenceRange seqRange in rangeList)
                {
                    actualRangeIDs    = string.Concat(actualRangeIDs, seqRange.ID.ToString(), ",");
                    actualRangeStarts = string.Concat(actualRangeStarts, seqRange.Start.ToString(), ",");
                    actualRangeEnds   = string.Concat(actualRangeEnds, seqRange.End.ToString(), ",");
                }
            }
            Assert.AreEqual(expectedSequenceRangeCount, rangeList.Count.ToString());
            Assert.AreEqual(expectedRangeIDs,
                            actualRangeIDs.Substring(0, actualRangeIDs.Length - 1));
            Assert.AreEqual(expectedStartIndex,
                            actualRangeStarts.Substring(0,
                                                        actualRangeStarts.Length - 1));
            Assert.AreEqual(expectedEndIndex,
                            actualRangeEnds.Substring(0, actualRangeEnds.Length - 1));
            Console.WriteLine(
                "SequenceRange BVT : Successfully validated the SequenceStart, SequenceID and SequenceEnd.");
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the GroupData class
 /// </summary>
 /// <param name="group">SequenceRangeGroup object</param>
 /// <param name="name">Name of SequenceRangeGroup</param>
 /// <param name="metadata">Metadata for SequenceRangeGroup</param>
 public GroupData(
     SequenceRangeGrouping group,
     string name,
     Dictionary <string, Dictionary <ISequenceRange, string> > metadata)
 {
     Group     = group;
     Name      = name;
     _metadata = metadata;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes out a grouping of ISequenceRange objects to a specified
        /// file location.
        /// </summary>
        /// <param name="rangeGroup">The range grouping to be formatted.</param>
        /// <param name="fileName">The file where the formatted data is to be written.</param>
        public void Format(SequenceRangeGrouping rangeGroup, string fileName)
        {
            if (rangeGroup == null)
            {
                throw new ArgumentNullException("rangeGroup");
            }

            Format(rangeGroup.Flatten(), fileName);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Parse a set of ISequenceRange objects into a SequenceRange
        ///     grouping from a stream.
        /// </summary>
        /// <param name="stream">The stream from which the sequence range is to be parsed.</param>
        /// <returns>The sequence range groups.</returns>
        public SequenceRangeGrouping ParseRangeGrouping(Stream stream)
        {
            var result = new SequenceRangeGrouping(this.ParseRange(stream));

            if (null == result.GroupIDs || !result.GroupIDs.Any())
            {
                string message = string.Format(CultureInfo.CurrentCulture, Resource.INVALID_INPUT_FILE, this.Name);
                throw new InvalidDataException(message);
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Parse a set of ISequenceRange objects into a SequenceRange
        /// grouping from a reader.
        /// </summary>
        /// <param name="reader">The reader from which the sequence range is to be parsed.</param>
        /// <returns>The sequence range groups.</returns>
        public SequenceRangeGrouping ParseRangeGrouping(TextReader reader)
        {
            SequenceRangeGrouping result = new SequenceRangeGrouping(ParseRange(reader));

            if (null == result.GroupIDs || !result.GroupIDs.Any())
            {
                string message = string.Format(CultureInfo.CurrentCulture, Properties.Resource.INVALID_INPUT_FILE, this.Name);
                throw new InvalidDataException(message);
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Writes out a grouping of ISequenceRange objects to a specified
        ///     stream.
        /// </summary>
        /// <param name="stream">The stream where the formatted data is to be written, it will be closed at the end.</param>
        /// <param name="rangeGroup">The range grouping to be formatted.</param>
        public void Format(Stream stream, SequenceRangeGrouping rangeGroup)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (rangeGroup == null)
            {
                throw new ArgumentNullException("rangeGroup");
            }

            this.Format(stream, rangeGroup.Flatten());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Writes out a grouping of ISequenceRange objects to a specified
        /// text writer.
        /// </summary>
        /// <param name="rangeGroup">The range grouping to be formatted.</param>
        /// <param name="writer">The writer stream where the formatted data is to be written.</param>
        public void Format(SequenceRangeGrouping rangeGroup, TextWriter writer)
        {
            if (rangeGroup == null)
            {
                throw new ArgumentNullException("rangeGroup");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            Format(rangeGroup.Flatten(), writer);
        }
Ejemplo n.º 8
0
        // default printing of SequenceRangeGrouping
        //
        public static void SequenceRangeGroupingToString(SequenceRangeGrouping srg, string name)
        {
            Console.Error.Write("[{0}] : SeqeuenceRangeGrouping: ", name);
            var srgm = new SequenceRangeGroupingMetrics(srg);

            Console.Error.WriteLine("{0}, {1}, {2}", srgm.groups, srgm.ranges, srgm.bases);

            foreach (string id in srg.GroupIDs)
            {
                Console.Error.WriteLine("--GroupID: {0}, {1}", id, srg.GetGroup(id).Count());
                ListSequenceRangeToString(srg.GetGroup(id));
            }
            Console.Error.WriteLine();
        }
Ejemplo n.º 9
0
        public void TestSequenceRangeGroupingToString()
        {
            ISequenceRange         range1 = new SequenceRange("chr20", 0, 3);
            ISequenceRange         range2 = new SequenceRange("chr21", 0, 4);
            IList <ISequenceRange> ranges = new List <ISequenceRange>();

            ranges.Add(range1);
            ranges.Add(range2);

            SequenceRangeGrouping rangegrouping = new SequenceRangeGrouping(ranges);
            string actualString = rangegrouping.ToString();

            string expectedString = "ID=chr20 Start=0 End=3\r\nID=chr21 Start=0 End=4\r\n".Replace("\r\n", Environment.NewLine);

            Assert.AreEqual(actualString, expectedString);
        }
Ejemplo n.º 10
0
        public void ValidateSequenceRangeGroupingToString()
        {
            ISequenceRange         range1 = new SequenceRange("chr20", 0, 3);
            ISequenceRange         range2 = new SequenceRange("chr21", 0, 4);
            IList <ISequenceRange> ranges = new List <ISequenceRange>();

            ranges.Add(range1);
            ranges.Add(range2);

            var    rangegrouping = new SequenceRangeGrouping(ranges);
            string actualString  = rangegrouping.ToString();
            string expectedStr   = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                        Constants.SequenceRangeGroupingExpectedNode);

            Assert.AreEqual(expectedStr.Replace("\\r\\n", ""), actualString.Replace(System.Environment.NewLine, ""));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Validate Parent Sequence ranges in result sequence range.
        /// </summary>
        /// <param name="resultSeq">Result seq range group.</param>
        /// <param name="refSeqRange">Reference seq range group.</param>
        /// <param name="querySeqRange">Query seq range group.</param>
        /// <param name="minOverlap">Minimum overlap.</param>
        /// <param name="isParentSeqRangeRequired">Flag to indicate whether
        /// result should contain parent seq ranges or not.</param>
        /// <returns>Returns true if the parent seq ranges are valid; otherwise returns false.</returns>
        private static bool ValidateParentSeqRange(SequenceRangeGrouping resultSeq,
                                                   SequenceRangeGrouping refSeq,
                                                   SequenceRangeGrouping querySeq,
                                                   bool IsParentSeqRangeRequired)
        {
            IList <ISequenceRange> refSeqRangeList   = new List <ISequenceRange>();
            IList <ISequenceRange> querySeqRangeList = new List <ISequenceRange>();

            IEnumerable <string> groupIds = resultSeq.GroupIDs;

            foreach (string groupId in groupIds)
            {
                if (null != refSeq)
                {
                    refSeqRangeList = refSeq.GetGroup(groupId);
                }

                if (null != querySeq)
                {
                    querySeqRangeList = querySeq.GetGroup(groupId);
                }

                foreach (ISequenceRange resultRange in resultSeq.GetGroup(groupId))
                {
                    if (!IsParentSeqRangeRequired)
                    {
                        if (0 != resultRange.ParentSeqRanges.Count)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        int refSeqRangeCount   = refSeqRangeList.Where(S => resultRange.ParentSeqRanges.Contains(S)).Count();
                        int querySeqRangeCount = querySeqRangeList.Where(S => resultRange.ParentSeqRanges.Contains(S)).Count();


                        if (resultRange.ParentSeqRanges.Count != refSeqRangeCount + querySeqRangeCount)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 12
0
        public void ComputeSequenceRangeGroupingMetrics(SequenceRangeGrouping srg)
        {
            cGroups = 0L;
            cRanges = 0L;
            cBases  = 0L;

            foreach (string id in srg.GroupIDs)
            {
                ++cGroups;
                cRanges += srg.GetGroup(id).Count;
                foreach (SequenceRange sr in srg.GetGroup(id))
                {
                    cBases += sr.Length;
                }
            }
            return;
        }
Ejemplo n.º 13
0
        public void ValidateFlatten()
        {
            // Get values from xml.
            string expectedRangeIDs = utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.IDNode);
            string expectedStartIndex = utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.StartNode);
            string expectedEndIndex = utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.EndNode);
            string expectedSequenceRangeCount = utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.SequenceRangeCountNode);

            string[] rangeIDs    = expectedRangeIDs.Split(',');
            string[] rangeStarts = expectedStartIndex.Split(',');
            string[] rangeEnds   = expectedEndIndex.Split(',');
            SequenceRangeGrouping seqRangeGrouping = new SequenceRangeGrouping();
            List <ISequenceRange> rangeList        = null;

            // Create a SequenceRange and add to SequenceRangeList.
            for (int i = 0; i < rangeIDs.Length; i++)
            {
                SequenceRange seqRange = new SequenceRange(rangeIDs[i],
                                                           long.Parse(rangeStarts[i], (IFormatProvider)null),
                                                           long.Parse(rangeEnds[i], (IFormatProvider)null));

                seqRangeGrouping.Add(seqRange);
            }

            //Convert SequenceRangeGroup to SequenceRangeList.
            rangeList = seqRangeGrouping.Flatten();

            int j = 0;

            // Validate created SequenceRanges.
            foreach (ISequenceRange seqRange in rangeList)
            {
                Assert.AreEqual(rangeStarts[j], seqRange.Start.ToString((IFormatProvider)null));
                Assert.AreEqual(rangeEnds[j], seqRange.End.ToString((IFormatProvider)null));
                Assert.AreEqual(rangeIDs[j], seqRange.ID.ToString((IFormatProvider)null));
                j++;
            }

            Assert.AreEqual(expectedSequenceRangeCount, rangeList.Count.ToString((IFormatProvider)null));
            Console.WriteLine(
                "SequenceRange BVT : Successfully validated the SequenceStart,SequenceID and SequenceEnd.");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Method to validate parent seq ranges in result.
        /// </summary>
        /// <param name="resultSeqRange">Result seq range group.</param>
        /// <param name="refSeqRange">Reference seq range group.</param>
        /// <param name="querySeqRange">Query seq range group.</param>
        /// <param name="isParentSeqRangeRequired">Flag to indicate whether result should contain parent seq ranges or not.</param>
        /// <returns>Returns true if the parent seq ranges are valid; otherwise returns false.</returns>
        private static bool ValidateParentSeqRange(SequenceRangeGrouping resultSeqRange, SequenceRangeGrouping refSeqRange,
                                                   SequenceRangeGrouping querySeqRange, bool isParentSeqRangeRequired)
        {
            IList <ISequenceRange> refSeqRangeList   = new List <ISequenceRange>();
            IList <ISequenceRange> querySeqRangeList = new List <ISequenceRange>();

            foreach (string groupid in resultSeqRange.GroupIDs)
            {
                if (refSeqRange != null)
                {
                    refSeqRangeList = refSeqRange.GetGroup(groupid);
                }

                if (querySeqRange != null)
                {
                    querySeqRangeList = querySeqRange.GetGroup(groupid);
                }


                foreach (ISequenceRange resultRange in resultSeqRange.GetGroup(groupid))
                {
                    if (!isParentSeqRangeRequired)
                    {
                        if (resultRange.ParentSeqRanges.Count != 0)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        int refCount   = refSeqRangeList.Where(R => resultRange.ParentSeqRanges.Contains(R)).Count();
                        int queryCount = querySeqRangeList.Where(R => resultRange.ParentSeqRanges.Contains(R)).Count();


                        if (refCount + queryCount != resultRange.ParentSeqRanges.Count)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 15
0
        //
        // Read a Bed file into memory
        //
        public static SequenceRangeGrouping ReadBedFile(string filename)
        {
            var parser = new BedParser();
            IList <ISequenceRange> listSequenceRange = parser.ParseRange(filename);

            if (verbose)
            {
                //listSequenceRange.ToString();
                Console.Error.WriteLine("Processed File: {0}", filename);
                ListSequenceRangeToString(listSequenceRange);
            }

            var srg = new SequenceRangeGrouping(listSequenceRange);

            if (arguments.normalizeInputs)
            {
                srg.MergeOverlaps(); // could be called Normalize() or Cannonicalize()
            }
            return(srg);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Tests chromoses with orphan regions
        /// </summary>
        /// <param name="alignmentMapobj">Sequence alignment map.</param>
        private static void TestOrphanRegions(SequenceAlignmentMap alignmentMapobj)
        {
            string expectedOutput;
            string actualOutput;

            expectedOutput = "9437-9447:";
            actualOutput   = string.Empty;

            // get reads from sequence alignment map object.
            IList <PairedRead> pairedReads = null;

            pairedReads = alignmentMapobj.GetPairedReads(0, 0);

            // Get the orphan regions.
            var orphans = pairedReads.Where(PR => PR.PairedType == PairedReadType.Orphan);

            if (orphans.Count() == 0)
            {
                Assert.Fail();
            }

            List <ISequenceRange> orphanRegions = new List <ISequenceRange>(orphans.Count());

            foreach (PairedRead orphanRead in orphans)
            {
                orphanRegions.Add(GetRegion(orphanRead.Read1));
            }

            // Get sequence range grouping object.
            SequenceRangeGrouping rangeGroup = new SequenceRangeGrouping(orphanRegions);

            SequenceRangeGrouping mergedRegions = rangeGroup.MergeOverlaps();

            foreach (var range in mergedRegions.GroupRanges)
            {
                actualOutput += range.Start + "-" + range.End + ":";
            }

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Display Sequence range grops
        /// </summary>
        /// <param name="seqRangeGrops">Sequence Ranges grops</param>
        private static void DisplaySequenceRange(SequenceRangeGrouping seqRangeGrop)
        {
            IEnumerable <string> rangeGroupIds = seqRangeGrop.GroupIDs;
            string rangeID = string.Empty;

            // Display Sequence Ranges
            Console.Write("\r\nChromosome\t\tStart\tEnd");

            foreach (string groupID in rangeGroupIds)
            {
                rangeID = groupID;

                // Get SequenceRangeIds.
                List <ISequenceRange> rangeList = seqRangeGrop.GetGroup(rangeID);

                foreach (ISequenceRange seqRange in rangeList)
                {
                    Console.Write("\n{0}\t\t\t{1}\t{2}", seqRange.ID.ToString(),
                                  seqRange.Start.ToString(), seqRange.End.ToString());
                }
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 ///     Parse a set of ISequenceRange objects into a SequenceRange
 ///     grouping from a stream.
 /// </summary>
 /// <param name="stream">The stream from which the sequence range is to be parsed.</param>
 /// <returns>The sequence range groups.</returns>
 public SequenceRangeGrouping ParseRangeGrouping(Stream stream)
 {
     var result = new SequenceRangeGrouping(this.ParseRange(stream));
     if (null == result.GroupIDs || !result.GroupIDs.Any())
     {
         string message = string.Format(CultureInfo.CurrentCulture, Resource.INVALID_INPUT_FILE, this.Name);
         throw new InvalidDataException(message);
     }
     return result;
 }
Ejemplo n.º 19
0
        //
        // print
        public static long SequenceRangeGroupingCBases(SequenceRangeGrouping srg)
        {
            var srgm = new SequenceRangeGroupingMetrics(srg);

            return(srgm.bases);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Formats the Range/RangeGroup for different test cases based
        /// on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        void FormatterGeneralTestCases(string nodeName,
                                       AdditionalParameters addParam)
        {
            IList <ISequenceRange> rangeList  = new List <ISequenceRange>();
            SequenceRangeGrouping  rangeGroup = new SequenceRangeGrouping();

            // Gets the file name.
            string filePath = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);

            // Condition to check if Parse() happens before Format()
            switch (addParam)
            {
            case AdditionalParameters.ParseRangeGroup:
            case AdditionalParameters.ParseRangeGroupTextWriter:
                BedParser initialParserGroupObj = new BedParser();
                rangeGroup =
                    initialParserGroupObj.ParseRangeGrouping(filePath);
                break;

            case AdditionalParameters.ParseRange:
            case AdditionalParameters.ParseRangeTextWriter:
                BedParser initialParserObj = new BedParser();
                rangeList = initialParserObj.ParseRange(filePath);
                break;

            default:
                // Gets all the expected values from xml.
                string expectedID = utilityObj.xmlUtil.GetTextValue(
                    nodeName, Constants.IDNode);
                string expectedStart = utilityObj.xmlUtil.GetTextValue(
                    nodeName, Constants.StartNode);
                string expectedEnd = utilityObj.xmlUtil.GetTextValue(
                    nodeName, Constants.EndNode);

                string[] expectedIDs    = expectedID.Split(',');
                string[] expectedStarts = expectedStart.Split(',');
                string[] expectedEnds   = expectedEnd.Split(',');

                // Gets the Range Group or Range based on the additional parameter
                switch (addParam)
                {
                case AdditionalParameters.RangeGroupTextWriter:
                case AdditionalParameters.RangeGroupFileName:
                    for (int i = 0; i < expectedIDs.Length; i++)
                    {
                        SequenceRange rangeObj1 =
                            new SequenceRange(expectedIDs[i],
                                              long.Parse(expectedStarts[i], (IFormatProvider)null),
                                              long.Parse(expectedEnds[i], (IFormatProvider)null));
                        rangeGroup.Add(rangeObj1);
                    }
                    break;

                default:
                    for (int i = 0; i < expectedIDs.Length; i++)
                    {
                        SequenceRange rangeObj2 =
                            new SequenceRange(expectedIDs[i],
                                              long.Parse(expectedStarts[i], (IFormatProvider)null),
                                              long.Parse(expectedEnds[i], (IFormatProvider)null));
                        rangeList.Add(rangeObj2);
                    }
                    break;
                }
                break;
            }

            BedFormatter formatterObj = new BedFormatter();

            // Gets the Range list/Range Group based on the parameters.
            switch (addParam)
            {
            case AdditionalParameters.RangeFileName:
            case AdditionalParameters.ParseRange:
                formatterObj.Format(rangeList, Constants.BedTempFileName);
                break;

            case AdditionalParameters.RangeTextWriter:
            case AdditionalParameters.ParseRangeTextWriter:
                using (TextWriter txtWriter =
                           new StreamWriter(Constants.BedTempFileName))
                {
                    formatterObj.Format(rangeList, txtWriter);
                }
                break;

            case AdditionalParameters.RangeGroupFileName:
            case AdditionalParameters.ParseRangeGroup:
                formatterObj.Format(rangeGroup, Constants.BedTempFileName);
                break;

            case AdditionalParameters.RangeGroupTextWriter:
            case AdditionalParameters.ParseRangeGroupTextWriter:
                using (TextWriter txtWriter =
                           new StreamWriter(Constants.BedTempFileName))
                {
                    formatterObj.Format(rangeGroup, txtWriter);
                }
                break;

            default:
                break;
            }

            // Reparse to validate the results
            BedParser parserObj = new BedParser();
            IList <ISequenceRange> newRangeList =
                parserObj.ParseRange(Constants.BedTempFileName);

            // Validation of all the properties.
            for (int i = 0; i < rangeList.Count; i++)
            {
                Assert.AreEqual(rangeList[0].ID, newRangeList[0].ID);
                Assert.AreEqual(rangeList[0].Start, newRangeList[0].Start);
                Assert.AreEqual(rangeList[0].End, newRangeList[0].End);
            }

            ApplicationLog.WriteLine(
                "Bed Formatter P1: Successfully validated the ID, Start and End Ranges");
            Console.WriteLine(
                "Bed Formatter P1: Successfully validated the ID, Start and End Ranges");

            // Cleanup the file.
            if (File.Exists(Constants.BedTempFileName))
            {
                File.Delete(Constants.BedTempFileName);
            }
        }
Ejemplo n.º 21
0
        public void IntersectOperationTest()
        {
            string       resultfilepath     = "tmp_mergeresult.bed";
            string       expectedresultpath = string.Empty;
            BedParser    parser             = new BedParser();
            BedFormatter formatter          = new BedFormatter();

            SequenceRangeGrouping result = null;
            bool resultvalue             = false;

            resultfilepath = "tmp_mergeresult.bed";

            string reffile   = @"testdata\BED\Intersect\Intersect_ref.BED";
            string queryFile = @"testdata\BED\Intersect\Intersect_query.BED";
            SequenceRangeGrouping refSeqRange   = parser.ParseRangeGrouping(reffile);
            SequenceRangeGrouping querySeqRange = parser.ParseRangeGrouping(queryFile);

            expectedresultpath = @"testdata\BED\Intersect\Result_Intersect_MinOverlap1_OverLappingBases.BED";
            result             = refSeqRange.Intersect(querySeqRange, 1, IntersectOutputType.OverlappingPiecesOfIntervals);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 1, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Intersect\Result_Intersect_MinOverlap1.BED";
            result             = refSeqRange.Intersect(querySeqRange, 1, IntersectOutputType.OverlappingIntervals);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 1, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Intersect\Result_Intersect_MinOverlap0_OverLappingBases.BED";
            result             = refSeqRange.Intersect(querySeqRange, 0, IntersectOutputType.OverlappingPiecesOfIntervals);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Intersect\Result_Intersect_MinOverlap0.BED";
            result             = refSeqRange.Intersect(querySeqRange, 0, IntersectOutputType.OverlappingIntervals);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Intersect\Result_Intersect_MinOverlap1_OverLappingBases.BED";
            result             = refSeqRange.Intersect(querySeqRange, 1, IntersectOutputType.OverlappingPiecesOfIntervals, 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\Intersect\Result_Intersect_MinOverlap1.BED";
            result             = refSeqRange.Intersect(querySeqRange, 1, IntersectOutputType.OverlappingIntervals, 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\Intersect\Result_Intersect_MinOverlap0_OverLappingBases.BED";
            result             = refSeqRange.Intersect(querySeqRange, 0, IntersectOutputType.OverlappingPiecesOfIntervals, 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\Intersect\Result_Intersect_MinOverlap0.BED";
            result             = refSeqRange.Intersect(querySeqRange, 0, IntersectOutputType.OverlappingIntervals, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, true);
            Assert.IsTrue(resultvalue);
        }
Ejemplo n.º 22
0
 public SequenceRangeGroupingMetrics(SequenceRangeGrouping srg)
 {
     ComputeSequenceRangeGroupingMetrics(srg);
 }
Ejemplo n.º 23
0
        /// <summary>
        ///     Formats the Range/RangeGroup for different test cases based
        ///     on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        private void FormatterGeneralTestCases(string nodeName,
                                               AdditionalParameters addParam)
        {
            IList <ISequenceRange> rangeList = new List <ISequenceRange>();
            var rangeGroup = new SequenceRangeGrouping();

            // Gets the file name.
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir();

            // Condition to check if Parse() happens before Format()
            switch (addParam)
            {
            case AdditionalParameters.ParseRangeGroup:
                var initialParserGroupObj = new BedParser();
                rangeGroup =
                    initialParserGroupObj.ParseRangeGrouping(filePath);
                break;

            case AdditionalParameters.ParseRange:
                var initialParserObj = new BedParser();
                rangeList = initialParserObj.ParseRange(filePath);
                break;

            default:
                // Gets all the expected values from xml.
                string expectedID = utilityObj.xmlUtil.GetTextValue(
                    nodeName, Constants.IDNode);
                string expectedStart = utilityObj.xmlUtil.GetTextValue(
                    nodeName, Constants.StartNode);
                string expectedEnd = utilityObj.xmlUtil.GetTextValue(
                    nodeName, Constants.EndNode);

                string[] expectedIDs    = expectedID.Split(',');
                string[] expectedStarts = expectedStart.Split(',');
                string[] expectedEnds   = expectedEnd.Split(',');

                // Gets the Range Group or Range based on the additional parameter
                switch (addParam)
                {
                case AdditionalParameters.RangeGroupTextWriter:
                case AdditionalParameters.RangeGroupFileName:
                    for (int i = 0; i < expectedIDs.Length; i++)
                    {
                        var rangeObj1 = new SequenceRange(expectedIDs[i],
                                                          long.Parse(expectedStarts[i], null),
                                                          long.Parse(expectedEnds[i], null));
                        rangeGroup.Add(rangeObj1);
                    }
                    break;

                default:
                    for (int i = 0; i < expectedIDs.Length; i++)
                    {
                        var rangeObj2 = new SequenceRange(expectedIDs[i],
                                                          long.Parse(expectedStarts[i], null),
                                                          long.Parse(expectedEnds[i], null));
                        rangeList.Add(rangeObj2);
                    }
                    break;
                }
                break;
            }

            var formatterObj = new BedFormatter();

            // Gets the Range list/Range Group based on the parameters.
            switch (addParam)
            {
            case AdditionalParameters.RangeFileName:
            case AdditionalParameters.ParseRange:
                formatterObj.Format(rangeList, Constants.BedTempFileName);
                break;

            case AdditionalParameters.RangeTextWriter:
                using (var txtWriter =
                           File.Create(Constants.BedTempFileName))
                {
                    formatterObj.Format(txtWriter, rangeList);
                }
                break;

            case AdditionalParameters.RangeGroupFileName:
            case AdditionalParameters.ParseRangeGroup:
                formatterObj.Format(rangeGroup, Constants.BedTempFileName);
                break;

            case AdditionalParameters.RangeGroupTextWriter:
                using (var txtWriter =
                           File.Create(Constants.BedTempFileName))
                {
                    formatterObj.Format(txtWriter, rangeGroup);
                }
                break;

            default:
                break;
            }

            // Reparse to validate the results
            var parserObj = new BedParser();
            IList <ISequenceRange> newRangeList =
                parserObj.ParseRange(Constants.BedTempFileName);

            // Validation of all the properties.
            for (int i = 0; i < rangeList.Count; i++)
            {
                Assert.AreEqual(rangeList[i].ID, newRangeList[i].ID);
                Assert.AreEqual(rangeList[i].Start, newRangeList[i].Start);
                Assert.AreEqual(rangeList[i].End, newRangeList[i].End);

                // Validation of all metadata information.
                if (rangeList[i].Metadata.Count > 0)
                {
                    if (rangeList[i].Metadata.ContainsKey("Name"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["Name"],
                                        newRangeList[i].Metadata["Name"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("Score"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["Score"],
                                        newRangeList[i].Metadata["Score"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("Strand"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["Strand"],
                                        newRangeList[i].Metadata["Strand"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("ThickStart"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["ThickStart"],
                                        newRangeList[i].Metadata["ThickStart"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("ThickEnd"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["ThickEnd"],
                                        newRangeList[i].Metadata["ThickEnd"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("ItemRGB"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["ItemRGB"],
                                        newRangeList[i].Metadata["ItemRGB"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("BlockCount"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["BlockCount"],
                                        newRangeList[i].Metadata["BlockCount"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("BlockSizes"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["BlockSizes"],
                                        newRangeList[i].Metadata["BlockSizes"]);
                    }

                    if (rangeList[i].Metadata.ContainsKey("BlockStarts"))
                    {
                        Assert.AreEqual(rangeList[i].Metadata["BlockStarts"],
                                        newRangeList[i].Metadata["BlockStarts"]);
                    }

                    ApplicationLog.WriteLine(
                        "Bed Formatter BVT: Successfully validated all the metadata information");
                }
            }

            ApplicationLog.WriteLine(
                "Bed Formatter BVT: Successfully validated the ID, Start and End Ranges");

            // Cleanup the file.
            if (File.Exists(Constants.BedTempFileName))
            {
                File.Delete(Constants.BedTempFileName);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Parsers the Bed file for different test cases based
        /// on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        static void ParserGeneralTestCases(string nodeName,
                                           AdditionalParameters addParam)
        {
            // Gets the Filename
            string filePath = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);

            Assert.IsNotEmpty(filePath);
            ApplicationLog.WriteLine(string.Format(
                                         "Bed Parser BVT: Reading the File from location '{0}'", filePath));

            // Get the rangelist after parsing.
            BedParser parserObj = new BedParser();

            IList <ISequenceRange> rangeList  = null;
            SequenceRangeGrouping  rangeGroup = null;

            // Gets the Range list/Range Group based on the parameters.
            switch (addParam)
            {
            case AdditionalParameters.RangeFileName:
                rangeList = parserObj.ParseRange(filePath);
                break;

            case AdditionalParameters.RangeTextReader:
                rangeList = parserObj.ParseRange(new StreamReader(filePath));
                break;

            case AdditionalParameters.RangeGroupFileName:
                rangeGroup = parserObj.ParseRangeGrouping(filePath);
                break;

            case AdditionalParameters.RangeGroupTextReader:
                rangeGroup = parserObj.ParseRangeGrouping(
                    new StreamReader(filePath));
                break;

            default:
                break;
            }

            // Gets the Range list from Group
            switch (addParam)
            {
            case AdditionalParameters.RangeGroupTextReader:
            case AdditionalParameters.RangeGroupFileName:
                IEnumerable <string> grpIDsObj = rangeGroup.GroupIDs;
                string rangeID = string.Empty;
                foreach (string grpID in grpIDsObj)
                {
                    rangeID = grpID;
                }
                rangeList = rangeGroup.GetGroup(rangeID);
                break;

            default:
                break;
            }

            // Gets all the expected values from xml.
            string expectedIDs = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.IDNode);
            string expectedStarts = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.StartNode);
            string expectedEnds = Utility._xmlUtil.GetTextValue(
                nodeName, Constants.EndNode);

            string actualStarts = string.Empty;
            string actualEnds   = string.Empty;
            string actualIDs    = string.Empty;

            // Reads all the ranges with comma seperated for validation
            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(expectedIDs,
                            actualIDs.Substring(0, actualIDs.Length - 1));
            Assert.AreEqual(expectedStarts,
                            actualStarts.Substring(0, actualStarts.Length - 1));
            Assert.AreEqual(expectedEnds,
                            actualEnds.Substring(0, actualEnds.Length - 1));
            ApplicationLog.WriteLine(
                "Bed Parser BVT: Successfully validated the ID, Start and End Ranges");
            Console.WriteLine(
                "Bed Parser BVT: Successfully validated the ID, Start and End Ranges");
        }
Ejemplo n.º 25
0
        public void MergeOperationTest()
        {
            string                filepath           = @"testdata\BED\Merge\Merge_single.BED";
            string                resultfilepath     = "tmp_mergeresult.bed";
            string                expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength0.BED";
            BedParser             parser             = new BedParser();
            BedFormatter          formatter          = new BedFormatter();
            SequenceRangeGrouping seqGrouping        = null;
            SequenceRangeGrouping result             = null;
            bool resultvalue = false;

            resultfilepath     = "tmp_mergeresult.bed";
            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength0.BED";
            seqGrouping        = parser.ParseRangeGrouping(filepath);

            result = seqGrouping.MergeOverlaps();
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, 0, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength0.BED";
            result             = seqGrouping.MergeOverlaps(0, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, 0, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength0.BED";
            result             = seqGrouping.MergeOverlaps(0, false);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, 0, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength0.BED";
            result             = seqGrouping.MergeOverlaps(0);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, 0, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength0.BED";
            result             = seqGrouping.MergeOverlaps(0, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, 0, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength0.BED";
            result             = seqGrouping.MergeOverlaps(0, false);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, 0, false);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength1.BED";
            result             = seqGrouping.MergeOverlaps(1);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, 1, false);
            Assert.IsTrue(resultvalue);


            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength-1.BED";
            result             = seqGrouping.MergeOverlaps(-1);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, -1, false);
            Assert.IsTrue(resultvalue);


            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Single_MinLength-3.BED";
            result             = seqGrouping.MergeOverlaps(-3);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, seqGrouping, null, -3, false);
            Assert.IsTrue(resultvalue);

            string firstFile  = @"testdata\BED\Merge\Merge_twofiles_1.BED";
            string secondFile = @"testdata\BED\Merge\Merge_twofiles_2.BED";
            SequenceRangeGrouping refSeqRange   = parser.ParseRangeGrouping(firstFile);
            SequenceRangeGrouping querySeqRange = parser.ParseRangeGrouping(secondFile);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Two_MinLength0.BED";
            result             = refSeqRange.MergeOverlaps(querySeqRange);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, false);
            Assert.IsTrue(resultvalue);

            result = refSeqRange.MergeOverlaps(querySeqRange, 0, false);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, false);
            Assert.IsTrue(resultvalue);

            result = refSeqRange.MergeOverlaps(querySeqRange, 0, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, true);
            Assert.IsTrue(resultvalue);

            result = refSeqRange.MergeOverlaps(querySeqRange, 0);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, false);
            Assert.IsTrue(resultvalue);

            result = refSeqRange.MergeOverlaps(querySeqRange, 0, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 0, true);
            Assert.IsTrue(resultvalue);

            result = refSeqRange.MergeOverlaps(querySeqRange, 0, 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\Merge\Result_Merge_Two_MinLength1.BED";
            result             = refSeqRange.MergeOverlaps(querySeqRange, 1, 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\Merge\Result_Merge_Two_MinLength-1.BED";
            result             = refSeqRange.MergeOverlaps(querySeqRange, -1, 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\Merge\Result_Merge_Two_MinLength-3.BED";
            result             = refSeqRange.MergeOverlaps(querySeqRange, -3, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, -3, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Two_MinLength2.BED";
            result             = refSeqRange.MergeOverlaps(querySeqRange, 2, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 2, true);
            Assert.IsTrue(resultvalue);

            expectedresultpath = @"testdata\BED\Merge\Result_Merge_Two_MinLength6.BED";
            result             = refSeqRange.MergeOverlaps(querySeqRange, 6, true);
            formatter.Format(result, resultfilepath);
            resultvalue = CompareBEDOutput(resultfilepath, expectedresultpath);
            Assert.IsTrue(resultvalue);
            resultvalue = ValidateParentSeqRange(result, refSeqRange, querySeqRange, 6, true);
            Assert.IsTrue(resultvalue);
        }
Ejemplo n.º 26
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);
        }
        public void ValidateFlatten()
        {
            // Get values from xml.
            string expectedRangeIDs = this.utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.IDNode);
            string expectedStartIndex = this.utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.StartNode);
            string expectedEndIndex = this.utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.EndNode);
            string expectedSequenceRangeCount = this.utilityObj.xmlUtil.GetTextValue(
                Constants.SmallSizeBedNodeName, Constants.SequenceRangeCountNode);

            string[] rangeIDs = expectedRangeIDs.Split(',');
            string[] rangeStarts = expectedStartIndex.Split(',');
            string[] rangeEnds = expectedEndIndex.Split(',');
            var seqRangeGrouping = new SequenceRangeGrouping();
            List<ISequenceRange> rangeList = null;

            // Create a SequenceRange and add to SequenceRangeList.
            for (int i = 0; i < rangeIDs.Length; i++)
            {
                var seqRange = new SequenceRange(rangeIDs[i],
                                                 long.Parse(rangeStarts[i], null),
                                                 long.Parse(rangeEnds[i], null));

                seqRangeGrouping.Add(seqRange);
            }

            //Convert SequenceRangeGroup to SequenceRangeList.
            rangeList = seqRangeGrouping.Flatten();

            int j = 0;
            // Validate created SequenceRanges.
            foreach (ISequenceRange seqRange in rangeList)
            {
                Assert.AreEqual(rangeStarts[j], seqRange.Start.ToString((IFormatProvider) null));
                Assert.AreEqual(rangeEnds[j], seqRange.End.ToString((IFormatProvider) null));
                Assert.AreEqual(rangeIDs[j], seqRange.ID.ToString(null));
                j++;
            }

            Assert.AreEqual(expectedSequenceRangeCount, rangeList.Count.ToString((IFormatProvider) null));
            ApplicationLog.WriteLine("SequenceRange BVT : Successfully validated the SequenceStart,SequenceID and SequenceEnd.");
        }
Ejemplo n.º 28
0
        public void ValidateSequenceRangeGroupingToString()
        {
            ISequenceRange range1 = new SequenceRange("chr20", 0, 3);
            ISequenceRange range2 = new SequenceRange("chr21", 0, 4);
            IList<ISequenceRange> ranges = new List<ISequenceRange>();
            ranges.Add(range1);
            ranges.Add(range2);

            var rangegrouping = new SequenceRangeGrouping(ranges);
            string actualString = rangegrouping.ToString();
            string expectedStr = this.utilityObj.xmlUtil.GetTextValue(Constants.ToStringNodeName,
                                                                 Constants.SequenceRangeGroupingExpectedNode);
            Assert.AreEqual(expectedStr.Replace("\\r\\n", ""), actualString.Replace(System.Environment.NewLine, ""));
        }
Ejemplo n.º 29
0
        public static int Main(string[] args)
        {
            try
            {
                Splash();
                arguments = ProcessCommandLineArguments(args);

                if (arguments.inputFiles.Count() == 2)
                {
                    // now read the 2 BED files and do the operation to isolate each set
                    SequenceRangeGrouping srg1 = ReadBedFile(arguments.inputFiles[0]);
                    SequenceRangeGrouping srg2 = ReadBedFile(arguments.inputFiles[1]);

                    SequenceRangeGrouping srgOnly_A, srgOnly_B, srgOnly_AB;

                    VennToNodeXL.CreateSequenceRangeGroupingsForVennDiagram(
                        srg1,
                        srg2,
                        out srgOnly_A,
                        out srgOnly_B,
                        out srgOnly_AB);

                    var srgmOnly_A  = new SequenceRangeGroupingMetrics(srgOnly_A);
                    var srgmOnly_B  = new SequenceRangeGroupingMetrics(srgOnly_B);
                    var srgmOnly_AB = new SequenceRangeGroupingMetrics(srgOnly_AB);

                    if (createVennToolInputFile)
                    {
                        Console.Error.Write("\nWriting file [{0}]", vennToolInputFileFullPath);
                        var VennOutput = new StreamWriter(vennToolInputFileFullPath);
                        VennOutput.WriteLine("{0} {1} {2}", srgmOnly_A.bases, srgmOnly_B.bases, srgmOnly_AB.bases);
                        VennOutput.Close();
                        Console.Error.Write(" ... Done.");
                    }

                    if (createExcelWorkbook)
                    {
                        // create the Excel workbook with a NodeXL Venn diagram
                        Console.Error.Write("\nWriting file [{0}]", excelWorkbookFullPath);
                        var vdd = new VennDiagramData(srgmOnly_A.bases, srgmOnly_B.bases, srgmOnly_AB.bases);
                        try
                        {
                            VennToNodeXL.CreateVennDiagramNodeXLFile(excelWorkbookFullPath, vdd);
                            Console.Error.Write(" ... Done.\n");
                        }
                        catch (Exception e)
                        {
                            Console.Error.Write("Error:  Unable to create Excel workbook.");
                            DisplayException(e);
                            Environment.Exit(-1);
                        }
                    }
                    if (verbose)
                    {
                        Console.Error.Write("\nDump Sequence Groupings from two files\n");
                        SequenceRangeGroupingToString(srgOnly_A, "srgOnly_A");
                        SequenceRangeGroupingToString(srgOnly_B, "srgOnly_B");
                        SequenceRangeGroupingToString(srgOnly_AB, "srgOnly_AB");
                        Console.Error.Write("\nEnd Sequence group from twoe files\n");
                    }

                    Console.Write("\nOutput basepair count for each set");
                    Console.Write("\nGroupA,GroupB,GroupAB");
                    Console.Write("\n{0},{1},{2}\n", srgmOnly_A.bases, srgmOnly_B.bases, srgmOnly_AB.bases);
                }
                else if (arguments.inputFiles.Count() == 3)
                {
                    // TODO:  Reduce memory usage by re-using the SRGs after debugging is complete
                    //
                    // now read the 3 BED files and do the operation to isolate each set
                    SequenceRangeGrouping srg1 = ReadBedFile(arguments.inputFiles[0]);
                    SequenceRangeGrouping srg2 = ReadBedFile(arguments.inputFiles[1]);
                    SequenceRangeGrouping srg3 = ReadBedFile(arguments.inputFiles[2]);

                    SequenceRangeGrouping srgOnly_A,
                                          srgOnly_B,
                                          srgOnly_C,
                                          srgOnly_AB,
                                          srgOnly_AC,
                                          srgOnly_BC,
                                          srgOnly_ABC;

                    VennToNodeXL.CreateSequenceRangeGroupingsForVennDiagram(
                        srg1,
                        srg2,
                        srg3,
                        out srgOnly_A,
                        out srgOnly_B,
                        out srgOnly_C,
                        out srgOnly_AB,
                        out srgOnly_AC,
                        out srgOnly_BC,
                        out srgOnly_ABC);

                    /*
                     * We have the set information data for the three files.
                     * Now what?
                     */
                    // generate the intersection Venn metrics
                    var srgmOnly_A   = new SequenceRangeGroupingMetrics(srgOnly_A);
                    var srgmOnly_B   = new SequenceRangeGroupingMetrics(srgOnly_B);
                    var srgmOnly_C   = new SequenceRangeGroupingMetrics(srgOnly_C);
                    var srgmOnly_AB  = new SequenceRangeGroupingMetrics(srgOnly_AB);
                    var srgmOnly_AC  = new SequenceRangeGroupingMetrics(srgOnly_AC);
                    var srgmOnly_BC  = new SequenceRangeGroupingMetrics(srgOnly_BC);
                    var srgmOnly_ABC = new SequenceRangeGroupingMetrics(srgOnly_ABC);

                    if (createVennToolInputFile)
                    {
                        Console.Error.Write("\nWriting file [{0}]", vennToolInputFileFullPath);
                        var VennOutput = new StreamWriter(vennToolInputFileFullPath);
                        VennOutput.WriteLine(
                            "{0} {1} {2} {3} {4} {5} {6}",
                            srgmOnly_A.bases,
                            srgmOnly_B.bases,
                            srgmOnly_C.bases,
                            srgmOnly_AB.bases,
                            srgmOnly_AC.bases,
                            srgmOnly_BC.bases,
                            srgmOnly_ABC.bases);
                        VennOutput.Close();
                        Console.Error.Write(" ... Done.");
                    }

                    if (createExcelWorkbook)
                    {
                        // create the NodeXL Venn diagram filefile
                        var vdd = new VennDiagramData(
                            srgmOnly_A.bases,
                            srgmOnly_B.bases,
                            srgmOnly_C.bases,
                            srgmOnly_AB.bases,
                            srgmOnly_AC.bases,
                            srgmOnly_BC.bases,
                            srgmOnly_ABC.bases);
                        // create the Excel workbook with a NodeXL Venn diagram
                        Console.Error.Write("\nWriting file [{0}]", excelWorkbookFullPath);
                        try
                        {
                            VennToNodeXL.CreateVennDiagramNodeXLFile(excelWorkbookFullPath, vdd);
                            Console.Error.Write(" ... Done.\n");
                        }
                        catch (Exception e)
                        {
                            Console.Error.Write("\nError:  Unable to create Excel workbook.");
                            DisplayException(e);
                            Environment.Exit(-1);
                        }
                    }
                    if (verbose)
                    {
                        Console.Error.Write("\nDump Sequence Groupings from three files\n");
                        SequenceRangeGroupingToString(srgOnly_A, "srgOnly_A");
                        SequenceRangeGroupingToString(srgOnly_B, "srgOnly_B");
                        SequenceRangeGroupingToString(srgOnly_C, "srgOnly_C");
                        SequenceRangeGroupingToString(srgOnly_AB, "srgOnly_AB");
                        SequenceRangeGroupingToString(srgOnly_AC, "srgOnly_AC");
                        SequenceRangeGroupingToString(srgOnly_BC, "srgOnly_BC");
                        SequenceRangeGroupingToString(srgOnly_ABC, "srgOnly_ABC");
                        Console.Error.Write("\nEnd Sequence group from three files\n");
                    }

                    Console.Write("\nOutput basepair count for each set");
                    Console.Write("\nGroupA,GroupB,GroupC,GroupAB,GroupAC,GroupBC,GroupABC");
                    Console.Write(
                        "\n{0},{1},{2},{3},{4},{5},{6}\n",
                        srgmOnly_A.bases,
                        srgmOnly_B.bases,
                        srgmOnly_C.bases,
                        srgmOnly_AB.bases,
                        srgmOnly_AC.bases,
                        srgmOnly_BC.bases,
                        srgmOnly_ABC.bases);
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
            }
            return(0);
        }
        /// <summary>
        ///     Create a SequenceRangeGrouping by passing RangeID,Start and End Index.
        ///     and validate created SequenceRange.
        /// </summary>
        /// <param name="nodeName">Xml Node name for different inputs.</param>
        private void CreateSequenceRangeGrouping(string nodeName)
        {
            // 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 expectedSequenceRangeCount = this.utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.SequenceRangeCountNode);

            string[] rangeIDs = expectedRangeIDs.Split(',');
            string[] rangeStarts = expectedStartIndex.Split(',');
            string[] rangeEnds = expectedEndIndex.Split(',');
            var seqRangeGrouping = new SequenceRangeGrouping();
            List<ISequenceRange> rangeList = null;

            // Create a SequenceRange and add to SequenceRangeList.
            for (int i = 0; i < rangeIDs.Length; i++)
            {
                var seqRange = new SequenceRange(rangeIDs[i],
                                                 long.Parse(rangeStarts[i], null), long.Parse(rangeEnds[i], null));

                seqRangeGrouping.Add(seqRange);
            }

            IEnumerable<string> rangeGroupIds = seqRangeGrouping.GroupIDs;
            string rangeID = string.Empty;
            int j = 0;

            foreach (string groupID in rangeGroupIds)
            {
                rangeID = groupID;

                // Get SequenceRangeIds.
                rangeList = seqRangeGrouping.GetGroup(rangeID);

                // Validate created SequenceRanges.
                foreach (ISequenceRange seqRange in rangeList)
                {
                    Assert.AreEqual(rangeStarts[j], seqRange.Start.ToString((IFormatProvider) null));
                    Assert.AreEqual(rangeEnds[j], seqRange.End.ToString((IFormatProvider) null));
                    Assert.AreEqual(rangeIDs[j], seqRange.ID.ToString(null));
                    j++;
                }
            }
            Assert.AreEqual(expectedSequenceRangeCount,
                            rangeList.Count.ToString((IFormatProvider) null));
            ApplicationLog.WriteLine(
                "SequenceRange BVT : Successfully validated the SequenceStart, SequenceID and SequenceEnd.");
        }
Ejemplo n.º 31
0
        /// <summary>
        ///     Parsers the Bed file for different test cases based
        ///     on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        private void ParserGeneralTestCases(string nodeName,
                                            AdditionalParameters addParam)
        {
            // Gets the Filename
            string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir();

            Assert.IsFalse(string.IsNullOrEmpty(filePath));
            ApplicationLog.WriteLine($"Bed Parser BVT: Reading the File from location '{filePath}'");

            // Get the rangelist after parsing.
            var parserObj = new BedParser();

            IList <ISequenceRange> rangeList  = null;
            SequenceRangeGrouping  rangeGroup = null;

            // Gets the Range list/Range Group based on the parameters.
            switch (addParam)
            {
            case AdditionalParameters.RangeFileName:
                rangeList = parserObj.ParseRange(filePath);
                break;

            case AdditionalParameters.RangeTextReader:
                using (var strObj = File.OpenRead(filePath))
                {
                    rangeList = parserObj.ParseRange(strObj);
                }
                break;

            case AdditionalParameters.RangeGroupFileName:
                rangeGroup = parserObj.ParseRangeGrouping(filePath);
                break;

            case AdditionalParameters.RangeGroupTextReader:
                using (var strObj = File.OpenRead(filePath))
                {
                    rangeGroup = parserObj.ParseRangeGrouping(strObj);
                }
                break;

            default:
                break;
            }

            // Gets the Range list from Group
            switch (addParam)
            {
            case AdditionalParameters.RangeGroupTextReader:
            case AdditionalParameters.RangeGroupFileName:
                IEnumerable <string> grpIDsObj = rangeGroup.GroupIDs;
                string rangeID = string.Empty;

                foreach (string grpID in grpIDsObj)
                {
                    rangeID = grpID;
                }

                rangeList = rangeGroup.GetGroup(rangeID);
                break;

            default:
                break;
            }

            // Gets all the expected values from xml.
            string[] expectedIDs = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.IDNode).Split(',');
            string[] expectedStarts = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.StartNode).Split(',');
            string[] expectedEnds = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.EndNode).Split(',');

            int i = 0;

            // Reads all the ranges with comma seperated for validation
            foreach (ISequenceRange range in rangeList)
            {
                Assert.AreEqual(expectedStarts[i], range.Start.ToString((IFormatProvider)null));
                Assert.AreEqual(expectedEnds[i], range.End.ToString((IFormatProvider)null));
                Assert.AreEqual(expectedIDs[i], range.ID.ToString(null));
                i++;
            }

            ApplicationLog.WriteLine(
                "Bed Parser BVT: Successfully validated the ID, Start and End Ranges");
        }
Ejemplo n.º 32
0
        /// <summary>
        ///     Writes out a grouping of ISequenceRange objects to a specified
        ///     stream.
        /// </summary>
        /// <param name="stream">The stream where the formatted data is to be written, it will be closed at the end.</param>
        /// <param name="rangeGroup">The range grouping to be formatted.</param>
        public void Format(Stream stream, SequenceRangeGrouping rangeGroup)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (rangeGroup == null)
            {
                throw new ArgumentNullException("rangeGroup");
            }

            this.Format(stream, rangeGroup.Flatten());
        }
Ejemplo n.º 33
0
        public static void Main(string[] args)
        {
            Splash();

            parsedArgs = ProcessCommandLineArguments(args);

            if (parsedArgs.inputFiles.Count() == 2)
            {
                // now read the 2 BED files and do the operation to isolate each set
                SequenceRangeGrouping srg1 = ReadBedFile(parsedArgs.inputFiles[0]);
                SequenceRangeGrouping srg2 = ReadBedFile(parsedArgs.inputFiles[1]);

                SequenceRangeGrouping srgOnly_A, srgOnly_B, srgOnly_AB;

                VennToNodeXL.CreateSequenceRangeGroupingsForVennDiagram(srg1, srg2, out srgOnly_A, out srgOnly_B, out srgOnly_AB);

                if (fCreateVennToolInputFile || fCreateExcelWorkbook)
                {
                    SequenceRangeGroupingMetrics srgmOnly_A  = new SequenceRangeGroupingMetrics(srgOnly_A);
                    SequenceRangeGroupingMetrics srgmOnly_B  = new SequenceRangeGroupingMetrics(srgOnly_B);
                    SequenceRangeGroupingMetrics srgmOnly_AB = new SequenceRangeGroupingMetrics(srgOnly_AB);

                    if (fCreateVennToolInputFile)
                    {
                        //SequenceRangeGroupingMetrics srgm = new SequenceRangeGroupingMetrics(srgOnly_A);
                        StreamWriter VennOutput = new StreamWriter(VennToolInputFileFullPath);
                        VennOutput.WriteLine("{0} {1} {2}"
                                             , srgmOnly_A.cBases
                                             , srgmOnly_B.cBases
                                             , srgmOnly_AB.cBases);
                        VennOutput.Close();
                    }

                    if (fCreateExcelWorkbook)
                    {
                        // create the Excel workbook with a NodeXL Venn diagram
                        VennDiagramData vdd = new VennDiagramData(srgmOnly_A.cBases
                                                                  , srgmOnly_B.cBases
                                                                  , srgmOnly_AB.cBases);
                        VennToNodeXL.CreateVennDiagramNodeXLFile(ExcelWorkbookFullPath, vdd);
                    }
                    if (fVerbose)
                    {
                        SequenceRangeGroupingToString(srgOnly_A, "srgOnly_A");
                        SequenceRangeGroupingToString(srgOnly_B, "srgOnly_B");
                        SequenceRangeGroupingToString(srgOnly_AB, "srgOnly_AB");
                        Console.WriteLine("end two file dump");
                    }
                }
            }
            if (parsedArgs.inputFiles.Count() == 3)
            {
                // TODO:  Reduce memory usage by re-using the SRGs after debugging is complete
                //
                // now read the 3 BED files and do the operation to isolate each set
                SequenceRangeGrouping srg1 = ReadBedFile(parsedArgs.inputFiles[0]);
                SequenceRangeGrouping srg2 = ReadBedFile(parsedArgs.inputFiles[1]);
                SequenceRangeGrouping srg3 = ReadBedFile(parsedArgs.inputFiles[2]);

                SequenceRangeGrouping srgOnly_A, srgOnly_B, srgOnly_C, srgOnly_AB, srgOnly_AC, srgOnly_BC, srgOnly_ABC;

                VennToNodeXL.CreateSequenceRangeGroupingsForVennDiagram(srg1, srg2, srg3,
                                                                        out srgOnly_A,
                                                                        out srgOnly_B,
                                                                        out srgOnly_C,
                                                                        out srgOnly_AB,
                                                                        out srgOnly_AC,
                                                                        out srgOnly_BC,
                                                                        out srgOnly_ABC);

                /*
                 * We have the set information data for the three files.
                 * Now what?
                 */
                if (fCreateVennToolInputFile || fCreateExcelWorkbook)
                {
                    // generate the intersection Venn metrics
                    SequenceRangeGroupingMetrics srgmOnly_A   = new SequenceRangeGroupingMetrics(srgOnly_A);
                    SequenceRangeGroupingMetrics srgmOnly_B   = new SequenceRangeGroupingMetrics(srgOnly_B);
                    SequenceRangeGroupingMetrics srgmOnly_C   = new SequenceRangeGroupingMetrics(srgOnly_C);
                    SequenceRangeGroupingMetrics srgmOnly_AB  = new SequenceRangeGroupingMetrics(srgOnly_AB);
                    SequenceRangeGroupingMetrics srgmOnly_AC  = new SequenceRangeGroupingMetrics(srgOnly_AC);
                    SequenceRangeGroupingMetrics srgmOnly_BC  = new SequenceRangeGroupingMetrics(srgOnly_BC);
                    SequenceRangeGroupingMetrics srgmOnly_ABC = new SequenceRangeGroupingMetrics(srgOnly_ABC);

                    if (fCreateVennToolInputFile)
                    {
                        StreamWriter VennOutput = new StreamWriter(VennToolInputFileFullPath);
                        VennOutput.WriteLine("{0} {1} {2} {3} {4} {5} {6}"
                                             , srgmOnly_A.cBases
                                             , srgmOnly_B.cBases
                                             , srgmOnly_C.cBases
                                             , srgmOnly_AB.cBases
                                             , srgmOnly_AC.cBases
                                             , srgmOnly_BC.cBases
                                             , srgmOnly_ABC.cBases);
                        VennOutput.Close();
                    }

                    if (fCreateExcelWorkbook)
                    {
                        // create the NodeXL Venn diagram filefile
                        VennDiagramData vdd = new VennDiagramData(srgmOnly_A.cBases
                                                                  , srgmOnly_B.cBases
                                                                  , srgmOnly_C.cBases
                                                                  , srgmOnly_AB.cBases
                                                                  , srgmOnly_AC.cBases
                                                                  , srgmOnly_BC.cBases
                                                                  , srgmOnly_ABC.cBases);
                        VennToNodeXL.CreateVennDiagramNodeXLFile(ExcelWorkbookFullPath, vdd);
                    }
                    if (fVerbose)
                    {
                        SequenceRangeGroupingToString(srgOnly_A, "srgOnly_A");
                        SequenceRangeGroupingToString(srgOnly_B, "srgOnly_B");
                        SequenceRangeGroupingToString(srgOnly_C, "srgOnly_C");
                        SequenceRangeGroupingToString(srgOnly_AB, "srgOnly_AB");
                        SequenceRangeGroupingToString(srgOnly_AC, "srgOnly_AC");
                        SequenceRangeGroupingToString(srgOnly_BC, "srgOnly_BC");
                        SequenceRangeGroupingToString(srgOnly_ABC, "srgOnly_ABC");
                        Console.Error.WriteLine("end three file dump");
                    }
                }
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        ///     Formats the Range/RangeGroup for different test cases based
        ///     on Additional parameter
        /// </summary>
        /// <param name="nodeName">Xml Node name</param>
        /// <param name="addParam">Additional parameter</param>
        private void FormatterGeneralTestCases(string nodeName,
                                               AdditionalParameters addParam)
        {
            IList<ISequenceRange> rangeList = new List<ISequenceRange>();
            var rangeGroup = new SequenceRangeGrouping();

            // Gets the file name.
            string filePath = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.FilePathNode);

            // Condition to check if Parse() happens before Format()
            switch (addParam)
            {
                case AdditionalParameters.ParseRangeGroup:
                case AdditionalParameters.ParseRangeGroupTextWriter:
                    var initialParserGroupObj = new BedParser();
                    rangeGroup =
                        initialParserGroupObj.ParseRangeGrouping(filePath);
                    break;
                case AdditionalParameters.ParseRange:
                case AdditionalParameters.ParseRangeTextWriter:
                    var initialParserObj = new BedParser();
                    rangeList = initialParserObj.ParseRange(filePath);
                    break;
                default:
                    // Gets all the expected values from xml.
                    string expectedID = utilityObj.xmlUtil.GetTextValue(
                        nodeName, Constants.IDNode);
                    string expectedStart = utilityObj.xmlUtil.GetTextValue(
                        nodeName, Constants.StartNode);
                    string expectedEnd = utilityObj.xmlUtil.GetTextValue(
                        nodeName, Constants.EndNode);

                    string[] expectedIDs = expectedID.Split(',');
                    string[] expectedStarts = expectedStart.Split(',');
                    string[] expectedEnds = expectedEnd.Split(',');

                    // Gets the Range Group or Range based on the additional parameter
                    switch (addParam)
                    {
                        case AdditionalParameters.RangeGroupTextWriter:
                        case AdditionalParameters.RangeGroupFileName:
                            for (int i = 0; i < expectedIDs.Length; i++)
                            {
                                var rangeObj1 =
                                    new SequenceRange(expectedIDs[i],
                                                      long.Parse(expectedStarts[i], null),
                                                      long.Parse(expectedEnds[i], null));
                                rangeGroup.Add(rangeObj1);
                            }
                            break;
                        default:
                            for (int i = 0; i < expectedIDs.Length; i++)
                            {
                                var rangeObj2 =
                                    new SequenceRange(expectedIDs[i],
                                                      long.Parse(expectedStarts[i], null),
                                                      long.Parse(expectedEnds[i], null));
                                rangeList.Add(rangeObj2);
                            }
                            break;
                    }
                    break;
            }

            var formatterObj = new BedFormatter();

            // Gets the Range list/Range Group based on the parameters.
            switch (addParam)
            {
                case AdditionalParameters.RangeFileName:
                case AdditionalParameters.ParseRange:
                    formatterObj.Format(rangeList, Constants.BedTempFileName);
                    break;
                case AdditionalParameters.RangeTextWriter:
                case AdditionalParameters.ParseRangeTextWriter:
                    using (var txtWriter = File.Create(Constants.BedTempFileName))
                    {
                        formatterObj.Format(txtWriter, rangeList);
                    }
                    break;
                case AdditionalParameters.RangeGroupFileName:
                case AdditionalParameters.ParseRangeGroup:
                    formatterObj.Format(rangeGroup, Constants.BedTempFileName);
                    break;
                case AdditionalParameters.RangeGroupTextWriter:
                case AdditionalParameters.ParseRangeGroupTextWriter:
                    using (var txtWriter = File.Create(Constants.BedTempFileName))
                    {
                        formatterObj.Format(txtWriter, rangeGroup);
                    }
                    break;
                default:
                    break;
            }

            // Reparse to validate the results
            var parserObj = new BedParser();
            IList<ISequenceRange> newRangeList =
                parserObj.ParseRange(Constants.BedTempFileName);

            // Validation of all the properties.
            for (int i = 0; i < rangeList.Count; i++)
            {
                Assert.AreEqual(rangeList[0].ID, newRangeList[0].ID);
                Assert.AreEqual(rangeList[0].Start, newRangeList[0].Start);
                Assert.AreEqual(rangeList[0].End, newRangeList[0].End);
            }

            ApplicationLog.WriteLine(
                "Bed Formatter P1: Successfully validated the ID, Start and End Ranges");

            // Cleanup the file.
            if (File.Exists(Constants.BedTempFileName))
                File.Delete(Constants.BedTempFileName);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Method called when the user clicks Ok button on InputSelectionDialog.
        /// Takes care of parsing the selections and returning the result to the user.
        /// In case there was an error parsing, it will show the input selection dialog again with the sequence highlighted.
        /// </summary>
        /// <param name="dialog">InputSequenceDialog object which raised this event</param>
        private void OnInputSequenceRangeDialogSubmit(ISelectionDialog dialog)
        {
            InputSelectionDialog selectionDialog = dialog as InputSelectionDialog;
            GroupData            cachedData      = null;

            // maps sheet to its column-mapping
            Dictionary <string, Dictionary <int, string> > columnMappedSheets =
                new Dictionary <string, Dictionary <int, string> >();

            // Goes in the cache and is the output of this method as well.
            Dictionary <SequenceRangeGrouping, GroupData> groupsData =
                new Dictionary <SequenceRangeGrouping, GroupData>();
            List <SequenceRangeGrouping> parsedSequences = new List <SequenceRangeGrouping>();

            SequenceRangeGrouping sequenceRangeGroup = null;
            Dictionary <string, Dictionary <ISequenceRange, string> > sheetData = null;
            Dictionary <ISequenceRange, string> rangeData = null;
            List <ISequenceRange> sequenceRanges          = null;

            List <Range> rangesInCurrentSequenceItem;

            // Regular expression to read the sheet name from address
            Regex  regexSheetname = new Regex(@"(?<Sheetname>^.[^!]*)", RegexOptions.IgnoreCase);
            Match  matchSheetname = null;
            string sheetName      = string.Empty;

            try
            {
                foreach (InputSequenceItem currentSequenceItem in selectionDialog.GetSequences())
                {
                    try
                    {
                        rangesInCurrentSequenceItem = GetRanges(currentSequenceItem.SequenceAddress);
                        // get from cache
                        cachedData = SequenceCache.TryGetSequence(rangesInCurrentSequenceItem, selectionDialog.InputParamsAsKey) as GroupData;
                        if (cachedData != null)
                        {
                            // got from cache
                            cachedData.Name = currentSequenceItem.SequenceName; // Set ID

                            if (currentSequenceItem.IsUseMetadataSelected)
                            {
                                parsedSequences.Insert(0, cachedData.Group);
                            }
                            else
                            {
                                parsedSequences.Add(cachedData.Group);
                            }

                            if (!groupsData.ContainsKey(cachedData.Group))
                            {
                                groupsData.Add(cachedData.Group, cachedData);
                            }
                        }
                        else
                        {
                            // parse it as its not in cache
                            sheetData      = new Dictionary <string, Dictionary <ISequenceRange, string> >();
                            sequenceRanges = new List <ISequenceRange>();
                            foreach (Range currentRange in rangesInCurrentSequenceItem)
                            {
                                bool firstRowIsHeader = false;

                                // See if the sheet in which this range is, has a column mapping
                                if (!columnMappedSheets.ContainsKey(GetMappingKey(currentRange)))
                                {
                                    (currentRange.Worksheet as _Worksheet).Activate();
                                    currentRange.Select();
                                    Dictionary <int, string> mapping = GetMappingForRange(currentRange, out firstRowIsHeader);
                                    if (mapping == null)
                                    {
                                        // Could not get a proper mapping. So redirect to previous window.
                                        selectionDialog.ShowDialog();
                                        return;
                                    }

                                    if (firstRowIsHeader)
                                    {
                                        UpdateColumnHeaders(currentRange, mapping);
                                    }

                                    columnMappedSheets.Add(GetMappingKey(currentRange), mapping);
                                }

                                // If range has a header, remove first row from it before sending it for parsing.
                                Range rangeToParse;
                                if (firstRowIsHeader)
                                {
                                    if (currentRange.Rows.Count == 1) // only one row which is marked as header, throw error
                                    {
                                        throw new InvalidOperationException(Resources.SelectionModel_ParsingFailed);
                                    }

                                    rangeToParse = currentRange.get_Offset(1, 0);
                                    rangeToParse = rangeToParse.get_Resize(currentRange.Rows.Count - 1, currentRange.Columns.Count);
                                }
                                else
                                {
                                    rangeToParse = currentRange;
                                }

                                Dictionary <ISequenceRange, string> srCollection =
                                    ExcelSelectionParser.RangeToSequenceRange(
                                        rangeToParse,
                                        columnMappedSheets[GetMappingKey(currentRange)]);

                                foreach (KeyValuePair <ISequenceRange, string> sr in srCollection)
                                {
                                    matchSheetname = regexSheetname.Match(sr.Value);
                                    if (matchSheetname.Success)
                                    {
                                        sheetName = matchSheetname.Groups["Sheetname"].Value;
                                        if (sheetData.TryGetValue(sheetName, out rangeData))
                                        {
                                            rangeData.Add(sr.Key, sr.Value);
                                        }
                                        else
                                        {
                                            rangeData = new Dictionary <ISequenceRange, string>();
                                            sheetData.Add(sheetName, rangeData);
                                            rangeData.Add(sr.Key, sr.Value);
                                        }

                                        sequenceRanges.Add(sr.Key);
                                    }
                                }
                            }

                            sequenceRangeGroup = new SequenceRangeGrouping(sequenceRanges);
                            cachedData         = new GroupData(sequenceRangeGroup,
                                                               currentSequenceItem.SequenceName,
                                                               sheetData);
                            SequenceCache.Add(rangesInCurrentSequenceItem, cachedData, selectionDialog.InputParamsAsKey);

                            if (currentSequenceItem.IsUseMetadataSelected)
                            {
                                parsedSequences.Insert(0, cachedData.Group);
                            }
                            else
                            {
                                parsedSequences.Add(cachedData.Group);
                            }

                            groupsData.Add(cachedData.Group, cachedData);
                        }
                    }
                    catch
                    {
                        // Set error status on the current item and re-throw the error
                        currentSequenceItem.SetErrorStatus(true);
                        throw;
                    }
                }

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add(InputSelection.OVERLAP, selectionDialog.OverlappingBasePairs);
                parameters.Add(InputSelection.MINIMUMOVERLAP, selectionDialog.MinOverLap);

                // On successful completion of parsing...
                if (inputSequenceRangeSelectionComplete != null)
                {
                    InputSequenceRangeSelectionEventArg eventArg =
                        new InputSequenceRangeSelectionEventArg(groupsData,
                                                                parsedSequences,
                                                                parameters,
                                                                argsForCallback);
                    inputSequenceRangeSelectionComplete(eventArg);
                }

                selectionDialog.InputSelectionDialogSubmitting -= OnInputSequenceDialogSubmit;
                selectionDialog.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                selectionDialog.ShowDialog();
            }
        }
        /// <summary>
        /// Validate Parent Sequence ranges in result sequence range.
        /// </summary>
        /// <param name="resultSeq">Result seq range group.</param>
        /// <param name="refSeq">Reference seq range group.</param>
        /// <param name="querySeq">Query seq range group.</param>
        /// <param name="isParentSeqRangeRequired">
        /// Flag to indicate whether result should contain parent seq ranges or not.
        /// </param>
        /// <returns>Returns true if the parent seq ranges are valid; otherwise returns false.</returns>
        private static bool ValidateParentSeqRange(SequenceRangeGrouping resultSeq, SequenceRangeGrouping refSeq,
                                                   SequenceRangeGrouping querySeq, bool isParentSeqRangeRequired)
        {
            IList<ISequenceRange> refSeqRangeList = new List<ISequenceRange>();
            IList<ISequenceRange> querySeqRangeList = new List<ISequenceRange>();

            IEnumerable<string> groupIds = resultSeq.GroupIDs;

            foreach (string groupId in groupIds)
            {
                if (null != refSeq)
                {
                    refSeqRangeList = refSeq.GetGroup(groupId);
                }

                if (null != querySeq)
                {
                    querySeqRangeList = querySeq.GetGroup(groupId);
                }

                foreach (ISequenceRange resultRange in resultSeq.GetGroup(groupId))
                {
                    if (!isParentSeqRangeRequired)
                    {
                        if (resultRange.ParentSeqRanges.Count != 0)
                        {
                            return false;
                        }
                    }
                    else
                    {
                        int refSeqRangeCount = refSeqRangeList.Count(s => resultRange.ParentSeqRanges.Contains(s));
                        int querySeqRangeCount = querySeqRangeList.Count(s => resultRange.ParentSeqRanges.Contains(s));
                        if (resultRange.ParentSeqRanges.Count != refSeqRangeCount + querySeqRangeCount)
                        {
                            return false;
                        }
                    }
                }
            }

            return true;
        }
        /// <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");
        }
Ejemplo n.º 38
0
        public void TestSequenceRangeGroupingToString()
        {
            ISequenceRange range1 = new SequenceRange("chr20", 0, 3);
            ISequenceRange range2 = new SequenceRange("chr21", 0, 4);
            IList<ISequenceRange> ranges = new List<ISequenceRange>();
            ranges.Add(range1);
            ranges.Add(range2);
            
            SequenceRangeGrouping rangegrouping = new SequenceRangeGrouping(ranges);
            string actualString = rangegrouping.ToString();

            string expectedString = "ID=chr20 Start=0 End=3\r\nID=chr21 Start=0 End=4\r\n".Replace("\r\n", Environment.NewLine);
            Assert.AreEqual(actualString, expectedString);
        }