コード例 #1
0
def user_summary(request):
    u = request.user
    plist = Profile.objects.filter(user = u, status="submitted")
    result = ""
    r = Json("array")
    for p in plist:
        ri = Json("object")
        ri.add_pair("model", str(p.name))
        ri.add_pair("type", str(p.model_type))
        ri.add_pair("status", str(p.status))
        r.add_item(ri)

    result += "{ response:     { status : 0, startRows: 0 , endRow: "
    if (len(plist) > 0):
        result += str(len(plist) - 1)
    else:
        result += "0"
    result += " , totalRows: "
    result += str(len(plist))
    result += " , data :"
    result += repr(r)
    result += "} } "
    q = request.GET
    nq = dict(q)
    result = get_callback(nq) + "(" + result + ")"
    return HttpResponse(content = result, status = 200, content_type = "text/html")
コード例 #2
0
def _process_sv_fetch(pathway):  # Merged
    sv = pathway.get_sv()
    ret = Json("array")
    for name in sv:
        j = Json()
        j.add_pair("c", pathway.get_long_name(name))
        j.add_pair("r", ''.join(sv[name]) + " = 0")
        ret.add_item(j)
    return ret
コード例 #3
0
def _process_pathway_fetch(pathway):
    public_key = 0
    ret = Json("array")
    for rname in pathway.reactions:
        r = pathway.reactions[rname]
        if not r.products or not r.substrates:
            continue
        json = r.getJson()
        json.add_pair("pk", public_key)
        public_key += 1
        ret.add_item(json)
    return ret
コード例 #4
0
def _process_pathway_fetch(pathway):
    public_key = 0
    ret = Json("array")
    for rname in pathway.reactions:
        r = pathway.reactions[rname]
        if not r.products or not r.substrates:
            continue 
        json = r.getJson()
        json.add_pair("pk", public_key)
        public_key += 1
        ret.add_item(json)
    return ret
コード例 #5
0
def _process_boundary_fetch(pathway):
    boundarys = pathway.get_bounds()
    ret = Json("array")
    public_key = 0
    for name in boundarys:
        j = Json()
        j.add_pair("pk", public_key)
        public_key +=1
        j.add_pair("r", name)
        j.add_pair("l", str(boundarys[name][0]))
        j.add_pair("u", str(boundarys[name][1]))
        ret.add_item(j)
    return ret
コード例 #6
0
def _process_object_fetch(pathway):
    weights = pathway.get_objective_weights()
    ret = Json("array")
    public_key = 1
    for name in pathway.reactions:
        j = Json()
        j.add_pair("pk", public_key)
        public_key +=1
        j.add_pair("r", name)
        if name not in weights:
            weight[name] = 1.0
        j.add_pair("w", str(weights[name]))
        ret.add_item(j)
    return ret
コード例 #7
0
def _process_sv_fetch(pathway):
    sv = pathway.get_sv()
    ret = Json("array")
    for name in sv:
        j = Json()
        j.add_pair("c", pathway.get_long_name(name))
        j.add_pair("r", ''.join(sv[name]) + " = 0")
        ret.add_item(j)
    return ret
コード例 #8
0
def _process_object_update(input_params, pathway):
    key = str(input_params["pk"])
    reaction = str(input_params["r"])
    w = input_params["w"]
    weight = float(w)
    pathway.objective[reaction] = weight
    r = Json()
    r.add_pair("pk", key)
    r.add_pair("r", reaction)
    r.add_pair("w", str(weight))
    return r
コード例 #9
0
def _process_boundary_update(input_params, pathway):
    bound = pathway.get_bounds()
    key = str(input_params["pk"])
    reactionid = str(input_params["r"])
    lb = float(input_params["l"].encode('ascii', 'ignore'))
    ub = float(input_params["u"].encode('ascii', 'ignore'))
    bound[reactionid][0] = lb
    bound[reactionid][1] = ub
    j = Json()
    j.add_pair("pk", key)
    j.add_pair("r", reactionid)
    j.add_pair("l", str(lb))
    j.add_pair("u", str(ub))
    return j
