Beispiel #1
0
def initial(request):
    """Send user-specific model data as JSON."""
    userid = authenticated_userid(request)
    result_list = []
    for name in request.matchdict["profiles"].split(","):
        dp = db.DisplayedProfile(userid, name)
        # dp.put(None)
        prof = dp.get()
        for ch in request.matchdict["chromosomes"].split(","):
            if ch in prof:
                m = prof[ch]  # contains breaks, copy number calls.
                m["breakpoints_regions"] = db.Breakpoints(userid, name,
                                                          ch).json()
                for b in m["breakpoints_regions"]:
                    # do not send numpy error.
                    b.pop("error")
                m["copies_regions"] = db.Copies(userid, name, ch).json()
                result_list.append({
                    "chromosome": ch,
                    "profile_id": name,
                    "update": m,
                })
    return {
        "updates": result_list,
    }
Beispiel #2
0
def delete_region(request):
    md = request.matchdict
    userid = authenticated_userid(request)
    table = db.REGION_TABLES_DICT[md["trackType"]]
    db.AnnotationCounts(userid, md["name"]).put(None)
    regions = table(userid, md["name"], md["chr"])
    removed, after = regions.remove(int(request.matchdict["id"]))
    result = {}
    # if md["trackType"] == "breakpoints":
    #     evec = db.ModelError(userid, md["name"], md["chr"])
    #     err_removed, err_after = evec.remove(removed["error"])
    #     chroms = update_model(db.Models(md["name"], md["chr"]).get(),
    #                           err_after,
    #                           after,
    #                           md["name"],
    #                           md["chr"],
    #                            userid)
    #  else:
    res = db.DisplayedProfile(userid, md["name"])
    chroms = res.remove(removed, md["chr"])
    result["updates"] = [
        {
            "profile_id": md["name"],
            "chromosome": ch,
            #    "update": model,
        } for ch in chroms.iteritems()
    ]
    #, model in chroms.iteritems()]
    return result
Beispiel #3
0
def update_model(models, error, regions, profile, ch, user):
    """Used in add/remove breakpoint regions."""
    # store error for learning later.
    uerr = db.UserError(user)
    uerr.add((profile, ch, error))
    model = db.chrom_model(models, error, regions, profile, ch, user)
    res = db.DisplayedProfile(user, profile)
    chroms = res.get()
    chroms[ch] = model
    db.infer_gain_loss(chroms)
    res.put(chroms)
    return chroms
Beispiel #4
0
def add_region(request):
    md = request.matchdict
    userid = authenticated_userid(request)
    table = db.REGION_TABLES_DICT[md["trackType"]]
    regions = table(userid, md["name"], md["chr"])
    # TODO: check if the region that we add has the same min value as
    # an existing annotation. In that case the SegAnnot segmentation
    # is undefined and so we should reject the new annotation.
    db.AnnotationCounts(userid, md["name"]).put(None)
    reg = {
        "min": int(md["min"]),
        "max": int(md["max"]),
        "annotation": md["annotation"],
    }
    # first calculate error of this region.
    ###if md["trackType"] == "breakpoints":
    #   models = db.Models(md["name"], md["chr"]).get()
    #   breaks = numpy.array([
    #       ((reg["min"] < m["breaks"]) & (m["breaks"] < reg["max"])).sum()
    #       for m in models
    #       ])
    #   error = breaks != TARGET_BREAKS[reg["annotation"]]
    #   reg["error"] = error.astype(int)
    added, after = regions.add(reg)
    # then add to the total error.
    result = {}
    #if md["trackType"] == "breakpoints":
    #    evec = db.ModelError(userid, md["name"], md["chr"])
    #    err_added, err_after = evec.add(reg["error"])
    #    chroms = update_model(models,
    #                          err_after,
    #                          after,
    #                          md["name"],
    #                          md["chr"],
    #                          userid)
    #else:
    res = db.DisplayedProfile(userid, md["name"])
    chroms = res.add(added, md["chr"])
    # do not send numpy error.
    if "error" in added:
        added.pop("error")
    result["updates"] = [
        {
            "profile_id": md["name"],
            "chromosome": ch,
            #    "update": model,
        } for ch in chroms.iteritems()
    ]
    #, models in chroms.iteritems()]
    result["region"] = added
    #return {}
    return result