Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group method #319

Merged
merged 13 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions conformance/tests/ot_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import absolute_import

import gripql

def test_childGroups(man):
errors = []
G = man.setGraph("swapi")

mapping = {
'Planet:1' : ['Luke Skywalker', 'C-3PO', 'Darth Vader', 'Owen Lars', 'Beru Whitesun lars', 'R5-D4', 'Biggs Darklighter'],
'Planet:2' : ['Leia Organa', 'Raymus Antilles']
}
mapping_hair = {
'Planet:1' : ["blond", None, "none", "brown, grey", "brown", None, "black"],
'Planet:2' : ["brown", "brown"]
}

for i in G.query().V().hasLabel("Planet").as_("planet").out("residents").as_("character").select("planet").group( {"people" : "$character.name"} ):
#print(i)
if sorted(i["data"]["people"]) != sorted(mapping[i["gid"]]):
errors.append("grouped output not equal: %s != %s" % (sorted(i["data"]["people"]) , sorted(mapping[i["gid"]])))

for i in G.query().V().hasLabel("Planet").as_("planet").out("residents").as_("character").select("planet").group(
{"people" : "$character.name", "hair":"$character.hair_color"} ):
#print(i)
print(i["data"])
if sorted(i["data"]["people"]) != sorted(mapping[i["gid"]]):
errors.append("grouped output not equal: %s != %s" % (sorted(i["data"]["people"]) , sorted(mapping[i["gid"]])))

if sorted(i["data"]["hair"], key=lambda x: (x is None, x)) != sorted(mapping_hair[i["gid"]], key=lambda x: (x is None, x)):
errors.append("grouped output not equal: %s != %s" % (sorted(i["data"]["hair"], key=lambda x: (x is None, x)) , sorted(mapping_hair[i["gid"]], key=lambda x: (x is None, x))))
return errors
62 changes: 62 additions & 0 deletions conformance/tests/ot_totype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import gripql

def test_totype(man):
errors = []

G = man.setGraph("swapi")

q = G.query().V().hasLabel("Character").totype("birth_year", "string").totype("eye_color", "float").totype("hair_color", "int").totype("skin_color", "list").totype("mass", "string").execute()
if len(q) == 0:
errors.append("ERROR, q returns no items")
for row in q:
data = row["data"]
# transforms that should work
if not isinstance(data["birth_year"], str):
errors.append("string field %s should be string" % (data["birth_year"]))
if not isinstance(data["skin_color"], list):
errors.append("string field %s should be list" % (data["skin_color"]))
# some masses are none by default
if data["mass"] is not None and not isinstance(data["mass"], str):
errors.append("int field %d should be string" % (data["mass"]))

# transforms that shouldn't work'
if data["eye_color"] != 0.0:
errors.append("string value %s should be 0.0" % (data["eye_color"]))
if data["hair_color"] != 0:
errors.append("%s should be 0" % (data["hair_color"]))

r = G.query().V().hasLabel("Starship").totype("hyperdrive_rating", "string").totype("length", "int").totype("length", "float").totype("system", "list").execute()
if len(r) == 0:
errors.append("ERROR, r returns no items")
for row in r:
data = row["data"]
if isinstance(data["hyperdrive_rating"], int) or isinstance(data["hyperdrive_rating"], float):
errors.append("float field %s should be int or float" %(data["hyperdrive_rating"]))
if not isinstance(data["length"], int):
errors.append("float field %s should be int" %(data["length"]))
if not isinstance(data["system"], list):
errors.append("dict object with key 'system' %s should be list" %(data["system"]))

s = G.query().V().hasLabel("Species").totype("system.created", "bool").execute()
if len(s) == 0:
errors.append("ERROR, s returns no items")
for row in s:
data = row["data"]
if data["system"]["created"] != True:
errors.append("string %s to bool should be False" %(data["system"]["created"]))


t = G.query().V().hasLabel("Starship").totype("MGLT", "bool").totype("eye_colors", "int").totype("classification", "int").execute()
if len(t) == 0:
errors.append("ERROR, t returns no items")

for row in t:
data = row["data"]
if data["length"] is False:
errors.append("int %s to bool should be True" %(data["MGLT"]))
if data["eye_colors"] != 0:
errors.append("list %s to bool should be False" %(data["eye_colors"]))
if data["classification"] != 0:
errors.append("string %s to bool should be False" %(data["classification"]))

