Exemplo n.º 1
0
        public CandidateAllele(string chromosome, int coordinate, string reference, string alternate, AlleleCategory type)
        {
            Type       = type;
            Chromosome = chromosome;
            Coordinate = coordinate;
            Reference  = reference;
            Alternate  = alternate;

            if (string.IsNullOrEmpty(chromosome))
            {
                throw new ArgumentException("Chromosome is empty.");
            }

            if (coordinate < 0)
            {
                throw new ArgumentException(string.Format("Coordinate {0} is invalid.", coordinate));
            }

            if (string.IsNullOrEmpty(reference))
            {
                throw new ArgumentException("Reference is empty.");
            }

            if (string.IsNullOrEmpty(alternate))
            {
                throw new ArgumentException("Alternate is empty.");
            }

            SupportByDirection  = new int[Constants.NumDirectionTypes];
            ReadCollapsedCounts = new int[Constants.NumReadCollapsedTypes];
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new candidate allele from alignment and add support.  Exposed only for unit testing.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="chromosome"></param>
        /// <param name="coordinate"></param>
        /// <param name="reference"></param>
        /// <param name="alternate"></param>
        /// <param name="alignment"></param>
        /// <param name="startIndexInRead"></param>
        /// <returns></returns>
        public static CandidateAllele Create(AlleleCategory type, string chromosome, int coordinate, string reference,
                                             string alternate, Read alignment, int startIndexInRead)
        {
            var candidate = new CandidateAllele(chromosome, coordinate, reference, alternate, type);
            var alleleSupportDirection = GetSupportDirection(candidate, alignment, startIndexInRead);

            candidate.SupportByDirection[(int)alleleSupportDirection]++;

            if (alignment.IsDuplex)
            {
                if (alleleSupportDirection == DirectionType.Stitched)
                {
                    candidate.ReadCollapsedCounts[(int)ReadCollapsedType.DuplexStitched]++;
                }
                else
                {
                    candidate.ReadCollapsedCounts[(int)ReadCollapsedType.DuplexNonStitched]++;
                }
            }
            else
            {
                if (alleleSupportDirection == DirectionType.Stitched)
                {
                    candidate.ReadCollapsedCounts[(int)ReadCollapsedType.SimplexStitched]++;
                }
                else
                {
                    candidate.ReadCollapsedCounts[(int)ReadCollapsedType.SimplexNonStitched]++;
                }
            }
            return(candidate);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new candidate allele from alignment and add support.  Exposed only for unit testing.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="chromosome"></param>
        /// <param name="coordinate"></param>
        /// <param name="reference"></param>
        /// <param name="alternate"></param>
        /// <param name="alignment"></param>
        /// <param name="startIndexInRead"></param>
        /// <returns></returns>
        public static CandidateAllele Create(AlleleCategory type, string chromosome, int coordinate, string reference,
                                             string alternate, Read alignment, int startIndexInRead)
        {
            var candidate = new CandidateAllele(chromosome, coordinate, reference, alternate, type);

            candidate.SupportByDirection[(int)GetSupportDirection(candidate, alignment, startIndexInRead)]++;

            return(candidate);
        }
Exemplo n.º 4
0
        private bool TestVariant(AlleleReader vr, AlleleCategory type)
        {
            var testVarList = new List <CalledAllele>()
            {
                new CalledAllele()
            };

            vr.GetNextVariants(out testVarList);
            return(testVarList[0].Type == type);
        }
Exemplo n.º 5
0
 public CalledAllele(AlleleCategory type)
 {
     Filters = new List <FilterType>();
     EstimatedCoverageByDirection = new int[Constants.NumDirectionTypes];
     StrandBiasResults            = new StrandBiasResults();
     SupportByDirection           = new int[Constants.NumDirectionTypes];
     ReadCollapsedCounts          = new int[Constants.NumReadCollapsedTypes];
     Genotype = Genotype.HeterozygousAltRef;
     Type     = type;
     if (Type == AlleleCategory.Reference)
     {
         Genotype = Genotype.HomozygousRef;
     }
 }
Exemplo n.º 6
0
        private void ExecuteTest(AlleleCategory variantType, DirectionType?expectedDirection, ReadCoverageSummary readSummary,
                                 int variantPosition = 10)
        {
            var calculator = new ExactCoverageCalculator();
            var allele     = new CalledAllele(variantType)
            {
                Coordinate = variantPosition
            };

            switch (allele.Type)
            {
            case AlleleCategory.Insertion:
                allele.Reference = "A";
                allele.Alternate = "ATTTT";
                break;

            case AlleleCategory.Deletion:
                allele.Alternate = "A";
                allele.Reference = "ATTTT";
                break;

            default:
                allele.Reference = "AAAA";
                allele.Alternate = "TTTT";
                break;
            }
            var source = new Mock <IAlleleSource>();

            source.Setup(s => s.GetSpanningReadSummaries(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(new List <ReadCoverageSummary> {
                readSummary
            });

            calculator.Compute(allele, source.Object);

            for (var i = 0; i < allele.EstimatedCoverageByDirection.Length; i++)
            {
                Assert.Equal(expectedDirection.HasValue && i == (int)expectedDirection ? 1 : 0, allele.EstimatedCoverageByDirection[i]);
            }
        }
Exemplo n.º 7
0
        private void ExecuteRMxNTest(string variantBases, string referenceSequence, int expectedRepeatLength, AlleleCategory category, int maxRepeatUnitLength)
        {
            var alleleCoordinate       = referenceSequence.IndexOf('*');
            var cleanReferenceSequence = referenceSequence.Replace("*", "");

            var refAllele = "";
            var altAllele = "";

            if (category == AlleleCategory.Insertion)
            {
                refAllele = cleanReferenceSequence.Substring(alleleCoordinate - 1, 1);
                altAllele = refAllele + variantBases;
            }
            else if (category == AlleleCategory.Deletion)
            {
                altAllele = cleanReferenceSequence.Substring(alleleCoordinate - 1, 1);
                refAllele = altAllele + variantBases;
            }
            else
            {
                refAllele = cleanReferenceSequence.Substring(alleleCoordinate - 1, variantBases.Length);
                altAllele = variantBases;
            }

            var allele = new CalledAllele(category)
            {
                ReferenceAllele   = refAllele,
                AlternateAllele   = altAllele,
                ReferencePosition = alleleCoordinate
            };

            RMxNFilterSettings rmxnFilterSettings = new RMxNFilterSettings();

            rmxnFilterSettings.RMxNFilterFrequencyLimit  = 1.1f;
            rmxnFilterSettings.RMxNFilterMaxLengthRepeat = maxRepeatUnitLength;
            rmxnFilterSettings.RMxNFilterMinRepetitions  = expectedRepeatLength;

            // If expected repeats == N, flag
            AlleleProcessor.Process(allele, 0.01f, 0, 0,
                                    true, 0, 0, null, rmxnFilterSettings, 0.6f, new ChrReference()
            {
                Sequence = cleanReferenceSequence
            });
            Assert.True(allele.Filters.Contains(FilterType.RMxN));

            // If expected repeats > N, flag
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength - 1;

            AlleleProcessor.Process(allele, 0.01f, 0, 0,
                                    true, 0, 0, null, rmxnFilterSettings, 0.6f, new ChrReference()
            {
                Sequence = cleanReferenceSequence
            });

            Assert.True(allele.Filters.Contains(FilterType.RMxN));

            // If expected repeats < N, flag
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength + 1;

            AlleleProcessor.Process(allele, 0.01f, 0, 0,
                                    true, 0, 0, null, rmxnFilterSettings, 0.6f, new ChrReference()
            {
                Sequence = cleanReferenceSequence
            });

            Assert.False(allele.Filters.Contains(FilterType.RMxN));

            // RMxN isn't valid on reference calls
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength + 1;

            AlleleProcessor.Process(new CalledAllele()
            {
            }, 0.01f, 0, 0,
                                    true, 0, 0, null, rmxnFilterSettings, 0.6f, new ChrReference()
            {
                Sequence = cleanReferenceSequence
            });

            Assert.False(allele.Filters.Contains(FilterType.RMxN));
        }
Exemplo n.º 8
0
        private void ExecuteRMxNTest(string variantBases, string referenceSequence, int expectedRepeatLength, AlleleCategory category, double allelefrequency, int maxRepeatUnitLength)
        {
            var alleleCoordinate       = referenceSequence.IndexOf('*');
            var cleanReferenceSequence = referenceSequence.Replace("*", "");

            var refAllele = "";
            var altAllele = "";

            if (category == AlleleCategory.Insertion)
            {
                refAllele = cleanReferenceSequence.Substring(alleleCoordinate - 1, 1);
                altAllele = refAllele + variantBases;
            }
            else if (category == AlleleCategory.Deletion)
            {
                altAllele = cleanReferenceSequence.Substring(alleleCoordinate - 1, 1);
                refAllele = altAllele + variantBases;
            }
            else
            {
                refAllele = cleanReferenceSequence.Substring(alleleCoordinate - 1, variantBases.Length);
                altAllele = variantBases;
            }

            var allele = new CalledAllele(category)
            {
                Reference  = refAllele,
                Alternate  = altAllele,
                Coordinate = alleleCoordinate
            };

            allele.TotalCoverage = 1000;
            allele.AlleleSupport = (int)(1000.0 * variantFrequncy);

            RMxNFilterSettings rmxnFilterSettings = new RMxNFilterSettings();

            rmxnFilterSettings.RMxNFilterFrequencyLimit  = 1.1f;
            rmxnFilterSettings.RMxNFilterMaxLengthRepeat = maxRepeatUnitLength;
            rmxnFilterSettings.RMxNFilterMinRepetitions  = expectedRepeatLength;

            // If expected repeats == N, flag
            Assert.True(RMxNCalculator.ShouldFilter(allele, rmxnFilterSettings, cleanReferenceSequence));

            // If expected repeats > N, flag
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength - 1;
            Assert.True(RMxNCalculator.ShouldFilter(allele, rmxnFilterSettings, cleanReferenceSequence));

            // If expected repeats < N, flag
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength + 1;
            Assert.False(RMxNCalculator.ShouldFilter(allele, rmxnFilterSettings, cleanReferenceSequence));

            // RMxN isn't valid on reference calls
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength + 1;
            Assert.False(RMxNCalculator.ShouldFilter(allele, rmxnFilterSettings, cleanReferenceSequence));

            // Even if expected repeats == N, dont flag if VF is too high
            rmxnFilterSettings.RMxNFilterFrequencyLimit = 0.10f;
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength;
            Assert.False(RMxNCalculator.ShouldFilter(allele, rmxnFilterSettings, cleanReferenceSequence));

            // Even if expected repeats > N, flag, dont flag if VF is too high
            rmxnFilterSettings.RMxNFilterFrequencyLimit = 0.10f;
            rmxnFilterSettings.RMxNFilterMinRepetitions = expectedRepeatLength - 1;
            Assert.False(RMxNCalculator.ShouldFilter(allele, rmxnFilterSettings, cleanReferenceSequence));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Warning. This algorithm has an inherent assumption:
        /// the VS must be in order of their true position (first base of difference).
        /// Thats not always how they appeared in the vcf.
        /// </summary>
        /// <param name="allele"></param>
        /// <param name="clusterVariantSites"></param>
        /// <param name="referenceSequence"></param>
        /// <param name="neighborhoodDepthAtSites"></param>
        /// <param name="clusterCountsAtSites"></param>
        /// <param name="chromosome"></param>
        /// <returns></returns>

        public static CalledAllele Create(string chromosome, int alleleCoordinate, string alleleReference,
                                          string alleleAlternate, int varCount, int noCallCount, int totalCoverage, int refSpt, AlleleCategory category, int qNoiselevel, int maxQscore)
        {
            if (totalCoverage < varCount)  //sometimes the orignal vcf and the bam dont agree...
            {
                totalCoverage = varCount;
            }

            // Nima: Commented this line for pics-1017
            //refSpt = totalCoverage - varCount;

            if (category == AlleleCategory.Reference)
            {
                refSpt = varCount;
            }

            var allele = new CalledAllele(category)
            {
                Chromosome        = chromosome,
                ReferencePosition = alleleCoordinate,
                ReferenceAllele   = alleleReference,
                AlternateAllele   = alleleAlternate,
                TotalCoverage     = totalCoverage,
                Type              = category,
                AlleleSupport     = varCount,
                ReferenceSupport  = refSpt,
                NumNoCalls        = noCallCount,
                VariantQscore     = VariantQualityCalculator.AssignPoissonQScore(varCount, totalCoverage, qNoiselevel, maxQscore),
                NoiseLevelApplied = qNoiselevel
            };

            allele.SetFractionNoCalls();
            return(allele);
        }
        /// <summary>
        /// Create a new candidate allele from alignment and add support.  Exposed only for unit testing.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="chromosome"></param>
        /// <param name="coordinate"></param>
        /// <param name="reference"></param>
        /// <param name="alternate"></param>
        /// <param name="alignment"></param>
        /// <param name="startIndexInRead"></param>
        /// <param name="wellAnchoredAnchorSize"></param>
        /// <returns></returns>
        public static CandidateAllele Create(AlleleCategory type, string chromosome, int coordinate, string reference,
                                             string alternate, Read alignment, int startIndexInRead, int wellAnchoredAnchorSize)
        {
            var candidate = new CandidateAllele(chromosome, coordinate, reference, alternate, type);
            var alleleSupportDirection = GetSupportDirection(candidate, alignment, startIndexInRead);

            candidate.SupportByDirection[(int)alleleSupportDirection]++;
            var anchor = Math.Min(coordinate - alignment.Position, alignment.EndPosition - coordinate);

            if (anchor > Math.Min(wellAnchoredAnchorSize - 1, alternate.Length - 1))
            {
                candidate.WellAnchoredSupportByDirection[(int)alleleSupportDirection]++;
            }

            if (alignment.IsCollapsedRead())
            {
                ReadCollapsedType?collapsedType = alignment.GetReadCollapsedType(alleleSupportDirection);
                if (collapsedType.HasValue) // ignore non-proper read pairs
                {
                    switch (collapsedType.Value)
                    {
                    case ReadCollapsedType.DuplexNonStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.DuplexNonStitched]++;
                        break;

                    case ReadCollapsedType.DuplexStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.DuplexStitched]++;
                        break;

                    case ReadCollapsedType.SimplexStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexStitched]++;
                        break;

                    case ReadCollapsedType.SimplexReverseStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexStitched]++;
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexReverseStitched]++;
                        break;

                    case ReadCollapsedType.SimplexForwardStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexStitched]++;
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexForwardStitched]++;
                        break;

                    case ReadCollapsedType.SimplexNonStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexNonStitched]++;
                        break;

                    case ReadCollapsedType.SimplexReverseNonStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexNonStitched]++;
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexReverseNonStitched]++;
                        break;

                    case ReadCollapsedType.SimplexForwardNonStitched:
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexNonStitched]++;
                        candidate.ReadCollapsedCountsMut[(int)ReadCollapsedType.SimplexForwardNonStitched]++;
                        break;

                    default:
                        throw new Exception();
                    }
                }
            }
            return(candidate);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Warning. This algorithm has an inherent assumption:
        /// the VS must be in order of their true position (first base of difference).
        /// Thats not always how they appeared in the vcf.
        /// </summary>
        /// <param name="allele"></param>
        /// <param name="clusterVariantSites"></param>
        /// <param name="referenceSequence"></param>
        /// <param name="neighborhoodDepthAtSites"></param>
        /// <param name="clusterCountsAtSites"></param>
        /// <param name="chromosome"></param>
        /// <returns></returns>

        public static CalledAllele Create(string chromosome, int alleleCoordinate, string alleleReference,
                                          string alleleAlternate, int varCount, int totalCoverage, AlleleCategory category, int qNoiselevel, int maxQscore)
        {
            if (totalCoverage < varCount)  //sometimes the orignal vcf and the bam dont agree...
            {
                totalCoverage = varCount;
            }

            if (category == AlleleCategory.Reference)
            {
                return(new CalledAllele()
                {
                    Chromosome = chromosome,
                    Coordinate = alleleCoordinate,
                    Reference = alleleReference,
                    Alternate = alleleAlternate,
                    TotalCoverage = totalCoverage,
                    AlleleSupport = varCount,
                    ReferenceSupport = varCount,
                    VariantQscore = VariantQualityCalculator.AssignPoissonQScore(varCount, totalCoverage, qNoiselevel, maxQscore)
                });
            }

            return(new CalledAllele(category)
            {
                Chromosome = chromosome,
                Coordinate = alleleCoordinate,
                Reference = alleleReference,
                Alternate = alleleAlternate,
                TotalCoverage = totalCoverage,
                AlleleSupport = varCount,
                ReferenceSupport = totalCoverage - varCount,
                VariantQscore = VariantQualityCalculator.AssignPoissonQScore(varCount, totalCoverage, qNoiselevel, maxQscore)
            });
        }
Exemplo n.º 12
0
 public CalledVariant(AlleleCategory type)
 {
     Genotype = Genotype.HeterozygousAlt;
     Type     = type;
 }