SWI-Prolog を使用しています。
一番上の行がプローブで、各行がサンプルである csv ファイルがあります。
1007_s_at 1053_at 117_at ...
GSM102447.CEL 1 0 0 ...
GSM102449.CEL 1 0 0 ...
GSM102451.CEL 1 0 0 ...
GSM102455.CEL 1 0 0 ...
GSM102507.CEL 1 0 1 ...
...
実際のファイルには、20,000 を超える列 (「プローブ」) と 150 行 (「サンプル」) しかありません。
各関係を抽出し、それらを事実として別のファイルに出力したいと考えています。
例えば:
%probe_value_in_sample(Probe,Sample_Strip,ProbeValue).
probe_value_in_sample('1007_s_at','GSM102447',1).
etc
これまでの私のコード:
foreach(csv_read_file_row_list('GSE2109_BarCode.csv', List), assert(['samples'|List])).
probe_value_in_sample(Probe,Sample_Strip,ProbeValue):-
[samples|[samples,Empty|ProbeList]],Empty='', %the first value is empty
indexOf(ProbeList,Probe,IndexOfProbe),
[samples|[samples,Sample|SampleValues]],Sample\='',
nth0(IndexOfProbe,SampleValues,ProbeValue),
name(Sample, CharSample),
append(Char_Sample_Strip,".CEL",CharSample),
name(Sample_Strip,Char_Sample_Strip).
%IndexOf(MyList, MyElement, MyIndex).
indexOf([Element|_], Element, 0).
indexOf([_|Tail], Element, Index):-
indexOf(Tail, Element, Index1),
Index is Index1+1.
これはうまく機能しているように見えますが、機能しないか、findall で使用できないほど遅いです。
何が問題なのですか?
助けてくれてありがとう。
アップデート
お返事ありがとうございます。
私は定義しました:
csv_read_file_row_list(File, List,Functor):-
csv_read_file_row(File,Row,[functor(Functor)]),Row=..List.
したがって、ストリームではなく開いているファイルがあり、現時点では Functor 変数は不要です。
maplist をどのように使用したか混乱していますか? そして、私はそれをうまく機能させることができません。
私が試してみました:
:- dynamic samples/3.
csv_read_file_row_list(File, List,Functor):-
csv_read_file_row(File,Row,[functor(Functor)]),Row=..List.
prepare_db(File) :-
( nonvar(File) ; File = 'GSE2109_BarCode.csv' ),
%open(File, read, S),
csv_read_file_row_list(File, ['thing',_Empty|ColKeys],'thing'),
forall(csv_read_file_row_list(File, ['thing',RowKeyDirty|Samples],'thing'),
( clean_rowkey(RowKeyDirty, RowKey),
maplist(store_sample(RowKey), ColKeys, Samples)
)).
%close(S).
store_sample(RowKey, ColKey, Sample) :-
assertz(samples(RowKey, ColKey, Sample)).
clean_rowkey(RowKeyDirty, RowKey) :- append(RowKey, ".CEL", RowKeyDirty).
としても:
:- dynamic samples/3.
csv_read_file_row_list(File, List,Functor):-
csv_read_file_row(File,Row,[functor(Functor)]),Row=..List.
prepare_db(File) :-
( nonvar(File) ; File = 'GSE2109_BarCode.csv' ),
%open(File, read, S),
csv_read_file_row_list(File, ['thing',_Empty|ColKeys],'thing'),
forall(csv_read_file_row_list(File, ['thing',RowKeyDirty|Samples],'thing'),
( clean_rowkey(RowKeyDirty, RowKey),
maplist(store_sample,[RowKey], ColKeys, Samples)
)).
%close(S).
store_sample(RowKey, ColKey, Sample) :-
assertz(samples(RowKey, ColKey, Sample)).
clean_rowkey(RowKeyDirty, RowKey) :- append(RowKey, ".CEL", RowKeyDirty).
しかし、どちらも失敗します。