Пример #1
0
def save_tree_image():
    #Requires a POST parameter format of the tree to be saved
    #print "save_tree_image called...."
    if request.json:
        source_dict = request.json
    else:
        source_dict = request.POST
    
    tree_newick = source_dict.get('tree_newick', '').strip()
    tree_id = str(source_dict.get('tree_id', '')).strip()
    actions = source_dict.get('actions', '')
    img_format = source_dict.get('format', '').strip()

    if not tree_newick or not tree_id:
        return json_return({'status_code': "400",'message':"Missing Parameter Error: No newick tree or tree id provided"}, response)
    
    if not img_format:
        return json_return({'status_code': "400",'message':"Missing Parameter Error: No image format provided"}, response)
    
    tree_handler = ctrl.create_tree_obj(tree_newick, tree_id)
    #check for errors related to parsing newick
    if type(tree_handler) == types.DictType:
       return json_return(tree_handler, response)

    # Renders initial tree image with actions applied
    if actions != '':
       tree_data = ctrl.apply_actions(tree_handler, actions) 
    
    # Renders initial tree
    html_url_part = tree_handler.save_image(img_format)
    return json_return({'tree_newick':tree_handler.treenewick, 'tree_id':tree_handler.treeid, 'html_data': html_url_part}, response)
Пример #2
0
def get_action():
    print "get_actions method called...."
    if request.json:
        source_dict = request.json
    else:
        source_dict = request.POST
    
    tree_newick = source_dict.get('tree_newick', '').strip()
    tree_id = str(source_dict.get('tree_id', '')).strip()
    node_actions = source_dict.get('node_actions')
    node_id = source_dict.get('node_id', '')

    #print "treeid: " + str(treeid) + " nodeid: " + str(nodeid)
    
    if not tree_newick or not tree_id:
        return json_return({'status_code': "400",'message':"Missing Parameter Error: No newick tree or tree id provided"}, response)

    tree_handler = ctrl.create_tree_obj(tree_newick, tree_id)

    if not ctrl.is_empty(node_actions):
       new_node_actions = ctrl.apply_node_actions(tree_handler, node_actions)
       #return json_return({'status_code': "400",'message':"Missing Parameter Error: No action provided for node"}, response)
    
    node_name = tree_handler.get_node_name(node_id)
    #print node_name
    #header = "Actions menu"
    if node_name:
       header = """
               <i>%s</i> actions
                """ %(node_name)
    else:
       header = "Node actions"
             
    html = """<div id="ete_popup_header"><span id="ete_popup_header_text">%s</span><div id="ete_close_popup" onClick='hide_popup();'></div></div><ul>""" % (header)
    
    for aindex, aname, aorder, html_generator in tree_handler.get_avail_actions(node_id):
        node = tree_handler.get_tree_node(node_id)
        if html_generator:
           html += html_generator(aindex, tree_id, node_id, node)
        else:
           html += """<li style="font-size:12pt"><a  onClick="run_action('%s', '%s', '%s');" >%s</a></li>""" %(tree_id, node_id, aindex, aname)
    html += "</ul>"
    #print "returning html for actions from get_actions.."
    
    return json_return({'tree_newick':tree_handler.treenewick, 'tree_id':tree_handler.treeid, 'html_data': html}, response)
Пример #3
0
def set_all_pictures():
    print "set_pictures method called...."
    if request.json:
        source_dict = request.json
    else:
        source_dict = request.POST
    
    tree_newick = source_dict.get('tree_newick', '').strip()
    tree_id = str(source_dict.get('tree_id', '')).strip()
    node_actions = source_dict.get('node_actions')
    
    #print "tree_id: " + str(tree_id) + " node_actions: " + str(node_actions)
    
    if not tree_newick or not tree_id:
        return json_return({'status_code': "400",'message':"Missing Parameter Error: No newick tree or tree id provided"}, response)

    tree_handler = ctrl.create_tree_obj(tree_newick, tree_id)

    new_node_actions = ctrl.set_all_picture_action(tree_handler, node_actions)
    
    return json_return({'tree_newick':tree_handler.treenewick, 'tree_id':tree_handler.treeid, 'actions': {'node_actions': new_node_actions}}, response)
Пример #4
0
def get_tree_image():
    # Requires a POST parameter "newick" containing the tree to be loaded.
    #print "get_tree_image called...."
    if request.json:
        source_dict = request.json
    else:
        source_dict = request.POST
    
    #tree_newick = source_dict.get('tree_newick', '').strip()
    #tree_id = str(source_dict.get('tree_id', '')).strip()
    #actions = source_dict.get('actions', '')
    tree_newick = source_dict["tree_newick"]
    tree_id = source_dict["tree_id"]
    actions = source_dict["actions"]
    print source_dict
    #source_json = json.loads(source_dict)
    
    if "top_offset" in source_dict:
       topoffset = source_dict["top_offset"]
    if "left_offset" in source_dict:
       leftoffset = source_dict["left_offset"]

    if not tree_newick or not tree_id:
        return json_return({'status_code': "400",'message':"Missing Parameter Error: No newick tree or tree id provided"}, response)

    tree_handler = ctrl.create_tree_obj(tree_newick, tree_id)
    #check for errors related to parsing newick
    if type(tree_handler) == types.DictType:
       return json_return(tree_handler, response)

    # Renders initial tree image with actions applied
    if actions != '':
       tree_data = ctrl.apply_actions(tree_handler, actions, topoffset, leftoffset)
       return json_return(tree_data, response) 
    else:
       # Renders initial tree image without any actions applied   
       html_img_data = tree_handler.redraw(topoffset, leftoffset)

    #print "returning initial image from get_tree_image.."
    return json_return({'tree_newick':tree_handler.treenewick, 'tree_id':tree_handler.treeid, 'html_data': html_img_data, 'actions':{'tree_actions':{}, 'node_actions':[]}}, response)