function [W,MF_good_cell,goodidx_in_graphs] = create_graph_oct05(filename,num_graphs) 
% Create a whole graph from the subgraphs of Borya's file
% Input:
% filename (character): name of data file
% num_graphs (integer): number of graphs in files to read (ascending order)
% Output 
% W (matrix): N*N sparse symmetric matrix
%             Provides weight for the unified graph. W(i,j) is the local
%             similarity weight between edges i and j 
%             the index of row (or coloumn) i correspond to the index of GO notation 
%             according to order in file 'filename'
% good_cell (a cell of length num_graphs-#empty graphs).
%             It lists the name of the molecular functions (with nonempty 
%             subgraphs) according to their order in file 'filename'
% idx_in_graphs (cell array of indices to GO notation of length num_graphs-#empty graphs). 
%               For each nonempty graph representing a GO molecular function, 
%               it has a list of indices according to order of appearances 
%               of the GO notation associated with the molecular functions, 
%               e.g. GO:0003824 obtains the index as it appears first. 
% file2myindex (sparse array 100000*1).
%               For each number part of GO notation, it provides the 
%               corresponding index according to order in file



[GOnum_vec,MF_cell,graphs,idx_in_graphs,GOnum_to_index,GOidx_to_MFidx,...
    index_bad,index_good] = readsubgraphs_oct05(filename,num_graphs); 


save GO_info_oct05 GOnum_vec MF_cell graphs idx_in_graphs GOnum_to_index ...
    GOidx_to_MFidx index_bad index_good

MF_good_cell = MF_cell(index_good);
MF_bad_cell = MF_cell(index_bad);
goodidx_in_graphs = idx_in_graphs(index_good);
good_graphs = graphs(index_good);

N = length(GOnum_vec);
size_gMF = length(MF_good_cell);

%Remark: may also use: load data_borya_mat_weights  
%compute the matrix of the whole subgraph
W = sparse(N,N); % weight matrix
for i= 1:size_gMF
    W = W + good_graphs{i};
end

%transform the weights appropiately.
%here I have decided to take their inverse, and scale.
[R,C,V] = find(W);
vec = 1./V;
vec = vec/max(vec);
W = sparse(R,C,vec);
%idx_in_graphs (cell array of indexes used in each subgraph)
%save graph_info W good_cell

%made a change
%[R,C,V] =find(file2myindex);

save all_graph_info GOnum_vec MF_cell MF_good_cell MF_bad_cell graphs...
    good_graphs idx_in_graphs goodidx_in_graphs GOnum_to_index...
    GOidx_to_MFidx index_bad index_good W