Example #1
0
    def print_gffline(self, fw, f, seqid, parent=None):

        score = phase = "."
        type = f.type
        if type == "source":
            type = "contig"

        attr = "ID=tmp"
        source = self.source

        start = get_number(f.location.start) + 1
        end = get_number(f.location.end)
        strand = '-' if f.strand < 0 else '+'
        g = "\t".join(str(x) for x in \
            (seqid, source, type, start, end, score, strand, phase, attr))
        g = GffLine(g)

        qual = f.qualifiers
        id = "tmp"
        if MT in qual:
            id = seqid
        elif LT in qual:
            id, = qual[LT]
        else:
            qual[LT] = [self.current_id]
            id, = qual[LT]

        id = id.split()[0]

        if parent:
            id, = parent.qualifiers[LT]
            id = id.split()[0]

        assert id != "tmp", f
        oid = id
        self.counter[(oid, type)].append((start, end))
        count = len(self.counter[(oid, type)])

        if type in ("mRNA", "gene"):
            if type == "gene" and count > 1:
                return
            self.start = min(a for a, b in self.counter[(id, type)])
            self.end = max(a for a, b in self.counter[(id, type)])
            self.set_attribute("gene", "Alias", qual, g)
            self.set_attribute("product", "Note", qual, g)
        else:
            suffix = ".{0}.{1}".format(type.lower(), count)
            id = id + suffix
            g.attributes["Parent"] = [oid]
            self.set_attribute("product", "Note", qual, g)

        g.attributes["ID"] = [id]
        g.update_attributes()
        print >> fw, g

        self.current_id = oid
Example #2
0
    def print_gffline(self, fw, f, seqid, parent=None):

        score = phase = "."
        type = f.type
        if type == "source":
            type = "contig"

        attr = "ID=tmp"
        source = self.source

        start = get_number(f.location.start) + 1
        end = get_number(f.location.end)
        strand = '-' if f.strand < 0 else '+'
        g = "\t".join(str(x) for x in \
            (seqid, source, type, start, end, score, strand, phase, attr))
        g = GffLine(g)

        qual = f.qualifiers
        id = "tmp"
        if MT in qual:
            id = seqid
        elif LT in qual:
            id, = qual[LT]
        else:
            qual[LT] = [self.current_id]
            id, = qual[LT]

        id = id.split()[0]

        if parent:
            id, = parent.qualifiers[LT]
            id = id.split()[0]

        if type == 'CDS':
            parent_id = id
            self.counter[id] += 1
            suffix = ".cds.{0}".format(self.counter[id])
            id = parent_id + suffix
            g.attributes["Parent"] = [parent_id]

        assert id != "tmp", f
        g.attributes["ID"] = [id]

        if type == "mRNA":
            g.attributes["Name"] = g.attributes["ID"]
            if "product" in qual:
                note, = qual["product"]
                g.attributes["Note"] = [note]

            if "pseudo" in qual:
                note = "Pseudogene"
                g.attributes["Note"] = [note]

        g.update_attributes()
        print >> fw, g

        self.current_id = id
Example #3
0
    def print_gffline(self, fw, f, seqid, parent=None):

        score = phase = "."
        type = f.type
        if type == "source":
            type = "contig"

        attr = "ID=tmp"
        source = self.source

        start = get_number(f.location.start) + 1
        end = get_number(f.location.end)
        strand = '-' if f.strand < 0 else '+'
        g = "\t".join(str(x) for x in \
            (seqid, source, type, start, end, score, strand, phase, attr))
        g = GffLine(g)

        qual = f.qualifiers
        id = "tmp"
        if MT in qual:
            id = seqid
        elif LT in qual:
            id, = qual[LT]
        else:
            qual[LT] = [self.current_id]
            id, = qual[LT]

        id = id.split()[0]

        if parent:
            id, = parent.qualifiers[LT]
            id = id.split()[0]

        if type == 'CDS':
            parent_id = id
            self.counter[id] += 1
            suffix = ".cds.{0}".format(self.counter[id])
            id = parent_id + suffix
            g.attributes["Parent"] = [parent_id]

        assert id != "tmp", f
        g.attributes["ID"] = [id]

        if type == "mRNA":
            g.attributes["Name"] = g.attributes["ID"]
            if "product" in qual:
                note, = qual["product"]
                g.attributes["Note"] = [note]

            if "pseudo" in qual:
                note = "Pseudogene"
                g.attributes["Note"] = [note]

        g.update_attributes()
        print >> fw, g

        self.current_id = id
Example #4
0
    def print_gffline(self, fw, f, seqid, parent=None):

        score = phase = "."
        type = f.type
        if type == "source":
            type = "contig"

        attr = "ID=tmp"
        source = self.source

        start = get_number(f.location.start) + 1
        end = get_number(f.location.end)
        strand = '-' if f.strand < 0 else '+'
        g = "\t".join(str(x) for x in \
            (seqid, source, type, start, end, score, strand, phase, attr))
        g = GffLine(g)

        qual = f.qualifiers
        id = "tmp"
        if MT in qual:
            id = seqid
        elif LT in qual:
            id, = qual[LT]
        else:
            qual[LT] = [self.current_id]
            id, = qual[LT]

        id = id.split()[0]

        if parent:
            id, = parent.qualifiers[LT]
            id = id.split()[0]

        assert id != "tmp", f
        oid = id
        self.counter[(oid, type)].append((start, end))
        count = len(self.counter[(oid, type)])

        if type in ("mRNA", "gene"):
            if type == "gene" and count > 1:
                return
            self.start = min(a for a, b in self.counter[(id, type)])
            self.end = max(a for a, b in self.counter[(id, type)])
            self.set_attribute("gene", "Alias", qual, g)
            self.set_attribute("product", "Note", qual, g)
        else:
            suffix = ".{0}.{1}".format(type.lower(), count)
            id = id + suffix
            g.attributes["Parent"] = [oid]
            self.set_attribute("product", "Note", qual, g)

        g.attributes["ID"] = [id]
        g.update_attributes()
        print(g, file=fw)

        self.current_id = oid