Пример #1
0
        public void ColumnsSetters()
        {
            // Arrange
            var rg = new RegionGenerator
            {
                ChrColumn     = 2,
                LeftColumn    = 2,
                RightColumn   = 9,
                StrandColumn  = -1,
                SourceColumn  = 2,
                FeatureColumn = -1
            };

            rg.StrandColumn  = 0;
            rg.StrandColumn  = 19;
            rg.FeatureColumn = 8;

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parsedGTF     = Features.ParseGTF(file.TempFilePath, rg);
                var parsedFeature = parsedGTF.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0];

                // Assert
                Assert.True(parsedFeature.CompareTo(rg.GFeature) == 0);
            }
        }
Пример #2
0
        public void ColumnsShuffle(
            byte chrColumn, sbyte sourceColumn, sbyte featureColumn, byte leftColumn, sbyte rightColumn,
            sbyte scoreColumn, sbyte strandColumn, sbyte frameColumn, sbyte attributeColumn)
        {
            // Arrange
            var rg = new RegionGenerator()
            {
                ChrColumn       = chrColumn,
                SourceColumn    = sourceColumn,
                FeatureColumn   = featureColumn,
                LeftColumn      = leftColumn,
                RightColumn     = rightColumn,
                ScoreColumn     = scoreColumn,
                StrandColumn    = strandColumn,
                FrameColumn     = frameColumn,
                AttributeColumn = attributeColumn
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parsedGTF     = Features.ParseGTF(file.TempFilePath, rg);
                var parsedFeature = parsedGTF.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0];

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

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

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

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

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

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

                // Assert
                Assert.True(parsedFeature.CompareTo(rg.GFeature) == 0);
            }
        }
Пример #6
0
        public void FullySetArguments()
        {
            // Arrange
            var rg = new RegionGenerator();

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

                // Assert
                Assert.True(parsedFeature.CompareTo(rg.GFeature) == 0);
            }
        }
Пример #7
0
        public void FeatureCount()
        {
            // Arrange
            var rg = new RegionGenerator {
                Feature = "feature"
            };
            int featureCount = 5;

            using (var file = new TempFileCreator(rg, featuresCount: featureCount))
            {
                // Act
                var parsedGTF = ParseGTF(file.TempFilePath, rg);

                // Assert
                Assert.True(parsedGTF.DeterminedFeatures[rg.Feature] == featureCount);
            }
        }
Пример #8
0
        public void ReadScore()
        {
            // Arrange
            var rg = new RegionGenerator {
                Score = 123.456
            };

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

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0].Score == rg.Score);
            }
        }
Пример #9
0
        public void ReadLeft()
        {
            // Arrange
            var rg = new RegionGenerator {
                Left = 10
            };

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

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0].Left == rg.Left);
            }
        }
Пример #10
0
        public void FailReadChr(string chr)
        {
            // Arrange
            var rg = new RegionGenerator {
                Chr = "chr1"
            };

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

                // Assert
                Assert.False(parsedData.Chromosomes.ContainsKey(chr));
            }
        }
Пример #11
0
        public void ReadAttribute()
        {
            // Arrange
            var rg = new RegionGenerator {
                Attribute = "att1=at1;att2=at2;att3=3"
            };

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

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

            using (var file = new TempFileCreator(rg, featuresCount: 10, headerLineCount: 2))
            {
                // Act
                var parsedData = ParseGTF(file.TempFilePath, rg);

                // Assert
                Assert.True(parsedData.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.Count == 10);
            }
        }
Пример #13
0
        public void TestInvalidFeatureColumn()
        {
            // Arrange
            var rg = new RegionGenerator
            {
                // a column number which is more than the number of columns written to the test file.
                FeatureColumn = 10
            };

            using (var file = new TempFileCreator("chr1\tDi4\t.\t10\t20\t100.0\t*\t0\tatt1=1;att2=v2"))
            {
                // Act
                var parsedGTF = Features.ParseGTF(file.TempFilePath, rg);

                // Assert
                Assert.False(parsedGTF.Chromosomes.ContainsKey("chr1"));
            }
        }
Пример #14
0
        public void TestFrameColumn(sbyte frameColumn, string frame)
        {
            // Arrange
            var rg = new RegionGenerator
            {
                Frame       = frame,
                FrameColumn = frameColumn
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parsedGTF     = Features.ParseGTF(file.TempFilePath, rg);
                var parsedFeature = parsedGTF.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals.ToList()[0];

                // Assert
                Assert.True(parsedFeature.Frame == frame);
            }
        }
Пример #15
0
        public void TestScoreColumn(sbyte scoreColumn, double score)
        {
            // Arrange
            var rg = new RegionGenerator
            {
                Score       = score,
                ScoreColumn = scoreColumn
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parsedGTF     = Features.ParseGTF(file.TempFilePath, rg);
                var parsedFeature = parsedGTF.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0];

                // Assert
                Assert.True(double.IsNaN(score) ? double.IsNaN(parsedFeature.Score) : parsedFeature.Score == score);
            }
        }
Пример #16
0
        public void TestAttributeColumn(sbyte attributeColumn, string attribute)
        {
            // Arrange
            var rg = new RegionGenerator
            {
                Attribute       = attribute,
                AttributeColumn = attributeColumn
            };

            using (var file = new TempFileCreator(rg))
            {
                // Act
                var parsedGTF     = Features.ParseGTF(file.TempFilePath, rg);
                var parsedFeature = parsedGTF.Chromosomes[rg.Chr].Strands[rg.Strand].Intervals[0];

                // Assert
                Assert.True(parsedFeature.Attribute == attribute);
            }
        }
Пример #17
0
        public TempFileCreator(RegionGenerator columns, int headerLineCount = 0, int featuresCount = 1)
        {
            TempFilePath = Path.GetTempPath() + Guid.NewGuid().ToString() + ".gtf";
            FileStream stream = File.Create(TempFilePath);

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

                while (featuresCount-- > 0)
                {
                    writer.WriteLine(columns.GetSampleLine());
                    if (featuresCount > 0)
                    {
                        columns.Left  = columns.Right + 10;
                        columns.Right = columns.Right + 20;
                    }
                }
            }
        }
Пример #18
0
        internal static Gtf <GeneralFeature> ParseGTF(string filePath, RegionGenerator rg)
        {
            var parser = new GtfParser(rg.Columns);

            return(parser.Parse(filePath));
        }