コード例 #10
0
def _process_object_update(input_params, pathway):
    key      = str(input_params["pk"])
    reaction = str(input_params["r"])
    w        = input_params["w"]
    weight   = float(w)
    pathway.objective[reaction] = weight
    r = Json()
    r.add_pair("pk", key)
    r.add_pair("r",  reaction)
    r.add_pair("w",  str(weight))
    return r
コード例 #11
0
def _process_boundary_update(input_params, pathway):
    bound = pathway.get_bounds()
    key = str(input_params["pk"])
    reactionid = str(input_params["r"])
    lb = float(input_params["l"].encode('ascii', 'ignore'))
    ub = float(input_params["u"].encode('ascii', 'ignore'))
    bound[reactionid][0] = lb
    bound[reactionid][1] = ub
    j = Json()
    j.add_pair("pk", key)
    j.add_pair("r", reactionid)
    j.add_pair("l", str(lb))
    j.add_pair("u", str(ub))
    return j
コード例 #12
0
    def newfn(arg):
        tempresult = f(arg)

        startRow = int(arg.GET['_startRow'])
        endRow = int(arg.GET['_endRow'])
        totalRow = len(tempresult.array_container)

        if endRow >= totalRow:
            endRow = totalRow - 1

        response = Json("object")

        status_label = Json()
        status_label.set_label("status")
        status_indicate_label = Json()
        status_indicate_label.set_label("0")
        response.add_pair(status_label, status_indicate_label)

        startrow_label = Json()
        startrow_label.set_label("startRow")
        startrow_value = Json()
        startrow_value.set_label(str(startRow))
        response.add_pair(startrow_label, startrow_value)

        endrow_label = Json()
        endrow_label.set_label("endRow")
        endrow_value = Json()
        endrow_value.set_label(str(endRow))
        response.add_pair(endrow_label, endrow_value)

        totalrow_label = Json() # note here might be a bug that those labels are not out
        totalrow_label.set_label("totalRows")
        totalrow_value = Json()
        totalrow_value.set_label(str(totalRow))
        response.add_pair(totalrow_label, totalrow_value)

        jarray = tempresult.array_container[startRow:endRow + 1]
        newjson = Json("array")
        newjson.array_container = jarray

        data_label = Json()
        data_label.set_label("data")
        response.add_pair(data_label, newjson)

        result = Json("object")
        response_label = Json()
        response_label.set_label("response")
        result.add_pair(response_label, response)
        return result
コード例 #13
0
def _process_pathway_info(input_params, pathway, cname):
    t = map(str, pathway.statistics())

    r0 = Json("object")
    r0.add_pair("name", "Name of the pathway")
    r0.add_pair("value", cname)

    r1 = Json("object")
    r1.add_pair("name", "Name of the organism")
    r1.add_pair("value", pathway.name)

    r2 = Json("object")
    r2.add_pair("name", "Number of all genes/orthologs")
    r2.add_pair("value", t[0])

    r3 = Json("object")
    r3.add_pair("name", "Number of annotated genes/orthologs")
    r3.add_pair("value", t[1])

    r4 = Json("object")
    r4.add_pair("name", "Number of all pathways")
    r4.add_pair("value", t[2])

    r5 = Json("object")
    r5.add_pair("name", "Number of active pathways")
    r5.add_pair("value", t[3])

    r = Json("array")
    r.add_item(r0)
    r.add_item(r1)
    r.add_item(r2)
    r.add_item(r3)
    r.add_item(r4)
    r.add_item(r5)
    return r
コード例 #14
0
def _process_pathway_update(input_params, pathway):
    key = input_params["pk"]
    new_key = input_params["reactionid"]
    ko = input_params['ko']
    reactants = input_params.get("reactants", "")
    arrow = input_params['arrow']
    if arrow == "<==>":
        arrow = '1'
    else:
        arrow = '0'
    products = input_params.get('products')
    pathway_name = input_params.get("pathway", "")
    pathway.update_pathway(new_key, ko, reactants, arrow, products,
                           pathway_name)

    # Pack results into a JSON object
    j = Json("object")
    j.add_pair("pk", key)  # respect input pathway
    j.add_pair("reactionid", new_key)
    j.add_pair("ko", ko)
    j.add_pair("reactants", reactants)
    if arrow == '1':
        j.add_pair("arrow", "<==>")
    else:
        j.add_pair("arrow", "===>")
    j.add_pair("products", products)
    j.add_pair("pathway", pathway_name)
    return j
