コード例 #1
0
ファイル: Read.cs プロジェクト: snashraf/Pisces
 public ReadCoverageSummary GetCoverageSummary()
 {
     return(new ReadCoverageSummary()
     {
         ClipAdjustedStartPosition = ClipAdjustedPosition,
         ClipAdjustedEndPosition = ClipAdjustedEndPosition,
         Cigar = CigarData.DeepCopy(),
         DirectionInfo = GetDirectionInfo()
     });
 }
コード例 #2
0
        /// <summary>
        /// This method takes in indexes in the "sequenced read" coordinate system and remaps them to indexes in the
        /// "extended read" coordinate system. The mapping between the two coordinate systems is determined by the cigar string.
        /// We output the expandedBaseDirectionMap as a by-product of the method, for any downstream consuptions.
        /// For helpful examples of what this means, pls check the unit tests.
        /// </summary>
        /// <param name="indexesInSequencedReadToRemap">An array of indexes in the sequeced read. Ie, if the read is ACXXGT, the sequenced indexes are 01XX23</param>
        /// <param name="expandedBaseDirectionMap">An array of the directions for each base (including deletions).  Ie, if the read is ACXXGT, the directions might be FFSSRR</param>
        /// <returns>indexesInExtendedReadCoordinates</returns>
        public int[] SequencedIndexesToExpandedIndexes(int[] indexesInSequencedReadToRemap)
        {
            var expandedBaseCigarOpMap = CigarData.Expand();
            var numIndexesToRemap      = indexesInSequencedReadToRemap.Length;
            var remappedIndexes        = new int[numIndexesToRemap];
            int whichIndex             = 0;
            int maxSequencedIndex      = _bamAlignment.Bases.Length - 1;
            int maxExpandedIndex       = expandedBaseCigarOpMap.Count - 1;
            var indexToRemap           = indexesInSequencedReadToRemap[whichIndex];

            int sequencedBaseIndex = 0;

            while (whichIndex < numIndexesToRemap)
            {
                for (int extendedIndex = 0; extendedIndex <= maxExpandedIndex; extendedIndex++)
                {
                    if ((indexToRemap < 0) || (indexToRemap > maxSequencedIndex))
                    {
                        throw new ArgumentException("Check index arguments for SequencedIndexesToExpandedIndexes method.");
                    }

                    var cigarOp = expandedBaseCigarOpMap[extendedIndex];

                    if (cigarOp.IsReadSpan())
                    {
                        if (sequencedBaseIndex == indexToRemap)
                        {
                            remappedIndexes[whichIndex] = extendedIndex;
                            whichIndex++;

                            if (whichIndex >= numIndexesToRemap)
                            {
                                return(remappedIndexes);
                            }

                            indexToRemap = indexesInSequencedReadToRemap[whichIndex];
                        }
                        sequencedBaseIndex++;
                    }
                }
            }

            return(remappedIndexes);
        }
コード例 #3
0
        private void UpdateMapFromCigar()
        {
            if (CigarData == null || CigarData.Count == 0)
            {
                return;
            }

            if (CigarData.GetReadSpan() != PositionMap.Length)
            {
                throw new Exception(string.Format("Invalid cigar '{0}': does not match length {1} of read", CigarData, ReadLength));
            }

            if (CigarData.Count == 1 && (CigarData[0].Type == 'I' || CigarData[0].Type == 'D'))
            {
                throw new Exception(string.Format("Invalid cigar '{0}': indel must have anchor", CigarData));
            }

            int readIndex         = 0;
            int referencePosition = Position;

            for (var cigarOpIndex = 0; cigarOpIndex < CigarData.Count; cigarOpIndex++)
            {
                var operation = CigarData[cigarOpIndex];
                var readSpan  = operation.IsReadSpan();
                var refSpan   = operation.IsReferenceSpan();

                for (var opIndex = 0; opIndex < operation.Length; opIndex++)
                {
                    if (readSpan)
                    {
                        PositionMap[readIndex] = refSpan ? referencePosition++ : -1;
                        readIndex++;
                    }
                    else if (refSpan)
                    {
                        referencePosition++;
                    }
                }
            }
        }