Ejemplo n.º 1
0
def get_case_hits(size, order, f, cy):
    hits = []
    cquery = ""
    if cy == "":
        order = order.split(":")
        retval = "RETURN DISTINCT Project.name,Study.subtype,Sample.id,Project.subtype,Sample.fma_body_site ORDER BY %s %s SKIP %s LIMIT %s"
        cquery = "%s %s" % (full_traversal, retval)
        if f != 0:
            f = f - 1
        cquery = cquery % (order[0], order[1].upper(), f, size)
    elif '"op"' in cy:
        cquery = build_cypher(match, cy, order, f, size, "cases")
    else:
        cquery = build_adv_cypher(match, cy, order, f, size, "cases")
    res = graph.data(cquery)
    for x in range(0, len(res)):
        cur = CaseHits(project=Project(
            projectId=res[x]['Project.subtype'],
            primarySite=res[x]['Sample.fma_body_site'],
            name=res[x]['Project.name'],
            studyName=res[x]['Study.name'],
            studyFullName=res[x]['Study.full_name']),
                       caseId=res[x]['Sample.id'])
        hits.append(cur)
    return hits
Ejemplo n.º 2
0
def count_props_and_files(node, prop, cy):

    cquery, with_distinct = ("" for i in range(2))

    if cy == "":
        retval = ("WITH (COUNT(DISTINCT(Sample))) as ccounts, "
                  "COUNT(DISTINCT(File)) AS dcounts, %s.%s AS prop, "
                  "collect(DISTINCT File) AS f UNWIND f AS fs "
                  "RETURN prop,ccounts,dcounts,SUM(toInt(fs.size)) as tot")

        mod_retval = retval % (node, prop)
        cquery = "%s %s" % (full_traversal, mod_retval)

    else:
        if node == 'Study' and prop == 'name':
            prop = 'sname'

        prop_detailed = "%s_detailed" % (prop)
        if "op" in cy:
            cquery = build_cypher(match, cy, "null", "null", "null",
                                  prop_detailed)
        else:
            cquery = build_adv_cypher(match, cy, "null", "null", "null",
                                      prop_detailed)

    return graph.data(cquery)
Ejemplo n.º 3
0
def get_total_file_size(cy):
    cquery = ""
    if cy == "":
        cquery = "MATCH (File) WHERE NOT File.node_type=~'.*prep' RETURN SUM(toInt(File.size)) AS tot"
    elif '"op"' in cy:
        cquery = build_cypher(match, cy, "null", "null", "null", "size")
    else:
        cquery = build_adv_cypher(match, cy, "null", "null", "null", "size")
    res = graph.data(cquery)
    return res[0]['tot']
Ejemplo n.º 4
0
def get_pagination(cy, size, f, c_or_f):
    cquery = ""
    if cy == "":
        if c_or_f == 'c':
            cquery = "MATCH (n:Case {node_type:'sample'}) RETURN count(n) AS tot"
        else:
            cquery = "MATCH (n:File) WHERE NOT n.node_type=~'.*prep' RETURN count(n) AS tot"
        res = graph.data(cquery)
        calcs = pagination_calcs(res[0]['tot'], f, size, c_or_f)
        return Pagination(count=calcs[2],
                          sort=calcs[4],
                          fromNum=f,
                          page=calcs[1],
                          total=calcs[3],
                          pages=calcs[0],
                          size=size)
    else:
        if '"op"' in cy:
            if c_or_f == 'c':
                cquery = build_cypher(match, cy, "null", "null", "null",
                                      "c_pagination")
            else:
                cquery = build_cypher(match, cy, "null", "null", "null",
                                      "f_pagination")
        else:
            if c_or_f == 'c':
                cquery = build_adv_cypher(match, cy, "null", "null", "null",
                                          "c_pagination")
            else:
                cquery = build_adv_cypher(match, cy, "null", "null", "null",
                                          "f_pagination")
        res = graph.data(cquery)
        calcs = pagination_calcs(res[0]['tot'], f, size, c_or_f)
        return Pagination(count=calcs[2],
                          sort=calcs[4],
                          fromNum=f,
                          page=calcs[1],
                          total=calcs[3],
                          pages=calcs[0],
                          size=size)
Ejemplo n.º 5
0
def count_props(node, prop, cy):
    cquery = ""
    if cy == "":
        if node in count_props_dict:
            cquery = count_props_dict[node] % (prop)
        elif node == 'sample':
            cquery = "MATCH (n:Case{node_type:'sample'})<-[:PREPARED_FROM]-(pf)<-[:SHORTCUT]-(File) WITH DISTINCT n RETURN n.%s AS prop, COUNT(n.%s) as counts" % (
                prop, prop)
        else:
            cquery = "Match (n:File) WHERE NOT n.node_type=~'.*prep' RETURN n.%s as prop, count(n.%s) as counts" % (
                prop, prop)
    else:
        cquery = build_cypher(match, cy, "null", "null", "null", prop)
    return graph.data(cquery)
Ejemplo n.º 6
0
def get_file_hits(size, order, f, cy):
    hits = []
    cquery = ""
    if cy == "":
        order = order.split(":")
        retval = "RETURN DISTINCT Project,File,Sample.id ORDER BY %s %s SKIP %s LIMIT %s"
        cquery = "%s %s" % (full_traversal, retval)
        if f != 0:
            f = f - 1
        cquery = cquery % (order[0], order[1].upper(), f, size)
    elif '"op"' in cy:
        cquery = build_cypher(match, cy, order, f, size, "files")
    else:
        cquery = build_adv_cypher(match, cy, order, f, size, "files")
    res = graph.data(cquery)
    for x in range(0, len(res)):
        case_hits = []  # reinit each iteration
        cur_case = CaseHits(project=Project(
            projectId=res[x]['Project']['subtype'],
            name=res[x]['Project']['name']),
                            caseId=res[x]['Sample.id'])
        case_hits.append(cur_case)
        furl = extract_url(res[x]['File'])  # File name is our URL
        if '.hmpdacc' in furl:  # HMP endpoint
            furl = re.search(r'/data/(.*)', furl).group(1)
        elif '.ihmpdcc':
            furl = re.search(r'.org/(.*)', furl).group(1)
        cur_file = FileHits(dataType=res[x]['File']['subtype'],
                            fileName=furl,
                            dataFormat=res[x]['File']['format'],
                            submitterId="null",
                            access="open",
                            state="submitted",
                            fileId=res[x]['File']['id'],
                            dataCategory=res[x]['File']['node_type'],
                            experimentalStrategy=res[x]['File']['subtype'],
                            fileSize=res[x]['File']['size'],
                            cases=case_hits)
        hits.append(cur_file)
    return hits