コード例 #15
0
def user_summary(request):
    u = request.user
    plist = Profile.objects.filter(user=u, status="submitted")
    result = ""
    r = Json("array")
    for p in plist:
        ri = Json("object")
        ri.add_pair("date", str(p.submitted_date))
        ri.add_pair("model", str(p.name))
        ri.add_pair("type", str(p.model_type))
        ri.add_pair("status", str(p.status))
        r.add_item(ri)

    result += "{ response:     { status : 0, startRows: 0 , endRow: "
    if (len(plist) > 0):
        result += str(len(plist) - 1)
    else:
        result += "0"
    result += " , totalRows: "
    result += str(len(plist))
    result += " , data :"
    result += repr(r)
    result += "} } "
    q = request.GET
    nq = dict(q)
    result = get_callback(nq) + "(" + result + ")"
    return HttpResponse(content=result, status=200, content_type="text/html")
コード例 #16
0
def _process_boundary_fetch(pathway):
    boundarys = pathway.get_bounds()
    ret = Json("array")
    public_key = 0
    for name in boundarys:
        j = Json()
        j.add_pair("pk", public_key)
        public_key += 1
        j.add_pair("r", name)
        j.add_pair("l", str(boundarys[name][0]))
        j.add_pair("u", str(boundarys[name][1]))
        ret.add_item(j)
    return ret
コード例 #17
0
def _process_object_fetch(pathway):
    weights = pathway.get_objective_weights()
    ret = Json("array")
    public_key = 1
    for name in pathway.reactions:
        j = Json()
        j.add_pair("pk", public_key)
        public_key += 1
        j.add_pair("r", name)
        j.add_pair("w", str(weights[name]))
        ret.add_item(j)
    return ret
コード例 #18
0
def _process_pathway_update(input_params, pathway):
    key = input_params["pk"]
    new_key = input_params["reactionid"]
    ko = input_params['ko']
    reactants = input_params.get("reactants", "")
    arrow = input_params['arrow']        
    if arrow == "<==>":
        arrow = '1'
    else:
        arrow = '0'
    products = input_params.get('products')
    pathway_name = input_params.get("pathway", "")
    pathway.update_pathway(new_key, ko, reactants, arrow, products, pathway_name)
    
    # Pack results into a JSON object
    j = Json("object")
    j.add_pair("pk", key)   # respect input pathway
    j.add_pair("reactionid", new_key)
    j.add_pair("ko", ko)
    j.add_pair("reactants", reactants)
    if arrow == '1':
        j.add_pair("arrow", "<==>")
    else:
        j.add_pair("arrow", "===>")
    j.add_pair("products", products)
    j.add_pair("pathway", pathway_name)
    return j
コード例 #19
0
def _process_pathway_info(input_params, pathway, cname):
    t = map(str, pathway.statistics())
    
    r0 = Json("object")
    r0.add_pair("name" , "Name of the pathway")
    r0.add_pair("value", cname)
    
    r1 = Json("object")
    r1.add_pair("name" , "Name of the organism")
    r1.add_pair("value", pathway.name)
    
    r2 = Json("object")
    r2.add_pair("name", "Number of all genes/orthologs")
    r2.add_pair("value", t[0])
    
    r3 = Json("object")
    r3.add_pair("name", "Number of annotated genes/orthologs")
    r3.add_pair("value", t[1])
    
    r4 = Json("object")
    r4.add_pair("name", "Number of all pathways")
    r4.add_pair("value", t[2])
    
    r5 = Json("object")
    r5.add_pair("name", "Number of active pathways")
    r5.add_pair("value", t[3])
    
    r = Json("array")
    r.add_item(r0)
    r.add_item(r1)
    r.add_item(r2)
    r.add_item(r3)
    r.add_item(r4)
    r.add_item(r5)
    return r
