Example #1
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('#'));
            }
        }
Example #2
0
        public void CountNumberOfExportedPeaksInEachSet(uint sampleID, Attributes attribute, int count)
        {
            // Arrange & Act
            string path         = RunMSPCAndExportResults();
            var    sampleFolder = Array.Find(Directory.GetDirectories(path), (string f) => { return(f.Contains(_sidfm[sampleID])); });
            var    file         = Array.Find(Directory.GetFiles(sampleFolder), (string f) => { return(Path.GetFileNameWithoutExtension(f).Equals(attribute.ToString())); });
            var    bedParser    = new BedParser
            {
                PValueFormat = PValueFormats.minus1_Log10_pValue
            };
            var parsedSample = bedParser.Parse(file);

            // Assert
            if (count == 0)
            {
                Assert.False(parsedSample.Chromosomes.ContainsKey(_chr));
            }
            else
            {
                Assert.True(parsedSample.Chromosomes[_chr].Strands[_strand].Intervals.Count == count);
            }

            // Clean up
            Directory.Delete(path, true);
        }
Example #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);
            }
        }
Example #4
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);
            }
        }
        public void TestNullFilePath()
        {
            // Arrange
            var parser = new BedParser();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => parser.Parse(null));
        }
Example #6
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"));
            }
        }
Example #7
0
        public void CompletedVCF()
        {
            // Arrange
            using (var file = new Vcf.TempFileCreator(new Vcf.RegionGenerator()))
            {
                // Act
                var parser = new BedParser();
                parser.Parse(file.TempFilePath);

                // Assert
                Assert.True(parser.Status == "100");
            }
        }
Example #8
0
        public void InvalidFile()
        {
            // Arrange
            string fileName = "a_file_name_which_does_not_exist_1234567890";
            var    parser   = new BedParser();

            // Act
            Exception exception = Assert.Throws <FileNotFoundException>(() => parser.Parse(fileName));

            // Assert
            Assert.False(string.IsNullOrEmpty(exception.Message));
            Assert.Equal(string.Format("The file `{0}` does not exist or is inaccessible.", fileName), exception.Message);
        }
Example #9
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);
            }
        }
Example #10
0
        public Bed <Peak> LoadSample(string fileName, ParserConfig parserConfig)
        {
            var bedParser = new BedParser(parserConfig)
            {
                PValueFormat           = parserConfig.PValueFormat,
                DefaultValue           = parserConfig.DefaultValue,
                DropPeakIfInvalidValue = parserConfig.DropPeakIfInvalidValue
            };
            var parsedSample = bedParser.Parse(fileName);

            _samples.Add(parsedSample);
            return(parsedSample);
        }
Example #11
0
        public void ReadTwoIntervalsWithExactSameInfo()
        {
            // Arrange
            var peak = "chr1\t10\t20\tGeUtilities_00\t0.01";

            using var file = new TempFileCreator(new string[] { peak, peak });

            // Act
            var parser    = new BedParser();
            var parsedBED = parser.Parse(file.Path);

            // Assert
            Assert.True(parsedBED.IntervalsCount == 2);
        }
Example #12
0
        public void CanTellIfStrandContainsAnInterval()
        {
            // Arrange
            using (var file = new TempFileCreator())
            {
                // Act
                var parser    = new BedParser();
                var parsedBED = parser.Parse(file.Path);
                var interval  = parsedBED.Chromosomes["chr1"].Strands['.'].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedBED.Chromosomes["chr1"].Strands['.'].Contains(interval));
            }
        }
Example #13
0
        public void Progress()
        {
            // Arrange
            _previousStatus = -1;
            using (var file = new Bed.TempFileCreator(new Bed.RegionGenerator(), peaksCount: 50))
            {
                // Act
                var bedParser = new BedParser();
                bedParser.StatusChanged += ParserStatusChanged;
                bedParser.Parse(file.Path);

                // Asserted in 'ParserStatusChanged'
            }
        }
Example #14
0
        public void TestFilePath()
        {
            // Arrange
            string peak = "chr1\t10\t20\tName\t100.0";

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

                // Assert
                Assert.True(parsedBED.FilePath == Path.GetFullPath(file.Path));
            }
        }
Example #15
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));
            }
        }
        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);
            }
        }
        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);
            }
        }
Example #18
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);
            }
        }
Example #19
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));
            }
        }
Example #20
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);
            }
        }
Example #21
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"));
            }
        }
Example #22
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"));
            }
        }
Example #23
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);
            }
        }
Example #24
0
        public void CanGetAnIntervalFromStrand()
        {
            // Arrange
            using (var file = new TempFileCreator())
            {
                // Act
                var parser    = new BedParser();
                var parsedBED = parser.Parse(file.Path);
                var expected  = parsedBED.Chromosomes["chr1"].Strands['.'].Intervals.ToList()[0];

                // Assert
                GeUtilities.Intervals.Model.Peak i;
                Assert.True(parsedBED.Chromosomes["chr1"].Strands['.'].TryGet(expected.GetHashCode(), out i));
                Assert.Equal(expected, i);
            }
        }
Example #25
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);
            }
        }
Example #26
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);
            }
        }
Example #27
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));
            }
        }
Example #28
0
        public void TestAssembly(Assemblies assembly)
        {
            // Arrange
            string peak = "chr1\t10\t20\tName\t100.0";

            using (var file = new TempFileCreator(peak))
            {
                // Act
                var parser = new BedParser()
                {
                    Assembly = assembly
                };
                var parsedBED = parser.Parse(file.Path);

                // Assert
                Assert.True(parsedBED.Assembly == assembly);
            }
        }
Example #29
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));
            }
        }
Example #30
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);
            }
        }