SPARQLthon17/GenomeRefine

提供:TogoWiki

移動: 案内, 検索

目次

事前準備 Annotation RDF更新

RDFデータモデルを BH12.12/SPARQLthon16/GenomeRefine#TogoAnnotation から更新した v0.3

@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@PREFIX oa: <http://www.w3.org/ns/oa#> .
@prefix foaf:    <http://xmlns.com/foaf/0.1/> .
@prefix cnt: <http://www.w3.org/2011/content#> .
@prefix prov: <http://www.w3.org/ns/prov#> .

<http://togo.annotation.jp/bookmarks/1427582>  a oa:Annotation;
    oa:motivatedBy oa:bookmarking ;
    oa:hasTarget <http://genome.microbedb.jp/cyanobase/Synechocystis/genes/slr0906>;
    oa:hasBody  <http://togo.annotation.jp/tags/pname:CP43> ;
    oa:hasBody  <http://togo.annotation.jp/tags/pmid:22197103> ;
    oa:hasBody  <<http://togo.annotation.jp/tags/so:polypeptide> ;
    oa:hasBody  <http://togo.annotation.jp/tags/fig1> ;
    oa:hasBody  <http://togo.annotation.jp/tags/GI2> ;

    oa:annotatedAt "2012-02-12T15:02:14Z" ;
    oa:annotatedBy <http://togo.annotation.jp/yoshimura_h>;
    oa:serializedBy <http://togo.annotation.jp> ;
    oa:serializedAt "2012-02-12T15:02:14Z” .


<http://togo.annotation.jp/tags/pname:CP43> a oa:Tag ;
  rdfs:label "pname:CP43" ;
  a cnt:ContentAsText ;
  cnt:chars "CP43" ;
  cnt:characterEncoding "utf-8" ;
  foaf:page <http://togo.annotation.jp/tags/pname> .


<http://togo.annotation.jp/tags/pmid:22197103> a oa:Tag ;
  rdfs:label "pmid:22197103" ;
  a cnt:ContentAsText;
  cnt:chars "22197103" ;
  cnt:characterEncoding "utf-8" ;
  foaf:page http://togo.annotation.jp/tags/pmid>.

<http://togo.annotation.jp/tags/so:polypeptide> a oa:Tag ;
  rdfs:label "so:polypeptide" ;
  a cnt:ContentAsText;
  cnt:chars "polypeptide" ;
  cnt:characterEncoding "utf-8” ;
  foaf:page <http://togo.annotation.jp/tags/so> .


<http://togo.annotation.jp/tags/fig1> a oa:Tag ;
  rdfs:label "fig1" ;
  a cnt:ContentAsText ;
  cnt:chars "fig1" ;
  cnt:characterEncoding "utf-8" .


<http://togo.annotation.jp/tags/GI2> a oa:Tag ;
  rdfs:label "GI2" ;
  a cnt:ContentAsText ;
  cnt:chars "GI2" ;
  cnt:characterEncoding "utf-8" .


<http://togo.annotation.jp> a foaf:Agent, prov:SoftwareAgent ;
  foaf:name "TogoAnnotation" . 


<http://togo.annotation.jp/yoshimura_h> a foaf:Person ;
  foaf:openid <http://...> ;
  foaf:name "yoshimura_h" .

遺伝子アノテーションのデータフロー

GenomeRefine TogoAnnotator.png

遺伝子アノテーションの取得

  • MiGAP, TogoAnnotator, TogoAnnotationのRDFをvirtuosoにインポートして、TogoAnnotation(>TogoAnnotator)>MiGAPの優先順位で遺伝子アノテーションを取得

優先アノテーションを取得するSPARQL

事前にRDFファイルの修正が必要な項目(推奨含む)

優先度判定ロジックをSPARQLだけで行う場合、データスキーマが異なると優先を決めるための比較条件を記述することがかなり難しい。
UNIONやOPTIONAL句を多用すれば出来る可能性はあるが、Virtuosoで変数のスコープエラー等がでてしまい成功しなかった
比較に使用するトリプルについては同じデータスキーマを持たせることが望ましいため、その部分を追加した。
また日付を比べるため、oa:annotatedAtやoa:serializedAtは日付型で宣言した。

