Example #1
0
        /// <summary>
        ///     initialize from SAM CIGAR string:
        /// </summary>
        public CigarAlignment(string cigarString)
            : this()
        {
            if (String.IsNullOrEmpty(cigarString) || (cigarString == "*"))
            {
                return;
            }

            int head = 0;

            for (int i = 0; i < cigarString.Length; ++i)
            {
                if (Char.IsDigit(cigarString, i))
                {
                    continue;
                }
                if (!BamUtilities.ArrayContains(BamConstants.CigarTypes, cigarString[i]))
                {
                    throw new InvalidDataException(string.Format("ERROR: Unexpected format in character {0} of CIGAR string: {1}",
                                                                 (i + 1), cigarString));
                }
                var length = uint.Parse(cigarString.Substring(head, i - head));
                var op     = new CigarOp(cigarString[i], length);
                _data.Add(op);
                head = i + 1;
            }
            if (head != cigarString.Length)
            {
                throw new InvalidDataException(string.Format("ERROR: Unexpected format in CIGAR string: {0}", cigarString));
            }
        }
Example #2
0
        public override bool Equals(Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // Throws an exception if the cast fails.
            CigarOp co = (CigarOp)obj;

            // Return true if the fields match:
            return((Type == co.Type) && (Length == co.Length));
        }
Example #3
0
        /// <summary>
        ///     provide the total trailing soft-clip
        /// </summary>
        public uint GetSuffixClip()
        {
            uint length = 0;

            for (int index = (_data.Count - 1); index >= 0; index--)
            {
                CigarOp op = _data[index];
                if (op.Type == 'S')
                {
                    length += op.Length;
                }
                else if (op.Type != 'H')
                {
                    break;
                }
            }
            return(length);
        }
Example #4
0
        public override bool Equals(Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            CigarOp co = (CigarOp)obj;

            if (co == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((Type == co.Type) && (Length == co.Length));
        }
Example #5
0
        /// <summary>
        ///     if duplicated adjacent tags are present, reduce them to one copy,
        ///     also reduce adjacent insertion/deletion tags to a single pair
        /// </summary>
        /// <returns>true if cigar was altered by compression</returns>
        public bool Compress()
        {
            for (int segmentIndex = 0; segmentIndex < _data.Count; ++segmentIndex)
            {
                if (_data[segmentIndex].Length == 0)
                {
                    continue;
                }
                for (int j = (segmentIndex + 1); j < _data.Count; ++j)
                {
                    if (_data[j].Length == 0)
                    {
                        continue;
                    }
                    if (_data[segmentIndex].Type != _data[j].Type)
                    {
                        break;
                    }
                    _data[segmentIndex] = new CigarOp(_data[segmentIndex].Type, _data[segmentIndex].Length + _data[j].Length);
                    _data[j]            = new CigarOp(_data[j].Type, 0);
                }
            }

            int insertIndex = -1;
            int deleteIndex = -1;

            for (int segmentIndex = 0; segmentIndex < _data.Count; ++segmentIndex)
            {
                if (_data[segmentIndex].Length == 0)
                {
                    continue;
                }
                if (_data[segmentIndex].Type == 'I')
                {
                    if (insertIndex >= 0 && deleteIndex >= 0)
                    {
                        _data[insertIndex]  = new CigarOp(_data[insertIndex].Type, _data[insertIndex].Length + _data[segmentIndex].Length);
                        _data[segmentIndex] = new CigarOp(_data[segmentIndex].Type, 0);
                    }
                    if (insertIndex == -1)
                    {
                        insertIndex = segmentIndex;
                    }
                }
                else if (_data[segmentIndex].Type == 'D')
                {
                    if (insertIndex >= 0 && deleteIndex >= 0)
                    {
                        _data[deleteIndex]  = new CigarOp(_data[deleteIndex].Type, _data[deleteIndex].Length + _data[segmentIndex].Length);
                        _data[segmentIndex] = new CigarOp(_data[segmentIndex].Type, 0);
                    }
                    if (deleteIndex == -1)
                    {
                        deleteIndex = segmentIndex;
                    }
                }
                else
                {
                    insertIndex = -1;
                    deleteIndex = -1;
                }
            }
            int numberRemoved = _data.RemoveAll(op => (op.Length == 0));

            return(numberRemoved != 0);
        }
Example #6
0
 public void Add(CigarOp op)
 {
     _data.Add(op);
 }
Example #7
0
 public void Insert(int index, CigarOp op)
 {
     _data.Insert(index, op);
 }