Exemplo n.º 1
0
        public static CigarAlignment GetReverse(this CigarAlignment cigar)
        {
            var reverseCigar = new CigarAlignment(cigar);

            reverseCigar.Reverse();

            return(reverseCigar);
        }
Exemplo n.º 2
0
        public static CigarAlignment GetReadCigarFromStitched(string stitchedCigar, int readLength, bool reverse)
        {
            var cigar = new CigarAlignment(stitchedCigar);

            if (reverse)
            {
                cigar.Reverse();
            }

            var totalLengthSofar = 0;
            var newCigar         = new CigarAlignment();

            for (var i = 0; i < cigar.Count; i++)
            {
                var operation = cigar[i];
                if (operation.IsReadSpan())
                {
                    if (totalLengthSofar + operation.Length > readLength)
                    {
                        newCigar.Add(new CigarOp(operation.Type, (uint)(readLength - totalLengthSofar)));
                        break;
                    }

                    newCigar.Add(operation);
                    totalLengthSofar += (int)operation.Length;

                    if (totalLengthSofar == readLength)
                    {
                        break;
                    }
                }
                else
                {
                    newCigar.Add(operation);
                }
            }

            if (reverse)
            {
                newCigar.Reverse();
            }

            return(newCigar);
        }
Exemplo n.º 3
0
        public void CigarString_Manipulation_Tests()
        {
            var cigarstring = new CigarAlignment("7M3I2D1S11M2S");

            Assert.Equal(6, cigarstring.Count);
            Assert.Equal("7M3I2D1S11M2S", cigarstring.ToString());

            cigarstring.Add(new CigarOp('M', 6));
            Assert.Equal("7M3I2D1S11M2S6M", cigarstring.ToString());
            Assert.Equal(7, cigarstring.Count);

            cigarstring.Reverse();
            Assert.Equal("6M2S11M1S2D3I7M", cigarstring.ToString());
            Assert.Equal(7, cigarstring.Count);

            cigarstring.Clear();
            Assert.Equal("", cigarstring.ToString());
            Assert.Equal(0, cigarstring.Count);
        }
Exemplo n.º 4
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);
        }