コード例 #20
0
def _process_pathway_add(input_params, pathway):
    public_key = len(pathway.reactions)
    
    ko = input_params['ko']
    print "Input ko value is ", ko
    
    reactants = input_params.get("reactants", "")
    arrow = input_params['arrow']
    products = input_params.get('products')
    pathway_name = input_params.get("pathway", "")
    if pathway_name == "BIOMASS":
        if pathway.reactions.has_key("BIOMASS0"):   # Already there
            reaction = pathway.reactions["BIOMASS0"]
            ret = ""
            for i in reaction.substrates:
                ret += str(reaction.stoichiometry[i])
                ret += " "
                ret += i
                ret += " + "
            pathway.update_pathway("BIOMASS0", False, ret + reactants, arrow, "BIOMASS", "BIOMASS")    # update
            new_key = "BIOMASS0"
        else:
            new_key = "BIOMASS0"
            pathway.add_pathway("BIOMASS0", ko, reactants, arrow, "BIOMASS", "BIOMASS")
    
    elif pathway_name == "Inflow":
        pathway.user_reaction_index += 1
        new_key = "Inflow" + str(pathway.user_reaction_index)
        reactants = _attach_suffix( reactants, ".ext" )
        pathway.register_user_pathway(new_key)
        pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
    
    elif pathway_name == "Outflow":
        pathway.user_reaction_index += 1
        new_key = "Outflow" + str(pathway.user_reaction_index)
        products = _attach_suffix( products, ".ext" )
        pathway.register_user_pathway(new_key)
        pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
    
    elif pathway_name == "Heterologous Pathways":
        pathway.user_reaction_index += 1
        new_key = "Heterologous" + str(pathway.user_reaction_index)
        pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
    else:
        pass
        
    j = Json("object")
    tpk = digital_pattern.match(new_key)
    pk = int(tpk.group(1))
    j.add_pair("pk", public_key)
    j.add_pair("reactionid", new_key)
    j.add_pair("ko", ko)
    j.add_pair("reactants", reactants)
    if arrow == '1':
        j.add_pair("arrow", "<==>")
    else:
        j.add_pair("arrow", "===>")
    j.add_pair("products", products)
    j.add_pair("pathway", pathway_name)
    return j
コード例 #21
0
    def newfn(arg):
        response = Json("object")
        status_label = Json()
        status_label.set_label("status")

        status_indicate_label = Json()
        status_indicate_label.set_label("0")

        data_label = Json()
        data_label.set_label("data")
        response_label = Json()
        response_label.set_label("response")
        response.add_pair(status_label, status_indicate_label)
        response.add_pair(data_label, f(arg))
        result = Json("object")
        result.add_pair(response_label, response)
        return result
コード例 #22
0
def _process_pathway_add(input_params, pathway):
    public_key = len(pathway.reactions)

    ko = input_params['ko']
    print "Input ko value is ", ko

    reactants = input_params.get("reactants", "")
    arrow = input_params['arrow']
    products = input_params.get('products')
    pathway_name = input_params.get("pathway", "")
    if pathway_name == "BIOMASS":
        if pathway.reactions.has_key("BIOMASS0"):  # Already there
            reaction = pathway.reactions["BIOMASS0"]
            ret = ""
            for i in reaction.substrates:
                ret += str(reaction.stoichiometry[i])
                ret += " "
                ret += i
                ret += " + "
            pathway.update_pathway("BIOMASS0", False, ret + reactants, arrow,
                                   "BIOMASS", "BIOMASS")  # update
            new_key = "BIOMASS0"
        else:
            new_key = "BIOMASS0"
            pathway.add_pathway("BIOMASS0", ko, reactants, arrow, "BIOMASS",
                                "BIOMASS")

    elif pathway_name == "Inflow":
        pathway.user_reaction_index += 1
        new_key = "Inflow" + str(pathway.user_reaction_index)
        reactants = _attach_suffix(reactants, ".ext")
        pathway.register_user_pathway(new_key)
        pathway.add_pathway(new_key, ko, reactants, arrow, products,
                            pathway_name)

    elif pathway_name == "Outflow":
        pathway.user_reaction_index += 1
        new_key = "Outflow" + str(pathway.user_reaction_index)
        products = _attach_suffix(products, ".ext")
        pathway.register_user_pathway(new_key)
        pathway.add_pathway(new_key, ko, reactants, arrow, products,
                            pathway_name)

    elif pathway_name == "Heterologous Pathways":
        pathway.user_reaction_index += 1
        new_key = "Heterologous" + str(pathway.user_reaction_index)
        pathway.add_pathway(new_key, ko, reactants, arrow, products,
                            pathway_name)
    else:
        pass

    j = Json("object")
    tpk = digital_pattern.match(new_key)
    pk = int(tpk.group(1))
    j.add_pair("pk", public_key)
    j.add_pair("reactionid", new_key)
    j.add_pair("ko", ko)
    j.add_pair("reactants", reactants)
    if arrow == '1':
        j.add_pair("arrow", "<==>")
    else:
        j.add_pair("arrow", "===>")
    j.add_pair("products", products)
    j.add_pair("pathway", pathway_name)
    return j
