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
def table_profiles(names, userid): profiles = [] for pname in names: p = db.Profile(pname).get_export(userid) # add info for how many annotations for this user. counts = db.AnnotationCounts(userid, pname).get() p.update(counts) profiles.append(p) return profiles
def unannotated(userid): """Find an un-annotated chromosome.""" names = db.UserProfiles(userid).get() shuffle(names) chorder = list(db.ChromLengths.CHROM_ORDER) shuffle(chorder) for name in names: ac = db.AnnotationCounts(userid, name) counts = ac.get() for ch in chorder: if counts[ch] == 0: return name, ch
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