Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void HasSoftclips()
        {
            var cigar = new CigarAlignment("1S5M");

            Assert.True(cigar.HasSoftclips);

            cigar = new CigarAlignment("5M1S");
            Assert.True(cigar.HasSoftclips);

            cigar = new CigarAlignment("5M");
            Assert.False(cigar.HasSoftclips);

            cigar.Add(new CigarOp('S', 1));
            Assert.True(cigar.HasSoftclips);

            cigar.Clear();
            Assert.False(cigar.HasSoftclips);

            cigar.Add(new CigarOp('S', 1));
            Assert.True(cigar.HasSoftclips);
        }
Ejemplo n.º 3
0
        public void HasIndels()
        {
            var cigar = new CigarAlignment("1M1I5M");

            Assert.True(cigar.HasIndels);

            cigar = new CigarAlignment("1M1D5M");
            Assert.True(cigar.HasIndels);

            cigar = new CigarAlignment("5M");
            Assert.False(cigar.HasIndels);

            cigar.Add(new CigarOp('I', 1));
            Assert.True(cigar.HasIndels);

            cigar.Clear();
            Assert.False(cigar.HasIndels);

            cigar.Add(new CigarOp('I', 1));
            Assert.True(cigar.HasIndels);
        }
Ejemplo n.º 4
0
        public static CigarAlignment GetClippedCigar(this CigarAlignment cigar, int start, int end, bool includeEndDels = true, bool includeWholeEndIns = false)
        {
            var numBases    = 0;
            var sourceCigar = cigar;

            var readCycles = end - start;

            var trimmedCigar = new CigarAlignment();

            var  prefixDels      = new CigarAlignment();
            bool lastWasDeletion = false;

            if (readCycles > 0)
            {
                for (var i = 0; i < sourceCigar.Count; i++)
                {
                    var operation = sourceCigar[i];

                    if (operation.IsReadSpan() && numBases + operation.Length - 1 < start)
                    {
                        lastWasDeletion = false;
                        numBases       += (int)operation.Length;
                        continue;
                    }

                    if (!operation.IsReadSpan())
                    {
                        if (prefixDels.Count > 0 && !lastWasDeletion)
                        {
                            prefixDels.Clear();
                        }
                        if (trimmedCigar.Count == 0 && includeEndDels)
                        {
                            prefixDels.Add(operation);
                        }

                        if (trimmedCigar.Count > 0 && (numBases < readCycles || includeEndDels))
                        {
                            trimmedCigar.Add(operation); // doesn't contribute any read cycles (e.g. deletion), just add
                        }
                    }
                    else if (operation.Length + numBases <= end)
                    {
                        if (lastWasDeletion && prefixDels.Count > 0)
                        {
                            foreach (CigarOp prefixDel in prefixDels)
                            {
                                trimmedCigar.Add(prefixDel);
                            }
                        }
                        trimmedCigar.Add(operation);
                        numBases += (int)operation.Length;
                    }
                    else
                    {
                        if (lastWasDeletion && prefixDels.Count > 0)
                        {
                            foreach (CigarOp prefixDel in prefixDels)
                            {
                                trimmedCigar.Add(prefixDel);
                            }
                        }
                        if (end - numBases > 0)
                        {
                            if (includeWholeEndIns && operation.Type == 'I')
                            {
                                trimmedCigar.Add(new CigarOp(operation.Type, operation.Length));
                            }
                            else
                            {
                                trimmedCigar.Add(new CigarOp(operation.Type, (uint)(end - numBases)));
                            }
                        }
                        break;
                    }

                    lastWasDeletion = operation.Type == 'D';
                }
            }

            //for (var i = 0; i < sourceCigar.Count; i++)
            //{
            //    if (numBases >= end)
            //    {
            //        break;
            //    }

            //    var operation = sourceCigar[i];
            //    if (!operation.IsReadSpan())
            //    {
            //        if (numBases >= start && numBases <= end || includeEndDels)
            //            trimmedCigar.Add(operation); // doesn't contribute any read cycles (e.g. deletion), just add
            //        continue;
            //    }

            //    if (operation.Length + numBases >= end)
            //    {
            //        if (end - numBases > 0)
            //            trimmedCigar.Add(new CigarOp(operation.Type, (uint)(end - numBases - start)));
            //        //break;
            //    }
            //    else
            //    {
            //        if (operation.Length + numBases >= start)
            //        {
            //            trimmedCigar.Add(operation);
            //        }
            //    }


            //    if (operation.IsReadSpan())
            //    {
            //        numBases += (int)operation.Length;
            //    }

            //}

            trimmedCigar.Compress();

            return(trimmedCigar);
        }