annotation_default.ttl

  • oa:annotatedAtの日付表現を文字列からRDFで有効な日付型に直す
  • oa:serializedAtを追加
  • oa:serializedByを値<http://www.migap.com>で追加

修正前(2014/2/17夕方時点)

<urn:uuid:f9189980-79e2-0131-8c79-38f6b11aa30b>
    a oa:Annotation ;
    oa:annotatedAt "Mon, 17 Feb 2014 09:22:39 +0000" ;
    oa:annotatedBy <http://www.migap.com> ;
    oa:hasBody <urn:uuid:f9189be0-79e2-0131-8c79-38f6b11aa30b> ;
    oa:hasTarget <http://genome.microbedb.jp/235/GR15/genes/GR15_10060> .

修正後

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .//先頭に追加
<urn:uuid:f9189980-79e2-0131-8c79-38f6b11aa30b>
    a oa:Annotation ;
    oa:annotatedAt "2014-02-17T09:22:39Z"^^xsd:dateTime ;//日付型の宣言
    oa:annotatedBy <http://www.migap.com> ;
    oa:serializedAt "2014-02-17T09:22:39Z"^^xsd:dateTime ;//追加
    oa:serializedBy <http://www.migap.com> ;//追加
    oa:hasBody <urn:uuid:f9189be0-79e2-0131-8c79-38f6b11aa30b> ;
    oa:hasTarget <http://genome.microbedb.jp/235/GR15/genes/GR15_10060> .

annotation_auto.ttl

  • oa:annotatedAtに日付型の宣言を追加
  • oa:annotatedAtのRDFの日付としては無効な表現のトリプルを削除
  • oa:serializedAtを追加
  • oa:serializedByを値<http://dbcls.jp/togoannotator>で追加

修正前(2014/2/17夕方時点)

<urn:uuid:39D9B230-97BF-11E3-986B-E6A9DFAFF0AE> a oa:Annotation;
    oa:hasTarget <http://genome.microbedb.jp/235/GR15/genes/GR15_123050>;
    oa:hasBody  <urn:uuid:39D9B8E8-97BF-11E3-986B-E6A9DFAFF0AE> ; 
    oa:annotatedAt "2014-01-17T15:02:14Z" ;
    oa:annotatedAt "Mon Feb 17 19:35:31 2014" ; //不要なので削除
    oa:annotatedBy <http://dbcls.jp/togoannotator>.

修正後

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .//先頭に追加
<urn:uuid:39D9B230-97BF-11E3-986B-E6A9DFAFF0AE> a oa:Annotation;
    oa:hasTarget <http://genome.microbedb.jp/235/GR15/genes/GR15_123050>;
    oa:hasBody  <urn:uuid:39D9B8E8-97BF-11E3-986B-E6A9DFAFF0AE> ; 
    oa:annotatedAt "2014-01-17T15:02:14Z"^^xsd:dateTime ;
    oa:annotatedBy <http://dbcls.jp/togoannotator> ;
    oa:serializedAt "2014-01-17T15:02:14Z"^^xsd:dateTime ; //追加
    oa:serializedBy <http://dbcls.jp/togoannotator> . //追加

annotation_manual.ttl

  • oa:annotatedAtに日付型の宣言を追加
  • oa:serializedAtに日付型の宣言を追加

修正前(2014/2/17夕方時点)

<http://togo.annotation.jp/bookmarks/1465393>
    a oa:Annotation ;
    oa:annotatedAt "2014-02-17T08:54:32Z" ;
    oa:annotatedBy <http://togo.annotation.jp/hidenba> ;
    oa:hasBody <http://togo.annotation.jp/tags/gname:%20protein_coding_gene_test> ;
    oa:hasTarget <http://genome.microbedb.jp/235/GR15/genes/GR15_10080> ;
    oa:motivatedBy oa:bookmarking ;
    oa:serializedAt "2014-02-17T11:03:50Z" ;
    oa:serializedBy <http://togo.annotation.jp/> .

