示例#1
0
    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
示例#2
0
文件: remap.py 项目: svviz/svviz
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
示例#3
0
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
示例#4
0
    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
示例#5
0
文件: remap.py 项目: svviz/svviz
    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
示例#6
0
    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
示例#7
0
文件: remap.py 项目: gatoravi/svviz
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
示例#8
0
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
示例#9
0
文件: remap.py 项目: gatoravi/svviz
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
示例#10
0
 def getSeq(self, chrom, start, end, strand):
     seq = self.seq[start:end+1]
     if strand == "-":
         seq = reverseComp(seq)
     return seq
示例#11
0
 def getSeq(self, chrom, start, end, strand):
     seq = self.fasta[chrom][start:end + 1]
     if strand == "-":
         seq = reverseComp(seq)
     return seq