Beispiel #1
0
        public void GetEmptySummaryForAmpliconTest()
        {
            AmpliconCounts exampleCounts = AmpliconCounts.GetEmptyAmpliconCounts();

            Assert.Equal(Constants.MaxNumOverlappingAmplicons, exampleCounts.AmpliconNames.Length);
            Assert.Equal(Constants.MaxNumOverlappingAmplicons, exampleCounts.CountsForAmplicon.Length);

            Assert.Equal(0, exampleCounts.GetCountsForAmplicon("amp1"));
            Assert.Equal(0, exampleCounts.GetCountsForAmplicon("amp2"));
            Assert.Equal(0, exampleCounts.GetCountsForAmplicon("amp3"));
            Assert.Equal(0, exampleCounts.GetCountsForAmplicon(""));
            Assert.Equal(0, exampleCounts.GetCountsForAmplicon("foo"));
        }
        private static void SetAmpliconName(bool trackAmpliconCounts, Read alignment, CandidateAllele variant)
        {
            if (!trackAmpliconCounts)
            {
                return;
            }

            var ampliconName = alignment.GetAmpliconNameIfExists();

            if (ampliconName != null)
            {
                var summary = AmpliconCounts.GetEmptyAmpliconCounts();
                summary.AmpliconNames[0]     = ampliconName;
                summary.CountsForAmplicon[0] = 1;
                variant.SupportByAmplicon    = summary;
            }
        }
        public void AddSupport(CandidateAllele fromAllele)
        {
            for (var i = 0; i < SupportByDirection.Length; i++)
            {
                SupportByDirection[i] += fromAllele.SupportByDirection[i];
            }

            for (var i = 0; i < WellAnchoredSupportByDirection.Length; i++)
            {
                WellAnchoredSupportByDirection[i] += fromAllele.WellAnchoredSupportByDirection[i];
            }

            if (fromAllele.SupportByAmplicon.AmpliconNames != null && fromAllele.SupportByAmplicon.AmpliconNames.Length > 0)
            {
                if (SupportByAmplicon.AmpliconNames == null || SupportByAmplicon.AmpliconNames.Length == 0)
                {
                    SupportByAmplicon = AmpliconCounts.GetEmptyAmpliconCounts();
                }

                for (var i = 0; i < fromAllele.SupportByAmplicon.AmpliconNames.Length; i++)
                {
                    var fromAlleleCount = fromAllele.SupportByAmplicon.CountsForAmplicon[i];
                    var fromAlleleName  = fromAllele.SupportByAmplicon.AmpliconNames[i];
                    var indexData       = SupportByAmplicon.GetAmpliconNameIndex(fromAlleleName);

                    if (indexData.IndexForAmplicon > -1)
                    {
                        SupportByAmplicon.CountsForAmplicon[indexData.IndexForAmplicon] += fromAlleleCount;
                    }
                    else
                    {
                        SupportByAmplicon.AmpliconNames[indexData.NextOpenSlot]      = fromAlleleName;
                        SupportByAmplicon.CountsForAmplicon[indexData.NextOpenSlot] += fromAlleleCount;
                    }
                }
            }
        }
Beispiel #4
0
        public void AddCandidate(CandidateAllele newCandidate, bool trackOpenEnded, bool trackAmplicon)
        {
            if (newCandidate.Type == AlleleCategory.Reference)
            {
                throw new ArgumentException(string.Format("Unable to add candidate '{0}': reference candidates are not tracked.", newCandidate));
            }

            if (!IsPositionInRegion(newCandidate.ReferencePosition))
            {
                throw new ArgumentException(string.Format("Unable to add candidate at position {0} to region '{1}'",
                                                          newCandidate.ReferencePosition, Name));
            }

            var regionIndex        = newCandidate.ReferencePosition - StartPosition;
            var existingCandidates = _candidateVariantsLookup[regionIndex];

            if (existingCandidates == null)
            {
                _candidateVariantsLookup[regionIndex] = new List <CandidateAllele> {
                    newCandidate
                }
            }
            ;
            else
            {
                //TJD - this used to be a hash table, not a find,
                //where each variants unique signature was the key.
                //this might be why we have seen a performance hit in the new pisces.

                var foundAtIndex = trackOpenEnded ?
                                   existingCandidates.FindIndex(c => c.Equals(newCandidate) &&
                                                                c.OpenOnLeft == newCandidate.OpenOnLeft &&
                                                                c.OpenOnRight == newCandidate.OpenOnRight) :
                                   existingCandidates.FindIndex(c => c.Equals(newCandidate));

                if (foundAtIndex == -1)
                {
                    existingCandidates.Add(newCandidate);
                }
                else
                {
                    var existingMatch = existingCandidates[foundAtIndex];

                    for (var i = 0; i < existingMatch.SupportByDirection.Length; i++)
                    {
                        existingMatch.SupportByDirection[i] += newCandidate.SupportByDirection[i];
                    }

                    for (var i = 0; i < existingMatch.WellAnchoredSupportByDirection.Length; i++)
                    {
                        existingMatch.WellAnchoredSupportByDirection[i] += newCandidate.WellAnchoredSupportByDirection[i];
                    }

                    for (var i = 0; i < existingMatch.ReadCollapsedCountsMut.Length; i++)
                    {
                        existingMatch.ReadCollapsedCountsMut[i] += newCandidate.ReadCollapsedCountsMut[i];
                    }

                    if ((trackAmplicon) && (newCandidate.SupportByAmplicon.AmpliconNames != null))
                    {
                        string[] ampliconList = newCandidate.SupportByAmplicon.AmpliconNames;
                        for (var i = 0; i < ampliconList.Length; i++)
                        {
                            var ampliconName = ampliconList[i];
                            if (ampliconName == null)
                            {
                                continue;
                            }

                            if (existingMatch.SupportByAmplicon.AmpliconNames == null || existingMatch.SupportByAmplicon.AmpliconNames.Length == 0)
                            {
                                existingMatch.SupportByAmplicon = AmpliconCounts.GetEmptyAmpliconCounts();
                            }

                            var existingAmpliconIndexData = existingMatch.SupportByAmplicon.GetAmpliconNameIndex(ampliconName);

                            var ampliconIndex = existingAmpliconIndexData.IndexForAmplicon;
                            var availableSlot = existingAmpliconIndexData.NextOpenSlot;

                            if (ampliconIndex == -1)
                            {
                                existingMatch.SupportByAmplicon.AmpliconNames[availableSlot]     = ampliconName;
                                existingMatch.SupportByAmplicon.CountsForAmplicon[availableSlot] = 1;
                            }
                            else
                            {
                                existingMatch.SupportByAmplicon.AmpliconNames[ampliconIndex] = ampliconName;
                                existingMatch.SupportByAmplicon.CountsForAmplicon[ampliconIndex]++;
                            }
                        }
                    }
                }
            }


            UpdateMaxPosition(newCandidate);
        }