修正後

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .//先頭に追加
<http://togo.annotation.jp/bookmarks/1465393>
    a oa:Annotation ;
    oa:annotatedAt "2014-02-17T08:54:32Z"^^xsd:dateTime ; //日付型の宣言
    oa:annotatedBy <http://togo.annotation.jp/hidenba> ;
    oa:hasBody <http://togo.annotation.jp/tags/gname:%20protein_coding_gene_test> ;
    oa:hasTarget <http://genome.microbedb.jp/235/GR15/genes/GR15_10080> ;
    oa:motivatedBy oa:bookmarking ;
    oa:serializedAt "2014-02-18T11:03:50Z"^^xsd:dateTime ; //日付型の宣言
    oa:serializedBy <http://togo.annotation.jp/> .

SPARQL

同一ターゲットの中で最も優先度が高いアノテーションのURIを取得するクエリ。
条件: manual annotation(serializeの日付が最新 > serializeの日付が古い) > auto annotation > default annotation
※グラフ名は任意の値
※Virtuoso以外でクエリ実行をする際には一行目のDEFINE sql:select-option "order"は削除する。Virtuosoではこれを削除すると、(おそらくBIND等から実行しようとして)変数が解釈できずエラーになるため必ず記述する。"Virtuoso 37000 Error SQ156: Internal Optimized compiler error : Bad dfe in sqlo_place_exp in sqldf.c:2199."(バグ?)


DEFINE sql:select-option "order"
PREFIX oa: <http://www.w3.org/ns/oa#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 

SELECT DISTINCT ?target ?selected_annotation
FROM <http://genome_refine/anno_test_v2>
{
 {
  SELECT
   ?target
   (MAX(?annotator_priority) AS ?priority) # calculates the top priority 
   (MAX(?serialized_date) AS ?prior_date) # ?prior_date is max value in only manual annotation for every ?target
  WHERE
  {
   ?anno oa:hasTarget ?target ;
    oa:serializedBy ?annotator .
   OPTIONAL  # This OPTIONAL will match on manual annotation.
   {
    ?anno oa:annotatedBy ?person .
    ?person rdf:type foaf:Person .
    ?anno oa:serializedAt ?serialized_date .
   }
   # expresses priority in integer 3 = mannual 2 = togoannotator 1 = others .
   BIND (IF(bound(?person), 3 , IF(?annotator = <http://dbcls.jp/togoannotator>,2, 1)) AS ?annotator_priority) .
  } GROUP BY ?target ORDER BY DESC (?priority)
 }
 # turns back from priority integer to annotator type
 BIND (IF(?priority = 3, <http://togo.annotation.jp/>, IF (?priority = 2 ,<http://dbcls.jp/togoannotator>, <http://www.migap.com> ) ) AS ?prior_annotator) 
 ?selected_annotation oa:hasTarget ?target .
 ?selected_annotation oa:serializedBy ?annotator2 .
 ?selected_annotation oa:serializedAt ?serialized_date2 .
 # filters annotation has top priority and has maximam date only if it's manual annotation 
 FILTER (STR(?annotator2) = STR(?prior_annotator) && ((?priority IN (1,2)) || (?priority = 3 && ?serialized_date2 = ?prior_date )))
}
  • 解説
    • (副問合せ内)targetとannotationURIを取得し、OPTIONAL句でmanual annotationの場合だけserializedの日付を取得する。
    • (副問合せ内)annotator(serializedByで判断)のタイプを優先度の高い順に整数値に変換する(BIND)。
    • (副問合せの結果) target毎に集約し、同一targetで一番高いannotationのタイプを取得する。manual annotationの場合にだけ取得されるserializedの日付の最新日を取得する。
    • (副問合せから抜けた後)整数表現にしていたannotationをURI表現に戻す。
    • 再度、targetを持つannotationURIを取得し、最優先のannotationタイプ及び、manual annotationならば最新日付を持つannotationURIに絞り込む
    • クエリでannotationURIの情報を辿りたい場合には最終行に足すか、上記クエリ全体をさらに副問い合わせで包んでから書く(見やすさだけの話)

MicrobeDB.jp連携

  • git、API連携テスト準備
    • ゲノムプロジェクトdelete操作時にgitサーバから削除することを確認