Example #1
0
        // make sure individual read cigars make sense against stitched cigar
        protected static void ValidateCigar(CigarAlignment stitchedCigar, CigarAlignment read1Cigar, CigarAlignment read2Cigar)
        {
            if (!stitchedCigar.IsSupported())
            {
                throw new Exception(String.Format("Unsupported cigar: {0}", stitchedCigar));
            }

            ValidateCigar(stitchedCigar, read1Cigar);
            ValidateCigar(stitchedCigar.GetReverse(), read2Cigar.GetReverse());
        }
Example #2
0
        // trim a cigar string up to a specified read length, cigar operations that don't span a read are taken as is
        public static CigarAlignment GetTrimmed(this CigarAlignment cigar, int readCycles, bool fromEnd = false, bool includeEndDels = true)
        {
            var numBases    = 0;
            var sourceCigar = fromEnd ? cigar.GetReverse() : cigar;

            var trimmedCigar = new CigarAlignment();

            if (readCycles > 0)
            {
                for (var i = 0; i < sourceCigar.Count; i++)
                {
                    var operation = sourceCigar[i];
                    if (!operation.IsReadSpan())
                    {
                        if (numBases < readCycles || includeEndDels)
                        {
                            trimmedCigar.Add(operation); // doesn't contribute any read cycles (e.g. deletion), just add
                        }
                    }
                    else if (operation.Length + numBases <= readCycles)
                    {
                        trimmedCigar.Add(operation);
                        numBases += (int)operation.Length;
                    }
                    else
                    {
                        if (readCycles - numBases > 0)
                        {
                            trimmedCigar.Add(new CigarOp(operation.Type, (uint)(readCycles - numBases)));
                        }
                        break;
                    }
                }
            }

            if (fromEnd)
            {
                trimmedCigar.Reverse();
            }

            return(trimmedCigar);
        }