private void Initialize() { var baseReader = new BamReader(_inputBam); _chroms = baseReader.GetReferenceNames(); _header = baseReader.GetHeader(); _references = baseReader.GetReferences(); _header = BamStitcher.UpdateBamHeader(_header); }
public void Process(string inputBam, string outFolder, StitcherOptions stitcherOptions) { var jobManager = new JobManager(10); var jobs = new List <IJob>(); var perChromBams = new List <string>(); // Process each of the chromosomes separately foreach (var chrom in _chroms) { var intermediateOutput = Path.Combine(outFolder, Path.GetFileNameWithoutExtension(inputBam) + "." + chrom + ".stitched.bam"); perChromBams.Add(intermediateOutput); var stitcher = new BamStitcher(inputBam, intermediateOutput, stitcherOptions, chrFilter: chrom); jobs.Add(new GenericJob(() => stitcher.Execute(), "Stitcher_" + chrom)); } jobManager.Process(jobs); // Combine the per-chromosome bams Logger.WriteToLog("Writing final bam."); var outputBam = Path.Combine(outFolder, Path.GetFileNameWithoutExtension(inputBam) + ".final.stitched.bam"); using (var finalOutput = new BamWriter(outputBam, _header, _references)) { foreach (var bam in perChromBams) { Logger.WriteToLog("Adding " + bam + " to final bam."); var bamAlignment = new BamAlignment(); using (var bamReader = new BamReader(bam)) { while (true) { var hasMoreReads = bamReader.GetNextAlignment(ref bamAlignment, false); if (!hasMoreReads) { break; } finalOutput.WriteAlignment(bamAlignment); } } File.Delete(bam); } } Logger.WriteToLog("Finished combining per-chromosome bams into final bam at " + outputBam); }
public void Process(string inputBam, string outFolder, StitcherOptions stitcherOptions) { var stitcher = new BamStitcher(inputBam, Path.Combine(outFolder, Path.GetFileNameWithoutExtension(inputBam) + ".stitched.bam"), stitcherOptions); stitcher.Execute(); }