private SortedList <int, List <CalledAllele> > CallForPositions(List <CandidateAllele> candidates, IAlleleSource source, int?maxPosition) { var calledAllelesByPosition = new SortedList <int, List <CalledAllele> >(); var failedMnvs = new List <CalledAllele>(); var callableAlleles = new List <CalledAllele>(); if (_collapser != null) { candidates = _collapser.Collapse(candidates.ToList(), source, maxPosition); } foreach (var candidate in candidates) { var variant = AlleleHelper.Map(candidate); if (variant.Type == AlleleCategory.Mnv) { ProcessVariant(source, variant); if (IsCallable(variant)) { callableAlleles.Add(variant); } else { failedMnvs.Add(variant); } } else { callableAlleles.Add(variant); } } var leftoversInNextBlock = MnvReallocator.ReallocateFailedMnvs(failedMnvs, callableAlleles, maxPosition); source.AddCandidates(leftoversInNextBlock.Select(AlleleHelper.Map)); source.AddGappedMnvRefCount(GetRefSupportFromGappedMnvs(callableAlleles)); // need to re-process variants since they may have additional support foreach (var baseCalledAllele in callableAlleles) { ProcessVariant(source, baseCalledAllele); if (IsCallable(baseCalledAllele) && ShouldReport(baseCalledAllele)) { List <CalledAllele> calledAtPosition; if (!calledAllelesByPosition.TryGetValue(baseCalledAllele.Coordinate, out calledAtPosition)) { calledAtPosition = new List <CalledAllele>(); calledAllelesByPosition.Add(baseCalledAllele.Coordinate, calledAtPosition); } calledAtPosition.Add(baseCalledAllele); } } // re-process variants by loci to get GT (to potentially take into account multiple var alleles at same loci) // and prune allele lists as needed. foreach (var allelesAtPosition in calledAllelesByPosition.Values) { //pruning ref calls if (allelesAtPosition.Any(v => v.Type != AlleleCategory.Reference))//(v => v is BaseCalledAllele)) { allelesAtPosition.RemoveAll(v => (v.Type == AlleleCategory.Reference)); } //set GT and GT score, and prune any variant calls that exceed the ploidy model var allelesToPrune = _genotypeCalculator.SetGenotypes(allelesAtPosition); foreach (var alleleToPrune in allelesToPrune) { allelesAtPosition.Remove(alleleToPrune); } foreach (var allele in allelesAtPosition) { if (_config.LowGTqFilter.HasValue && allele.GenotypeQscore < _config.LowGTqFilter) { allele.AddFilter(FilterType.LowGenotypeQuality); } } allelesAtPosition.Sort((a1, a2) => { var refCompare = a1.Reference.CompareTo(a2.Reference); return(refCompare == 0 ? a1.Alternate.CompareTo(a2.Alternate) : refCompare); }); } return(calledAllelesByPosition); }
private SortedList <int, List <CalledAllele> > CallForPositions(List <CandidateAllele> candidates, IAlleleSource source, int?maxPosition) { var failedMnvs = new List <CalledAllele>(); var callableAlleles = new List <CalledAllele>(); if (_collapser != null) { candidates = _collapser.Collapse(candidates.ToList(), source, maxPosition); } foreach (var candidate in candidates) { var variant = AlleleHelper.Map(candidate); if (variant.Type == AlleleCategory.Mnv) { ProcessVariant(source, variant); if (IsCallable(variant)) { callableAlleles.Add(variant); } else { failedMnvs.Add(variant); } } else { callableAlleles.Add(variant); } } var leftoversInNextBlock = MnvReallocator.ReallocateFailedMnvs(failedMnvs, callableAlleles, maxPosition); source.AddCandidates(leftoversInNextBlock.Select(AlleleHelper.Map)); source.AddGappedMnvRefCount(GetRefSupportFromGappedMnvs(callableAlleles)); var calledAllelesByPosition = new SortedList <int, List <CalledAllele> >(); // foreach (var failedMNV in failedMnvs) { //if any of these failed MNVs was an injected ForcedGT varaint, we need to spike it back in, //so it still gets reported to the VCF if (IsForcedAllele(failedMNV)) { callableAlleles.Add(failedMNV); } } // need to re-process variants since they may have additional support foreach (var baseCalledAllele in callableAlleles) { ProcessVariant(source, baseCalledAllele); if (IsForcedAllele(baseCalledAllele) && !(IsCallable(baseCalledAllele) && ShouldReport(baseCalledAllele))) { baseCalledAllele.IsForcedToReport = true; baseCalledAllele.AddFilter(FilterType.ForcedReport); } if ((IsCallable(baseCalledAllele) && ShouldReport(baseCalledAllele)) || IsForcedAllele(baseCalledAllele)) { List <CalledAllele> calledAtPosition; if (!calledAllelesByPosition.TryGetValue(baseCalledAllele.ReferencePosition, out calledAtPosition)) { calledAtPosition = new List <CalledAllele>(); calledAllelesByPosition.Add(baseCalledAllele.ReferencePosition, calledAtPosition); } calledAtPosition.Add(baseCalledAllele); } } // re-process variants by loci to get GT (to potentially take into account multiple var alleles at same loci) // and prune allele lists as needed. foreach (var allelesAtPosition in calledAllelesByPosition.Values) { ComputeGenotypeAndFilterAllele(allelesAtPosition); _locusProcessor.Process(allelesAtPosition); } return(calledAllelesByPosition); }