Пример #1
0
        public void ColumnsSetters()
        {
            // Arrange
            var rg = new RegionGenerator
            {
                ChrColumn      = 2,
                PositionColumn = 2,
                IDColumn       = 9,
                RefbColumn     = 0,
                AltbColumn     = 2,
                QualityColumn  = 2,
                FilterColumn   = 0,
                InfoColumn     = 6,
                StrandColumn   = 12
            };

            rg.InfoColumn = 12;

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parsedVCF  = ParseVCF(file.TempFilePath, rg);
                var parsedPeak = parsedVCF.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedPeak.CompareTo(rg.Variant) == 0);
            }
        }
Пример #2
0
        public void TestColumnsShuffle(
            byte chrColumn, byte positionColumn, byte idColumn, byte refBPColumn, byte altBPColumn,
            byte qualityColumn, byte filterColumn, byte infoColumn, sbyte strandColumn)
        {
            // Arrange
            var rg = new RegionGenerator()
            {
                ChrColumn      = chrColumn,
                PositionColumn = positionColumn,
                IDColumn       = idColumn,
                RefbColumn     = refBPColumn,
                AltbColumn     = altBPColumn,
                QualityColumn  = qualityColumn,
                FilterColumn   = filterColumn,
                InfoColumn     = infoColumn,
                StrandColumn   = strandColumn
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parsedVCF     = ParseVCF(file.TempFilePath, rg);
                var parsedVariant = parsedVCF.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedVariant.CompareTo(rg.Variant) == 0);
            }
        }
Пример #3
0
        public void AssignHashKey()
        {
            // Arrange
            var rg = new RegionGenerator();

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

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0].GetHashCode() != 0);
            }
        }
Пример #4
0
        public void TestDefaultVCFColumnOrder()
        {
            // Arrange
            var rg = new RegionGenerator();

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

                // Assert
                Assert.True(parsedVariant.CompareTo(rg.Variant) == 0);
            }
        }
Пример #5
0
        public void OneBaseLenghtInterval()
        {
            // Arrange
            var rg = new RegionGenerator();

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

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0].Right == rg.Position + 1);
            }
        }
Пример #6
0
        public void FullySetArguments()
        {
            // Arrange
            var rg = new RegionGenerator();

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

                // Assert
                Assert.True(parsedVariant.CompareTo(rg.Variant) == 0);
            }
        }
Пример #7
0
        public void MultiVariantFile()
        {
            // Arrange
            var rg = new RegionGenerator {
                StrandColumn = 12
            };

            using (var file = new TempFileCreator(rg, variantsCount: 10, headerLineCount: 2))
            {
                // Act
                var parser     = new VcfParser();
                var parsedData = parser.Parse(file.TempFilePath);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.Count == 10);
            }
        }
Пример #8
0
        public void FailToReadID()
        {
            // Arrange
            var rg = new RegionGenerator()
            {
                IDColumn = 20
            };
            string line = "chr1\t10\tAAC\tCCA\t123.456\tFilter\tInfo\t*";

            using (var file = new TempFileCreator(line))
            {
                // Act
                var parsedVCF = ParseVCF(file.TempFilePath, rg);

                // Assert
                Assert.False(parsedVCF.Chromosomes.ContainsKey("chr1"));
            }
        }
Пример #9
0
        public TempFileCreator(RegionGenerator columns, int headerLineCount = 0, int variantsCount = 1)
        {
            TempFilePath = Path.GetTempPath() + Guid.NewGuid().ToString() + ".vcf";
            FileStream stream = File.Create(TempFilePath);

            using (StreamWriter writer = new StreamWriter(stream))
            {
                while (headerLineCount-- > 0)
                {
                    writer.WriteLine(columns.GetSampleHeader());
                }

                while (variantsCount-- > 0)
                {
                    writer.WriteLine(columns.GetSampleLine());
                    if (variantsCount > 0)
                    {
                        columns.Position += 10;
                    }
                }
            }
        }
Пример #10
0
        private Vcf <Variant> ParseVCF(string filePath, RegionGenerator rg)
        {
            var parser = new VcfParser(rg.Columns);

            return(parser.Parse(filePath));
        }