def makeConsensusSequence(self): min_confscore = self.settings.getMinConfScore() # Get the raw sequences and align the forward/reverse traces if we have both. if self.numseqs == 2: align = PairwiseAlignment() align.setSequences(self.seqtraces[0].getBaseCalls(), self.seqtraces[1].getBaseCalls()) align.doAlignment() self.alignedseqs[0], self.alignedseqs[ 1] = align.getAlignedSequences() self.seqindexes[0], self.seqindexes[ 1] = align.getAlignedSeqIndexes() else: self.alignedseqs[0] = self.seqtraces[0].getBaseCalls() self.seqindexes[0] = range(0, len(self.alignedseqs[0])) # If we have primers, align them to the alignment or single sequence. haveprimers = (self.settings.getForwardPrimer() != '' and self.settings.getReversePrimer() != '') if haveprimers: if self.numseqs == 1: self.alignPrimerToSequence() else: self.alignPrimersToAlignment() # Build the consensus sequence. if self.numseqs == 1: self.makeSingleConsensus(min_confscore) else: if self.settings.getConsensusAlgorithm() == 'Bayesian': self.makeBayesianConsensus(min_confscore) else: self.makeLegacyConsensus(min_confscore) # Do sequence trimming, if requested. if self.settings.getTrimConsensus(): if self.settings.getTrimPrimers() and haveprimers: if self.numseqs == 1: self.trimPrimerFromSequence() else: self.trimPrimersFromAlignment() if self.settings.getTrimEndGaps(): self.trimEndGaps() if self.settings.getDoQualityTrim(): winsize, basecnt = self.settings.getQualityTrimParams() self.trimConsensus(winsize, basecnt)
def makeConsensusSequence(self): min_confscore = self.settings.getMinConfScore() # Get the raw sequences and align the forward/reverse traces if we have both. if self.numseqs == 2: align = PairwiseAlignment() align.setSequences(self.seqtraces[0].getBaseCalls(), self.seqtraces[1].getBaseCalls()) align.doAlignment() self.alignedseqs[0], self.alignedseqs[1] = align.getAlignedSequences() self.seqindexes[0], self.seqindexes[1] = align.getAlignedSeqIndexes() else: self.alignedseqs[0] = self.seqtraces[0].getBaseCalls() self.seqindexes[0] = range(0, len(self.alignedseqs[0])) # If we have primers, align them to the alignment or single sequence. haveprimers = (self.settings.getForwardPrimer() != '' and self.settings.getReversePrimer() != '') if haveprimers: if self.numseqs == 1: self.alignPrimerToSequence() else: self.alignPrimersToAlignment() # Build the consensus sequence. if self.numseqs == 1: self.makeSingleConsensus(min_confscore) else: if self.settings.getConsensusAlgorithm() == 'Bayesian': self.makeBayesianConsensus(min_confscore) else: self.makeLegacyConsensus(min_confscore) # Do sequence trimming, if requested. if self.settings.getTrimConsensus(): if self.settings.getTrimPrimers() and haveprimers: if self.numseqs == 1: self.trimPrimerFromSequence() else: self.trimPrimersFromAlignment() if self.settings.getTrimEndGaps(): self.trimEndGaps() if self.settings.getDoQualityTrim(): winsize, basecnt = self.settings.getQualityTrimParams() self.trimConsensus(winsize, basecnt)
def alignPrimerToSequence(self): """ Aligns a primer sequence to the base calls of a single trace file. Also adjusts the alignment and alignment indices to accomodate the alignment with the primer, if extra gaps are needed. An alignment-length string containing the aligned primer in the appropriate location is saved as self.alignedprimers. """ if self.numseqs == 2: return # Figure out if we're working on a reverse trace and get the # appropriate primer sequence to search for. isreverse = self.seqtraces[0].isReverseComplemented() if isreverse: primer = self.settings.getForwardPrimer() else: primer = sequencetrace.reverseCompSequence( self.settings.getReversePrimer()) if primer == '': return # Align the primer sequence to the trace sequence. Using a harsher gap # penalty (-12 instead of -6) seems to improve the chances of getting the # primer to align in the correct location. align = PairwiseAlignment() align.setGapPenalty(-12) align.setSequences(primer, self.alignedseqs[0]) align.doAlignment() praligned, seqaligned = align.getAlignedSequences() # Use the new alignment for the trace sequence and index list. self.alignedseqs[0] = seqaligned self.seqindexes[0] = align.getAlignedSeqIndexes()[1] # Replace starting and ending gap characters in the aligned primer # sequences with spaces. praligned = self.trimAlignedPrimerEnds(praligned) self.alignedprimers = praligned
def alignPrimerToSequence(self): """ Aligns a primer sequence to the base calls of a single trace file. Also adjusts the alignment and alignment indices to accomodate the alignment with the primer, if extra gaps are needed. An alignment-length string containing the aligned primer in the appropriate location is saved as self.alignedprimers. """ if self.numseqs == 2: return # Figure out if we're working on a reverse trace and get the # appropriate primer sequence to search for. isreverse = self.seqtraces[0].isReverseComplemented() if isreverse: primer = self.settings.getForwardPrimer() else: primer = sequencetrace.reverseCompSequence(self.settings.getReversePrimer()) if primer == '': return # Align the primer sequence to the trace sequence. Using a harsher gap # penalty (-12 instead of -6) seems to improve the chances of getting the # primer to align in the correct location. align = PairwiseAlignment() align.setGapPenalty(-12) align.setSequences(primer, self.alignedseqs[0]) align.doAlignment() praligned, seqaligned = align.getAlignedSequences() # Use the new alignment for the trace sequence and index list. self.alignedseqs[0] = seqaligned self.seqindexes[0] = align.getAlignedSeqIndexes()[1] # Replace starting and ending gap characters in the aligned primer # sequences with spaces. praligned = self.trimAlignedPrimerEnds(praligned) self.alignedprimers = praligned