public CompactSAMSequence CreateTrimmedSequence(int newLength) { if (newLength > this.sequenceData.Length || newLength < 1) { throw new ArgumentOutOfRangeException("length"); } byte[] newSequenceData = new byte[newLength]; sbyte[] newQualityScores = new sbyte[newLength]; Array.Copy(sequenceData, 0, newSequenceData, 0, newLength); Array.Copy(qualityScores, 0, newQualityScores, 0, newLength); //now to adjust cigar string newCigar = CIGAR; if (!CigarUtils.NoInformationCigar(CIGAR)) { var elements = CigarUtils.GetCigarElements(CIGAR); int curLen = 0; for (int i = 0; i < elements.Count; i++) { var ce = elements [i]; var op = ce.Operation; if (op == CigarOperations.HARD_CLIP || op == CigarOperations.DELETION) { continue; } else if (op == CigarOperations.PADDING || op == CigarOperations.SKIPPED) { throw new NotImplementedException(); } else if (op == CigarOperations.SOFT_CLIP || op == CigarOperations.INSERTION || CigarOperations.OperationIsMatch(op)) { curLen += ce.Length; if (curLen == newLength) { newCigar = CigarUtils.CreateCigarString(elements.Take(i + 1)); break; } else if (curLen > newLength) { var dif = curLen - newLength; ce.Length -= dif; elements [i] = ce; newCigar = CigarUtils.CreateCigarString(elements.Take(i + 1)); break; } } } } var ns = new CompactSAMSequence(this.Alphabet, this.FormatType, newSequenceData, newQualityScores, false); ns.Pos = Pos; ns.CIGAR = newCigar; return(ns); }
public void TrimSequence(int newLength) { Count = newLength; if (newLength > this.sequenceData.Length || newLength < 1) { throw new ArgumentOutOfRangeException("length"); } Array.Resize(ref sequenceData, newLength); Array.Resize(ref qualityScores, newLength); //now to adjust cigar string newCigar = CIGAR; if (!CigarUtils.NoInformationCigar(CIGAR)) { var elements = CigarUtils.GetCigarElements(CIGAR); int curLen = 0; for (int i = 0; i < elements.Count; i++) { var ce = elements [i]; var op = ce.Operation; if (op == CigarOperations.HARD_CLIP || op == CigarOperations.DELETION) { continue; } else if (op == CigarOperations.PADDING || op == CigarOperations.SKIPPED) { throw new NotImplementedException(); } else if (op == CigarOperations.SOFT_CLIP || op == CigarOperations.INSERTION || CigarOperations.OperationIsMatch(op)) { curLen += ce.Length; if (curLen == newLength) { newCigar = CigarUtils.CreateCigarString(elements.Take(i + 1)); break; } else if (curLen > newLength) { ce.Length -= curLen - newLength; elements [i] = ce; newCigar = CigarUtils.CreateCigarString(elements.Take(i + 1)); break; } } } } CIGAR = newCigar; }