예제 #1
0
        /// <summary>
        /// Gets the reference sequence alignment length depending on the CIGAR value.
        /// </summary>
        /// <returns>Length of the alignment.</returns>
        private int GetRefSeqAlignmentLengthFromCIGAR()
        {
            const string CIGARforClen = "MDNX=";

            if (string.IsNullOrWhiteSpace(CIGAR) || CIGAR.Equals("*"))
            {
                return(DefaultReadLength);
            }

            var charsAndPositions = new List <KeyValuePair <char, int> >();

            for (int i = 0; i < CIGAR.Length; i++)
            {
                char ch = CIGAR[i];
                if (Char.IsDigit(ch))
                {
                    continue;
                }
                charsAndPositions.Add(new KeyValuePair <char, int>(ch, i));
            }
            int len = 0;

            for (int i = 0; i < charsAndPositions.Count; i++)
            {
                char ch = charsAndPositions[i].Key;
                if (CIGARforClen.Contains(ch))
                {
                    int start = i == 0 ? 0 : charsAndPositions[i - 1].Value + 1;
                    int end   = charsAndPositions[i].Value - start;
                    len += int.Parse(CIGAR.Substring(start, end), CultureInfo.InvariantCulture);
                }
            }
            return(len);
        }
예제 #2
0
        /// <summary>
        /// Gets the read sequence length depending on the CIGAR value.
        /// </summary>
        /// <returns>Length of the read.</returns>
        private int GetReadLengthFromCIGAR()
        {
            if (string.IsNullOrWhiteSpace(CIGAR) || CIGAR.Equals("*"))
            {
                return(DefaultReadLength);
            }

            List <char>           chars = new List <char>();
            Dictionary <int, int> dic   = new Dictionary <int, int>();

            for (int i = 0; i < CIGAR.Length; i++)
            {
                char ch = CIGAR[i];
                if (Char.IsDigit(ch))
                {
                    continue;
                }

                chars.Add(ch);
                dic.Add(chars.Count - 1, i);
            }

            string CIGARforClen = "MDN";
            int    len          = 0;

            for (int i = 0; i < chars.Count; i++)
            {
                char ch    = chars[i];
                int  start = 0;
                int  end   = 0;
                if (CIGARforClen.Contains(ch))
                {
                    if (i == 0)
                    {
                        start = 0;
                    }
                    else
                    {
                        start = dic[i - 1] + 1;
                    }

                    end = dic[i] - start;

                    len += int.Parse(CIGAR.Substring(start, end), CultureInfo.InvariantCulture);
                }
            }

            return(len);
        }
예제 #3
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);
        }