Exemple #1
0
        public void BuildGraph_GenerateDotFile_WriteContigs(string fastaPath)
        {
            var assemblyName = "IntegrationTests";
            var projectPath  = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.IndexOf(assemblyName) + assemblyName.Length);

            fastaPath = Path.Combine(projectPath, fastaPath);
            var fileService    = new FileService();
            var kmerLength     = 19;
            var errorCorrector = new ErrorCorrector(kmerLength);
            var fastaReader    = new FastaReader(fileService);

            var reads = fastaReader.ParseFastaFile(fastaPath);

            errorCorrector.BuildHistogram(reads);

            var graphBuilder = new DeBruijnGraphBuilder(kmerLength, errorCorrector);
            var graph        = graphBuilder.Build(reads);

            errorCorrector.PrintResult();

            graph.CleanUp();
            var dotFileDirectory = Path.Combine(Path.GetDirectoryName(fastaPath), "graphs");

            Directory.CreateDirectory(dotFileDirectory);
            graphBuilder.ToDot(fileService, Path.Combine(dotFileDirectory, Path.GetFileNameWithoutExtension(fastaPath) + ".dot"), graph);

            var contigs          = graph.GetContigs();
            var contigsDirectory = Path.Combine(Path.GetDirectoryName(fastaPath), "contigs");

            Directory.CreateDirectory(contigsDirectory);
            fastaReader.WriteFastaFile(Path.Combine(contigsDirectory, Path.GetFileNameWithoutExtension(fastaPath) + ".contigs.fasta"), contigs);
        }
Exemple #2
0
        private void Run()
        {
            var fileService    = new FileService();
            var kmerLength     = K ?? 19;
            var errorCorrector = new ErrorCorrector(kmerLength, true);
            var fastaReader    = new FastaReader(fileService);

            var reads = fastaReader.ParseFastaFile(ReadsPath);
            // errorCorrector.BuildHistogram(reads);

            var graphBuilder = new DeBruijnGraphBuilder(kmerLength, errorCorrector);
            var graph        = graphBuilder.Build(reads);

            errorCorrector.PrintResult();

            graph.CleanUp();

            if (!string.IsNullOrWhiteSpace(DotFilePath))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(DotFilePath));
                graphBuilder.ToDot(fileService, DotFilePath, graph);
            }

            var contigs = graph.GetContigs();

            Directory.CreateDirectory(Path.GetDirectoryName(ContigsPath));
            fastaReader.WriteFastaFile(ContigsPath, contigs);
        }
Exemple #3
0
        public void Simplify(int mergedNodeCount, int totalMergedNodeValuesLength, params string[] str)
        {
            var k            = 4;
            var graphBuilder = new DeBruijnGraphBuilder(k, new TestErrorCorrector(k));
            var graph        = graphBuilder.Build(str);

            graph.Simplify();
            Assert.Equal(mergedNodeCount, graph.Nodes.Count());
            Assert.Equal(totalMergedNodeValuesLength, graph.Nodes.Select(n => n.Value).Aggregate((a, b) => a + b).Length);
        }
Exemple #4
0
        public void RemoveShortChains(int chainsCount, params string[] str)
        {
            var k            = 4;
            var graphBuilder = new DeBruijnGraphBuilder(k, new TestErrorCorrector(k));
            var graph        = graphBuilder.Build(str);

            graph.Simplify();

            graph.RemoveShortChains();
            Assert.Equal(chainsCount, graph.Nodes.Count());
        }
Exemple #5
0
        public void RemoveTips_WithSimplify(int k, int chainsCount, params string[] str)
        {
            var graphBuilder = new DeBruijnGraphBuilder(k, new TestErrorCorrector(k));
            var graph        = graphBuilder.Build(str);

            graph.Simplify();

            graph.RemoveTips();
            Assert.Equal(chainsCount, graph.Nodes.Count());

            graph.Simplify();
            Assert.Single(graph.Nodes);
        }