Exemple #1
0
def get_taxo_by_name():
    data = request.get_json()
    pid = data["pid"]
    uid = data["uid"]
    sid = data["sid"]
    tid = data["tid"]
    lid = data["lid"]
    pip = data["pip"]
    dbname = data["rid"]
    pipeline = pip
    # dbname="isuezrouja"
    analysis = "taxonomy"
    x = sql.SQL(main_db)
    rf = rootvar.result_files(pid, analysis, pip, sid, dbname)
    samples = x.exe('select * from samples where project_id="' +
                    pid+'" and sample_id="'+sid+'"')
    xpath = x.project(pid)[0][4]
    sample = rootvar.samples(samples[0], xpath)
    x.close()
    view = rootvar.ViewSampleResults(sample, pipeline, dbname, analysis, rf)
    try:
        # return jsonify(x=pip)
        return jsonify(matrix=view.level(lid, type="matches"))
    except Exception as inst:
        return "ERROR: "+str(inst)
Exemple #2
0
def get_tree():
    try:
        data = request.get_json()
        pid = data["pid"]
        uid = data["uid"]
        sid = data["sid"]
        selval = data["value"]
        pipeline = data["pip"]
        dbname = data["rid"]
        # dbname="isuezrouja"
        analysis = "taxonomy"
        rf = rootvar.result_files(pid, analysis, pipeline, sid, dbname)
        x = sql.SQL(main_db)
        samples = x.exe('select * from samples where project_id="' +
                        pid+'" and sample_id="'+sid+'"')
        xpath = x.project(pid)[0][4]
        sample = rootvar.samples(samples[0], xpath)
        with open(rf.json) as data_file:
            data = json.load(data_file)
        x.close()
        ###print data
        view = rootvar.ViewSampleResults(
            sample, pipeline, dbname, analysis, rf)
        return jsonify(tree=[data], range=view.range(selval)[0], pip=pipeline)
    except Exception as inst:
        return "ERROR: "+str(inst)
def functional(data):
    pid = data["pid"]
    uid = data["uid"]
    sids = data["sid"]
    pipeline = data["pip"]
    rid = data["rid"]
    edges = []
    FULL_MATRIX = []
    #first see if the data set contains taxonomy, function or both annotations
    analysis = "function"
    #print rid
    #
    #
    os.system("mkdir " + rootvar.__ROOTPRO__ + "/" + pid + "/" + pipeline +
              "/RESULTS/ >> " + rootvar.log + " 2>&1")
    all_samples_tree_file = rootvar.__ROOTPRO__ + "/" + pid + "/" + pipeline + "/RESULTS/" + rid + ".all_samples_tree.pk"

    log = open(
        rootvar.__ROOTPRO__ + "/" + pid + "/" + pipeline + "/RESULTS/" + rid +
        ".log", "w")

    #
    # if os.path.isfile(all_samples_tree_file):
    #     x=sql.SQL(all_samples_tree_file+".db")
    #     val=x.exe("select distinct sample_name from full_matrix")
    #     stored_samples=len(val)
    #
    # x=sql.SQL(main_db)
    # # load all the samples that have been finalized to run
    # sids=x.exe('select c.sample_id from (select * from samples a inner join (select * from sample_status where pip="'+str(pipeline)+'") b on a.sample_id==b.sid) c where c.project_id=="'+pid+'" and c.status="Done" and c.rid="'+rid+'"')
    # x.close()
    # if os.path.isfile(all_samples_tree_file) and stored_samples == len(sids):
    #     x=sql.SQL(all_samples_tree_file+".db")
    #     FULL_MATRIX=x.exe("select * from full_matrix")
    #     return ["function",FULL_MATRIX,all_samples_tree_file+".json"]
    # nodes={}

    x = sql.SQL(main_db)
    log.write("echo #LOG for Project ID: " + str(pid) + "\n")
    for sid in sids:
        samples = x.exe('select * from samples where project_id="' + pid +
                        '" and sample_id="' + sid + '"')
        # log.write(str(sid)+"\n")
        xpath = x.project(pid)[0][4]
        sample = rootvar.samples(samples[0], xpath)
        #print sample.name
        # log.write(str(samples[0])+"\n")
        rf = rootvar.result_files(pid, analysis, pipeline, sample.id, rid)
        view = rootvar.ViewSampleResults(sample, pipeline, rid, analysis, rf)
        FULL_MATRIX += view.all_func()
        #print sample.name
    x.close()
    # log.write(str(FULL_MATRIX))
    #print FULL_MATRIX[0]
    #rootvar.full_matrix_function(all_samples_tree_file+".db", FULL_MATRIX)
    #print "matrix done"
    # tree=["none"]
    return ["function", FULL_MATRIX, all_samples_tree_file + ".json"]
