Exemplo n.º 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)
Exemplo n.º 2
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)