Ejemplo n.º 1
0
        public void ColumnsShuffle(byte chrColumn, byte leftColumn, sbyte rightColumn, byte nameColumn, byte valueColumn)
        {
            // Arrange
            var rg = new RegionGenerator
            {
                ChrColumn   = chrColumn,
                LeftColumn  = leftColumn,
                RightColumn = rightColumn,
                NameColumn  = nameColumn,
                ValueColumn = valueColumn
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser(
                    new BedColumns()
                {
                    Chr   = chrColumn,
                    Left  = leftColumn,
                    Right = rightColumn,
                    Name  = nameColumn,
                    Value = valueColumn
                });
                var parsedPeak = parser.Parse(file.Path).Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedPeak.CompareTo(rg.Peak) == 0);
            }
        }
Ejemplo n.º 2
0
        public void TestMultiStrand()
        {
            // Arrange
            string[] peaks = new string[]
            {
                "chr1\t10\t20\t*\tGeUtilities_00\t0.1",
                "chr1\t30\t40\t+\tGeUtilities_01\t0.11",
                "chr1\t50\t60\t-\tGeUtilities_02\t0.111",
                "chr1\t50\t60\t#\tGeUtilities_02\t0.111", // Any strand name other than '+', '-', and '*' will be parsed as '*'.
            };

            using (var file = new TempFileCreator(peaks))
            {
                // Act
                var parser = new BedParser(
                    new BedColumns
                {
                    Chr    = 0,
                    Left   = 1,
                    Right  = 2,
                    Strand = 3,
                    Name   = 4,
                    Value  = 5
                });

                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes["chr1"].Strands.ContainsKey('*'));
                Assert.True(parsedData.Chromosomes["chr1"].Strands.ContainsKey('+'));
                Assert.True(parsedData.Chromosomes["chr1"].Strands.ContainsKey('-'));
                Assert.False(parsedData.Chromosomes["chr1"].Strands.ContainsKey('#'));
            }
        }
Ejemplo n.º 3
0
        public void TestMinMaxValueWhenDefaultValueIsUsed()
        {
            // Arrange
            double defaultValue = 1e-8;

            string[] peaks = new string[]
            {
                "chr1\t10\t20",
                "chr1\t30\t40",
                "chr1\t50\t60",
                "chr1\t70\t80",
            };
            using (var file = new TempFileCreator(peaks))
            {
                // Act
                var parser = new BedParser()
                {
                    DropPeakIfInvalidValue = false,
                    DefaultValue           = defaultValue
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.PValueMax.Value == defaultValue);
                Assert.True(parsedData.PValueMin.Value == defaultValue);
            }
        }
Ejemplo n.º 4
0
        public void FailReadValue()
        {
            // Arrange
            using (var file = new TempFileCreator("chr1\t10\t20\tGeUtilities_01\t123..45"))
            {
                // Act
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.False(parsedData.Chromosomes.ContainsKey("chr1"));
            }
        }
Ejemplo n.º 5
0
        public void AvoidEmptyLines()
        {
            // Arrange
            using (var file = new TempFileCreator("             "))
            {
                // Act
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes.Count == 0);
            }
        }
Ejemplo n.º 6
0
        public void DefaultColumnsOrder()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator())
            {
                // Act
                var parser     = new BedParser();
                var parsedPeak = parser.Parse(file.Path).Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedPeak.CompareTo(rg.Peak) == 0);
            }
        }
Ejemplo n.º 7
0
        public void FullySetArguments()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser     = new BedParser(rg.Columns);
                var parsedPeak = parser.Parse(file.Path).Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0];

                // Assert
                Assert.True(parsedPeak.CompareTo(rg.Peak) == 0);
            }
        }
Ejemplo n.º 8
0
        public void ReadStrand()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // ACt
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands.ContainsKey(rg.Strand));
            }
        }
Ejemplo n.º 9
0
        public void AssignHashKey()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0].GetHashCode() != 0);
            }
        }