Exemple #4
0
def get_childs_of_taxonomy():
    data = request.get_json()
    pid = data["pid"]
    uid = data["uid"]
    sid = data["sid"]
    tid = data["tid"]
    lid = data["lid"]
    cond = data["cond"]
    pip = data["pip"]
    rid = data["rid"]

    dbname = data["rid"]
    analysis = "taxonomy"

    ##print cond, pip, rid, pid, uid, sid, tid, lid

    if cond == "one":  # this is if I am analyzing one or multiple samples
        rf = rootvar.result_files(pid, analysis, pip, sid, dbname)
        x = sql.SQL(main_db)
        samples = x.exe('select * from samples where project_id="' +
                        pid+'" and sample_id="'+sid+'"')
        xpath = x.project(pid)[0][4]
        sample = rootvar.samples(samples[0], xpath)
        x.close()
        view = rootvar.ViewSampleResults(sample, pip, dbname, analysis, rf)
        matrix = view.childs_of(tid, 'rpkm')
        ###print matrix
        return jsonify(matrix=matrix)
    else:
        # load big tree
        all_samples_tree_file = rootvar.__ROOTPRO__+"/" + \
            pid+"/"+pip+"/RESULTS/"+rid+".all_samples_tree.pk"
        G = nx.read_gpickle(all_samples_tree_file)
        tree = json_graph.tree_data(G, root='R')
        data = []
        for i in G.successors(tid):
            data.append(i)
        x = sql.SQL(all_samples_tree_file+".db")

        matrix = rootvar.get_matrix_level_childs(x, data)
        samples_sel = list(set([str(i[0]) for i in matrix]))
        M, N = rootvar.v2m(matrix, samples_sel, 0, 0)
        ##print M
        heatmap = 'none'  # heatmap=iclust.main(M,None)
        return jsonify(data=matrix[0], heatmap=heatmap)
Exemple #5
0
def get_functional_counts():
    try:
        data = request.get_json()
        pid = data["pid"]
        uid = data["uid"]
        sid = data["sid"]
        pip = data["pip"]
        rid = data["rid"]
        pip = data['pip']
        analysis = "function"
        # lid="assembly"
        # file=rootvar.__ROOTPRO__+"/"+pid+"/assembly/idba_ud/"+sid+"/pred.genes."+rid+".matches.function.abundance.results.sqlite3.db"
        x = sql.SQL(main_db)
        rf = rootvar.result_files(pid, "function", pip, sid, rid)
        samples = x.exe('select * from samples where project_id="' +
                        pid+'" and sample_id="'+sid+'"')
        xpath = x.project(pid)[0][4]
        sample = rootvar.samples(samples[0], xpath)
        x.close()
        view = rootvar.ViewSampleResults(sample, pip, rid, analysis, rf)
        return jsonify(matrix=view.func_one_sample(), m2=view.func_structure(pid, pip, sid))
    except Exception as inst:
        return "ERROR: "+str(inst)
def taxonomy(data):
    pid = data["pid"]
    uid = data["uid"]
    sids = data["sid"]
    pipeline = data["pip"]
    rid = data["rid"]
    edges = []
    FULL_MATRIX = []
    #first see if the data set contains taxonomy, function or both annotations
    analysis = "taxonomy"
    #print '\n\n\n here we goo!!!\n\n\n', pipeline
    rootvar.mkdir(rootvar.__ROOTPRO__ + "/" + pid + "/" + pipeline +
                  "/RESULTS/")
    all_samples_tree_file = rootvar.__ROOTPRO__ + "/" + pid + "/" + pipeline + "/RESULTS/" + rid + ".all_samples_tree.pk"
    #
    stored_samples = 0
    if os.path.isfile(all_samples_tree_file):
        #print '\n\n\n if the X file has been created'
        x = sql.SQL(all_samples_tree_file + ".db")
        val = x.exe("select distinct sample_name from full_matrix")
        stored_samples = len(val)
    #
    x = sql.SQL(main_db)
    sids = x.exe(
        'select c.sample_id from (select * from samples a inner join (select * from sample_status where pip="'
        + str(pipeline) +
        '") b on a.sample_id==b.sid) c where c.project_id=="' + pid +
        '" and c.status="Done" and c.rid="' + rid + '"')
    #
    #
    #print '\n\n\n\n super important \n', sids
    #print '\n\n\n get all the samples from the X file'
    #
    if os.path.isfile(all_samples_tree_file) and stored_samples == len(sids):
        #print 'both have the same length'
        G = nx.read_gpickle(all_samples_tree_file)
        tree = json_graph.tree_data(G, root='R')
        return ["taxonomy", tree]
    #section
    #print '\n\n\n SO the file has not been created, because the matrix of abundances has not been fetched for those samples'
    nodes = {}
    #print '\n\n\n So for each sample I get all the information from the sql tables. And create the tree \n\n\n\n\n\n'
    #
    for sid in sids:
        samples = x.exe('select * from samples where project_id="' + pid +
                        '" and sample_id="' + sid[0] + '"')
        xpath = x.project(pid)[0][4]
        sample = rootvar.samples(samples[0], xpath)
        rf = rootvar.result_files(pid, analysis, pipeline, sample.id, rid)
        view = rootvar.ViewSampleResults(sample, pipeline, rid, analysis, rf)
        FULL_MATRIX += view.all()
        Gp = nx.read_gpickle(rf.pk)
        edges += Gp.edges()
        for node in Gp.nodes():
            if not node in nodes:
                nodes[node] = Gp.node[node]['level']
    x.close()
    rootvar.full_matrix_sql(all_samples_tree_file + ".db", FULL_MATRIX)
    G = nx.DiGraph()
    for i in edges:
        if not i in G.edges():
            if not i[1] in G.nodes():
                G.add_node(i[1], samples=1, level=nodes[i[1]])
            else:
                G.node[i[1]]['samples'] += 1
            if not i[0] in G.nodes():
                G.add_node(i[0], samples=1, level=nodes[i[0]])
            else:
                G.node[i[0]]['samples'] += 1
            if not G.predecessors(i[1]):
                G.add_edge(i[0], i[1])
        else:
            G.node[i[0]]['samples'] += 1
            G.node[i[1]]['samples'] += 1
    tree = json_graph.tree_data(G, root='R')
    nx.write_gpickle(G, all_samples_tree_file)
    return ["taxonomy", tree, all_samples_tree_file + ".json"]