-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdata_extractor.erl
204 lines (184 loc) · 7.44 KB
/
data_extractor.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This source code and work is provided and developed by Gene I. Sher & DXNN Research Group WWW.DXNNResearch.COM
%
%Copyright (C) 2009 by Gene Sher, DXNN Research Group, [email protected]
%All rights reserved.
%
%This code is licensed under the version 3 of the GNU General Public License. Please see the LICENSE file that accompanies this project for the terms of use.
%%%%%%%%%%%%%%%%%%%% Deus Ex Neural Network :: DXNN %%%%%%%%%%%%%%%%%%%%
-module(data_extractor).
-compile(export_all).
-include("records.hrl").
-define(PACKAGER,epitopes).
check_table(TableName)->
{ok,TN} = ets:file2tab(TableName),
io:format("TN:~p~n",[TN]),
table_dump(TN,ets:first(TN),0),
ets:delete(TN).
table_dump(TN,'$end_of_table',Index)->
io:format("Total entries in table:~p~n",[Index]);
table_dump(TN,Key,Index)->
io:format("~p~n",[ets:lookup(TN,Key)]),
table_dump(TN,ets:next(TN,Key),Index+1).
start(URL,SplitVals,FileName)->
start(URL,SplitVals,FileName,?PACKAGER).
start(URL,SplitVals,FileName,Packager)->
io:format("URL:~p~n SplitVals:~p~n FileName:~p~n PACKAGER:~p~n",[URL,SplitVals,FileName,Packager]),
case file:read_file(URL) of
{ok,Data} ->
file:close(URL),
List = binary_to_list(Data),
Extracted_Values = list_to_dvals(SplitVals,List,[]),
store(Extracted_Values,FileName,Packager);
{error,Error} ->
io:format("Error:~p~n",[Error])
end.
list_to_dvals(_SplitVals,[],Acc)->
lists:reverse(Acc);
list_to_dvals(SplitVals,List,Acc)->
{DVal_Line,Remainder} = splitter(SplitVals,List,[]),
io:format("DVal_Line:~p~n",[DVal_Line]),
list_to_dvals(SplitVals,Remainder,[DVal_Line|Acc]).
splitter([SplitVal|SplitVals],List,Acc)->
case SplitVal of
skip ->
[_|Remainder] = List,
splitter(SplitVals,Remainder,Acc);
_ ->
{Val,Remainder}=split_with(SplitVal,List),
Number = list_to_number(Val),
splitter(SplitVals,Remainder,[Number|Acc])
end;
splitter([],List,Acc)->
{lists:reverse(Acc),List}.
split_with(Seperator,List)->split_with(Seperator,List,[]).
split_with(Seperator,[Char|List],ValAcc)->
case Char of
Seperator->
{lists:reverse(ValAcc),List};
_ ->
split_with(Seperator,List,[Char|ValAcc])
end;
split_with(_Seperator,[],ValAcc)->
{lists:reverse(ValAcc),[]}.
list_to_number(List)->
try list_to_float(List) of
Float ->
Float
catch
_:_ ->
try list_to_integer(List) of
Int ->
Int
catch
_:_ ->
List
end
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Packagers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
store(Extracted_Values,Name,Packager)->
io:format("Extracted_Values:~p~n Name:~p Packager:~p~n",[Extracted_Values,Name,Packager]),
TableName = ets:new(Name,[set,private]),
io:format("TableName:~p~n",[TableName]),
data_extractor:Packager(TableName,Extracted_Values,1),
ets:tab2file(TableName,Name),
ets:delete(TableName).
simple_store(TableName,[Line|Lines],Index)->
ets:insert(TableName,{Index,Line}),
simple_store(TableName,Lines,Index+1);
simple_store(TableName,[],Index)->
io:format("Stored to ETS table:~p Index reached:~p~n",[TableName,Index-1]).
%0 0 0 -3.639 0.418 -0.670 1.779 -0.168 1.627 -0.388 0.529 -0.874 -0.814 0
%data_extractor:start("Vowel_Recognition",[32,32,32,32,32,32,32,32,32,32,32,32,32,skip,10],vowel_recognition).
vowel_recognition(TableName,[Line|Lines],Index)->
{Type,Remainder}=lists:split(3,Line),
{Features,Classification} = lists:split(10,Remainder),
ets:insert(TableName,{Index,Type,Features,Classification}),
vowel_recognition(TableName,Lines,Index+1);
vowel_recognition(TableName,[],Index)->
io:format("Stored to ETS table:~p Index reached:~p~n",[TableName,Index-1]).
%*CM078: 0.0491 0.0279 0.0592 0.1270 0.1772 0.1908 0.2217 0.0768 0.1246 0.2028 0.0947 0.2497 0.2209 0.3195 0.3340 0.3323 0.2780 0.2975 0.2948 0.1729 0.3264 0.3834 0.3523 0.5410 0.5228 0.4475 0.5340 0.5323 0.3907 0.3456 0.4091 0.4639 0.5580 0.5727 0.6355 0.7563 0.6903 0.6176 0.5379 0.5622 0.6508 0.4797 0.3736 0.2804 0.1982 0.2438 0.1789 0.1706 0.0762 0.0238 0.0268 0.0081 0.0129 0.0161 0.0063 0.0119 0.0194 0.0140 0.0332 0.0439}
rw()->
{ok,MT}=ets:file2tab(mines),
{ok,RT}=ets:file2tab(rocks),
TableName = ets:new(mines_vs_rocks,[set,public,named_table]),
I1=mines_vs_rocks(TableName,ets:tab2list(MT),1,0),
I2=mines_vs_rocks(TableName,ets:tab2list(RT),I1,0),
I3=mines_vs_rocks(TableName,ets:tab2list(MT),I2,1),
I4=mines_vs_rocks(TableName,ets:tab2list(RT),I3,1),
ets:tab2file(TableName,mines_vs_rocks),
ets:delete(TableName),
{I2,I4}.
mines_vs_rocks(TableName,[{_,Line}|Lines],Index,TestFlag)->
io:format("~p~n",[Line]),
[Identifier|Features]=Line,
U_Index=case {Identifier,TestFlag} of
{[42,67,77|_],0} ->
ets:insert(TableName,{Index,0,Features,[1,0]}),
Index+1;
{[42,67,82|_],0} ->
ets:insert(TableName,{Index,0,Features,[0,1]}),
Index+1;
{[67,77|_],1} ->
ets:insert(TableName,{Index,1,Features,[1,0]}),
Index+1;
{[67,82|_],1} ->
ets:insert(TableName,{Index,1,Features,[0,1]}),
Index+1;
_ ->
Index
end,
mines_vs_rocks(TableName,Lines,U_Index,TestFlag);
mines_vs_rocks(_TableName,[],Index,_TestFlag)->
Index.
abc_pred(TableName,[Line|Lines],Index)->
[Sequence,Classification] = Line,
ets:insert(TableName,{Index,Sequence,Classification}),
abc_pred(TableName,Lines,Index+1);
abc_pred(TableName,[],Index)->
io:format("Stored to ETS table:~p Index reached:~p~n",[TableName,Index-1]).
%data_extractor:start("Bioinformatics_Data/incompletelearnepitopemarkup/AntiJen.how",[10,32],training).
epitopes(TableName,[Line|Lines],Index)->
%ets:insert(TableName,{Index,Description,PrimSeq,MarkerSeq}),
io:format("Line: ~p~n",[Line]),
[Description,SeqP] = Line,
io:format("Description:~p~n SeqP:~p~n",[Description,SeqP]),
{PrimSeq,MarkerSeq}=lists:split(round(length(SeqP)/2),SeqP),
io:format("~p Description:~p~n PrimSeq:~p~n MarkerSeq:~p~n",[Index,Description,[C||C<-PrimSeq,C=/=10],[C||C<-MarkerSeq,C=/=10]]),
ets:insert(TableName,{Index,Description,[C||C<-PrimSeq,C=/=10],[C||C<-MarkerSeq,C=/=10]}),
epitopes(TableName,Lines,Index+1);
epitopes(TableName,[],Index)->
io:format("Stores to ETS table:~p Index reached:~p~n",[TableName,Index-1]).
%aaindex1(TableName,[Line|Lines],Index)->
%data_extractor:start("Bioinformatics_Data/incompletelearnepitopemarkup/AntiJen.how",[10,32],training).
glass(TableName,[Line|Lines],_Index1)->
%ets:insert(TableName,{Index,Description,PrimSeq,MarkerSeq}),
io:format("Line: ~p~n",[Line]),
[Index|SeqP] = Line,io:format("Here~n"),
[Label|RevSeq] = lists:reverse(SeqP),
Seq = lists:reverse(RevSeq),
io:format("Index:~p Seq:~p Label:~p~n",[Index, Seq, Label]),
ets:insert(TableName,{Index,Seq,Label}),
glass(TableName,Lines,_Index1+1);
glass(TableName,[],_Index1)->
_Index1.
pima(TableName,[Line|Lines],Index)->
%ets:insert(TableName,{Index,Description,PrimSeq,MarkerSeq}),
io:format("Line: ~p~n",[Line]),
[Label|RevSeq] = lists:reverse(Line),
Seq = lists:reverse(RevSeq),
io:format("Index:~p Seq:~p Label:~p~n",[Index, Seq, Label]),
ets:insert(TableName,{Index,Seq,Label}),
pima(TableName,Lines,Index+1);
pima(TableName,[],Index)->
Index.
sat(TableName,[Line|Lines],Index)->
%ets:insert(TableName,{Index,Description,PrimSeq,MarkerSeq}),
io:format("Line: ~p~n",[Line]),
[Label|RevSeq] = lists:reverse(Line),
Seq = lists:reverse(RevSeq),
io:format("Index:~p Seq:~p Label:~p~n",[Index, Seq, Label]),
ets:insert(TableName,{Index,Seq,Label}),
sat(TableName,Lines,Index+1);
sat(TableName,[],Index)->
Index.