diff options
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/api/metadata.py | 702 |
1 files changed, 332 insertions, 370 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py index eb42be4..fbdc8f5 100644 --- a/gn3/api/metadata.py +++ b/gn3/api/metadata.py @@ -1,11 +1,8 @@ """API for fetching metadata using an API""" from string import Template -from http.client import RemoteDisconnected -from urllib.error import URLError from pathlib import Path from flask import Blueprint -from flask import jsonify from flask import request from flask import current_app @@ -143,12 +140,11 @@ metadata = Blueprint("metadata", __name__) @metadata.route("/datasets/<name>", methods=["GET"]) def datasets(name): """Fetch a dataset's metadata given it's ACCESSION_ID or NAME""" - try: - _query = Template(""" + _query = Template(""" $prefix CONSTRUCT { - ?dataset ?predicate ?term ; + ?dataset ?predicate ?term ; gnt:usesNormalization ?normalization . ?inbredSet rdfs:label ?inbredSetName . ?platform ?platformPred ?platformObject . @@ -158,7 +154,7 @@ CONSTRUCT { foaf:homepage ?homepage . ?type skos:prefLabel ?altName . } WHERE { - ?dataset rdf:type dcat:Dataset ; + ?dataset rdf:type dcat:Dataset ; ?predicate ?term ; (rdfs:label|dct:identifier|skos:prefLabel) "$name" . FILTER (!regex(str(?predicate), '(usesNormalization)', 'i')) . @@ -192,32 +188,29 @@ CONSTRUCT { ?tissuePred ?tissueObj . } . }""").substitute(prefix=RDF_PREFIXES, name=name) - _context = { - "@context": BASE_CONTEXT | DATASET_CONTEXT, - "type": "dcat:Dataset", - } - __result = query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - return __result | retrieve_dataset_metadata( - (Path( - current_app.config.get("DATA_DIR") - ) / "gn-docs/general/datasets" / - Path(__result.get("id", "")).stem).as_posix() - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | DATASET_CONTEXT, + "type": "dcat:Dataset", + } + __result = query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) + return __result | retrieve_dataset_metadata( + (Path( + current_app.config.get("DATA_DIR") + ) / "gn-docs/general/datasets" / + Path(__result.get("id", "")).stem).as_posix() + ) @metadata.route("/datasets/<group>/list", methods=["GET"]) def list_datasets_by_group(group): """List datasets that belong to a given group""" - try: - args = request.args - page = args.get("page", 0) - page_size = args.get("per-page", 10) - _query = Template(""" + args = request.args + page = args.get("page", 0) + page_size = args.get("per-page", 10) + _query = Template(""" $prefix CONSTRUCT { @@ -233,7 +226,7 @@ CONSTRUCT { } WHERE { { SELECT ?datasetName ?accessionId ?createTime ?title WHERE { - ?dataset rdf:type dcat:Dataset ; + ?dataset rdf:type dcat:Dataset ; rdfs:label ?datasetName . ?inbredSet ^skos:member gnc:Set ; ^xkos:classifiedUnder ?dataset ; @@ -258,26 +251,23 @@ CONSTRUCT { } } """).substitute(prefix=RDF_PREFIXES, group=group, limit=page_size, offset=page) - _context = { - "@context": BASE_CONTEXT | DATASET_SEARCH_CONTEXT, - "type": "resultItem", - } - return query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | DATASET_SEARCH_CONTEXT, + "type": "resultItem", + } + return query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/datasets/search/<term>", methods=["GET"]) def search_datasets(term): """Search datasets""" - try: - args = request.args - page = args.get("page", 0) - page_size = args.get("per-page", 10) - _query = Template(""" + args = request.args + page = args.get("page", 0) + page_size = args.get("per-page", 10) + _query = Template(""" $prefix CONSTRUCT { @@ -293,7 +283,8 @@ CONSTRUCT { ] } WHERE { { - SELECT DISTINCT ?dataset ?label ?inbredSetName ?datasetType ?title WHERE { + SELECT DISTINCT ?dataset ?label ?inbredSetName ?datasetType ?title + WHERE { ?dataset rdf:type dcat:Dataset ; rdfs:label ?label ; ?datasetPredicate ?datasetObject ; @@ -308,13 +299,14 @@ CONSTRUCT { ?classification ^xkos:classifiedUnder ?dataset ; ^skos:member gnc:DatasetType ; ?typePredicate ?typeName ; - skos:prefLabel ?datasetType . + skos:prefLabel ?datasetType . } } ORDER BY ?dataset LIMIT $limit OFFSET $offset } { - SELECT (COUNT(DISTINCT ?dataset)/$limit+1 AS ?pages) (COUNT(DISTINCT ?dataset) AS ?hits) WHERE { + SELECT (COUNT(DISTINCT ?dataset)/$limit+1 AS ?pages) + (COUNT(DISTINCT ?dataset) AS ?hits) WHERE { ?dataset rdf:type dcat:Dataset ; ?p ?o . ?o bif:contains "'$term'" . @@ -323,27 +315,24 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES, term=term, limit=page_size, offset=page) - _context = { - "@context": BASE_CONTEXT | DATASET_SEARCH_CONTEXT, - "type": "resultItem", - } - return query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | DATASET_SEARCH_CONTEXT, + "type": "resultItem", + } + return query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/publications/<name>", methods=["GET"]) def publications(name): """Fetch a publication's metadata given it's NAME""" - try: - if "unpublished" in name: - name = f"gn:unpublished{name}" - else: - name = f"pubmed:{name}" - _query = Template(""" + if "unpublished" in name: + name = f"gn:unpublished{name}" + else: + name = f"pubmed:{name}" + _query = Template(""" $prefix CONSTRUCT { @@ -354,22 +343,19 @@ CONSTRUCT { FILTER (!regex(str(?predicate), '(hasPubMedId)', 'i')) . } """).substitute(name=name, prefix=RDF_PREFIXES) - return query_and_compact( - _query, {"@context": BASE_CONTEXT | PUBLICATION_CONTEXT}, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + return query_and_compact( + _query, {"@context": BASE_CONTEXT | PUBLICATION_CONTEXT}, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/publications/search/<term>", methods=["GET"]) def search_publications(term): """Search publications""" - try: - args = request.args - page = args.get("page", 0) - page_size = args.get("per-page", 10) - _query = Template(""" + args = request.args + page = args.get("page", 0) + page_size = args.get("per-page", 10) + _query = Template(""" $prefix CONSTRUCT { @@ -399,38 +385,36 @@ CONSTRUCT { } } """).substitute(prefix=RDF_PREFIXES, term=term, limit=page_size, offset=page) - _context = { - "@context": BASE_CONTEXT | SEARCH_CONTEXT | { - "dct": "http://purl.org/dc/terms/", - "ex": "http://example.org/stuff/1.0/", - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "fabio": "http://purl.org/spar/fabio/", - "title": "dct:title", - "pubmed": "fabio:hasPubMedId", - "currentPage": "ex:currentPage", - "url": "rdfs:label", - }, - "type": "resultItem", - "paper": { - "@type": "fabio:ResearchPaper", - "@container": "@index" - } + _context = { + "@context": BASE_CONTEXT | SEARCH_CONTEXT | { + "dct": "http://purl.org/dc/terms/", + "ex": "http://example.org/stuff/1.0/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "fabio": "http://purl.org/spar/fabio/", + "title": "dct:title", + "pubmed": "fabio:hasPubMedId", + "currentPage": "ex:currentPage", + "url": "rdfs:label", + }, + "type": "resultItem", + "paper": { + "@type": "fabio:ResearchPaper", + "@container": "@index" } - return query_and_frame( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + } + return query_and_frame( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) + -@metadata.route("/phenotypes/<name>",methods=["GET"]) +@metadata.route("/phenotypes/<name>", methods=["GET"]) @metadata.route("/phenotypes/<group>/<name>", methods=["GET"]) def phenotypes(name, group=None): """Fetch a phenotype's metadata given it's name""" - try: - if group: - name = f"{group}_{name}" - _query = Template(""" + if group: + name = f"{group}_{name}" + _query = Template(""" $prefix CONSTRUCT { @@ -466,38 +450,35 @@ CONSTRUCT { gnt:chr ?chr ; gnt:mb ?mb . } . - OPTIONAL { - ?dataset rdf:type dcat:Dataset ; - gnt:belongsToGroup ?inbredSet ; - xkos:classifiedUnder gnc:Phenotype ; - rdfs:label ?datasetLabel ; - skos:prefLabel ?datasetName . - ?type ^skos:member gnc:DatasetType . - FILTER(?type = gnc:Phenotype) . - } + OPTIONAL { + ?dataset rdf:type dcat:Dataset ; + gnt:belongsToGroup ?inbredSet ; + xkos:classifiedUnder gnc:Phenotype ; + rdfs:label ?datasetLabel ; + skos:prefLabel ?datasetName . + ?type ^skos:member gnc:DatasetType . + FILTER(?type = gnc:Phenotype) . + } } """).substitute(prefix=RDF_PREFIXES, name=name) - _context = { - "@context": PHENOTYPE_CONTEXT, - "dataset": { - "type": "dcat:Dataset", - }, - "type": "gnc:Phenotype", - } - return query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": PHENOTYPE_CONTEXT, + "dataset": { + "type": "dcat:Dataset", + }, + "type": "gnc:Phenotype", + } + return query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/genotypes/<name>", methods=["GET"]) @metadata.route("/genotypes/<dataset>/<name>", methods=["GET"]) def genotypes(name, dataset=""): """Fetch a genotype's metadata given it's name""" - try: - _query = Template(""" + _query = Template(""" $prefix CONSTRUCT { @@ -526,52 +507,49 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES, name=name, dataset=dataset) - _context = { - "@context": BASE_CONTEXT | { - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "gnt": "http://genenetwork.org/term/", - "xkos": "http://rdf-vocabulary.ddialliance.org/xkos#", - "gnc": "http://genenetwork.org/category/", - "xsd": "http://www.w3.org/2001/XMLSchema#", - "name": "rdfs:label", - "chr": "gnt:chr", - "skos": "http://www.w3.org/2004/02/skos/core#", - "prefLabel": "skos:prefLabel", - "dcat": "http://www.w3.org/ns/dcat#", - "dataset": "dcat:dataset", - "mb": "gnt:mb", - "mbMm8": "gnt:mbMm8", - "mb2016": "gnt:mb2016", - "sequence": "gnt:hasSequence", - "source": "gnt:hasSource", - "species": "gnt:belongsToSpecies", - "speciesName": "gnt:shortName", - "alternateSource": "gnt:hasAltSourceName", - "comments": "rdfs:comments", - "group": "gnt:belongsToGroup", - "chrNum": { - "@id": "gnt:chrNum", - "@type": "xsd:int", - } - }, - "type": "gnc:Genotype", - } - return query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | { + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "gnt": "http://genenetwork.org/term/", + "xkos": "http://rdf-vocabulary.ddialliance.org/xkos#", + "gnc": "http://genenetwork.org/category/", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "name": "rdfs:label", + "chr": "gnt:chr", + "skos": "http://www.w3.org/2004/02/skos/core#", + "prefLabel": "skos:prefLabel", + "dcat": "http://www.w3.org/ns/dcat#", + "dataset": "dcat:dataset", + "mb": "gnt:mb", + "mbMm8": "gnt:mbMm8", + "mb2016": "gnt:mb2016", + "sequence": "gnt:hasSequence", + "source": "gnt:hasSource", + "species": "gnt:belongsToSpecies", + "speciesName": "gnt:shortName", + "alternateSource": "gnt:hasAltSourceName", + "comments": "rdfs:comments", + "group": "gnt:belongsToGroup", + "chrNum": { + "@id": "gnt:chrNum", + "@type": "xsd:int", + } + }, + "type": "gnc:Genotype", + } + return query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/genewikis/gn/<symbol>", methods=["GET"]) def get_gn_genewiki_entries(symbol): """Fetch the GN and NCBI GeneRIF entries""" - try: - args = request.args - page = args.get("page", 0) - page_size = args.get("per-page", 10) - _query = Template(""" + args = request.args + page = args.get("page", 0) + page_size = args.get("per-page", 10) + _query = Template(""" $prefix CONSTRUCT { @@ -588,7 +566,8 @@ CONSTRUCT { ex:currentPage $offset . } WHERE { { - SELECT ?symbol ?comment (GROUP_CONCAT(DISTINCT ?speciesName; SEPARATOR='; ') AS ?species_) + SELECT ?symbol ?comment + (GROUP_CONCAT(DISTINCT ?speciesName; SEPARATOR='; ') AS ?species_) ?createTime ?creator (GROUP_CONCAT(DISTINCT ?pubmed; SEPARATOR='; ') AS ?pmids) (GROUP_CONCAT(DISTINCT ?category; SEPARATOR='; ') AS ?categories) @@ -610,7 +589,8 @@ CONSTRUCT { ^dct:creator _:entry . } . OPTIONAL { _:entry gnt:belongsToCategory ?category . } . - } GROUP BY ?comment ?symbol ?createTime ?creator ORDER BY ?createTime LIMIT $limit OFFSET $offset + } GROUP BY ?comment ?symbol ?createTime + ?creator ORDER BY ?createTime LIMIT $limit OFFSET $offset } { @@ -625,44 +605,41 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES, symbol=symbol, limit=page_size, offset=page) - _context = { - "@context": BASE_CONTEXT | { - "ex": "http://example.org/stuff/1.0/", - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "gnt": "http://genenetwork.org/term/", - "gnc": "http://genenetwork.org/category/", - "dct": "http://purl.org/dc/terms/", - "xsd": "http://www.w3.org/2001/XMLSchema#", - "entries": "ex:entries", - "comment": "rdfs:comment", - "species": "ex:species", - "category": 'gnt:belongsToCategory', - "author": "dct:creator", - "pubmed": "dct:references", - "currentPage": "ex:currentPage", - "pages": "ex:totalCount", - "created": { - "@id": "dct:created", - "@type": "xsd:datetime" - }, + _context = { + "@context": BASE_CONTEXT | { + "ex": "http://example.org/stuff/1.0/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "gnt": "http://genenetwork.org/term/", + "gnc": "http://genenetwork.org/category/", + "dct": "http://purl.org/dc/terms/", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "entries": "ex:entries", + "comment": "rdfs:comment", + "species": "ex:species", + "category": 'gnt:belongsToCategory', + "author": "dct:creator", + "pubmed": "dct:references", + "currentPage": "ex:currentPage", + "pages": "ex:totalCount", + "created": { + "@id": "dct:created", + "@type": "xsd:datetime" }, - "type": "gnc:GNWikiEntry" - } - return query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + }, + "type": "gnc:GNWikiEntry" + } + return query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/genewikis/ncbi/<symbol>", methods=["GET"]) def get_ncbi_genewiki_entries(symbol): """Fetch the NCBI GeneRIF entries""" - try: - args = request.args - page, page_size = args.get("page", 0), args.get("per-page", 10) - _query = Template(""" + args = request.args + page, page_size = args.get("page", 0), args.get("per-page", 10) + _query = Template(""" $prefix CONSTRUCT { @@ -679,7 +656,8 @@ CONSTRUCT { ex:currentPage $offset . } WHERE { { - SELECT ?symbol ?comment ?geneId (GROUP_CONCAT(DISTINCT ?speciesName; SEPARATOR='; ') AS ?species_) + SELECT ?symbol ?comment ?geneId + (GROUP_CONCAT(DISTINCT ?speciesName; SEPARATOR='; ') AS ?species_) ?createTime ?creator (GROUP_CONCAT(DISTINCT ?pubmed; SEPARATOR='; ') AS ?pmids) WHERE { @@ -700,7 +678,8 @@ CONSTRUCT { ?investigator foaf:name ?creator ; ^dct:creator _:entry . } . - } GROUP BY ?comment ?symbol ?createTime ?creator ?geneId ORDER BY ?createTime LIMIT $limit OFFSET $offset + } GROUP BY ?comment ?symbol ?createTime ?creator ?geneId + ORDER BY ?createTime LIMIT $limit OFFSET $offset } { @@ -715,43 +694,40 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES, symbol=symbol, limit=page_size, offset=page) - _context = { - "@context": BASE_CONTEXT | { - "ex": "http://example.org/stuff/1.0/", - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "gnt": "http://genenetwork.org/term/", - "gnc": "http://genenetwork.org/category/", - "dct": "http://purl.org/dc/terms/", - "xsd": "http://www.w3.org/2001/XMLSchema#", - "entries": "ex:entries", - "comment": "rdfs:comment", - "category": 'gnt:belongsToCategory', - "author": "dct:creator", - "species": "ex:species", - "geneId": "gnt:hasGeneId", - "pubmed": "dct:references", - "currentPage": "ex:currentPage", - "pages": "ex:totalCount", - "created": { - "@id": "dct:created", - "@type": "xsd:datetime" - }, + _context = { + "@context": BASE_CONTEXT | { + "ex": "http://example.org/stuff/1.0/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "gnt": "http://genenetwork.org/term/", + "gnc": "http://genenetwork.org/category/", + "dct": "http://purl.org/dc/terms/", + "xsd": "http://www.w3.org/2001/XMLSchema#", + "entries": "ex:entries", + "comment": "rdfs:comment", + "category": 'gnt:belongsToCategory', + "author": "dct:creator", + "species": "ex:species", + "geneId": "gnt:hasGeneId", + "pubmed": "dct:references", + "currentPage": "ex:currentPage", + "pages": "ex:totalCount", + "created": { + "@id": "dct:created", + "@type": "xsd:datetime" }, - "type": "gnc:GNWikiEntry" - } - return query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + }, + "type": "gnc:GNWikiEntry" + } + return query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/species", methods=["GET"]) def list_species(): """List all species""" - try: - _query = Template(""" + _query = Template(""" $prefix CONSTRUCT { @@ -767,32 +743,29 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES) - _context = { - "@context": BASE_CONTEXT | { - "skos": "http://www.w3.org/2004/02/skos/core#", - "gnt": "http://genenetwork.org/term/", - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "name": "rdfs:label", - "family": "gnt:family", - "shortName": "gnt:shortName", - "alternateName": "skos:altLabel", - "taxonomicId": "skos:notation", - "fullName": "skos:prefLabel", - }, - } - return query_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | { + "skos": "http://www.w3.org/2004/02/skos/core#", + "gnt": "http://genenetwork.org/term/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "name": "rdfs:label", + "family": "gnt:family", + "shortName": "gnt:shortName", + "alternateName": "skos:altLabel", + "taxonomicId": "skos:notation", + "fullName": "skos:prefLabel", + }, + } + return query_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/species/<name>", methods=["GET"]) def fetch_species(name): """Fetch a Single species information""" - try: - _query = Template(""" + _query = Template(""" $prefix CONSTRUCT { @@ -809,32 +782,29 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES, name=name) - _context = { - "@context": BASE_CONTEXT | { - "skos": "http://www.w3.org/2004/02/skos/core#", - "gnt": "http://genenetwork.org/term/", - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "name": "rdfs:label", - "family": "gnt:family", - "shortName": "gnt:shortName", - "alternateName": "skos:altLabel", - "taxonomicId": "skos:notation", - "fullName": "skos:prefLabel", - }, - } - return query_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | { + "skos": "http://www.w3.org/2004/02/skos/core#", + "gnt": "http://genenetwork.org/term/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "name": "rdfs:label", + "family": "gnt:family", + "shortName": "gnt:shortName", + "alternateName": "skos:altLabel", + "taxonomicId": "skos:notation", + "fullName": "skos:prefLabel", + }, + } + return query_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/groups", methods=["GET"]) def groups(): """Fetch the list of groups""" - try: - _query = Template(""" + _query = Template(""" $prefix CONSTRUCT { @@ -850,33 +820,30 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES) - _context = { - "@context": BASE_CONTEXT | { - "skos": "http://www.w3.org/2004/02/skos/core#", - "gnt": "http://genenetwork.org/term/", - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "name": "rdfs:label", - "family": "gnt:family", - "shortName": "gnt:shortName", - "code": "gnt:code", - "mappingMethod": "gnt:mappingMethod", - "geneticType": "gnt:geneticType", - "fullName": "skos:prefLabel", - }, - } - return query_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | { + "skos": "http://www.w3.org/2004/02/skos/core#", + "gnt": "http://genenetwork.org/term/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "name": "rdfs:label", + "family": "gnt:family", + "shortName": "gnt:shortName", + "code": "gnt:code", + "mappingMethod": "gnt:mappingMethod", + "geneticType": "gnt:geneticType", + "fullName": "skos:prefLabel", + }, + } + return query_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/groups/<name>", methods=["GET"]) def fetch_group_by_species(name): """Fetch the list of groups (I.e. Inbredsets)""" - try: - _query = Template(""" + _query = Template(""" $prefix CONSTRUCT { @@ -895,34 +862,31 @@ CONSTRUCT { } """).substitute(prefix=RDF_PREFIXES, name=name) - _context = { - "@context": BASE_CONTEXT | { - "skos": "http://www.w3.org/2004/02/skos/core#", - "gnt": "http://genenetwork.org/term/", - "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "name": "rdfs:label", - "family": "gnt:family", - "shortName": "gnt:shortName", - "code": "gnt:code", - "mappingMethod": "gnt:mappingMethod", - "geneticType": "gnt:geneticType", - "fullName": "skos:prefLabel", - }, - } - return query_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + _context = { + "@context": BASE_CONTEXT | { + "skos": "http://www.w3.org/2004/02/skos/core#", + "gnt": "http://genenetwork.org/term/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "name": "rdfs:label", + "family": "gnt:family", + "shortName": "gnt:shortName", + "code": "gnt:code", + "mappingMethod": "gnt:mappingMethod", + "geneticType": "gnt:geneticType", + "fullName": "skos:prefLabel", + }, + } + return query_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) @metadata.route("/probesets/<name>", methods=["GET"]) @metadata.route("/probesets/<dataset>/<name>", methods=["GET"]) def probesets(name, dataset=""): """Fetch a probeset's metadata given it's name""" - try: - _query = Template(""" + _query = Template(""" $prefix CONSTRUCT { @@ -975,60 +939,58 @@ CONSTRUCT { OPTIONAL { ?inbredSet ^skos:member gnc:Set ; ^gnt:belongsToGroup ?dataset ; - rdfs:label ?groupName ; + rdfs:label ?groupName ; xkos:generalizes ?species . ?species gnt:shortName ?speciesShortName . } . } """).substitute(prefix=RDF_PREFIXES, name=name, dataset=dataset) - _context = { - "@context": BASE_CONTEXT | { - "alias": "skos:altLabel", - "alignID": "gnt:hasAlignID", - "blatMbEnd": "gnt:hasBlatMbEnd", - "blatMbStart": "gnt:hasBlatMbStart", - "blatScore": "gnt:hasBlatScore", - "blatSeq": "gnt:hasBlatSeq", - "chip": "gnt:hasChip", - "chr": "gnt:chr", - "chromosome": "gnt:chromosome", - "comments": "rdfs:comments", - "dct": "http://purl.org/dc/terms/", - "description": "dct:description", - "geneID": "gnt:hasGeneId", - "group": "gnt:belongsToGroup", - "dataset": "gnt:belongsToDataset", - "tissue": "gnt:hasTissue", - "kgID": "gnt:hasKgID", - "location": "gnt:location", - "mb": "gnt:mb", - "name": "rdfs:label", - "proteinID": "gnt:hasProteinID", - "references": "dct:references", - "rgdID": "gnt:hasRgdID", - "skos": "http://www.w3.org/2004/02/skos/core#", - "species": "gnt:belongsToSpecies", - "specificity": "gnt:hasSpecificity", - "strand": "gnt:Strand", - "strandProbe": "gnt:strandProbe", - "symbol": "gnt:geneSymbol", - "targetID": "gnt:hasTargetId", - "targetRegion": "gnt:targetsRegion", - "targetSequence": "gnt:hasTargetSeq", - "transcript": "gnt:transcript", - "txEnd": "gnt:TxEnd", - "txStart": "gnt:TxStart", - "unigenID": "gnt:hasUnigenID", - "uniprot": "gnt:uniprot", - }, - "probeset": { - "type": "gnc:Probeset", - }, + _context = { + "@context": BASE_CONTEXT | { + "alias": "skos:altLabel", + "alignID": "gnt:hasAlignID", + "blatMbEnd": "gnt:hasBlatMbEnd", + "blatMbStart": "gnt:hasBlatMbStart", + "blatScore": "gnt:hasBlatScore", + "blatSeq": "gnt:hasBlatSeq", + "chip": "gnt:hasChip", + "chr": "gnt:chr", + "chromosome": "gnt:chromosome", + "comments": "rdfs:comments", + "dct": "http://purl.org/dc/terms/", + "description": "dct:description", + "geneID": "gnt:hasGeneId", + "group": "gnt:belongsToGroup", + "dataset": "gnt:belongsToDataset", + "tissue": "gnt:hasTissue", + "kgID": "gnt:hasKgID", + "location": "gnt:location", + "mb": "gnt:mb", + "name": "rdfs:label", + "proteinID": "gnt:hasProteinID", + "references": "dct:references", + "rgdID": "gnt:hasRgdID", + "skos": "http://www.w3.org/2004/02/skos/core#", + "species": "gnt:belongsToSpecies", + "specificity": "gnt:hasSpecificity", + "strand": "gnt:Strand", + "strandProbe": "gnt:strandProbe", + "symbol": "gnt:geneSymbol", + "targetID": "gnt:hasTargetId", + "targetRegion": "gnt:targetsRegion", + "targetSequence": "gnt:hasTargetSeq", + "transcript": "gnt:transcript", + "txEnd": "gnt:TxEnd", + "txStart": "gnt:TxStart", + "unigenID": "gnt:hasUnigenID", + "uniprot": "gnt:uniprot", + }, + "probeset": { "type": "gnc:Probeset", - } - return query_frame_and_compact( - _query, _context, - current_app.config.get("SPARQL_ENDPOINT") - ) - except (RemoteDisconnected, URLError): - return jsonify({}) + }, + "type": "gnc:Probeset", + } + return query_frame_and_compact( + _query, _context, + current_app.config.get("SPARQL_ENDPOINT") + ) |