public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List <Variant> variants) { var aligned = aln == null ? "FALSE" : "TRUE"; var end = String.Join(",", read.MutationsTested.ToString(), read.MutationsApplied.ToString(), read.ProcessingTimeMS.ToString(), read.Barcode1.ToString(), read.Barcode2.ToString()); string start = String.Join(",", read.Movie, read.HoleNumber.ToString(), read.SnrA.ToString(), read.SnrC.ToString(), read.SnrG.ToString(), read.SnrT.ToString(), aligned, read.ReadQuality.ToString(), read.AvgZscore.ToString(), read.Sequence.Count.ToString(), read.NumPasses.ToString(), read.ReadCountSuccessfullyAdded.ToString(), read.ReadCountBadZscore.ToString(), read.ReadCountAlphaBetaMismatch.ToString(), read.ReadCountOther.ToString()); if (aln == null) { start = start + ",NA,NA,NA,NA,NA,NA," + end; } else { var indels = variants.Count(z => z.Type == VariantType.INDEL); var snps = variants.Count(z => z.Type == VariantType.SNP); var total = variants.Count; var length = aln.AlignedSAMSequence.RefEndPos - aln.AlignedSAMSequence.Pos; start = start + "," + String.Join(",", length.ToString(), aln.AlignedSAMSequence.Pos, total.ToString(), indels.ToString(), snps.ToString(), aln.AlignedSAMSequence.RName, end); } SW.WriteLine(start); }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List <Variant> variants) { if (variants == null) { return; } foreach (var v in variants) { var common = String.Join(",", read.Movie, read.HoleNumber.ToString(), v.RefName, v.StartPosition.ToString(), v.Length.ToString(), v.Type.ToString(), v.QV.ToString(), v.AtEndOfAlignment.ToString()); var snp = v as SNPVariant; string unique; if (snp != null) { unique = String.Join(",", snp.RefBP, snp.AltBP, "NA,NA,NA,NA,NA"); } else { var indel = v as IndelVariant; unique = string.Join(",", "NA,NA", indel.InsertionOrDeletion.ToString(), indel.InHomopolymer.ToString(), indel.InsertedOrDeletedBases.ToString(), indel.HomopolymerLengthInReference.ToString(), indel.HomopolymerBase); } SW.WriteLine(common + "," + unique); } }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List<Variant> variants) { var aligned = aln==null ? "FALSE" : "TRUE"; var end = String.Join (",", read.MutationsTested.ToString (), read.MutationsApplied.ToString (), read.ProcessingTimeMS.ToString (), read.Barcode1.ToString(), read.Barcode2.ToString ()); string start = String.Join (",", read.Movie, read.HoleNumber.ToString (), read.SnrA.ToString (), read.SnrC.ToString (), read.SnrG.ToString (), read.SnrT.ToString (), aligned, read.ReadQuality.ToString (), read.AvgZscore.ToString (), read.Sequence.Count.ToString (), read.NumPasses.ToString (), read.ReadCountSuccessfullyAdded.ToString(), read.ReadCountBadZscore.ToString(), read.ReadCountAlphaBetaMismatch.ToString(), read.ReadCountOther.ToString()); if (aln == null) { start = start + ",NA,NA,NA,NA,NA,NA," + end; } else { var indels = variants.Count (z => z.Type == VariantType.INDEL); var snps = variants.Count (z => z.Type == VariantType.SNP); var total = variants.Count; var length = aln.AlignedSAMSequence.RefEndPos - aln.AlignedSAMSequence.Pos; start = start + "," + String.Join (",", length.ToString (), aln.AlignedSAMSequence.Pos, total.ToString (), indels.ToString (), snps.ToString (), aln.AlignedSAMSequence.RName, end ); } SW.WriteLine (start); }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List<Variant> variants) { if (variants == null) { return; } foreach (var v in variants) { incorrectCounts [v.QV]++; if (v.Type == VariantType.SNP) { snpErrorCounts [v.QV]++; } else { var id = v as IndelVariant; if (id.InsertionOrDeletion == IndelType.Deletion) { deletionErrorCounts [v.QV]++; } else if (id.InsertionOrDeletion == IndelType.Insertion) { insertionErrorCounts [v.QV]++; } } } var refseq = aln.AlignedRefSeq; var qseq = aln.AlignedQuerySeq as QualitativeSequence; for (int i = 0; i < refseq.Count; i++) { if (refseq [i] == qseq [i]) { correctCounts [qseq.GetQualityScore (i)]++; } } }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List<Variant> variants) { int i = 1; foreach (var v in read.ZScores) { var s = String.Join (",", read.Movie, read.HoleNumber, i.ToString (), v.ToString ()); SW.WriteLine (s); i++; } }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List<Variant> variants) { var prefix = String.Join (",", read.Movie, read.HoleNumber.ToString ()); SW.WriteLine (prefix + ",A," + read.SnrA); SW.WriteLine (prefix + ",C," + read.SnrC); SW.WriteLine (prefix + ",G," + read.SnrG); SW.WriteLine (prefix + ",T," + read.SnrT); }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List <Variant> variants) { int i = 1; foreach (var v in read.ZScores) { var s = String.Join(",", read.Movie, read.HoleNumber, i.ToString(), v.ToString()); SW.WriteLine(s); i++; } }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List <Variant> variants) { var prefix = String.Join(",", read.Movie, read.HoleNumber.ToString()); SW.WriteLine(prefix + ",A," + read.SnrA); SW.WriteLine(prefix + ",C," + read.SnrC); SW.WriteLine(prefix + ",G," + read.SnrG); SW.WriteLine(prefix + ",T," + read.SnrT); }
public CCSDataSet(Sequence ccs, List<Sequence> subreads, BWAPairwiseAlignment aln) { // Call Variants var results = VariantCaller.LeftAlignIndelsAndCallVariants (aln); Variants = results.Item2; Variants.ForEach (p => { p.StartPosition += aln.AlignedSAMSequence.Pos; p.RefName = aln.Reference; }); // Get the ungapped reference var ccs_aligned = results.Item1.SecondSequence; // Generate an ungapped reference var refseq = results.Item1.PairwiseAlignedSequences.First().FirstSequence; var reference = new Sequence (DnaAlphabet.Instance, refseq.Where (bp => bp != '-').ToArray (), false) { ID = aln.Reference + "/" + aln.AlignedSAMSequence.Pos + "-" + aln.AlignedSAMSequence.RefEndPos }; var reference_rc = reference.GetReverseComplementedSequence () as Sequence; Reads = subreads.Select(z => new AlignedSequence(z, reference, reference_rc)).Where( x => (Math.Abs((x.Sequence.Length - reference.Count)) / (double) reference.Count) < 0.2).ToList(); Reads.Insert (0, new AlignedSequence (reference, reference, reference_rc)); ccs.ID = "CCS"; Reads.Insert(1, new AlignedSequence(ccs, reference, reference_rc)); // Now to rejigger the alignments int[] metaOffSets = Enumerable.Range(0, (int)reference.Count). Select (i => Reads.Max( r => r.GetInsertsBeforePosition(i))). ToArray(); Reads.ForEach(r => { r.ReJiggerAlignment(metaOffSets); Console.WriteLine(r.Sequence);}); CCS = ccs; Reference = reference; Aln = aln; }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List<Variant> variants) { if (variants == null) { return; } foreach (var v in variants) { var common = String.Join (",", read.Movie, read.HoleNumber.ToString (), v.RefName, v.StartPosition.ToString (), v.Length.ToString (), v.Type.ToString (), v.QV.ToString (), v.AtEndOfAlignment.ToString ()); var snp = v as SNPVariant; string unique; if (snp != null) { unique = String.Join (",", snp.RefBP, snp.AltBP, "NA,NA,NA,NA,NA"); } else { var indel = v as IndelVariant; unique = string.Join (",", "NA,NA", indel.InsertionOrDeletion.ToString (), indel.InHomopolymer.ToString (), indel.InsertedOrDeletedBases.ToString (), indel.HomopolymerLengthInReference.ToString (), indel.HomopolymerBase); } SW.WriteLine (common + "," + unique); } }
public override void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List <Variant> variants) { if (variants == null) { return; } foreach (var v in variants) { incorrectCounts [v.QV]++; if (v.Type == VariantType.SNP) { snpErrorCounts [v.QV]++; } else { var id = v as IndelVariant; if (id.InsertionOrDeletion == IndelType.Deletion) { deletionErrorCounts [v.QV]++; } else if (id.InsertionOrDeletion == IndelType.Insertion) { insertionErrorCounts [v.QV]++; } } } var refseq = aln.AlignedRefSeq; var qseq = aln.AlignedQuerySeq as QualitativeSequence; for (int i = 0; i < refseq.Count; i++) { if (refseq [i] == qseq [i]) { correctCounts [qseq.GetQualityScore(i)]++; } } }
public abstract void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List <Variant> variants);
public abstract void ConsumeCCSRead(PacBioCCSRead read, BWAPairwiseAlignment aln, List<Variant> variants);
public static void Main(string[] args) { try { PlatformManager.Services.MaxSequenceSize = int.MaxValue; PlatformManager.Services.DefaultBufferSize = 4096; PlatformManager.Services.Is64BitProcessType = true; if (args.Length > 3) { Console.WriteLine("Too many arguments"); DisplayHelp(); } else if (args.Length < 2) { Console.WriteLine("Not enough arguments"); DisplayHelp(); } else if (args [0] == "h" || args [0] == "help" || args [0] == "?" || args [0] == "-h") { DisplayHelp(); } else { string bam_name = args [0]; string out_dir = args [1]; string ref_name = args.Length > 2 ? args [2] : null; if (!File.Exists(bam_name)) { Console.WriteLine("Can't find file: " + bam_name); return; } if (ref_name != null && !File.Exists(ref_name)) { Console.WriteLine("Can't find file: " + ref_name); return; } if (Directory.Exists(out_dir)) { Console.WriteLine("The output directory already exists, please specify a new directory or delete the old one."); return; } Directory.CreateDirectory(out_dir); List <CCSReadMetricsOutputter> outputters = new List <CCSReadMetricsOutputter> () { new ZmwOutputFile(out_dir), new ZScoreOutputter(out_dir), new VariantOutputter(out_dir), new SNROutputFile(out_dir), new QVCalibration(out_dir) }; ISequenceParser reader; if (bam_name.EndsWith(".fastq", StringComparison.OrdinalIgnoreCase)) { reader = new FastQCCSReader(); } else { reader = new PacBioCCSBamReader(); } BWAPairwiseAligner bwa = null; bool callVariants = ref_name != null; if (callVariants) { bwa = new BWAPairwiseAligner(ref_name, false); } // Produce aligned reads with variants called in parallel. var reads = new BlockingCollection <Tuple <PacBioCCSRead, BWAPairwiseAlignment, List <Variant> > >(); Task producer = Task.Factory.StartNew(() => { try { Parallel.ForEach(reader.Parse(bam_name), y => { var z = y as PacBioCCSRead; try { BWAPairwiseAlignment aln = null; List <Variant> variants = null; if (callVariants) { aln = bwa.AlignRead(z.Sequence) as BWAPairwiseAlignment; if (aln != null) { variants = VariantCaller.CallVariants(aln); variants.ForEach(p => { p.StartPosition += aln.AlignedSAMSequence.Pos; p.RefName = aln.Reference; }); } } var res = new Tuple <PacBioCCSRead, BWAPairwiseAlignment, List <Variant> >(z, aln, variants); reads.Add(res); } catch (Exception thrown) { Console.WriteLine("CCS READ FAIL: " + z.Sequence.ID); Console.WriteLine(thrown.Message); } }); } catch (Exception thrown) { Console.WriteLine("Could not parse BAM file: " + thrown.Message); while (thrown.InnerException != null) { Console.WriteLine(thrown.InnerException.Message); thrown = thrown.InnerException; } } reads.CompleteAdding(); }); // Consume them into output files. foreach (var r in reads.GetConsumingEnumerable()) { foreach (var outputter in outputters) { outputter.ConsumeCCSRead(r.Item1, r.Item2, r.Item3); } } // throw any exceptions (this should be used after putting the consumer on a separate thread) producer.Wait(); // Close the files outputters.ForEach(z => z.Finish()); } } catch (DllNotFoundException thrown) { Console.WriteLine("Error thrown when attempting to generate the CCS results."); Console.WriteLine("A shared library was not found. To solve this, please add the folder" + " with the downloaded files libbwasharp and libMonoPosixHelper" + "to your environmental variables (LD_LIBRARY_PATH on Ubuntu, DYLD_LIBRARY_PATH on Mac OS X)."); Console.WriteLine("Error: " + thrown.Message); Console.WriteLine(thrown.StackTrace); } catch (Exception thrown) { Console.WriteLine("Error thrown when attempting to generate the CCS results"); Console.WriteLine("Error: " + thrown.Message); Console.WriteLine(thrown.StackTrace); while (thrown.InnerException != null) { Console.WriteLine("Inner Exception: " + thrown.InnerException.Message); thrown = thrown.InnerException; } } }