コード例 #23
0
def new_get_json(method, input_params, pathway):
    r = ""
    if method == "pathway_add": # merged
        """ Input parameters: pathway, products, reactants"""
        ko = input_params['ko']
        reactants = input_params.get("reactants", "")
        arrow = input_params['arrow']
        products = input_params.get('products')
        pathway_name = input_params.get("pathway", "")
        new_key = ''
        # pk = 0
        if pathway_name == "BIOMASS":
            """ If user gives us biomass, we have to make sure that 
                the left side of the equation is updated
                reactants --> BIOMASS
            """
            # 1. Check if we can find a metabolism that contains USER:BIOMASS pathway
            for m in pathway.metabolism:
                if m.name == "USER:BIOMASS" and len(m.reactions) > 0:
                    new_key = m.reactions.keys()[0]
                    break
            # 2.1. If there is already a biomass, we have to update its reactant list 
            if len(new_key) > 0:
                reaction = pathway.reactions[new_key]
                ret = ""
                for i in reaction.substrates:
                    ret += str(reaction.stoichiometry[i])
                    ret += " "
                    ret += i
                    ret += " + "
                pathway.add_pathway(new_key, False, ret + reactants, arrow, "BIOMASS", "BIOMASS")
            else:       # 2.2. If there is no existing BIOMASS pathway, add a new BIOMASS 
                pathway.user_reaction += 1
                new_key = "Biomass" + str(pathway.user_reaction)
                pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
        
        elif pathway_name == "Inflow":
            pathway.user_reaction += 1
            new_key = "Inflow" + str(pathway.user_reaction)
            pathway.register_user_pathway(new_key)
            pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
        
        elif pathway_name == "Outflow":
            pathway.user_reaction += 1
            new_key = "Outflow" + str(pathway.user_reaction)
            pathway.register_user_pathway(new_key)
            pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
        
        elif pathway_name == "Heterologous Pathways":
            pathway.user_reaction += 1
            new_key = "Heterologous" + str(pathway.user_reaction)
            pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
        else:
            pass
            
        j = Json("object")
        tpk = digital_pattern.match(new_key)
        pk = int(tpk.group(1))
        j.add_pair("pk", 100000 + pk)
        j.add_pair("reactionid", new_key)
        j.add_pair("ko", ko)
        j.add_pair("reactants", reactants)
        if arrow == '1':
            j.add_pair("arrow", "<==>")
        else:
            j.add_pair("arrow", "===>")
        j.add_pair("products", products)
        j.add_pair("pathway", pathway_name)
        return j
    
    elif method == "pathway_update": # merged
        key = input_params["pk"]
        new_key = input_params["reactionid"]
        ko = input_params['ko']
        reactants = input_params.get("reactants", "")
        arrow = input_params['arrow']        
        if arrow == "<==>":
            arrow = '1'
        else:
            arrow = '0'
        products = input_params.get('products')
        pathway_name = input_params.get("pathway", "")
        pathway.update_pathway(new_key, ko, reactants, arrow, products, pathway_name)
        
        j = Json("object")
        j.add_pair("pk", key)
        j.add_pair("reactionid", new_key)
        j.add_pair("ko", ko)
        j.add_pair("reactants", reactants)
        if arrow == '1':
            j.add_pair("arrow", "<==>")
        else:
            j.add_pair("arrow", "===>")
        j.add_pair("products", products)
        j.add_pair("pathway", pathway_name)
        return j
        
    elif method == "pathway_info": # merged
        t = map(str, pathway.statistics())
        r1 = Json("object")
        r1.add_pair("name" , "Name of the pathway")
        r1.add_pair("value", pathway.name)

        r2 = Json("object")
        r2.add_pair("name", "Number of all genes/orthologs")
        r2.add_pair("value", t[0])

        r3 = Json("object")
        r3.add_pair("name", "Number of annotated genes/orthologs")
        r3.add_pair("value", t[1])

        r4 = Json("object")
        r4.add_pair("name", "Number of all pathways")
        r4.add_pair("value", t[2])

        r5 = Json("object")
        r5.add_pair("name", "Number of active pathways")
        r5.add_pair("value", t[3])

        r = Json("array")
        r.add_item(r1)
        r.add_item(r2)
        r.add_item(r3)
        r.add_item(r4)
        r.add_item(r5)
    
    elif method == "user_obj_update":   # changed
        key = str(input_params["pk"])
        if len(key) < 5:
            new_key = 'R' + '0' * (5 - len(key)) + key
        else:
            new_key = 'R' + key
        #w = input_params["w"][0].encode('ascii', 'ignore')
        w = input_params["w"]
        weight = float(w)
        pathway.objective[new_key] = weight
        
        r = Json()
        r.add_pair("pk", key)
        r.add_pair("r", new_key)
        r.add_pair("w", str(weight))
        return r

    elif method == "user_obj_fetch":    # changed
        objective_json = pathway.json_objective()
        return objective_json

    elif method == "model_sv":
        """ Output the SV=0 equations """
        sv = pathway.json_sv()
        # print "In Model SV, Now SV is", len(pathway.sv)
        t = len(pathway.sv)
        input_params['startRows'] = '0'
        input_params['endRow'] = str(t - 1)
        input_params['totalRows'] = str(t)     # later get_header will use it
        return "[" + sv + "]"

    elif method == "model_bound_fetch":
        bound = pathway.get_bounds_as_json()
        # print "In Model bound, Now bound is", len(pathway.bound)

        t = len(pathway.reactions)
        input_params['startRows'] = '0'
        input_params['endRow'] = str(t - 1)
        input_params['totalRows'] = str(t)     # later get_header will use it
        return "[" + bound + "]"

    elif method == "model_bound_update":
        bound = pathway.get_bounds()
        key = str(input_params["pk"][0])
        # print "key is", key
        if len(key) < 5:
            new_key = 'R' + '0' * (5 - len(key)) + key
        else:
            new_key = 'R' + key
        # print new_key
        
        lb = float(input_params["l"][0].encode('ascii', 'ignore'))
        ub = float(input_params["u"][0].encode('ascii', 'ignore'))
        # print lb, ub
        bound[new_key][0] = lb
        bound[new_key][1] = ub
        r += '"pk":"' + key + '",'
        r += '"r":"' + new_key + '",'
        r += '"l":"' + str(lb) + '",'
        r += '"u":"' + str(ub) + '"'
    else:
        r = ""
        pass
    return r
