Skip to content

Commit

Permalink
start of graphml loader
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Aug 23, 2024
1 parent 12d58c8 commit df54adc
Show file tree
Hide file tree
Showing 26 changed files with 4,655 additions and 20 deletions.
Empty file modified library/genome/chado_xml_loader.pl
100755 → 100644
Empty file.
Empty file modified library/genome/das_classic_loader.pl
100755 → 100644
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% ==============================
% FA/FASTA Reader
% ==============================
:- ensure_loaded(gff_loader). % parse_and_store_attributes/2
:- ensure_loaded(ext_loader_gff). % parse_and_store_attributes/2

load_fb_fa(Fn,Filename):-
track_load_into_file(Filename,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion library/genome/json_loader.pl → library/genome/ext_loader_json.pl
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
assert_JSON(P):- note_doing(assert_OBO(P)).

:- ensure_loaded(flybase_main).
:- ensure_loaded(obo_loader).
:- ensure_loaded(ext_loader_obo).

%:- listing(assert_OBO/1).

Expand Down
File renamed without changes.
File renamed without changes.
Empty file modified library/genome/flybase_convert.pl
100755 → 100644
Empty file.
Empty file modified library/genome/flybase_induced_types.pl
100755 → 100644
Empty file.
Empty file modified library/genome/flybase_learn.pl
100755 → 100644
Empty file.
9 changes: 5 additions & 4 deletions library/genome/flybase_loader.pl
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
*/
:- discontiguous column_names/2.

load_data_fb_data:-
load_data( 64, fb_current('./chado-xml/chado_FBim.dtd')),
load_data( 76, fb_current('./chado-xml/chado_FBst.dtd')),
Expand Down Expand Up @@ -204,9 +206,8 @@
!.


:- ensure_loaded(obo_loader).
:- ensure_loaded(graphml_loader).

%:- ensure_loaded(obo_loader).
%
create_flybase_qlf:-
shell('swipl -g "qcompile(whole_flybase)').

Expand Down Expand Up @@ -1030,7 +1031,7 @@
:- dynamic(is_loaded_from_file_count/2).

:- use_module(library(http/json)).
:- ensure_loaded(json_loader).
%:- ensure_loaded(json_loader).
load_fb_json(Fn,File):- fbug(load_fb_json(Fn,File)),
current_predicate(load_flybase_json/2),
absolute_file_name(File,Filename),
Expand Down
9 changes: 7 additions & 2 deletions library/genome/flybase_main.pl
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
% OBO LOADER
% ==============
:- set_option_value(encoding,utf8).
:- ensure_loaded('./obo_loader').
:- ensure_loaded(json_loader).
%:- ensure_loaded('./obo_loader').
%:- ensure_loaded(json_loader).

:- ensure_loaded(library(metta_interp)).

Expand Down Expand Up @@ -1494,4 +1494,9 @@
%:- ensure_loaded(metta_python).


ping_file_loaders:-
expand_file_name('library/*/ext_loader_*.pl',List),
maplist(absolute_file_name,List,AList),
maplist(ensure_loaded,AList).
:- ping_file_loaders.

Empty file modified library/genome/flybase_scheme.pl
100755 → 100644
Empty file.
37 changes: 25 additions & 12 deletions library/genome/graphml_loader.pl → library/graphml/ext_loader_graphml.pl
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*/

:- module(read_graphml, [read_graphml/2,
rgml/0,
rgml/0,rgml2/0,
load_graphml/2,
load_fb_graphml/2]).


Expand All @@ -34,15 +35,22 @@


load_fb_graphml_read(Id,In):- is_list(In),!,maplist(load_fb_graphml_read(Id),In).
load_fb_graphml_read(Id,In):- wdmsg(Id=In),!.
load_fb_graphml_read(Id,In):- In=..[P|InL],Save=..[P,Id|InL],assert_OBO(Save),writeln(Save).

s_list_assert(S,List,Assert):-
must_det_ll((into_name_values(List,Ns,Vs),
atomic_list_concat([S|Ns],'_',Pred),
Assert=..[Pred|Vs])).

elements_are_kv(Data,element(Data,[id=Key],Value),Key=Value).
elements_are_kv(Data,element(Data,[key=Key],Value),Key=Value).
fix_value(X,Y):- \+ callable(X),X=Y.
fix_value([X],Y):- !, fix_value(X,Y).
fix_value(X,Y):- is_list(X),!,maplist(fix_value,X,Y).
fix_value(X,Y):- \+ atom(X),!,X=Y.
fix_value(X,Y):- atom_number(X,Y),!.
fix_value(X,X).

elements_are_kv(Data,element(Data,[id=Key],LValue),Key=Value):- fix_value(LValue,Value).
elements_are_kv(Data,element(Data,[key=Key],LValue),Key=Value):- fix_value(LValue,Value).
%elements_are_kv(S2,Content,List2):- maplist(elements_are_kv(S2),Content,List2).

restructure_graphml(Term_list,Terms):- is_list(Term_list),!,maplist(restructure_graphml,Term_list,Terms).
Expand All @@ -52,10 +60,10 @@
restructure_graphml(element(S,[ source=B,target=E],Term_list),Assert):- S == edge,
%atomic_list_concat([B,E],'_',Id),
maplist(elements_are_kv(data),Term_list,NVList),
findall(edge_prop(B,E,N,V),(member(N=V,NVList), \+ member(V,[['false'],['None']])),Assert).
findall(edge_prop(B,E,N,V),(member(N=V,NVList), \+ member(V,['false','None'])),Assert).
restructure_graphml(element(S,[id=Id],Term_list),Assert):- S == node,
maplist(elements_are_kv(data),Term_list,NVList),
findall(node_prop(Id,N,V),(member(N=V,NVList), \+ member(V,[['false'],['None']])),Assert).
findall(node_prop(Id,N,V),(member(N=V,NVList), \+ member(V,['false','None'])),Assert).
restructure_graphml(IO,IO).

%! read_graphml(+File_basename:atom, -Term_list:list) is det
Expand Down Expand Up @@ -293,18 +301,23 @@

into_name_values([],[],[]):-!.
into_name_values([N=V|List],[FN|Ns],[FV|Vs]):-
fix_name(N,FN),fix_name(V,FV),into_name_values(List,Ns,Vs).
fix_name(N,FN),fix_value(V,FV),into_name_values(List,Ns,Vs).

fix_name(N,FN):- \+ atom(N),!,FN=N.
fix_name(N,FN):- atom_concat('attr.',FFN,N),!,fix_name(FFN,FN).
fix_name(N,FN):- atom_concat('v_',FFN,N),!,fix_name(FFN,FN).
fix_name(N,FN):- atom_concat('e_',FFN,N),!,fix_name(FFN,FN).
%fix_name(N,FN):- atom_concat('v_',FFN,N),!,fix_name(FFN,FN).
%fix_name(N,FN):- atom_concat('n_',FFN,N),!,fix_name(FFN,FN).
%fix_name(N,FN):- atom_concat('e_',FFN,N),!,fix_name(FFN,FN).
fix_name(N,FN):- atom_concat('_',FFN,N),!,fix_name(FFN,FN).
fix_name(N,N).

rgml:-
read_graphml('tests/performance/knowledge_graphs/graphml_csv/cml/ckg_neighbors_cml_graph_n15612_e21425.graphml',S),
load_fb_graphml_read('CKG_N',S).
rgml:- load_graphml('CKG_N','tests/performance/knowledge_graphs/graphml_csv/cml/ckg_neighbors_cml_graph_n15612_e21425.graphml').
rgml2:- load_graphml('&self','library/graphml/tests/*.graphml').

load_graphml(KB,Paths):- atom(Paths),expand_file_name(Paths,List),List\==[Paths],!,maplist(load_graphml(KB),List).
load_graphml(KB,Paths):- is_list(Paths),!,maplist(load_graphml(KB),Paths).
load_graphml(KB,Paths):- read_graphml(Paths,To),!,load_fb_graphml_read(KB,To).




Expand Down
Loading

0 comments on commit df54adc

Please sign in to comment.