25. 参考:MapReduce
Lecture - Biological Databases: Structured Data Processing
Proposed by Google [SOSP2004]
An open-source implementation: Apache Hadoop
Split the data file into several chunks
Map
Apply the function f to each chunk of the input input file
records
Function f produces (key, value) pairs
Gives program semantics for parallelization
The evaluation order of the records does not matter Map f f f
hashing records
Reduce
Receives the sorted output from the map function.
pull model chr1 chr2 chr1
chr2 chr3 chr2
chr3 chr3
sort and merge …
Reduce chr1 chr2 chr3
output file (s)
25
26. 木構造からオブジェクトへのマッピング
Lecture - Biological Databases: Structured Data Processing
プログラミング言語で使うオブジェクトと木構造を対応付ける (Object-Tree Mapping)
Gene
class Gene {
int id object
string name
string chr
int start
int end id:1 start:11617 end:16804 exon
List<Exon> exon
}
array
class Exon {
int start
int end Exon Exon
} object object
start:11617 end:11589 start:16472 end:16804
26
27. オブジェクトストリームの生成
Lecture - Biological Databases: Structured Data Processing
class Gene { Gene
int id object
string name
string chr
int start
int end id:1 start:11617 end:16804 exon
List<Exon> exon
}
array
class Exon {
int start
int end Exon Exon
} object object
startObject g = new Gene()
key:id, value:1 g.id = 1 start:11617 end:11589 start:16472 end:16804
key:start, value:11617 g.start = 11617
key:end, value:16804 g.end = 16804
key:exon
startArray e = new List<Exon>()
startObject e0 = new Exon()
key:start, value:11617 e0.start = 11617
key:end, value:11689 e0.end = 11689
endObject e.add(e0) // 配列にExonを追加
startObject e1 = new Exon()
key:start, value:16472 e1.start = 16427
key:end, value:16804 e1.end = 16804
endObject e.add(e1)
endArray g.exon = e
endObject emit(g) // Gene オブジェクトを出力
27
28. オブジェクトの直列化
Lecture - Biological Databases: Structured Data Processing
生物情報学では解析の数だけオブジェクト(型定義)があるといっても過言ではない
class Gene {
プログラムの解析結果をいかに保存するか? int id
string name
string chr
Object Serialization int start
オブジェクトのデータをバト列に変換する int end
List<Exon> exon
主な用途 }
デゖスク・ネットワークにデータを書き出す
データベースに保存する
簡単な方法: オブジェクト -> 木構造データに変換(XML/JSON など) class Exon {
int start
オブジェクトの各パラメータごとにノードを出力 int end
構造を持った型のパラメータは、再帰的に処理 }
function toJSON(Object) {
output “{“
for each parameter p in Object
output “(p.name):”
if p is primitive type // int, string, float, etc.
output “(p.value)”
else if p is array type
output “ [”
for each element e in p { output(“, “) if e.index == 0; toJSON(e) }
output “]”
else
toJSON(p)
output “}”
}
出力例
{“id”:1, “name”:”gene A”, … , “exon”:[{“start”:…, “end”:…}, {“start”:…, “end”:…} ] }
28
29. スキーマを使ったオブジェクトの直列化
Lecture - Biological Databases: Structured Data Processing
JSONに出力する形式 class Gene {
オブジェクト毎に、毎回同じパラメータ名を出力しており冗長 int id
string name
よりコンパクトに表現できないか? string chr
int start
int end
オブジェクトの型定義からスキーマを構成 List<Exon> exon
}
Gene (id:int, name:string, chr:string, start:int, end:int, exon:Exon*)
Exon (start:int, end:int)
class Exon {
パラメータ名を出力せずにデータを連結したレコードを作成 int start
int end
| type id | param1 | param2 | … | param k | }
各パラメータは型ごとにシリゕラズ
int -> 4 bytes or 可変長整数表現 (固定長レコード)
string -> 文字列の長さ、バト列 (可変長レコード)
配列 -> 配列の長さ、各エントリのレコード …
参考
serializationのためのツールはいくつかある
Google Protocol Buffers, MessagePack, Boost::Serialize、Ruby on Railsなど
29