コード例 #24
0
    def newfn(arg):
        tempresult = f(arg)

        startRow = int(arg.GET['_startRow'])
        endRow = int(arg.GET['_endRow'])
        totalRow = len(tempresult.array_container)

        if endRow >= totalRow:
            endRow = totalRow - 1

        response = Json("object")

        status_label = Json()
        status_label.set_label("status")
        status_indicate_label = Json()
        status_indicate_label.set_label("0")
        response.add_pair(status_label, status_indicate_label)

        startrow_label = Json()
        startrow_label.set_label("startRow")
        startrow_value = Json()
        startrow_value.set_label(str(startRow))
        response.add_pair(startrow_label, startrow_value)

        endrow_label = Json()
        endrow_label.set_label("endRow")
        endrow_value = Json()
        endrow_value.set_label(str(endRow))
        response.add_pair(endrow_label, endrow_value)

        totalrow_label = Json() # note here might be a bug that those labels are not out
        totalrow_label.set_label("totalRows")
        totalrow_value = Json()
        totalrow_value.set_label(str(totalRow))
        response.add_pair(totalrow_label, totalrow_value)

        jarray = tempresult.array_container[startRow:endRow + 1]
        newjson = Json("array")
        newjson.array_container = jarray

        data_label = Json()
        data_label.set_label("data")
        response.add_pair(data_label, newjson)

        result = Json("object")
        response_label = Json()
        response_label.set_label("response")
        result.add_pair(response_label, response)
        return result
