---
layout: default
navsection: userguide
+navmenu: Tutorials
title: "Querying the Metadata Database"
-navorder: 116
+navorder: 16
---
h1. Tutorial: Querying the Metadata Database
notextile. <pre><code>>>> <span class="userinput">import arvados</span></pre></code>
-This tutorial will also use the regular expression (re) and json python modules:
+This tutorial will also use the regular expression (re) python module:
<notextile>
<pre><code>>>> <span class="userinput">import re</span>
->>> <span class="userinput">import json</span>
</code></pre>
</notextile>
We query the "links" resource to find humans that report the selected trait. Links are directional connections between Arvados data items, for example, from a human to their reported traits.
<notextile>
-<pre><code>>>> <span class="userinput">trait_query = json.dumps({
+<pre><code>>>> <span class="userinput">trait_query = {
'link_class': 'human_trait',
'tail_kind': 'arvados#human',
'head_uuid': non_melanoma_cancer
- })
+ }
</code></pre>
</notextile>
h2. Find Personal Genome Project identifiers from Arvados UUIDs
<notextile>
-<pre><code>>>> <span class="userinput">human_query = json.dumps({
+<pre><code>>>> <span class="userinput">human_query = {
"link_class": "identifier",
"head_uuid": human_uuids
- })</span>
+ }</span>
>>> <span class="userinput">pgpid_links = arvados.api('v1').links().list(limit=1000, where=human_query).execute()</span>
>>> <span class="userinput">map(lambda l: l['name'], pgpid_links['items'])</span>
[u'hu01024B', u'hu11603C', u'hu15402B', u'hu174334', u'hu1BD549', u'hu237A50',
Now we want to find collections in Keep that were provided by these humans. We search the "links" resource for "provenance" links that point to subjects in list of humans with the non-melanoma skin cancer trait:
<notextile>
-<pre><code>>>> <span class="userinput">provenance_links = arvados.api().links().list(limit=1000, where=json.dumps({
+<pre><code>>>> <span class="userinput">provenance_links = arvados.api().links().list(limit=1000, where={
"link_class": "provenance",
"name": "provided",
"tail_uuid": human_uuids
- })).execute()
+ }).execute()
collection_uuids = map(lambda l: l['head_uuid'], provenance_links['items'])
# build map of human uuid -> PGP ID
pgpid[p_link['head_uuid']] = pgpid[p_link['tail_uuid']]
# get details (e.g., list of files) of each collection
-collections = arvados.api('v1').collections().list(where=json.dumps({
+collections = arvados.api('v1').collections().list(where={
"uuid": collection_uuids
- })).execute()
+ }).execute()
# print PGP public profile links with file locators
for c in collections['items']: