Пример #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("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")
Пример #2
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")
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
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