コード例 #25
0
    def newfn(arg):
        response = Json("object")
        status_label = Json()
        status_label.set_label("status")

        status_indicate_label = Json()
        status_indicate_label.set_label("0")

        data_label = Json()
        data_label.set_label("data")
        response_label = Json()
        response_label.set_label("response")
        response.add_pair(status_label, status_indicate_label)
        response.add_pair(data_label, f(arg))
        result = Json("object")
        result.add_pair(response_label, response)
        return result
コード例 #26
0
def new_get_json(method, input_params, pathway):
    r = ""
    if method == "pathway_add": # merged
        """ Input parameters: pathway, products, reactants"""
        ko = input_params['ko']
        reactants = input_params.get("reactants", "")
        arrow = input_params['arrow']
        products = input_params.get('products')
        pathway_name = input_params.get("pathway", "")
        new_key = ''
        # pk = 0
        if pathway_name == "BIOMASS":
            """ If user gives us biomass, we have to make sure that
                the left side of the equation is updated
                reactants --> BIOMASS
            """
            # 1. Check if we can find a metabolism that contains USER:BIOMASS pathway
            for m in pathway.metabolism:
                if m.name == "USER:BIOMASS" and len(m.reactions) > 0:
                    new_key = m.reactions.keys()[0]
                    break
            # 2.1. If there is already a biomass, we have to update its reactant list
            if len(new_key) > 0:
                reaction = pathway.reactions[new_key]
                ret = ""
                for i in reaction.substrates:
                    ret += str(reaction.stoichiometry[i])
                    ret += " "
                    ret += i
                    ret += " + "
                pathway.add_pathway(new_key, False, ret + reactants, arrow, "BIOMASS", "BIOMASS")
            else:       # 2.2. If there is no existing BIOMASS pathway, add a new BIOMASS
                pathway.user_reaction += 1
                new_key = "Biomass" + str(pathway.user_reaction)
                pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)

        elif pathway_name == "Inflow":
            pathway.user_reaction += 1
            new_key = "Inflow" + str(pathway.user_reaction)
            pathway.register_user_pathway(new_key)
            pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)

        elif pathway_name == "Outflow":
            pathway.user_reaction += 1
            new_key = "Outflow" + str(pathway.user_reaction)
            pathway.register_user_pathway(new_key)
            pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)

        elif pathway_name == "Heterologous Pathways":
            pathway.user_reaction += 1
            new_key = "Heterologous" + str(pathway.user_reaction)
            pathway.add_pathway(new_key, ko, reactants, arrow, products, pathway_name)
        else:
            pass

        j = Json("object")
        tpk = digital_pattern.match(new_key)
        pk = int(tpk.group(1))
        j.add_pair("pk", 100000 + pk)
        j.add_pair("reactionid", new_key)
        j.add_pair("ko", ko)
        j.add_pair("reactants", reactants)
        if arrow == '1':
            j.add_pair("arrow", "<==>")
        else:
            j.add_pair("arrow", "===>")
        j.add_pair("products", products)
        j.add_pair("pathway", pathway_name)
        return j

    elif method == "pathway_update": # merged
        key = input_params["pk"]
        new_key = input_params["reactionid"]
        ko = input_params['ko']
        reactants = input_params.get("reactants", "")
        arrow = input_params['arrow']
        if arrow == "<==>":
            arrow = '1'
        else:
            arrow = '0'
        products = input_params.get('products')
        pathway_name = input_params.get("pathway", "")
        pathway.update_pathway(new_key, ko, reactants, arrow, products, pathway_name)

        j = Json("object")
        j.add_pair("pk", key)
        j.add_pair("reactionid", new_key)
        j.add_pair("ko", ko)
        j.add_pair("reactants", reactants)
        if arrow == '1':
            j.add_pair("arrow", "<==>")
        else:
            j.add_pair("arrow", "===>")
        j.add_pair("products", products)
        j.add_pair("pathway", pathway_name)
        return j

    elif method == "pathway_info": # merged
        t = map(str, pathway.statistics())
        r1 = Json("object")
        r1.add_pair("name" , "Name of the pathway")
        r1.add_pair("value", pathway.name)

        r2 = Json("object")
        r2.add_pair("name", "Number of all genes/orthologs")
        r2.add_pair("value", t[0])

        r3 = Json("object")
        r3.add_pair("name", "Number of annotated genes/orthologs")
        r3.add_pair("value", t[1])

        r4 = Json("object")
        r4.add_pair("name", "Number of all pathways")
        r4.add_pair("value", t[2])

        r5 = Json("object")
        r5.add_pair("name", "Number of active pathways")
        r5.add_pair("value", t[3])

        r = Json("array")
        r.add_item(r1)
        r.add_item(r2)
        r.add_item(r3)
        r.add_item(r4)
        r.add_item(r5)

    elif method == "user_obj_update":   # changed
        key = str(input_params["pk"])
        if len(key) < 5:
            new_key = 'R' + '0' * (5 - len(key)) + key
        else:
            new_key = 'R' + key
        #w = input_params["w"][0].encode('ascii', 'ignore')
        w = input_params["w"]
        weight = float(w)
        pathway.objective[new_key] = weight

        r = Json()
        r.add_pair("pk", key)
        r.add_pair("r", new_key)
        r.add_pair("w", str(weight))
        return r

    elif method == "user_obj_fetch":    # changed
        objective_json = pathway.json_objective()
        return objective_json

    elif method == "model_sv":
        """ Output the SV=0 equations """
        sv = pathway.json_sv()
        t = len(pathway.sv)
        input_params['startRows'] = '0'
        input_params['endRow'] = str(t - 1)
        input_params['totalRows'] = str(t)     # later get_header will use it
        return "[" + sv + "]"

    elif method == "model_bound_fetch":
        bound = pathway.get_bounds_as_json()

        t = len(pathway.reactions)
        input_params['startRows'] = '0'
        input_params['endRow'] = str(t - 1)
        input_params['totalRows'] = str(t)     # later get_header will use it
        return "[" + bound + "]"

    elif method == "model_bound_update":
        bound = pathway.get_bounds()
        key = str(input_params["pk"][0])
        if len(key) < 5:
            new_key = 'R' + '0' * (5 - len(key)) + key
        else:
            new_key = 'R' + key

        lb = float(input_params["l"][0].encode('ascii', 'ignore'))
        ub = float(input_params["u"][0].encode('ascii', 'ignore'))
        bound[new_key][0] = lb
        bound[new_key][1] = ub
        r += '"pk":"' + key + '",'
        r += '"r":"' + new_key + '",'
        r += '"l":"' + str(lb) + '",'
        r += '"u":"' + str(ub) + '"'
    else:
        r = ""
        pass
    return r
コード例 #27
0
    def getJson(self):
        """ Return a JSON object """
        r = Json("object")
        r.add_pair("reactionid", self.name)
        s = []
        for t in self.substrates:
            s.append(str(self.stoichiometry[t]) + ' ' + self._get_long_name(t))
        r.add_pair("reactants", " + ".join(s))
        s = []
        for t in self.products:
            s.append(str(self.stoichiometry[t]) + ' ' + self._get_long_name(t))
        r.add_pair("products", " + ".join(s))
        if self.reversible:
            r.add_pair("arrow", "<==>")
        else:
            r.add_pair("arrow", "===>")

        ko_label = Json()
        ko_label.set_label('"ko"')
        ko_value = Json()

        if self.ko:
            ko_value.set_label("true")
        else:
            ko_value.set_label("false")

        r.add_pair(ko_label, ko_value)
        if self.metabolism:
            r.add_pair("pathway", self.metabolism)
        return r