Skip to content

Latest commit

 

History

History
115 lines (98 loc) · 3.06 KB

gmdb_list_components_by_keyword.md

File metadata and controls

115 lines (98 loc) · 3.06 KB

List growth media components with the given keyword (for pagenation)

Show a list of growth media components with the given keyword.

Parameters

  • keyword keyword
    • default: Glucose
    • examples: yeast extract, Glutamic acid, Juice, Magnesium nitrate
  • limit limit
    • default: 10
  • offset offset
    • default: 0

Endpoint

http://togomedium.org/sparql

count retrieve GMO component information

PREFIX gmo: <http://purl.jp/bio/10/gmo/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>

SELECT (COUNT(DISTINCT ?component) AS ?total) ?limit ?offset
FROM <http://togomedium.org/gmo>
WHERE {
  ?component rdfs:subClassOf+ gmo:GMO_000002 ;
    dcterms:identifier ?gmo_id ;
    skos:prefLabel ?pref_label ;
    (skos:prefLabel | skos:altLabel | rdfs:label) ?label .
  FILTER(REGEX(?label, "{{keyword}}", "i"))
  OPTIONAL {
    ?component skos:altLabel ?alt_label .
    FILTER(lang(?alt_label) = "en")
  }
  BIND("{{limit}}" AS ?limit)
  BIND("{{offset}}" AS ?offset)
}

result retrieve GMO component information

PREFIX gmo: <http://purl.jp/bio/10/gmo/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>

SELECT
  ?gmo_id ?component ?pref_label
  (GROUP_CONCAT(DISTINCT ?alt_label; SEPARATOR = ", ") AS ?alt_labels)
FROM <http://togomedium.org/gmo>
WHERE {
  ?component rdfs:subClassOf+ gmo:GMO_000002 ;
    dcterms:identifier ?gmo_id ;
    skos:prefLabel ?pref_label ;
    (skos:prefLabel | skos:altLabel | rdfs:label) ?label .
  FILTER(REGEX(?label, "{{keyword}}", "i"))
  OPTIONAL {
    ?component skos:altLabel ?alt_label .
    FILTER(lang(?alt_label) = "en")
  }
}
GROUP BY ?gmo_id ?component ?pref_label
LIMIT {{limit}}
OFFSET {{offset}}

Output

({
  json({result, count}) {
    let rows = result.results.bindings;
    let count_rows = count.results.bindings[0];
    let components = {};
    components.contents = [];
    
    components.total = 0;
    components.limit = 0;
    components.offset = 0;
    
    if (rows.length == 0) {
      return components;
    }
    
    for (let i = 0; i < rows.length ;i++) {
      if (rows[i].alt_labels.value.length > 0) {
        components.contents.push({
          gmo_id: {label: rows[i].gmo_id.value,
                   href: "/component/" + rows[i].gmo_id.value},
          name: rows[i].pref_label.value + "; " + rows[i].alt_labels.value
        });
      } else {
        components.contents.push({
          gmo_id: {label: rows[i].gmo_id.value,
                   href: "/component/" + rows[i].gmo_id.value},
          name: rows[i].pref_label.value
        });
      }
    }
    
    components.columns = [];
    components.columns.push({key: "gmo_id", label: "GMO ID"});
    components.columns.push({key: "name", label: "Name"});
    components.total = count_rows.total.value ;
    components.limit = count_rows.limit.value ;
    components.offset = count_rows.offset.value ;
    return components;
  }
})