/// <summary> /// Take in a vcf, do stuff to it, write out a vcf. Streamed line by line, loci by loci, so as not to blow up your computer. /// </summary> /// <param name="vcfOut"> the output file name</param> /// <param name="options"> all the parameters associated with writing out a vcf</param> /// <param name="recalibrationData">the data you need for doing your "stuff" </param> /// <param name="whatToDoWithSingleAllele">how you want to change each allele</param> /// <param name="whatToDoWithCoLocatedAlleles">how you want to change each set of alleles, by loci</param> /// <param name="canSkipLinesWithoutProcessing">when you can skip lines (saves CPU time)</param> /// <param name="getVcfFileWriter">what your special vcf writer should be, includes special header lines, etc</param> /// <param name="shouldTrimComplexAlleles">if ACGT-> ACCT is ok, or if you want it trimmed to G -> C. this might affect position and ordering. Generally turn if OFF for processing vcfs, post scylla. </param> private static void UpdateVcf(string vcfOut, VcfConsumerAppOptions options, bool shouldTrimComplexAlleles, T recalibrationData, UpdateSingleAlleleMethod whatToDoWithSingleAllele, UpdateCoLocatedAllelesMethod whatToDoWithCoLocatedAlleles, CanSkipVcfLinesMethod canSkipLinesWithoutProcessing, GetVcfFileWriter getVcfFileWriter) { using (AlleleReader reader = new AlleleReader(options.VcfPath, shouldTrimComplexAlleles)) { using (VcfFileWriter writer = getVcfFileWriter(options, vcfOut)) { writer.WriteHeader(); writer.FlushBuffer(); var variantListFromFile = new List <CalledAllele>() { }; string incomingHangingLine = null; string outgoingHangingLine = null; while (true) { //get the next group to process incomingHangingLine = outgoingHangingLine; var coLocatedVcfLinesToProcess = reader.CloseColocatedLines(incomingHangingLine, out outgoingHangingLine); //how we know we are done if (coLocatedVcfLinesToProcess.Count == 0) { break; } bool updateNeededForLocus = false; TypeOfUpdateNeeded updatedNeededForLine = canSkipLinesWithoutProcessing(coLocatedVcfLinesToProcess); switch (updatedNeededForLine) { case TypeOfUpdateNeeded.NoChangeNeeded: writer.Write(coLocatedVcfLinesToProcess); break; case TypeOfUpdateNeeded.Modify: //then we need to change them into alleles and do stuff to them variantListFromFile = AlleleReader.VcfLinesToAlleles(coLocatedVcfLinesToProcess); List <CalledAllele> modifiedVariantListToWrite = WhatToDoToAlleles(options, recalibrationData, whatToDoWithSingleAllele, whatToDoWithCoLocatedAlleles, variantListFromFile, ref updateNeededForLocus); if (updateNeededForLocus) { writer.Write(modifiedVariantListToWrite); } else { writer.Write(coLocatedVcfLinesToProcess); } break; case TypeOfUpdateNeeded.DeleteCompletely: default: break; } } } } }
public static void UpdateVcfLociByLoci(string vcfOut, VcfConsumerAppOptions options, bool shouldTrimComplexAlleles, T recalibrationData, UpdateCoLocatedAllelesMethod whatToDoWithCoLocatedAlleles, CanSkipVcfLinesMethod canSkipLineWithoutProcessing, GetVcfFileWriter getVcfFileWriter) { UpdateVcf(vcfOut, options, shouldTrimComplexAlleles, recalibrationData, NeverUpdateByAlleleOnly, whatToDoWithCoLocatedAlleles, canSkipLineWithoutProcessing, getVcfFileWriter); }