FCS (.fcs,.lmd)
FCS (.fcs,.lmd)
予備知識
-
- FCS分子生物学形式.
- フローサイトメトリーデータの保管と交換のための標準形式.
- ASCII/バイナリ混合形式.
- 細胞のイベントのシグナル強度を配列として保管する.
- ファイルにはデータ取得についてのメタ情報が保管される.
ImportとExport
- Import["file.fcs"]ファイルに保管されている細胞のイベントを表す配列を返す.
- Export["file.fcs",{paramnames,events}]はパラメータ名のリストとイベントの配列をFCS形式にエキスポートする.
- Export["file.fcs",{paramnames,paramreagents,events}]はパラメータ名のリスト,パラメータ試薬のリスト,イベントの配列をFCS形式にエキスポートする.
- Import["file.fcs",elem]はFCSファイルから指定の要素をインポートする.
- Import["file.fcs",{{elem1,elem2,…}}]は複数の要素をインポートする.
- インポート形式はImport["file","FCS"]またはImport["file",{"FCS",elem,…}]で指定できる.
- Export["file.fcs",{expr1,expr2,…},{{elem1,elem2,…}}]は各 expri が対応する elemi を指定しているとして扱う.
- Export["file.fcs",expr,opt1->val1,…]は指定の値を持つ指定のオプション要素で expr をエキスポートする.
- Export["file.fcs",{elem1->expr1,elem2->expr2,…},"Rules"]は規則を使ってエキスポートする要素を指定する.
- ImportとExportについての一般的な全情報は,関数ページを参照のこと.
- ImportStringとExportStringはFCS形式をサポートする.
- 一般的な情報は,以下の関数ページを参照のこと.
-
Import, Export ファイルからインポートする,あるいはファイルへエキスポートする CloudImport, CloudExport クラウドオブジェクトからインポートする,あるいはクラウドオブジェクトへエキスポートする ImportString, ExportString 文字列からインポートする,あるいは文字列へエキスポートする ImportByteArray, ExportByteArray バイト配列からインポートする,あるいはバイト配列へエキスポートする
要素
- 一般的なImport要素:
-
"Elements" ファイル中の有効な要素とオプションのリスト "Summary" ファイルの概要 "Rules" 使用可能なすべての要素の規則のリスト - ファイルのメタデータ:
-
"Header" 規則のリストで与えられた生のファイルヘッダ - データ表現要素:
-
"Events" 細胞のイベントの配列 "ParameterName" 規則のリスト(インポート)またはリスト(エキスポート)で表されるパラメータ名 "ParameterReagent" 規則のリスト(インポート)またはリスト(エキスポート)で表されるパラメータ試薬 - その他のデータ要素:
-
"Data" 細胞のイベントの配列 "LabeledData" ファイルに保管されたデータの規則のリスト - ImportはデフォルトではFCS形式に"Events"要素を使用する.
- Exportは少なくともパラメータ名のリスト1つとイベントの配列1つを必要とする.
- Exportはパラメータ試薬のリストをオプションとして取る.他のすべてのオプションのキーは"OptionalKeys"オプションで指定しなければならない.
オプション
- 高度なExportオプション:
-
"DataType" Automatic イベントの符号化に使用されたデータ型 "OptionalKeys" {} 規則のリストとしてヘッダに含む,オプションのキー - Wolfram言語はイベントが符号化できる最も圧縮された形式の特定を試みる.字殿データ型特定は"DataType"オプションでオーバーライドできる.
- "DataType"の有効な設定:
-
"UnsignedInteger8" 8ビット符号なし整数 "UnsignedInteger16" 16ビット符号なし整数 "UnsignedInteger24" 24ビット符号なし整数 "UnsignedInteger32" 32ビット符号なし整数 "Real32" IEEE単精度実数 "Real64" IEEE倍精度実数 - Wolfram言語は"OptionalKeys"で指定されている特定の保護されたキー("$BEGINDATA","$BYTEORD"等)を自動的にオーバーライドする.そのため,インポートされたFCSを再度エキスポートする場合は,"OptionalKeys"をインポートされたFCSファイルの"Header"要素の値に直接設定できる.パラメータ試薬("$PnS"キー)は,Export式でパラメータ試薬が提供されている場合にのみ"OptionalKeys"から削除される.
例題
すべて開く すべて閉じる例 (7)
Import["ExampleData/5k.fcs", {"FCS", "Header"}]//Short[#, 3]&Import["ExampleData/5k.fcs", {"FCS", {"ParameterReagent", "ParameterName"}}]{events, params} = Import["ExampleData/5k.fcs", {"FCS", {"Events", "ParameterName"}}];
TableForm[Transpose[events[[ ;; 5]]], TableHeadings -> {params[[All, 2]], None}]ExportString[{{"FSC-A", "SSC-A"}, {{1, 2}, {1, 2}, {1, 3}, {1, 4}, {1, 5}}}, "FCS"]ExportString[{{"FSC-A", "SSC-A"}, {{1, 2}, {1, 2}, {1, 3}, {1, 4}, {1, 5}}}, "FCS", "DataType" -> "UnsignedInteger16"]イベントの値,パラメータ名,パラメータの試薬の配列をエキスポートする:
ExportString[{{"FSC-A", "SSC-A"}, {"P1", "P2"}, {{1, 2}, {1, 2}, {1, 3}, {1, 4}, {1, 5}}}, "FCS"]同じヘッダのデータファイルをイベントの少数の部分集合とともにエキスポートする:
{pns, evs, head} = Import["ExampleData/5k.fcs", {"FCS", {"ParameterName", "Events", "Header"}}];ExportString[{"ParameterName" -> pns[[All, 2]], "Events" -> evs[[ ;; 5]]}, "FCS", "OptionalKeys" -> head]スコープ (6)
events = Import["ExampleData/5k.fcs", {"FCS", "Events"}];
DensityHistogram[events[[All, {2, 1}]], 100, AspectRatio -> 1, AxesOrigin -> {-200, -200}, PlotRange -> Full, FrameLabel -> {"FSC-W", "FSC-A"}]ArcSinhで変換した軸に影付等高線プロットでイベントをプロットする:
events = Import["ExampleData/5k.fcs", {"FCS", "Events"}];
ticks = {ArcSinh[# / 150], #, Scaled[0.00005]}& /@ {1, 10, 100, 1000, 10000, 100000};
scaling = {ArcSinh[# / 150]&, 150Sinh[#]&};
range = {ArcSinh[-200 / 150], ArcSinh[10000 / 150]};SmoothDensityHistogram[
ArcSinh[# / 150]& /@ events[[ ;; 5000, {6, 9}]],
ColorFunction -> ColorData["Rainbow"],
Mesh -> 10,
FrameTicks -> {{ticks, None}, {ticks, None}},
RegionFunction -> (#3 > 0.01&),
ScalingFunctions -> scaling,
PlotRange -> {range, range},
FrameLabel -> Text /@ Style /@ {"B220", "CD90"}]FindClustersを使って自動的に類似の細胞群を検出する:
events = Import["ExampleData/5k.fcs", {"FCS", "Events"}];
xticks = Join[
(*Major labeled ticks*)
{ArcSinh[# / 150], #}& /@ (10 ^ Range[Log10[1], Log10[100000]]),
-{ArcSinh[# / 150], #}& /@ (10 ^ Range[Log10[1], Log10[100000]]),
(*Minor unlabeled ticks*)
{ArcSinh[# / 150], ""}& /@
Flatten@Outer[Times, 10 ^ Range[0, 4], Join[Range[-9, -1], Range[9]]]
];
ListPlot[FindClusters[ArcSinh[# / 150]& /@ events[[All, {6, 9}]], 3], AspectRatio -> 1, AxesOrigin -> {ArcSinh[-200 / 150], ArcSinh[-200 / 150]}, PlotRange -> Full, AxesLabel -> {Text@Style@"B220", Text@Style@"CD90"}, Ticks -> {xticks, xticks}]{params, events} = Import["ExampleData/5k.fcs", {"FCS", {"ParameterReagent", "Events"}}];(*Global plot range*)
pr = Round[ArcSinh[# / 150]& /@ {Min[events[[All, 4 ;; 8]]], Max[events[[All, 4 ;; 8]]]}, 0.25];
labels = Text[Style[#]]& /@ params[[4 ;; 8, 2]];
Grid[
Join[Partition[{Null}~Join~(Rotate[#, π / 2]& /@ labels), 1],
Join[{labels},
Table[ListPlot[ArcSinh[# / 150]& /@ events[[All, {y, x}]], AspectRatio -> 1, ImageSize -> {80, 80}, FrameTicks -> None, Frame -> True, PlotRange -> {pr, pr}, AxesOrigin -> {-0.5, -0.5}], {x, 4, 8}, {y, 4, 8}]], 2]]{strings, params, events} = Import["ExampleData/5k.fcs", {"FCS", {"ParameterReagent", "ParameterName", "Events"}}];(*Ray casting algorithm*)
PointInPolygonQ[{x_, y_}, poly_] := PointInPolygonQi[x, y, poly];
PointInPolygonQi = Compile[{{ptx, _Real}, {pty, _Real}, {poly, _Real, 2}}, Module[{i, j, c = False, vertx, verty},
{vertx, verty} = Transpose@poly;
For[i = 1;j = Length[vertx], i ≤ Length[vertx], j = i++,
If[(((verty[[i]] > pty) ≠ (verty[[j]] > pty)) && (ptx < (vertx[[j]] - vertx[[i]]) * (pty - verty[[i]]) / (verty[[j]] - verty[[i]]) + vertx[[i]])), c = !c];
];
Return[c]
]];(*Use reagent names when available*)
params = Table[strings[[i, 2]] /. " " -> params[[i, 2]], {i, Length@strings}];is = ImageSize -> {300, 300};
twoDopts = {PlotRange -> {{-.5, 7}, {-.5, 7}}, is, AspectRatio -> 1, AxesOrigin -> {-0.5, -0.5}};
Manipulate[
Column[
{
Labeled[Overlay[{
ListPlot[Map[ArcSinh[# / 150]&, events[[All, {Position[params, x1][[1, 1]], Position[params, y1][[1, 1]]}]], {2}],
twoDopts
],
Graphics[{EdgeForm[Thick], Opacity[0.5], Red, Polygon[pt]}, Frame -> True, twoDopts]
(*Note that we're showing the frame, ticks and labels for both parts of the overlay to provide visual verification that they're overlaid properly*)
}, is], {x1, y1}, {Bottom, Left}, RotateLabel -> True],
subpop = Pick[events[[All, {Position[params, x2][[1, 1]], Position[params, y2][[1, 1]]}]], Map[PointInPolygonQ[#, pt]&, Map[ArcSinh[# / 150]&, events[[All, {Position[params, x1][[1, 1]], Position[params, y1][[1, 1]]}]], {2}]]];
If[SecondDisplay == "2D",
If[Length@subpop > 0,
Labeled[
ListPlot[Map[ArcSinh[# / 150]&, subpop, {2}], twoDopts], {x2, y2}, {Bottom, Left}, RotateLabel -> True], Graphics[{White, Rectangle[]}, is]],
Labeled[SmoothHistogram[Map[ArcSinh[# / 150]&, subpop[[All, 1]]], AspectRatio -> 1, is], x2, Bottom]
]
}
]
,
{{pt, {{-.25, 1.55}, {-.25, 3.25}, {0.5, 3.75}, {1.1, 3.25}, {1.1, 1.75}, {.5, 1.5}}}, Locator, LocatorAutoCreate -> True},
{{x1, params[[6]]}, params, ControlType -> PopupMenu},
{{y1, params[[9]]}, params, ControlType -> PopupMenu},
{{x2, params[[11]]}, params, ControlType -> PopupMenu},
{{y2, params[[7]]}, params, ControlType -> PopupMenu},
{{SecondDisplay, "1D", "Secondary Plot Type"}, {"2D", "1D"}},
ControlPlacement -> {Automatic, Top, Top, Bottom, Bottom, Bottom},
SaveDefinitions -> True
]ExportString[{"ParameterName" -> {"FSC-A", "SSC-A"}, "Events" -> {{1, -2}, {1, 2}, {1, 3}, {1, 4}, {1, 5}}}, "FCS"]ExportString[{"ParameterName" -> {"FSC-A", "SSC-A"}, "Events" -> {{1, -2}, {1, 2}, {1, 3}, {1, 4}, {1, 5}}}, "FCS", "DataType" -> "Real32"]関連するガイド
-
▪
- インポートとエキスポート ▪
- 全形式のリスト ▪
- 科学,医学データ形式
履歴
2012 で導入 (9.0)