Esempio n. 1
0
 def view(request):
     names = request.matchdict["name"].split(",")
     for name in names:
         pinfo = db.Profile(name).get()
         if pinfo is None or pinfo["export"] == "no":
             return forbidden_userprofiles(request)
     return fn(request)
Esempio n. 2
0
def export(request):
    """export annotations and models in plain text formats.

    Access rights: for public profiles, everyone can read everyone
    else's annotations and models. That way we can have a button for
    export to UCSC.

    For non-public profiles, deny un-authorized access to annotations
    and models as well.

    """
    # oldargs=,user_id,profile_id,table,file_format)

    # mdkeys user name what format
    md = request.matchdict
    pro = db.Profile(md["name"])
    fun = getattr(pro, md["what"])
    # need to
    dicts = fun(md["user"])
    pinfo = pro.get()
    pinfo["table"] = md["what"]
    pinfo["visibility"] = EXPORT_VISIBILITY[md["what"]]
    for d in dicts:
        d["user_id"] = md["user"]
        d["profile_id"] = md["name"]
    response = respond_bed_csv(md["what"], md["format"], pinfo, dicts)
    return response
Esempio n. 3
0
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
Esempio n. 4
0
def delete_profile(request):
    userid = authenticated_userid(request)
    profile = db.Profile(request.matchdict["name"])
    profile_info = profile.get()
    if profile_info["uploader"] != userid:
        raise Forbidden("profile can only be deleted by uploader")
    try:
        pro_msg = profile.delete()
    except Exception, e:
        pro_msg = "ERROR: " + str(e)
Esempio n. 5
0
def links(request):
    """Show a list of breakpoints and copy number alterations."""
    names = request.matchdict["name"]
    namelist = names.split(',')
    alterations = []
    export = ""
    export_db = ""
    userid = authenticated_userid(request)
    for name in namelist:
        pro = db.Profile(name)
        copies = pro.copies(userid)
        tables = (
            #("breaks",pro.breaks(userid)),
            ("copies", [a for a in copies if a["annotation"] in ALTERED]), )
        added = False
        for table, dicts in tables:
            for d in dicts:
                added = True
                d["name"] = name
                d["type"] = table
                d["size"] = d["max"] - d["min"]
                d["size_kb"] = d["size"] / 1000
                mid = (d["max"] + d["min"]) / 2
                d["zoom"] = []
                for f in ZOOM_FACTORS:
                    width = f * d["size"] / 2
                    d["zoom"].append({
                        "min": max(mid - width, 1),
                        "max": mid + width,
                    })
                alterations.append(d)
        # If any added for this profile, add it to the export form.
        if added:
            ex = pro.get_export(userid)
            if ex["export"] == "yes":
                export_db = ex["db"]
                export += ex["ucsc"]
    alterations.sort(key=lambda d: (d["name"], db.ChromLengths.CHROM_RANK[d[
        "chromosome"]], d["min"]))
    return {
        "export": export,
        "db": export_db,
        "alterations": alterations,
        "user": userid,
        "zoom": ZOOM_FACTORS,
        "names": names,
    }
Esempio n. 6
0
def prof_info(name_str, chroms, size):
    """
    Parameters -
    name-str - name of profile
    chroms - number of chromosomes
    size - zoom level

    Returns -
    a dict containing the profile data
    """
    out = {"names": name_str}
    if "," in name_str:
        namelist = name_str.split(",")
        out["p"] = None
    else:
        namelist = [name_str]
        out["p"] = db.Profile(name_str).get()
    out["plot"] = plotJS(namelist, chroms, size)
    return out
Esempio n. 7
0
def plotJS(profiles, chroms, size):
    """JSON to pass to profilePlot JS code.

    A list of list of objects. The first list corresponds to
    rows/profiles in the plot table, the second list corresponds to
    columns/chroms.

    """
    # TODO: when we have multiple genomes, check to make sure we are
    # only displaying profiles from one!
    pinfo = []
    for name in profiles:
        pro = db.Profile(name).get()
        meta = pro["chrom_meta"]
        cinfo = []
        for ch in chroms:
            d = meta[ch]["plots"][size] if ch in meta else {}
            d["profile"] = name
            d["chr"] = ch
            d["db"] = pro["db"]
            cinfo.append(d)
        pinfo.append(cinfo)
    return json.dumps(pinfo)
Esempio n. 8
0
         return {"error": "profile named '%(name)s' already in db" % info}
     probeInfo = read_probes(f, cl)
 except ValueError, e:
     return {"error": e}
 chroms = probeInfo.pop("chroms")
 for cname, probes in chroms.iteritems():
     # the regexp that we use for validating the logratio column is
     # quite permissive: \S+ so it can match 213E-2 and also NaN,
     # thus we need to check to make sure there are no NaN
     # logratios, and stop with an error if there are.
     nan_probes = numpy.isnan(probes["logratio"]).sum()
     if 0 < nan_probes:
         return {"error": "%d nan probes on chr%s" % (nan_probes, cname)}
     r = db.ChromProbes(info["name"], cname)
     r.put(probes)
 r = db.Profile(info["name"])
 info.update(probeInfo)
 info["uploader"] = userid
 info["uploaded_on"] = datetime.now()
 info["ready"] = False
 r.put(info)
 # save gz profile to disk.
 f.seek(0)
 out_name = db.secret_file("%(name)s.bedGraph.gz" % info)
 saved = gzip.open(out_name, "w")
 for data in f:
     saved.write(data)
 saved.close()
 # add profile to user lists.
 uprofs = [db.UserProfiles(u) for u in db_users]
 to_update = [r for r in uprofs if r.compatible(info)]