Ejemplo n.º 10
0
        public void FailReadChr(string chr)
        {
            // Arrange
            using (var file = new TempFileCreator(new RegionGenerator {
                Chr = "chr1"
            }))
            {
                // Act
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.False(parsedData.Chromosomes.ContainsKey(chr));
            }
        }
Ejemplo n.º 11
0
        public void ReadValue()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0].Value == rg.Value);
            }
        }
Ejemplo n.º 12
0
        public void FailReadRightColumnIndexOutOfRange()
        {
            // Arrange
            using (var file = new TempFileCreator("chr1\t10\t20\tGeUtilities_01\t123.4"))
            {
                // Act
                var parser = new BedParser(new BedColumns()
                {
                    Right = 10
                });
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.False(parsedData.Chromosomes.ContainsKey("chr1"));
            }
        }
Ejemplo n.º 13
0
        public void AvoidHeader(int headerCount, byte readOffset)
        {
            // Arrange
            using (var file = new TempFileCreator(new RegionGenerator(), headerLineCount: headerCount))
            {
                // Act
                var parser = new BedParser()
                {
                    ReadOffset = readOffset
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes.Count == 1);
            }
        }
Ejemplo n.º 14
0
        public void DropPeaksHavingInvalidPValue()
        {
            // Arrange
            using (var file = new TempFileCreator("chr1\t10\t20\tGeUtilities_01\t123..45"))
            {
                // Act
                var parser = new BedParser()
                {
                    DropPeakIfInvalidValue = true
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.False(parsedData.Chromosomes.ContainsKey("chr1"));
            }
        }
Ejemplo n.º 15
0
        public void BEDWithAllOptionalColumnsAndSomeExtraColumns()
        {
            // Arrange
            var rg = new RegionGenerator {
                SummitColumn = 10, StrandColumn = 11
            };

            using (var file = new TempFileCreator(rg, headerLineCount: 2, peaksCount: 10))
            {
                // Act
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.Count == 10);
            }
        }
Ejemplo n.º 16
0
        public void MaxLinesToRead(int numberOfPeaksToWrite, uint numberOfPeaksToRead)
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg, peaksCount: numberOfPeaksToWrite))
            {
                // Act
                var parser = new BedParser()
                {
                    MaxLinesToRead = numberOfPeaksToRead
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.Count == Math.Min(numberOfPeaksToWrite, numberOfPeaksToRead));
            }
        }
Ejemplo n.º 17
0
        public void TestStrand(sbyte strandColumn, char strand)
        {
            // Arrange
            var rg = new RegionGenerator
            {
                Strand       = strand,
                StrandColumn = strandColumn
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser(rg.Columns);

                // Assert
                Assert.True(parser.Parse(file.Path).Chromosomes[rg.Chr].Strands.ContainsKey(strand));
            }
        }
Ejemplo n.º 18
0
        public void ReadNoPeak()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg, peaksCount: 4))
            {
                // Act
                var parser = new BedParser()
                {
                    MaxLinesToRead = 0
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes.Count == 0);
            }
        }
Ejemplo n.º 19
0
        public void TestSummit(sbyte summitColumn, int summit)
        {
            // Arrange
            var rg = new RegionGenerator {
                SummitColumn = summitColumn
            };

            rg.Summit = summit == -1 ? rg.Left + ((rg.Right - rg.Left) / 2) : summit;

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser     = new BedParser(rg.Columns);
                var parsedPeak = parser.Parse(file.Path).Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedPeak.Summit == rg.Summit);
            }
        }
Ejemplo n.º 20
0
        public void ThrowExceptionForInvalidCultureInfo()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var exception = Assert.Throws <ArgumentOutOfRangeException>(
                    () => new BedParser
                {
                    Culture = "invalid_culture"
                });

                // Assert
                Assert.False(string.IsNullOrEmpty(exception.Message));
                Assert.Contains("Invalid culture info", exception.Message);
            }
        }
Ejemplo n.º 21
0
        public void UseDefaultPValueForPeaksWithInvalidPValue()
        {
            // Arrange
            double defaultValue = 0.112233;

            using (var file = new TempFileCreator("chr1\t10\t20\tGeUtilities_01\t123..45"))
            {
                // Act
                var parser = new BedParser()
                {
                    DropPeakIfInvalidValue = false,
                    DefaultValue           = defaultValue
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes["chr1"].Strands['*'].Intervals[0].Value == defaultValue);
            }
        }