return errors
21 changes: 21 additions & 0 deletions conformance/tests/ot_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,24 @@ def test_unwind(man):
errors.append("There should be 2 vertices after unwind process and filter")

return errors


def test_unwind_group_totype(man):
errors = []
G = man.writeTest()
bulk = G.bulkAdd()
bulk.addVertex("1", "Observation", {"resourceType": "Observation", "id": "e87cecef-c91d-3861-a35e-6eaed41580c8", "status": "final", "category": [{"coding": [{"system": "http://terminology.hl7.org/CodeSystem/observation-category", "code": "laboratory", "display": "laboratory"}]}], "code": {"coding": [{"system": "http://loinc.org", "code": "81247-9", "display": "Master HL7 genetic variant reporting panel"}]}, "subject": {"reference": "Patient/ac0d7a82-82cb-4aec-b859-e37375f3de8b"}, "specimen": {"reference": "Specimen/dc48f578-193c-4740-93f3-61a78e3c6ba0"}, "focus": [{"reference": "Specimen/dc48f578-193c-4740-93f3-61a78e3c6ba0"}], "effectiveDateTime": "2024-06-03T08:00:00+00:00", "valueString": "Sequencing parameters", "component": [{"code": {"coding": [{"system": "https://cadsr.cancer.gov/sample_laboratory_observation", "code": "concentration", "display": "concentration"}], "text": "concentration"}, "valueQuantity": {"value": 0.16}}, {"code": {"coding": [{"system": "https://cadsr.cancer.gov/sample_laboratory_observation", "code": "aliquot_quantity", "display": "aliquot_quantity"}], "text": "aliquot_quantity"}, "valueQuantity": {"value": 2.13}}, {"code": {"coding": [{"system": "https://cadsr.cancer.gov/sample_laboratory_observation", "code": "aliquot_volume", "display": "aliquot_volume"}], "text": "aliquot_volume"}, "valueQuantity": {"value": 13.3}}]})

bulk.addVertex("2", "Specimen", {"resourceType": "Specimen", "id": "dc48f578-193c-4740-93f3-61a78e3c6ba0", "status": "final", "category": [{"coding": [{"system": "http://terminology.hl7.org/CodeSystem/observation-category", "code": "laboratory", "display": "laboratory"}]}], "code": {"coding": [{"system": "http://loinc.org", "code": "81247-9", "display": "Master HL7 genetic variant reporting panel"}]}, "subject": {"reference": "Patient/ac0d7a82-82cb-4aec-b859-e37375f3de8b"}, "specimen": {"reference": "Specimen/dc48f578-193c-4740-93f3-61a78e3c6ba0"}, "focus": [{"reference": "Specimen/dc48f578-193c-4740-93f3-61a78e3c6ba0"}], "effectiveDateTime": "2024-06-03T08:00:00+00:00", "valueString": "Sequencing parameters", "component": [{"code": {"coding": [{"system": "https://cadsr.cancer.gov/sample_laboratory_observation1", "code": "concentration", "display": "concentration"}], "text": "concentration"}, "valueQuantity": {"value": 0.16}}, {"code": {"coding": [{"system": "https://cadsr.cancer.gov/sample_laboratory_observation2", "code": "aliquot_quantity", "display": "aliquot_quantity"}], "text": "aliquot_quantity"}, "valueQuantity": {"value": 2.13}}, {"code": {"coding": [{"system": "https://cadsr.cancer.gov/sample_laboratory_observation3", "code": "aliquot_volume", "display": "aliquot_volume"}], "text": "aliquot_volume"}, "valueQuantity": {"value": 13.3}}]})
bulk.addEdge("1", "2", "focus_Specimen")
err = bulk.execute()

orig_row = {}
for i in G.query().V().hasLabel("Observation").as_("f0").out("focus_Specimen"):
orig_row = i

for i in G.query().V().hasLabel("Observation").as_("f0").out("focus_Specimen").unwind("component").unwind("component.code.coding").as_("f1").totype("$f1.component.code.coding","list").group({"component":"$f1.component"}):
if not isinstance(i["data"]["component"][0]["code"]["coding"], list) and isinstance(orig_row["data"]["component"][0]["code"]["coding"], list):
errors.append("Original row list format not preserved: %s !=\n\n %s" % (orig_row, i))

