Example #1
0
        /// <summary>
        ///     If duplicated adjacent tags are present, reduce them to one copy
        /// </summary>
        /// <returns>true if cigar was altered by compression</returns>
        public bool Compress()
        {
            var newDirections = DirectionHelper.CompressDirections(Directions);

            Directions = newDirections;
            return(true);
        }
        private static string RecalculateApproximateStitchedDirections(CigarDirection cigarDirections, CigarAlignment cigarData, CigarAlignment newCigarData)
        {
            var cigarBaseDirectionMap = cigarDirections.Expand().ToArray();

            var cigarBaseAlleleMap    = cigarData.Expand();
            var newCigarBaseAlleleMap = newCigarData.Expand();

            var sequencedBaseDirectionMap = new DirectionType[cigarData.GetReadSpan()];

            var directions = new List <DirectionOp>();

            var sequencedBaseIndex = 0;

            var cigarBaseIndex    = 0;
            var newCigarBaseIndex = 0;

            while (true)
            {
                if (cigarBaseIndex >= cigarBaseAlleleMap.Count || newCigarBaseIndex >= newCigarBaseAlleleMap.Count)
                {
                    // If new is longer than old, fill out the rest with the last direction of the old cigar
                    if (newCigarBaseIndex < newCigarBaseAlleleMap.Count)
                    {
                        directions.Add(new DirectionOp(cigarBaseDirectionMap[cigarBaseIndex - 1], newCigarBaseAlleleMap.Count - newCigarBaseIndex));
                    }

                    break;
                }

                while (!cigarBaseAlleleMap[cigarBaseIndex].IsReadSpan())
                {
                    // Skip these
                    cigarBaseIndex++;

                    // TODO is it ever possible to go off the end here?
                }

                while (!newCigarBaseAlleleMap[newCigarBaseIndex].IsReadSpan())
                {
                    directions.Add(new DirectionOp(cigarBaseDirectionMap[cigarBaseIndex], 1)); // TODO perhaps something more nuanced here? unclear what the best solution is. For now, just be consistent: take the last one that we were on at this point in the old cigar
                    newCigarBaseIndex++;

                    // TODO is it ever possible to go off the end here?
                }

                sequencedBaseDirectionMap[sequencedBaseIndex] = cigarBaseDirectionMap[cigarBaseIndex];
                directions.Add(new DirectionOp(cigarBaseDirectionMap[cigarBaseIndex], 1));
                sequencedBaseIndex++;

                cigarBaseIndex++;
                newCigarBaseIndex++;
            }

            var compressedDirections = DirectionHelper.CompressDirections(directions);

            return(new CigarDirection(compressedDirections).ToString());
        }