예제 #1
0
    def get_aligns(self,
                   species,
                   chrom,
                   start,
                   end,
                   mainspecies=lambda keys: keys[0],
                   collapse=False):
        """By default assumes main species is 1st sequence"""

        # get records for this region
        records = self.get(species, chrom, start, end)
        records.sort(key=lambda x: x["start"])

        # read alignments
        alns = []
        for record in records:
            aln = fasta.read_fasta(record["filename"])

            # collapse alignment
            if collapse:
                ind = util.findneq("-", aln[mainspecies(aln.keys())])

                for key, seq in aln.iteritems():
                    if len(seq) != 0:
                        aln[key] = "".join(util.mget(seq, ind))

            l2a = alignlib.local2align(aln[mainspecies(aln.keys())])

            # trim front
            if start > record["start"]:
                trimstart = l2a[start - record["start"]]
            else:
                trimstart = 0

            # trim end
            if end < record["end"]:
                trimend = l2a[-(record["end"] - end)]
            else:
                trimend = aln.alignlen()

            # perform trim
            for key, seq in aln.iteritems():
                aln[key] = seq[trimstart:trimend]

            alns.append(aln)

        return alns
예제 #2
0
    def __init__(self,
                 aln,
                 collapse=None,
                 cols=None,
                 color_bases=False,
                 seqtype=None,
                 show_color_bases=True,
                 show_bases=True,
                 show_labels=True,
                 rowspacing=None,
                 **options):
        Track.__init__(self, **options)
        self.size = [aln.alignlen(), len(aln)]
        self.multiscale = Multiscale(marginx=.5, marginy=.5)
        self.collapse = collapse

        self.show_color_bases = show_color_bases
        self.show_bases = show_bases
        self.show_labels = show_labels
        self.rowspacing = rowspacing
        self.always_color = False
        self.color_bases_vis = None

        if seqtype == None:
            self.seqtype = guessAlign(aln)
        else:
            self.seqtype = seqtype

        if color_bases == True:
            if self.seqtype == "dna":
                self.color_bases = dna_colors
            elif self.seqtype == "pep":
                self.color_bases = pep_colors
        else:
            self.color_bases = color_bases

        if collapse != None:
            assert collapse in aln.keys()
            cols = util.findneq('-', aln[collapse])

        if cols != None:
            self.aln = alignlib.subalign(aln, cols)
        else:
            self.aln = aln
    def get_aligns(self, species, chrom, start, end,
                   mainspecies=lambda keys: keys[0],
                   collapse=False):
        """By default assumes main species is 1st sequence"""

        # get records for this region
        records = self.get(species, chrom, start, end)
        records.sort(key=lambda x: x["start"])

        # read alignments
        alns = []
        for record in records:
            aln = fasta.read_fasta(record["filename"])

            # collapse alignment
            if collapse:
                ind = util.findneq("-", aln[mainspecies(aln.keys())])

                for key, seq in aln.iteritems():
                    if len(seq) != 0:
                        aln[key] = "".join(util.mget(seq, ind))

            l2a = alignlib.local2align(aln[mainspecies(aln.keys())])

            # trim front
            if start > record["start"]:
                trimstart = l2a[start - record["start"]]
            else:
                trimstart = 0

            # trim end
            if end < record["end"]:
                trimend = l2a[-(record["end"]-end)]
            else:
                trimend = aln.alignlen()

            # perform trim
            for key, seq in aln.iteritems():
                aln[key] = seq[trimstart:trimend]

            alns.append(aln)

        return alns
 def __init__(self, aln, collapse=None, cols=None, color_bases=False, 
              seqtype=None, show_color_bases=True, show_bases=True,
              show_labels=True,
              rowspacing=None,
              **options):
     Track.__init__(self, **options)
     self.size = [aln.alignlen(), len(aln)]
     self.multiscale = Multiscale(marginx=.5, marginy=.5)
     self.collapse = collapse
     
     self.show_color_bases = show_color_bases
     self.show_bases = show_bases
     self.show_labels = show_labels
     self.rowspacing = rowspacing
     self.always_color = False
     self.color_bases_vis = None
     
     if seqtype == None:
         self.seqtype = guessAlign(aln)
     else:
         self.seqtype = seqtype
     
     if color_bases == True:
         if self.seqtype == "dna":
             self.color_bases = dna_colors
         elif self.seqtype == "pep":
             self.color_bases = pep_colors
     else:
         self.color_bases = color_bases
     
     if collapse != None:
         assert collapse in aln.keys()
         cols = util.findneq('-', aln[collapse])
         
     if cols != None:
         self.aln = alignlib.subalign(aln, cols)
     else:
         self.aln = aln