public void CreateMnvsFromClusters(IEnumerable <ICluster> clusters, int qNoiselevel, int maxQscore, bool crushNbhd = false) { if (clusters == null) { return; } if (clusters.Count() == 0) { return; } var depthAtSites = new int[0]; var nocallsAtSites = new int[0]; DepthAtSites(clusters, out depthAtSites, out nocallsAtSites); Logger.WriteToLog("Creating MNVs from clusters."); int anchorPosition = -1; //if we are crushing the vcf, or in diploid mode, always report all phased alleles throug the nbhd, starting at the first position of interest. (ie, the first position we started phasing on) //If we are in somatic mode or uncrushed mode, we just report the variants at the loci we find them on (normal Pisces) if (crushNbhd || _nbhdGTcalculator.PloidyModel == Pisces.Domain.Types.PloidyModel.Diploid) { anchorPosition = FirstPositionOfInterest; } foreach (var cluster in clusters) { CalledAllele mnv; var clusterConsensus = cluster.GetConsensusSites(); Logger.WriteToLog(cluster.Name + "\tVariantSites\t" + VariantSite.ArrayToString(clusterConsensus)); Logger.WriteToLog(cluster.Name + "\tVariantPositions\t" + VariantSite.ArrayToPositions(clusterConsensus)); var referenceRemoval = PhasedVariantExtractor.Extract(out mnv, clusterConsensus, ReferenceSequence, depthAtSites, nocallsAtSites, cluster.CountsAtSites, ReferenceName, qNoiselevel, maxQscore, anchorPosition); if ((mnv.Type != Pisces.Domain.Types.AlleleCategory.Reference) && mnv.AlleleSupport != 0) { Logger.WriteToLog(cluster.Name + "mnv accepted:\t" + mnv.ToString()); AddAcceptedPhasedVariant(mnv); //keep track of reference calls sucked into MNVs. //We will need to subtract this from the ref counts when we write out the final vcf. foreach (var refPosition in referenceRemoval.Keys) { if (!UsedRefCountsLookup.ContainsKey(refPosition)) { var suckedUpRefRecord = new SuckedUpRefRecord() { Counts = 0, AlleleThatClaimedIt = mnv }; UsedRefCountsLookup.Add(refPosition, suckedUpRefRecord); } UsedRefCountsLookup[refPosition].Counts += referenceRemoval[refPosition].Counts; } } else if (mnv.TotalCoverage != 0) //dont add empty stuff.. { Logger.WriteToLog("mnv rejected:\t" + mnv.ToString()); AddRejectedPhasedVariant(mnv); } } foreach (var phasedVariant in CandidateVariants) { var calledPhasedVariant = phasedVariant as CalledAllele; if (calledPhasedVariant == null) { continue; } calledPhasedVariant.ReferenceSupport = phasedVariant.TotalCoverage - phasedVariant.AlleleSupport; if (UsedRefCountsLookup.ContainsKey(phasedVariant.ReferencePosition) && (UsedRefCountsLookup[phasedVariant.ReferencePosition].AlleleThatClaimedIt != phasedVariant)) { calledPhasedVariant.ReferenceSupport = calledPhasedVariant.ReferenceSupport - UsedRefCountsLookup[phasedVariant.ReferencePosition].Counts; } calledPhasedVariant.ReferenceSupport = Math.Max(0, calledPhasedVariant.ReferenceSupport); } }
public void AddMnvsFromClusters(IEnumerable <ICluster> clusters, int qNoiselevel, int maxQscore, bool crushNbhd = false) { if (clusters == null) { return; } if (clusters.Count() == 0) { return; } var depthAtSites = DepthAtSites(clusters); Logger.WriteToLog("Creating MNVs from clusters."); int anchorPosition = -1; foreach (var cluster in clusters) { CalledAllele mnv; var clusterConsensus = cluster.GetConsensusSites(); if (crushNbhd && (anchorPosition == -1)) { anchorPosition = clusterConsensus.First().VcfReferencePosition; } Logger.WriteToLog(cluster.Name + "\tVariantSites\t" + VariantSite.ArrayToString(clusterConsensus)); Logger.WriteToLog(cluster.Name + "\tVariantPositions\t" + VariantSite.ArrayToPositions(clusterConsensus)); var referenceRemoval = PhasedVariantExtractor.Extract(out mnv, clusterConsensus, ReferenceSequence, depthAtSites.ToList(), cluster.CountsAtSites, ReferenceName, qNoiselevel, maxQscore, anchorPosition); if ((mnv.Type != Pisces.Domain.Types.AlleleCategory.Reference) && mnv.AlleleSupport != 0) { Logger.WriteToLog(cluster.Name + "mnv accepted:\t" + mnv.ToString()); AddAcceptedPhasedVariant(mnv); //keep track of reference calls sucked into MNVs. //We will need to subtract this from the ref counts when we write out the final vcf. foreach (var refPosition in referenceRemoval.Keys) { if (!UsedRefCountsLookup.ContainsKey(refPosition)) { UsedRefCountsLookup.Add(refPosition, 0); } UsedRefCountsLookup[refPosition] += referenceRemoval[refPosition]; } } else if (mnv.TotalCoverage != 0) //dont add empty stuff.. { Logger.WriteToLog("mnv rejected:\t" + mnv.ToString()); AddRejectedPhasedVariant(mnv); } } foreach (var phasedVariant in CandidateVariants) { var calledPhasedVariant = phasedVariant as CalledAllele; if (calledPhasedVariant == null) { continue; } calledPhasedVariant.ReferenceSupport = phasedVariant.TotalCoverage - phasedVariant.AlleleSupport; if (UsedRefCountsLookup.ContainsKey(phasedVariant.Coordinate)) { calledPhasedVariant.ReferenceSupport = calledPhasedVariant.ReferenceSupport - UsedRefCountsLookup[phasedVariant.Coordinate]; } calledPhasedVariant.ReferenceSupport = Math.Max(0, calledPhasedVariant.ReferenceSupport); } }