Exemplo n.º 1
0
        /// <summary>
        /// Gets the reference sequence alignment length depending on the CIGAR value.
        /// </summary>
        /// <returns>Length of the alignment.</returns>
        private int GetRefSeqAlignmentLengthFromCIGAR()
        {
            if (string.IsNullOrWhiteSpace(CIGAR) || CIGAR.Equals("*"))
            {
                return(DefaultReadLength);
            }
            var elements = CigarUtils.GetCigarElements(CIGAR);
            int len      = 0;

            foreach (var v in elements)
            {
                if (CigarUtils.CigarElementis_MDNX_Equal(v.Operation))
                {
                    len += v.Length;
                }
            }
            return(len);
        }
        public int?GetReadIndexOfAlignmentPosition(int referencePosition)
        {
            if (string.IsNullOrWhiteSpace(CIGAR) || CIGAR.Equals("*"))
            {
                return(null);
            }
            int curRef   = this.Pos;     //location on ref
            int curQuery = 0;            //location on query

            if (curRef == referencePosition)
            {
                return(curQuery);
            }
            var    elements     = CigarUtils.GetCigarElements(CIGAR);
            string CIGARforClen = "MDNX=";

            foreach (var e in elements)
            {
                char ch = e.Operation;
                if (ch == 'P' || ch == 'N')
                {
                    throw new Exception("Not built to handle clipping yet");
                }
                int start = 0;
                int end   = 0;
                int len;
                if (CigarUtils.CigarElementis_MDNX_Equal(ch))
                {
                    len = e.Length;
                    bool addRef   = false;
                    bool addQuery = false;
                    if (ch == 'M' || ch == '=' || ch == 'X')
                    {
                        addRef   = true;
                        addQuery = true;
                    }
                    else if (ch == 'D')
                    {
                        addRef = true;
                    }
                    else if (ch == 'I' || ch == 'S' || ch == 'H')
                    {
                        addQuery = true;
                    }
                    for (int j = 0; j < len; j++)
                    {
                        if (addRef)
                        {
                            curRef++;
                        }
                        if (addQuery)
                        {
                            curQuery++;
                        }
                        if (curRef == referencePosition && addQuery)
                        {
                            return(curQuery);
                        }
                    }
                    if (curRef > referencePosition)
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }