Ejemplo n.º 1
0
def blast_closest(fasta, e=1e-10):
    f = NCBIWWW.qblast("blastn", "nr", fasta, expect=e, hitlist_size=1)
    rec = NCBIXML.read(f)
    d = rec.descriptions[0]
    result = Storage()
    gi = re.findall(r'gi[|]([0-9]+)', d.title) or None
    if gi: result.gi = int(gi[0])
    ac = re.findall(r'gb[|]([^|]+)', d.title) or None
    if ac: result.ac = ac[0].split(".")[0]
    result.title = d.title.split("|")[-1].strip()
    return result
Ejemplo n.º 2
0
def blast_closest(fasta, e=1e-10):
    f = NCBIWWW.qblast("blastn", "nr", fasta, expect=e, hitlist_size=1)
    rec = NCBIXML.read(f)
    d = rec.descriptions[0]
    result = Storage()
    gi = re.findall(r'gi[|]([0-9]+)', d.title) or None
    if gi: result.gi = int(gi[0])
    ac = re.findall(r'gb[|]([^|]+)', d.title) or None
    if ac: result.ac = ac[0].split(".")[0]
    result.title = d.title.split("|")[-1].strip()
    return result
Ejemplo n.º 3
0
def render_node_label(node, isleaf, onclick=None):
    if not onclick: onclick = lambda x: ""
    node_id = node.rec.id
    if isleaf and node.rec.otu.taxon:
        label = node.rec.otu.taxon.name
    else:
        label = node.label or ""
    style = Storage()
    if isleaf:
        anchor = A(label, _onclick=onclick(node_id))
        d = SPAN(anchor, _style="cursor:pointer;")
    else:
        anchor = A(label, _onclick=onclick(node_id))
        d = SPAN(anchor, _style="background-color:yellow;cursor:pointer;")
    return d
Ejemplo n.º 4
0
def search_namebank(term, keycode=KEY):
    assert keycode, "set parameter 'keycode' or os.environ['UBIOKEY']"
    params = dict(function="namebank_search",
                  searchName=term,
                  sci=1,
                  keyCode=keycode)
    url = (WSURL + "?" + "&".join("%s=%s" % (k, v) for k, v in params.items()))

    e = etree.parse(url)
    v = []
    for rec in e.findall("scientificNames/value"):
        d = Storage()
        for c in rec.iterchildren():
            s = c.text
            if c.tag in ("nameString", "fullNameString"):
                s = b64decode(s)
            d[c.tag] = s
        v.append(d)
    return v
Ejemplo n.º 5
0
    def __init__(self, fig, rect, *args, **kwargs):
        self.app = kwargs.pop("app", None)
        self.support = kwargs.pop("support", 70.0)
        self.snap = kwargs.pop("snap", True)
        self.scaled = kwargs.pop("scaled", True)
        self.leaflabels = kwargs.pop("leaflabels", True)
        self.branchlabels = kwargs.pop("branchlabels", True)
        self._mark_named = kwargs.pop("mark_named", True)
        self.name = None
        Axes.__init__(self, fig, rect, *args, **kwargs)
        self.nleaves = 0
        self.callbacks.connect("ylim_changed", self.draw_labels)
        self.highlighted = None
        self.highlightpatch = None
        self.pan_start = None
        self.decorators = {
            "__selected_nodes__": (Tree.highlight_selected_nodes, [], {})
            }
        self.decorations = Storage()
        self._active = False

        self.selector = RectangleSelector(self, self.rectselect, useblit=True)
        def f(e):
            if e.button != 1: return True
            else: return RectangleSelector.ignore(self.selector, e)
        self.selector.ignore = f
        self.xoffset_value = 0.05
        self.selected_nodes = set()
        self.leaf_offset = 4
        self.leaf_valign = "center"
        self.leaf_halign = "left"
        self.leaf_fontsize = 10
        self.branch_offset = -5
        self.branch_valign = "center"
        self.branch_halign = "right"
        self.branch_fontsize = 10

        self.spines["top"].set_visible(False)
        self.spines["left"].set_visible(False)
        self.spines["right"].set_visible(False)
        self.xaxis.set_ticks_position("bottom")
Ejemplo n.º 6
0
def style_nodes(root, collapsed=None, selected_node_id=None, wscale=1.0):
    style = defaultdict(Storage)
    collapsed = collapsed or set()
    bgcolor = "gray"
    selcolor = "red"
    leaves = getleaves(root, collapsed=collapsed)
    l2d = leaf_distances(root, collapsed=collapsed)
    height = len(leaves) * 2.5
    unit = 3.0
    width = max([l2d[lf] for lf in leaves]) * unit * wscale
    width = min(width, 65)
    rpad = max([len(lf.label or "") for lf in leaves]) * 0.7
    lpad = max(1, len(root.label or []) * 0.7)
    width += rpad + 2 + lpad
    branchwidth = 0.75
    n2c = layout.calc_node_positions(root,
                                     width,
                                     height,
                                     lpad=lpad + 1,
                                     tpad=1,
                                     bpad=2.5,
                                     rpad=rpad + 1,
                                     collapsed=collapsed,
                                     scaled=False)
    n2c[root].px = 1
    for node in root.iternodes(f=lambda x: x.rec.id not in collapsed):
        coords = n2c[node]
        style[node].x = coords.x
        style[node].y = coords.y
        w = coords.x - coords.px
        pos = "absolute"
        style[node].hbranch = Storage()
        hbranch = style[node].hbranch
        hbranch["position"] = pos
        hbranch["width"] = w
        hbranch["height"] = branchwidth
        hbranch["top"] = coords.y + 0.5
        hbranch["left"] = coords.px
        hbranch["background-color"] = bgcolor
        if float(node.rec.bootstrap_support or 0) > 0.70:
            hbranch["background-color"] = "green"

        if coords.py is None:
            coords.py = coords.y
        if coords.py < coords.y:
            h = coords.y - coords.py
            y = coords.py
        else:
            h = coords.py - coords.y
            y = coords.y
        style[node].vbranch = Storage()
        vbranch = style[node].vbranch
        vbranch["position"] = pos
        vbranch["width"] = 0.5 * branchwidth
        vbranch["height"] = h
        vbranch["top"] = y + 0.5
        vbranch["left"] = coords.px
        vbranch["background-color"] = bgcolor

        style[node].label = Storage()
        label = style[node].label
        label["position"] = pos
        if node.isleaf or node.rec.id in collapsed:
            label["top"] = coords.y - 0.75
            label["left"] = coords.x + 0.25
            if node.rec.otu and node.rec.otu.taxon:
                s = node.rec.otu.taxon.name
                label["width"] = len(s)
            else:
                label["width"] = len(node.label or "")
            label["text-align"] = "left"
        else:
            label["text-align"] = "right"
            label["width"] = len(node.label or "")
            label["top"] = coords.y - 0.75
            label["left"] = coords.x - len(str(node.label or ""))

        style[node].ref = Storage()
        ref = style[node].ref
        ref["position"] = pos
        ref["top"] = coords.y - 0.5
        ref["left"] = coords.x + 0.25

    if selected_node_id:
        for n in root.iternodes(f=lambda x: x.rec.id not in collapsed):
            if n.rec.id == selected_node_id:
                for m in n.iternodes():
                    style[m].vbranch["background-color"] = selcolor
                    style[m].hbranch["background-color"] = selcolor
                break

    return width, height, style