Ejemplo 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()
        {
            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);
        }
Ejemplo n.º 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);
        }