return errors
2 changes: 1 addition & 1 deletion docs/categories/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Categories on GRIP</title>
<link>https://bmeg.github.io/grip/categories/</link>
<description>Recent content in Categories on GRIP</description>
<generator>Hugo</generator>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="https://bmeg.github.io/grip/categories/index.xml" rel="self" type="application/rss+xml" />
</channel>
Expand Down
88 changes: 44 additions & 44 deletions docs/docs/queries/jsonpath/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -394,50 +394,50 @@ <h1 id="referencing-vertexedge-properties">Referencing Vertex/Edge Properties</h
}
</code></pre><p>Below is a table of field and the values they would reference in subsequent traversal operations.</p>
<table>
<thead>
<tr>
<th style="text-align: left">jsonpath</th>
<th style="text-align: left">result</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">_gid</td>
<td style="text-align: left">&ldquo;NM_007294.3:c.4963_4981delTGGCCTGACCCCAGAAG&rdquo;</td>
</tr>
<tr>
<td style="text-align: left">_label</td>
<td style="text-align: left">&ldquo;variant&rdquo;</td>
</tr>
<tr>
<td style="text-align: left">_data.type</td>
<td style="text-align: left">&ldquo;deletion&rdquo;</td>
</tr>
<tr>
<td style="text-align: left">type</td>
<td style="text-align: left">&ldquo;deletion&rdquo;</td>
</tr>
<tr>
<td style="text-align: left">publications[0].pmid</td>
<td style="text-align: left">29480828</td>
</tr>
<tr>
<td style="text-align: left">publications[:].pmid</td>
<td style="text-align: left">[29480828, 23666017]</td>
</tr>
<tr>
<td style="text-align: left">publications.pmid</td>
<td style="text-align: left">[29480828, 23666017]</td>
</tr>
<tr>
<td style="text-align: left">$gene.symbol.hugo</td>
<td style="text-align: left">&ldquo;BRCA1&rdquo;</td>
</tr>
<tr>
<td style="text-align: left">$gene.transcripts[0]</td>
<td style="text-align: left">&ldquo;ENST00000471181.7&rdquo;</td>
</tr>
</tbody>
<thead>
<tr>
<th style="text-align:left">jsonpath</th>
<th style="text-align:left">result</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">_gid</td>
<td style="text-align:left">&ldquo;NM_007294.3:c.4963_4981delTGGCCTGACCCCAGAAG&rdquo;</td>
</tr>
<tr>
<td style="text-align:left">_label</td>
<td style="text-align:left">&ldquo;variant&rdquo;</td>
</tr>
<tr>
<td style="text-align:left">_data.type</td>
<td style="text-align:left">&ldquo;deletion&rdquo;</td>
</tr>
<tr>
<td style="text-align:left">type</td>
<td style="text-align:left">&ldquo;deletion&rdquo;</td>
</tr>
<tr>
<td style="text-align:left">publications[0].pmid</td>
<td style="text-align:left">29480828</td>
</tr>
<tr>
<td style="text-align:left">publications[:].pmid</td>
<td style="text-align:left">[29480828, 23666017]</td>
</tr>
<tr>
<td style="text-align:left">publications.pmid</td>
<td style="text-align:left">[29480828, 23666017]</td>
</tr>
<tr>
<td style="text-align:left">$gene.symbol.hugo</td>
<td style="text-align:left">&ldquo;BRCA1&rdquo;</td>
</tr>
<tr>
<td style="text-align:left">$gene.transcripts[0]</td>
<td style="text-align:left">&ldquo;ENST00000471181.7&rdquo;</td>
</tr>
</tbody>
</table>
<h2 id="usage-example">Usage Example:</h2>
<pre tabindex="0"><code>O.query().V([&#34;ENSG00000012048&#34;]).as_(&#34;gene&#34;).out(&#34;variant&#34;).render({&#34;variant_id&#34;: &#34;_gid&#34;, &#34;variant_type&#34;: &#34;type&#34;, &#34;gene_id&#34;: &#34;$gene._gid&#34;})
Expand Down
Loading
Loading