Ejemplo n.º 22
0
        public void TestMeanValue()
        {
            // Arrange
            string[] peaks = new string[]
            {
                "chr1\t10\t20\tGeUtilities_00\t0.1",
                "chr1\t30\t40\tGeUtilities_01\t0.01",
                "chr3\t50\t60\tGeUtilities_02\t0.001",
                "chr4\t70\t80\tGeUtilities_03\t0.0001",
            };
            using (var file = new TempFileCreator(peaks))
            {
                // Act
                var parser     = new BedParser();
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.PValueMean == 0.027775);
            }
        }
Ejemplo n.º 23
0
        public void PValueConversion(double originalValue, double convertedValue, PValueFormats pvalueFormat)
        {
            // Arrange
            var rg = new RegionGenerator {
                Value = convertedValue
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser()
                {
                    PValueFormat = pvalueFormat
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0].Value == originalValue);
            }
        }
Ejemplo n.º 24
0
        public void DontFailIfGivenColumnNumberIsInvalid()
        {
            // Arrange
            using (var file = new TempFileCreator("chr1\t10\t20"))
            {
                var parser = new BedParser(new BedColumns()
                {
                    Chr = 0, Left = 1, Right = 2, Name = 3, Strand = 4, Summit = 5, Value = 6
                })
                {
                    DropPeakIfInvalidValue = false,
                };

                // Act
                var parsedPeak = parser.Parse(file.Path).Chromosomes["chr1"].Strands['.'].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedPeak.Left == 10 && parsedPeak.Right == 20);
            }
        }
Ejemplo n.º 25
0
        public void UseDefaultValueIfInvalidPValueColumn()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser(new BedColumns()
                {
                    Value = 9
                })
                {
                    DropPeakIfInvalidValue = false
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes.ContainsKey(rg.Chr));
            }
        }
Ejemplo n.º 26
0
        public void TestMissingChrs()
        {
            // Arrange
            var rg = new RegionGenerator {
                Chr = "chr1"
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser()
                {
                    Assembly             = Assemblies.hg19,
                    ReadOnlyAssemblyChrs = false
                };
                parser.Parse(file.Path);

                // Assert
                Assert.True(parser.MissingChrs.Count == References.GetGenomeSizes(Assemblies.hg19).Count - 1);
            }
        }
Ejemplo n.º 27
0
        public void LogErrorIfFailedToReadALine()
        {
            // Arrange
            var rg = new RegionGenerator();

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser(new BedColumns()
                {
                    Value = 9
                })
                {
                    DropPeakIfInvalidValue = true
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Messages.Count > 0);
            }
        }
Ejemplo n.º 28
0
        public void TestExcessChrs(string chr)
        {
            // Arrange
            var rg = new RegionGenerator {
                Chr = chr
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                BedParser <Peak> parser = new BedParser()
                {
                    Assembly             = Assemblies.hg19,
                    ReadOnlyAssemblyChrs = false
                };
                parser.Parse(file.Path);

                // Assert
                Assert.True(parser.ExcessChrs.Count == 1);
            }
        }
Ejemplo n.º 29
0
        public void DropLineIfInvalidChr(string chr)
        {
            // Arrange
            var rg = new RegionGenerator {
                Chr = chr
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser()
                {
                    Assembly             = Assemblies.hg19,
                    ReadOnlyAssemblyChrs = true
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes.Count == 0);
            }
        }
Ejemplo n.º 30
0
        public void ParseIntervalChrWhenChrPrefixIsMissing(string chr)
        {
            // Arrange
            var rg = new RegionGenerator {
                Chr = chr
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parser = new BedParser()
                {
                    Assembly             = Assemblies.hg19,
                    ReadOnlyAssemblyChrs = true
                };
                var parsedData = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedData.Chromosomes.ContainsKey("chr" + chr));
            }
        }