Introduction to Bio SPARQL
-
Upload
amrapali-zaveri-phd -
Category
Education
-
view
128 -
download
2
Transcript of Introduction to Bio SPARQL
![Page 1: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/1.jpg)
SPARQLSPARQLProtocolAndRDFQueryLanguage
AmrapaliZaveri,Ph.D.
![Page 2: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/2.jpg)
What is SPARQL?SPARQL(pronouncedsparkle)standsfor:SPARQLProtocolAndRDFQueryLanguage• SPARQL1.0W3C-RecommendaFonsinceJanuary15th2008• SPARQL1.1W3C-RecommendaFonsinceMarch21st2013• QuerylanguagetoqueryinstancesinRDFdocuments• GreatpracFcalimportance(almostallapplicaFonsneedit)
![Page 3: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/3.jpg)
SPARQL ExampleSELECT
*
WHERE {
?subject?predicate?object.
}
Similar to SQL !
![Page 4: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/4.jpg)
SPARQL ComponentsASPARQLquerycomprises,inorder:• PREFIXdeclaraFons,forabbreviaFngURIs• Datasetdefini;on,staFngwhatRDFgraph(s)arebeingqueried• Aresultclause,idenFfyingwhatinformaFontoreturnfromthequery
• Thequerypa@ern,specifyingwhattoqueryforintheunderlyingdataset
• Querymodifiers,slicing,ordering,andotherwiserearrangingqueryresults
![Page 5: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/5.jpg)
SPARQL Components#prefixdeclara;onsPREFIXfoo:<h`p://example.com/resources/>#datasetdefini;onFROM#resultclauseSELECT#querypa@ernWHERE{...}#querymodifiersORDERBY...
![Page 6: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/6.jpg)
SPARQL ExampleSELECT*WHERE{
?bookrdf:type<h`p://dbpedia.org/ontology/Book>.
}
Try it yourself: dbpedia.org/sparql/
![Page 7: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/7.jpg)
SPARQL ExamplePREFIXdbo:<h@p://dbpedia.org/ontology/>
SELECT*WHERE{
?bookadbo:Book.
?bookdbo:author?author.
}
Try it yourself: dbpedia.org/sparql/
![Page 8: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/8.jpg)
SPARQL ExamplePREFIXdbo:<h@p://dbpedia.org/ontology/>
SELECT*WHERE{
?bookadbo:Book.
?bookdbo:author?author.
}LIMIT10
Try it yourself: dbpedia.org/sparql/
![Page 9: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/9.jpg)
SPARQL ExamplePREFIXdbo:<h@p://dbpedia.org/ontology/>
SELECT?authorWHERE{
?bookadbo:Book.
?bookdbo:author?author.
}LIMIT10
Try it yourself: dbpedia.org/sparql/
![Page 10: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/10.jpg)
Filter in SPARQL• KeywordFILTER,followedbyfilterexpressioninparentheses• FiltercondiFonsoutputtruthvalues(andpossiblyerrors)• ManyfilterfuncFonsarenotspecifiedbyRDF funcFons• partlytakenfromXQuery/XPath-StandardforXML
![Page 11: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/11.jpg)
Filter FunctionsComparisonoperators:<,=,>,<=,>=,!=• Comparisonofdataliteralsaccordingtonaturalorder• Supportfornumericaldatatypes,xsd:dateTime,xsd:string
(alphabeFcordering),xsd:Boolean(1>0)• ForothertypesandotherRDF-elements,only=and!=are
available• ComparisonofliteralsofincompaFbletypes(e.g.xsd:stringand
xsd:integer)isnotallowedArithmaFcoperators:+,-,*,/• Supportfornumericaldatatypes• UsedtocombinevaluesinfiltercondiFonsEx.:FILTER(?weight/
(?size*?size)>=25)
![Page 12: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/12.jpg)
SPARQL ExamplePREFIXdbo:<h`p://dbpedia.org/ontology/>
SELECT?authorWHERE{
?bookadbo:Book.
?bookdbo:author?author.
?bookdbo:numberOfPages?pages.
FILTER(?pages>500)
}LIMIT10
Try it yourself: dbpedia.org/sparql/
![Page 13: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/13.jpg)
Special Filter FunctionsOtherRDF-specificfilterfuncFons:
sameTERM(A,B) true,ifAandBarethesameRDF-terms.
langMATCHES(A,B) true,ifthelanguagespecificaFonAfitsthepa`ernB
REGEX(A,B) true,ifthecharacterstringAcontainstheregularexpressionB
![Page 14: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/14.jpg)
SPARQL ExamplePREFIXdbo:<h`p://dbpedia.org/ontology/>PREFIXdbp:<h@p://dbpedia.org/property/>
SELECT*WHERE{
?bookadbo:Book.
?bookdbo:author?author.?bookdbo:numberOfPages?pages.
?bookdbp:name?name.
FILTER(?pages>500)
FILTER(langMATCHES(LANG(?name),"en))}LIMIT10
Try it yourself: dbpedia.org/sparql/
![Page 15: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/15.jpg)
Filter Functions: Boolean operators
FiltercondiFonscanbelinkedwithbooleanoperators:&&,||,!• ParFallyalsoexpressiblethroughgraphpa`ern:
• ConjuncFoncorrespondstospecificaFonsofseveralfilters• DisjuncFoncorrespondstoapplicaFonoffiltersinalternaFvepa`erns
![Page 16: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/16.jpg)
Filter Functions: Boolean operators
UnFlnow,onlybasicformaongseongforresults:• Howcanoneretrievedefinedpartsoftheoutputset?• Howaretheresultsordered?• Canduplicateresultrowsberemovedinstantaneously?
![Page 17: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/17.jpg)
Result SortingPREFIXdbo:<h`p://dbpedia.org/ontology/>PREFIXdbp:<h`p://dbpedia.org/property/>
SELECT*WHERE{
?bookadbo:Book.
?bookdbo:author?author.?bookdbo:numberOfPages?pages.
?bookdbp:name?name.
FILTER(?pages>500)
FILTER(langMATCHES(LANG(?name),"en))}ORDERBY?pagesLIMIT10
Try it yourself: dbpedia.org/sparql/
![Page 18: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/18.jpg)
Resulting Sorting• SorFngsameaswithfiltercomparisonoperators• SorFngofURIsalphabeFcallyassequenceofcharacters
OtherpossiblespecificaFons:•ORDERBYDESC(?price):descending•ORDERBYASC(?price):ascending,defaultseong•ORDERBYDESC(?price),?Ftle:hierarchicalclassificaFoncriteria
![Page 19: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/19.jpg)
LIMIT, OFFSET, DISTINCTRestricFonofoutputset:• LIMIT:maximalnumberofresults(tablerows)• OFFSET:posiFonofthefirstdeliveredresult• SELECTDISTINCT:removalofduplicatetablerows
LIMITandOFFSETonlymakesensewithORDERBY!
![Page 20: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/20.jpg)
Hands-on Bio2RDF• SPARQL endpoint
• http://sparql.openlifedata.org/
• Datasets
• http://download.bio2rdf.org/release/3/release.html
![Page 21: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/21.jpg)
Hands-on DIY -1
DESCRIBE <http://bio2rdf.org/drugbank:DB00088>
The DESCRIBE query result clause allows the server to return whatever RDF it wants that describes the given resource(s).
![Page 22: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/22.jpg)
Hands-on Bio2RDF -2<http://bio2rdf.org/drugbank:DB00088>
• Retrieve title, affected organism, target and group of this Drug
TIP: View it as NTriples to construct your query!
![Page 23: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/23.jpg)
Hands-on Bio2RDF - 3
SELECT * WHERE { ?drug a <http://bio2rdf.org/drugbank_vocabulary:Drug>. }
• filter for drugs starting with A
![Page 24: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/24.jpg)
Hands-on Bio2RDF -3
SELECT * WHERE { ?drug a <http:bio2rdf.orgdrugbank_vocabulary:Drug>. }
• filter for drugs starting with A
• FILTER regex(?title, "A")
![Page 25: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/25.jpg)
Hands-on Bio2RDF -3
SELECT * WHERE { ?drug a <http://bio2rdf.org/drugbank_vocabulary:Drug>. }
• filter for drugs starting with A
• FILTER regex(?title, “A")
• sort them alphabetically
![Page 26: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/26.jpg)
Hands-on DIY
• Get 100 drug-metabolizing enzymes
• Get phenotypes and genes associated with OMIM diseases
• Retrieve unique diseases and publications associated with the BRCA1 gene
![Page 27: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/27.jpg)
Hands-on DIY• Get 100 drug-metabolizing enzymes
• Get phenotypes and genes associated with OMIM diseases
• Retrieve unique diseases and publications associated with the BRCA1 gene
TIPS: - View the resource as NTriples to construct your query- Use prefix.cc to look up prefixes- Always use LIMIT- Start by getting results one triple at a time and build up.
![Page 28: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/28.jpg)
Answer 1
PREFIX dv: <http://bio2rdf.org/drugbank_vocabulary:> PREFIX dct: <http://purl.org/dc/terms/>
SELECT distinct ?enzyme_name ?drug_name { ?s a dv:Enzyme-Relation . ?s dv:enzyme/dct:title ?enzyme_name . ?s dv:drug/dct:title ?drug_name .} LIMIT 100
![Page 29: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/29.jpg)
Answer 2PREFIX om: <http://bio2rdf.org/omim_vocabulary:>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX b: <http://bio2rdf.org/bio2rdf_vocabulary:>
SELECT * {
?s a om:Phenotype .
?s dct:title ?name .
?s om:clinical-synopsis ?cs .
?cs om:feature ?f .
?f om:x-umls/b:identifier ?umls .
?f om:x-hp/dct:identifier ?hp .
?s om:phenotype-map ?pm .
?pm om:gene-symbol ?gene.
} LIMIT 10
![Page 30: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/30.jpg)
Answer 3PREFIX om: <http://bio2rdf.org/omim_vocabulary:>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX hgnc:<http://bio2rdf.org/hgnc.symbol>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?geneName ?name ?pubmedArticle{
?s a om:Phenotype .
?s dct:title ?name .
?s om:phenotype-map ?pm .
?pm om:gene-symbol ?gene.
?gene dct:title ?geneName.
?s om:article ?pubmed.
?pubmed dct:title ?pubmedArticle.
FILTER regex(?gene, “BRCA1") }
![Page 31: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/31.jpg)
SPARQL Components#prefixdeclara;onsPREFIXfoo:<h`p://example.com/resources/>#datasetdefini;onFROM#resultclauseSELECT#querypa@ernWHERE{...}#querymodifiersORDERBY...
![Page 32: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/32.jpg)
SummaryBASIC Structure
PREFIX
WHERE
GRAPH Patternsimple graph pattern
{…}OPTIONAL
UNION
FILTERLANG
DATATYPEREGEX
OUTPUT FormatSELECT
CONSTRUCTASK
DESCRIBE
MODIFIERSORDER BY
LIMITOFFSET
DISTINCT
![Page 33: Introduction to Bio SPARQL](https://reader033.fdocuments.net/reader033/viewer/2022042605/58f30c431a28abe3448b45df/html5/thumbnails/33.jpg)
THANK YOU! QUESTIONS?
@AmrapaliZ
Contact me if you are interested in doing a project at the Institute of Data Science, Uni Maastricht!