def getSeq(self, chrom, start, end, strand): chrom = matchChromFormat(chrom, self.fasta.keys()) seq = self.fasta[chrom][start:end+1] if strand == "-": seq = reverseComp(seq) return seq
def alignBothStrands(seq, aligner): #, target): revseq = reverseComp(seq) forward_al = aligner.align(seq) reverse_al = aligner.align(revseq) strand = None if not forward_al: if reverse_al: strand = "-" else: if not reverse_al: strand = "+" else: if forward_al.score >= reverse_al.score: strand = "+" if reverse_al.score > forward_al.score2: forward_al.score2 = reverse_al.score forward_al.ref_end2 = -1 else: strand = "-" if forward_al.score > reverse_al.score2: reverse_al.score2 = forward_al.score reverse_al.ref_end2 = -1 if strand == "+": return "+", forward_al else: return "-", reverse_al
def alignBothStrands(seq, aligner): revseq = reverseComp(seq) forward_al = aligner.align(seq) reverse_al = aligner.align(revseq) strand = None if not forward_al: if reverse_al: strand = "-" else: if not reverse_al: strand = "+" else: if forward_al.score >= reverse_al.score: strand = "+" if reverse_al.score > forward_al.score2: forward_al.score2 = reverse_al.score forward_al.ref_end2 = -1 else: strand = "-" if forward_al.score > reverse_al.score2: reverse_al.score2 = forward_al.score reverse_al.ref_end2 = -1 if strand == "+": return "+", forward_al else: return "-", reverse_al
def getSeq(self, chrom, start, end, strand): chrom = matchChromFormat(chrom, list(self.fasta.keys())) seq = self.fasta[chrom][start:end+1] if strand == "-": seq = reverseComp(seq) return seq
def remap(self, seq): results = {} for name, aligner in self.namesToAligners.items(): results[name] = None if self.tryExact: revseq = reverseComp(seq) results[name] = tryAlignExact(seq, revseq, self.namesToRefs[name], aligner) if results[name] is None: results[name] = alignBothStrands(seq, aligner)#, self.namesToRefs[name]) return seq, results
def remap(self, seq): results = {} for name, aligner in self.namesToAligners.items(): results[name] = None if self.tryExact: revseq = reverseComp(seq) results[name] = tryAlignExact(seq, revseq, self.namesToRefs[name], aligner) if results[name] is None: results[name] = alignBothStrands( seq, aligner) #, self.namesToRefs[name]) return seq, results
def chooseBestAlignment(read, mappings, chromPartsCollection): # TODO: this is kind of ridiculous; we need to make pickleable reads that can be sent to # and from the Multimapper # mappings: name -> (strand, aln) bestName = None bestAln = None bestStrand = None secondScore = None for name, mapping in mappings.iteritems(): strand, aln = mapping if bestAln is None or aln.score > bestAln.score: bestName = name bestAln = aln bestStrand = strand for name, mapping in mappings.iteritems(): strand, aln = mapping if name == bestName: if secondScore is None or bestAln.score2 > secondScore: secondScore = bestAln.score2 else: if secondScore is None or aln.score > secondScore: secondScore = aln.score seq = read.seq genome_seq = chromPartsCollection.getPart(bestName).getSeq()[bestAln.ref_begin : bestAln.ref_end + 1].upper() if bestStrand == "-": seq = reverseComp(seq) if read.is_reverse: bestStrand = "+" if bestStrand == "-" else "-" bestAln = Alignment( read.qname, bestName, bestAln.ref_begin, bestAln.ref_end, bestStrand, seq, bestAln.cigar_string, bestAln.score, genome_seq, secondScore, read.mapq, ) return bestAln
def chooseBestAlignment(read, mappings, chromPartsCollection): # TODO: this should be read-pair aware # TODO: this is kind of ridiculous; we need to make pickleable reads that can be sent to # and from the Multimapper # mappings: name -> (strand, aln) bestName = None bestAln = None bestStrand = None secondScore = None for name, mapping in mappings.items(): if mapping is None: return None strand, aln = mapping if bestAln is None or aln.score > bestAln.score: bestName = name bestAln = aln bestStrand = strand for name, mapping in mappings.items(): strand, aln = mapping if name == bestName: if secondScore is None or bestAln.score2 > secondScore: secondScore = bestAln.score2 else: if secondScore is None or aln.score > secondScore: secondScore = aln.score seq = read.seq genome_seq = chromPartsCollection.getPart( bestName).getSeq()[bestAln.ref_begin:bestAln.ref_end + 1].upper() if bestStrand == "-": seq = reverseComp(seq) if read.is_reverse: bestStrand = "+" if bestStrand == "-" else "-" bestAln = Alignment(read.qname, bestName, bestAln.ref_begin, bestAln.ref_end, bestStrand, seq, bestAln.cigar_string, bestAln.score, genome_seq, secondScore, read.mapq) return bestAln
def findBestAlignment(seq, aligner): revseq = reverseComp(seq) forward_al = aligner.align(seq) reverse_al = aligner.align(revseq) strand = None if not forward_al: if reverse_al: strand = "-" else: if not reverse_al: strand = "+" else: if forward_al.score >= reverse_al.score: strand = "+" else: strand = "-" if strand == "+": return "+", forward_al else: return "-", reverse_al
def getSeq(self, chrom, start, end, strand): seq = self.seq[start:end+1] if strand == "-": seq = reverseComp(seq) return seq
def getSeq(self, chrom, start, end, strand): seq = self.fasta[chrom][start:end + 1] if strand == "-": seq = reverseComp(seq) return seq