BACKGROUND
large networks, such as social networks, computer and biological networks, consisting of thousands to millions of vertices, have recently attracted much attention  <cit> .
biological networks, including protein-protein interaction networks, gene regulatory networks, and metabolic networks, are among those most widely studied  <cit> .
in order to extract meaningful information from the vast amount of data encrypted in the networks, powerful methods for computational analysis need to be developed.
milo et al.
proposed that the existence of specific sub-graphs that repeat themselves in a specific network or even among various networks would be consistent with the tenets of evolutionary theory.
each of these sub-graphs, defined by a particular pattern of interactions between vertices, may reflect a framework in which particular functions are achieved efficiently.
these sub-graphs are called network motifs.
motifs are of notable importance largely because they may reflect functional properties.
nevertheless, as possible associated functions may be unknown initially, defining motifs independent of function and based on frequency of occurrence is commonly accepted.
as such, motifs can be considered as sub-graphs, which occur at significantly higher frequencies in the network under investigation than in random networks.
the task of discovering motifs in networks is known as motif-finding problem.
the various proposed protocols for finding motifs are designed to identify either all possible sub-graphs or the most frequent ones.
mfinder, pajek, mavisto, and fanmod are the notable existing tools for the motif-finding problem  <cit> .
relevant features for evaluation of these tools include whether or not they can present results of analysis visually; they are capable of enumerating sub-graphs; a sampling protocol is used instead of analysis of the entire network; sub-graphs are discovered or only queried graphs are found; as well as the memory usage and time needed in each algorithm and the growth of cpu time with sub-graph size.
the memory usage and cpu time determine the maximum size of sub-graphs that can be analyzed.
mfinder, the first motif-mining tool, implements two kinds of motif finding algorithms: a full enumeration and a sampling method.
the sampling protocol is the faster one, that assigns probability values to motifs identified, and infers frequencies from these values  <cit> .
it is also the only tool without the option of a visual presentation and results are only provided in the format of a text.
concerning motif discovery pajek only offers limited functionality, because it only finds specific motifs such as triads and particular tetrads in a network  <cit> .
fanmod algorithm is clearly the best among these with regard to computational time  <cit> .
for example, for enumeration of all 5-size sub-graphs in the transcriptional network of escherichia coli using a laptop with a  <dig>  ghz pentium m processor and  <dig> mb ram, mfinder, mavisto, and fanmod requires  <dig>   <dig>  and  <dig> seconds, respectively  <cit> .
there are  <dig>  ×  <dig> 5-size sub-graphs in this network.
the only problem with fanmod is that it can handle sub-graphs consisting maximally of eight vertices.
its memory usage increases notably both with increase in sub-graph size and network size.
in addition to the mentioned tools, nemofinder given by j. chen and et al.
<cit>  is an efficient network motif finding algorithm for motifs up to size  <dig> only for protein-protein interaction networks, which are presented by undirected graphs.
also in the case of protein interaction networks, some clustering tools are used to simplify the motif finding problem.
mcode  <cit>  and mulic  <cit>  are two clustering approaches to be used.
"power graph analysis" is an approach for understanding protein interaction networks features  <cit> .
obviously the algorithms designed for both directed and undirected graphs are more time-consuming and general.
we aim to derive an algorithm with lower cpu time and less memory usage that would be capable of supporting sub-graphs of all sizes.
this is particularly important for analysis of biological networks where the total number of sub-graphs growths exponentially by the size of sub-graph.
our algorithm is based on counting all sub-graphs of a given graph.
for enumeration of sub-graphs in the network, a novel and efficient method is presented.
we evaluate our algorithm on the biological networks: the metabolic pathway of bacteria e. coli  <cit>  and the transcription network of yeast s. cerevisiae  <cit> , and also non-biological networks: a real social network and an electronic network.
the obtained results of our algorithm are compared with three well-known motif finding tools: mfinder, mavisto, and fanmod  <cit> .
by this comparison, we show the efficiency of our algorithm.
also, our tool can be employed for finding motifs of size greater than eight, while most of the other algorithms have restriction on the size of motifs.
methods
definitions
a network considered as a large graph consists of vertices and edges.
a directed graph  is usually shown by g =  where v is a finite set of vertices and e is a finite set of edges, where e ⊆ .
an edge e =  ∈ e goes from vertex u, the source, to another vertex v, the target.
the vertices u and v are incident with the edge e and adjacent to each other.
a sub-graph of the graph g =  is a graph gs =  where vs ⊆ v and es ⊆  ∩ e.
the in-degree and out-degree of a vertex is defined as the number of edges coming into the vertex and the number of edges going out of it, respectively.
the degree of a vertex is the total number of edges it is incident to.
we define the sub-graph size as the number of vertices present in the sub-graph.
two sub-graphs g <dig> =  and g <dig> =  are isomorphic if there is a one-to-one correspondence between their vertices, and there is an edge directed from one vertex to another vertex of one sub-graph if and only if there is an edge with the same direction between the corresponding vertices in the other sub-graph.
for a particular sub-graph gp, all sub-graphs isomorphic to gp in the network are considered as matches of gp .
the frequency of a particular directed sub-graph in an input network is the number of its matches in the network.
in this paper, it is assumed that different matches can have overlap in vertices or edges.
motifs are defined as sub-graphs, which have higher frequencies in the network than in random networks of equal size.
algorithm
our algorithm for finding network motifs is called kavosh and consists of four subtasks: enumeration: finding all sub-graphs of a given size that occur in the input graph; classification: classifying each found sub-graph into isomorphic groups; random graph generation: generating random graphs with respect to the input network  and motif identification: distinguishing motifs among all found sub-graphs on basis of statistical parameters.
in kavosh, one of the most significant subtasks is the enumeration part.
this subtask makes kavosh different from other algorithms.
building an implicit tree according to the restrictions that will be discussed later causes improvement in both time and memory usage.
the tree structure with its restrictions ensures that each individual sub-graph is enumerated only once that leads us to an efficient solution.
also using some powerful tools such as "revolving door ordering" algorithm  <cit>  in this subtask, is an advantage of our algorithm.
classification is another major subtasks of motif finding algorithms.
in kavosh, nauty algorithm which is the best known tool for this subtask is used.
this is another feature for the efficiency of kavosh.
the details of the subtasks are presented below:
enumeration
here we present an efficient method for enumeration of sub-graphs of size k. for counting all k-size sub-graphs of a given graph g =  whose vertices are numerically labeled, all sub-graphs that include a particular vertex are discovered.
subsequently, this vertex is removed from the network, and the process is repeated consecutively for successive vertices.
for counting the sub-graphs of size k that include a particular vertex, trees with maximum depth of k, rooted at this vertex and based on neighborhood relationship are implicitly built.
children of each vertex include both incoming and outgoing adjacent vertices.
to descend the tree, a child is chosen at each level with the restriction that a particular child can be included only if it has not been included at any upper level.
after having descended to the lowest level possible, the tree is again ascended and the process is repeated with the stipulation that vertices visited in earlier paths of descendent are now considered unvisited vertices.
a final restriction in building trees is that all children in a particular tree must have numerical labels larger than the label of the root of the tree.
the protocol for extracting sub-graphs can now be described in greater details.
the protocol makes use of the composition operation of an integer.
for extraction of sub-graphs of size k, all possible compositions of the integer k -  <dig> must be considered.
the compositions of k -  <dig> consist of all possible manners of expressing k -  <dig> as a sum of positive integers.
summations in which the order of the summands differs are considered distinct.
a composition can be expressed as k <dig>  k <dig> , ... km where k <dig> + k <dig> + ... + km = k -  <dig>  to count sub-graphs based on the composition, ki vertices are selected from the i -th level of the tree to be vertices of the sub-graphs .
the k -  <dig> selected vertices along with the vertex at the root define a sub-graph within the network.
as an example, we can consider finding sub-graphs of size  <dig> .
all compositions of k -  <dig> =  <dig> need to be considered; these are , ,  and .
for example, sub-graphs defined by  would include the root vertex and one valid child vertex at each of three subsequent levels.
it is possible that for a particular level i, ki < ni, where ni is the number of vertices present at level i. at level i, c  is the number of different combinations of k elements through n elements) different selection of vertices need to be considered.
here, by using the "revolving door ordering" algorithm  <cit>  all combinations containing ki vertices from the ni vertices are selected.
the "revolving door ordering" algorithm is considered the fastest algorithm for generating combinations of vertices.
the pseudocode for our algorithm for the enumeration subtask, which produces all k-size sub-graphs present in an input graph g = , is presented in algorithm  <dig> .
in this algorithm, the vertex u defines the root of a tree.
each vertex is marked as visited, if and only if it has been observed as an adjacent of any selected vertex in the upper levels.
si  is the set of all vertices from the i-th level included in a particular sub-graph.
the subtask enumerate_vertex is described in algorithm  <dig> .
this algorithm enumerates all sub-graphs in which a particular vertex acts as root.
in algorithm  <dig>  the validate function  used to create list of valid vertices from which vertex selection can be made is described in algorithm  <dig>  the initial_comb and next_comb functions make use of the "revolving door ordering" algorithm as described earlier to make vertex combination selections at each level.
the above algorithms clearly identify all k-size sub-graphs in the network.
also, the constrictions placed on the manner in which trees are constructed also ensure that no single sub-graph will be counted more than once.
because, if a selected vertex  for the current level  were allowed to be among vertices adjacent to vertices at levels before i -  <dig>  sub-graphs would be duplicated and enumerated more than once.
this is because vertex v could be one of the vertices selected for two different compositions of a graph of size k. this possibility is precluded by algorithm  <dig> because vertices adjacent to vertices at levels <i -  <dig>  are not allowed to be candidate vertices for level i.
this step is described by an example on a given graph shown in figure  <dig>  for this graph, all 4-size sub-graphs containing the vertex  <dig>  are going to be found.
this is illustrated in figure  <dig>  the vertex  <dig> is considered as the root of the tree and its label is considered as visited.
as mentioned before, all the compositions of k -  <dig> =  <dig> are considered as the different patterns of selection.
starting with the composition  as the selecting pattern, valid children of the root are found.
due to its neighbors, the vertices  <dig>   <dig> and  <dig> are the valid ones, which according to the pattern one of them have to be chosen.
the labels of these three vertices are now visited.
using the "revolving door ordering", the vertex  <dig> is the first chosen vertex.
by using this pattern, one of the valid vertices of the vertex  <dig> has to be selected.
the vertex  <dig>  has three neighbors, the vertices  <dig>  and  <dig>  but the vertex  <dig> is previously visited, so it is not a valid child.
so this process continues with the vertices  <dig> and  <dig>  which are visited now.
again using "revolving door ordering", the vertex  <dig> is selected to be continued.
as the pattern shows, one of the valid children of the vertex  <dig> have to be chosen as the last vertex of the sub-graph.
the vertex  <dig> has five neighbors, the vertices  <dig>   <dig>   <dig>   <dig> and  <dig>  but just the vertex  <dig> has not been visited yet, so its only valid child is the vertex  <dig>  the vertex  <dig> is selected as the last vertex of the sub-graph.
now the vertices  <dig>   <dig>   <dig> and  <dig> make a sub-graph involved in the network of size  <dig>  containing the vertex  <dig>
by recursively ascending the tree, for processing the other choices of selection, the lower vertices, are not visited anymore.
so at this point, recursively ascending vertex  <dig>  causes that the vertex  <dig> is not visited anymore.
by continuing using this pattern, only one other sub-graph with vertices  <dig>   <dig>   <dig> and  <dig> is found; the details are shown in figure 2a.
the composition  is the next selecting pattern to be considered.
the same as the previous selecting pattern, the vertices  <dig>   <dig> and  <dig> are the valid vertices in the first level which one of them have to be chosen according to the first element of the composition.
using "revolving door ordering", the vertex  <dig> is selected and is processed.
the same as the previous pattern, the vertices  <dig> and  <dig> are the valid children of the vertex  <dig>  here, in this step, two vertices of this level have to be chosen according to the second element of the composition which is  <dig>  so both the vertex  <dig> and  <dig> are selected now, and produce the sub-graph containing the vertices  <dig>   <dig>   <dig> and  <dig>  recursively ascending to level two, the next selection is the vertex  <dig>  by ascending, the vertices  <dig> and  <dig> that became visited in the last step are reset to unvisited.
among all the neighbors of the vertex  <dig>  the vertices  <dig>   <dig> and  <dig> are valid.
using "revolving door ordering", all different selections of two vertices from these three vertices are computed, which results in three different sub-graphs containing the vertices {  <dig>   <dig>   <dig>  6},{  <dig>   <dig> , 7} and {  <dig>   <dig>   <dig>  7}.
details are shown in figure 2b.
in the same manner, the selecting pattern  finds the sub-graphs containing the vertices { <dig>   <dig>   <dig>  6}, { <dig>   <dig>   <dig>  7}, { <dig>   <dig>   <dig>  4}, {  <dig>   <dig>   <dig>  6}, {  <dig> ,  <dig>  7}, {  <dig>   <dig>   <dig>  4}, {  <dig>   <dig>   <dig>  4}, {  <dig>   <dig>   <dig>  6} and {  <dig>   <dig>   <dig>  7} which is shown in figure 2c.
and using the pattern , the sub-graph with vertices {  <dig>   <dig>   <dig>  5} is found, its tree is shown in figure 2d.
it should be noted that the reason for the efficiency of our enumeration algorithm would be the implicit tree constructed by the underlying recursion in our algorithm.
the depth of this implicit recursion tree depends on the number of elements in a composition of k.
classification
after discovering a sub-graph involved as a match in the input network, in order to be able to evaluate the size of each class according to the input network, there is a need to classify it into isomorphic classes.
the most powerful algorithm, which is usually used for finding isomorphism is nauty  <cit> .
in this algorithm, a unique identifier is assigned to each class of isomorphism and called the canonical labeling.
the canonical labeling is generated by the transformation of the adjacency matrix into a string by concatenating it row-by-row.
as different orderings of the vertices generate different strings, an ordering of the vertices with the lexicographically largest or smallest string is chosen as canonical labeling between all possible permutations.
as an example for the graph illustrated in figure  <dig> with the corresponding adjacency matrix, the canonical labeling is  <dig>  related to the  ordering of vertices, which is the lexicographically largest string among all possible strings obtained by different orderings on vertices.
in this step of our approach, the adjacency matrix of each obtained sub-graph in the first step, is given to nauty as an input in order to generate its canonical labeling as the class identifier of that sub-graph.
this obtained identifier causes increment of the size of the corresponding class of isomorphism, by one.
random graph generation
according to the definition of a motif, the proper determination of sub-graph significance, needs comparison by an ensemble of appropriate random graphs.
so generation of this ensemble due to a given random graph model is a necessary step of the algorithm.
one of the popular random graph models on which we also focused is to preserve the degree sequence of the original graph in random graphs.
there has been some researches concerning the problem of sub-graph distribution within such graphs for directed sparse random graphs  <cit> .
since biological networks are scale-free networks  <cit>  the fraction of vertices having k edges, p, decays as a power law p ~k-λ, where λ is often between  <dig> and  <dig>  therefore they are sparse.
so using this random graph model is appropriate for them.
in our approach, similar to milo's random model  <cit>  switching operations are applied on the edges of the input network repeatedly, until the network is well randomized.
this switching operation is applied on the randomly chosen vertices of the network as it is shown in figure  <dig>  by applying this switching operation repeatedly on the input network, an ensemble of random networks is generated.
for each network in the generated ensemble sub-graphs are found by using step  <dig> of the algorithm, and then using step  <dig>  the size of the isomorphism classes for found sub-graphs are evaluated.
this generation is necessary for comparing the real network with some random networks in order to obtain the significance of each sub-graph.
motif determination
by using the result of the last step, the significance of each sub-graph found in the input network is calculated.
here, some statistical measures are introduced, that lead us to the probable motifs in the input network.
frequency
this is the simplest measurement for estimating the significance of a motif.
for a given network, assume that gp is a representative of an isomorphism class involved in that class.
the frequency is defined as the number of occurrence gp in the input network.
zscore
this measure reflects how randomly the class occurred in the input network.
for the assumed motif gp, this measure is defined as below:
where np is the number which gp occurred in the input network,  is the mean number which gp occurred in random networks and σ is the standard deviation.
the larger zscore, the more significant is the motif.
pvalue
this measure indicates the number of random networks in which a motif gp occurred more often than in the input network, divided by the total number of random networks.
therefore, pvalue ranges from  <dig> to  <dig>  the smaller the pvalue, the more significant is the motif.
these are some statistical measures implied in our algorithm to indicate the significance of a motif.
for each motif found in step  <dig>  according to the result obtained from step  <dig> and  <dig>  these measures are calculated in this step.
until now, motifs found in the input network are available including some statistical measures related to them.
as mentioned in the previous step, three different measures are used in this algorithm.
there are no exact thresholds for these measures to distinguish a motif, and the more restricted thresholds; the more precise is the motif.
but according to the experimental results by milo , the following conditions may be used to describe a network motif:
<dig>  by using  <dig> randomized network, the pvalue is smaller than  <dig> .
<dig>  the frequency is larger than four.
<dig>  by using  <dig> randomized network, the zscore is larger than one.
according to the above conditions and with respect to the sufficient preciseness, the patterns with significant measures are the ones which describe network motifs.
RESULTS
in this section, we present the results of applying kavosh to some real networks.
applications were made to network instances that are both biological and non-biological.
the metabolic pathway of the bacteria e. coli and the transcription network of yeast s. cereviciae  <cit> , a real social network, and an electronic network were targeted.
these instances for testing the algorithm were up-to-date versions of the motif detection tests used by other existing algorithms .
the biological networks, as reflected by the number of vertices therein, were notably larger than the non-biological networks used here.
the numbers of sub-graphs of different sizes observed in each network are presented in table  <dig>  the numbers of different isomorphic groups of specific sizes observed are presented in table  <dig>  in all the networks, both the number of sub-graphs and the number of isomorphic groups increase exponentially with sub-graph size.
application of the fanmod algorithm for finding sub-graphs and isomorphic groups of sizes up to eight, resulted in the identification of the same numbers as kavosh.
additionally, here we present some sub-graphs, which are determined as motifs by kavosh.
we present five most significant sub-graphs of size  <dig>   <dig> and  <dig> in the e. coli network in figures  <dig>   <dig> and  <dig>  respectively.
in this section, we aim to compare the efficiency and power of kavosh with three previously presented programs.
we apply each of the four algorithms  to the networks described.
the computer system we used was equipped with a  <dig>  ghz amd opteron processor and  <dig> gb ram.
for each of the real networks,  <dig> random networks were generated as described.
subsequently, each of the algorithms was applied to the real and all randomly generated networks.
the cpu time and memory needed to perform this task was assessed for the different algorithms .
for all networks, the cpu time was maximum for mavisto.
as our algorithm is a full enumeration algorithm, we apply full enumeration version of mfinder.
the cpu time of mfinder, although generally at least an order of magnitude less than that of mavisto, was still an order of magnitude or larger than that of fanmod and kavosh.
the cpu times of fanmod and kavosh were comparable for the e. coli network but in other networks the cpu time for kavosh is less than the time for fanmod .
although their time differences are sometimes not very significant, but this is because of the limitations in implementing a general motif finder tool in comparison with a limited one.
also, the time performance of kavosh according to the number of found sub-graphs and sub-graph size in four tested network is given in table  <dig>  this table shows the numbers of sub-graphs counted per second for each network.
the largest degree is an important reason for different performances in networks.
the largest degree in s. cereviciae, e. coli, electronic and social networks are respectively  <dig>   <dig>   <dig> and  <dig>  as the table shows these degrees have influence in the performance.
another important aspect in this performance is that as the sub-graph size increases, the classification part takes more time, and this makes the algorithm slower for larger sub-graohs.
in terms of memory usage, both mavisto and mfinder were inefficient and our computer systems could not support finding even relatively small sub-graphs, particularly in the larger tested networks.
the combined effects of large cpu time and large memory usage in effect precluded size  <dig> sub-graph identification in even the smallest electronic network by mavisto.
mfinder could not identify size  <dig> sub-graphs in the tested biological networks under the conditions of our computer system.
fanmod produced results for sub-graphs of size up to  <dig> in all networks used.
the limitation of size  <dig> is inherent in the implementation protocol of fanmod.
kavosh does not have this limitation, and the size of sub-graphs queried is only limited by computer power.
using the system described here, sub-graphs of size up to  <dig> were identified by kavosh in all the networks used.
for the smaller electronic network, sub-graphs of size  <dig> and  <dig> could also be identified .
the fanmod cpu time was generally somewhat larger than that of kavosh.
importantly, fanmod memory usage was considerably higher than the memory usage of our kavosh .
in all tables, the time values are in seconds and the empty cells indicate that the algorithm cannot support that specific size or its time cannot be calculated because of the complexity.
additionally, we present the memory usage for both kavosh and fanmod, which was computed with the valgrind- <dig> .
<dig> package  <cit> .
the chart in figure  <dig> compares fanmod with kavosh and shows that how better kavosh works in comparison to fanmod in this case.
as it is shown in figure  <dig>  the growth of sub-graph numbers according to its size causes large requirement in memory.
so, memory usage will be one of the problems for finding motifs of larger size.
as we can see in the tables  <dig>   <dig>   <dig>  and  <dig>  the only comparable algorithm with ours is fanmod, but still is not as efficient as our algorithm.
in addition to the above results, in order to show the high performance of our algorithm on large networks, we apply both kavosh and fanmod on homo sapiens ppi network  <cit>  and on drosophila melanogaster ppi network  <cit> , both included more than  <dig> nodes.
because of the high growth of the number of sub-graphs, these large networks are tested for sub-graphs of size  <dig>   <dig>  and  <dig>  the results of both kavosh and fanmod on homo sapiens ppi network and drosophila melanogaster ppi network are rfespectively shown in tables  <dig> and  <dig>  as the tables show, kavosh performs much better for larger networks.
CONCLUSIONS
to improve the efficiency of our algorithm the comparison of the obtained results with three well-known motif finding tools is discussed.
for comparison, the cpu time, memory usage and the similarities of obtained motifs are considered.
also, kavosh can be employed for finding motifs of size greater than eight, while most of the other algorithms have restriction on motifs with size greater than eight.
besides, comparing with other algorithms kavosh has better performance for large networks.
in conclusion, the presented method  is a general motif finder that has no restrictions on motif size and also it has less time and memory consuming in comparison with other existing algorithms.
authors' contributions
initial idea of the research was proposed by zrmk, ha, and and amn.
the kavosh is designed, implemented, and tested by es, sa, sm, and zrmk.
all authors participated in designing the structure and organization of the manuscript equally.
all authors read and approved the final manuscript.
appendix: algorithms
appendix 1
input: g: input graph.
output: extract all k-size sub-graphs of graph g.
1: for each u ∈ g do
2:    visited  ← true
3:    s <dig> ← u
4:    enumerate_vertex
5:    visited  ← false
6: end for
algorithm 1: kavosh
appendix 2
input: g: input graph, u: root vertex, s: selection , remainder: number of remaining vertices to be selected,
i: current depth of the tree.
output: all k-size sub-graphs of graph g rooted in u.
1: if remainder =  <dig> then
2:    return
3: else
4:    v allist ← validate
5:    ni ← min
6:    for ki =  <dig> to ni do
7:       c ← initial_comb
8:       repeat
9:          si ← c
10:          enumerate_vertex
11:          next_comb
12:       until c = nill
13:    end for
14:    for each v ∈ v allist do
15:       visited  ← false
16:    end for
17: end if
algorithm 2: enumerate_vertex
appendix 3
input: g: input graph, parents: selected vertices of last layer, u: root vertex.
output: valid vertices of the current level.
1: v allist ← nill
2: for each v ∈ parents do
3:    for each w ∈ neighbor  do
4:       if label  < label  and not visited  then
5:          visited  ← true
6:          v allist = v allist + w
7:       end if
8:    end for
9: end for
10: return vallist
algorithm 3: validate

 large networks, such as social networks, computer and biological networks, consisting of thousands to millions of vertices, have recently attracted much attention. biological networks, including protein-protein interaction networks, gene regulatory networks, and metabolic networks, are among those most widely studied. in order to extract meaningful information from the vast amount of data encrypted in the networks, powerful methods for computational analysis need to be developed. milo et al. proposed that the existence of specific sub-graphs that repeat themselves in a specific network or even among various networks would be consistent with the tenets of evolutionary theory. each of these sub-graphs, defined by a particular pattern of interactions between vertices, may reflect a framework in which particular functions are achieved efficiently. these sub-graphs are called network motifs. motifs are of notable importance largely because they may reflect functional properties. nevertheless, as possible associated functions may be unknown initially, defining motifs independent of function and based on frequency of occurrence is commonly accepted. as such, motifs can be considered as sub-graphs, which occur at significantly higher frequencies in the network under investigation than in random networks. the task of discovering motifs in networks is known as motif-finding problem. the various proposed protocols for finding motifs are designed to identify either all possible sub-graphs or the most frequent ones. mfinder, pajek, mavisto, and fanmod are the notable existing tools for the motif-finding problem. relevant features for evaluation of these tools include whether or not they can present results of analysis visually; they are capable of enumerating sub-graphs; a sampling protocol is used instead of analysis of the entire network; sub-graphs are discovered or only queried graphs are found; as well as the memory usage and time needed in each algorithm and the growth of cpu time with sub-graph size. the memory usage and cpu time determine the maximum size of sub-graphs that can be analyzed. mfinder, the first motif-mining tool, implements two kinds of motif finding algorithms: a full enumeration and a sampling method. the sampling protocol is the faster one, that assigns probability values to motifs identified, and infers frequencies from these values. it is also the only tool without the option of a visual presentation and results are only provided in the format of a text. concerning motif discovery pajek only offers limited functionality, because it only finds specific motifs such as triads and particular tetrads in a network. fanmod algorithm is clearly the best among these with regard to computational time. for example, for enumeration of all 5-size sub-graphs in the transcriptional network of escherichia coli using a laptop with a ghz pentium m processor and mb ram, mfinder, mavisto, and fanmod requires and seconds, respectively. there are × 5-size sub-graphs in this network. the only problem with fanmod is that it can handle sub-graphs consisting maximally of eight vertices. its memory usage increases notably both with increase in sub-graph size and network size. in addition to the mentioned tools, nemofinder given by j. chen and et al. is an efficient network motif finding algorithm for motifs up to size only for protein-protein interaction networks, which are presented by undirected graphs. also in the case of protein interaction networks, some clustering tools are used to simplify the motif finding problem. mcode and mulic are two clustering approaches to be used. "power graph analysis" is an approach for understanding protein interaction networks features. obviously the algorithms designed for both directed and undirected graphs are more time-consuming and general. we aim to derive an algorithm with lower cpu time and less memory usage that would be capable of supporting sub-graphs of all sizes. this is particularly important for analysis of biological networks where the total number of sub-graphs growths exponentially by the size of sub-graph. our algorithm is based on counting all sub-graphs of a given graph. for enumeration of sub-graphs in the network, a novel and efficient method is presented. we evaluate our algorithm on the biological networks: the metabolic pathway of bacteria e. coli and the transcription network of yeast s. cerevisiae, and also non-biological networks: a real social network and an electronic network. the obtained results of our algorithm are compared with three well-known motif finding tools: mfinder, mavisto, and fanmod. by this comparison, we show the efficiency of our algorithm. also, our tool can be employed for finding motifs of size greater than eight, while most of the other algorithms have restriction on the size of motifs. methods definitions a network considered as a large graph consists of vertices and edges. a directed graph is usually shown by g = where v is a finite set of vertices and e is a finite set of edges, where e ⊆. an edge e = ∈ e goes from vertex u, the source, to another vertex v, the target. the vertices u and v are incident with the edge e and adjacent to each other. a sub-graph of the graph g = is a graph gs = where vs ⊆ v and es ⊆ ∩ e. the in-degree and out-degree of a vertex is defined as the number of edges coming into the vertex and the number of edges going out of it, respectively. the degree of a vertex is the total number of edges it is incident to. we define the sub-graph size as the number of vertices present in the sub-graph. two sub-graphs g = and g = are isomorphic if there is a one-to-one correspondence between their vertices, and there is an edge directed from one vertex to another vertex of one sub-graph if and only if there is an edge with the same direction between the corresponding vertices in the other sub-graph. for a particular sub-graph gp, all sub-graphs isomorphic to gp in the network are considered as matches of gp. the frequency of a particular directed sub-graph in an input network is the number of its matches in the network. in this paper, it is assumed that different matches can have overlap in vertices or edges. motifs are defined as sub-graphs, which have higher frequencies in the network than in random networks of equal size. algorithm our algorithm for finding network motifs is called kavosh and consists of four subtasks: enumeration: finding all sub-graphs of a given size that occur in the input graph; classification: classifying each found sub-graph into isomorphic groups; random graph generation: generating random graphs with respect to the input network and motif identification: distinguishing motifs among all found sub-graphs on basis of statistical parameters. in kavosh, one of the most significant subtasks is the enumeration part. this subtask makes kavosh different from other algorithms. building an implicit tree according to the restrictions that will be discussed later causes improvement in both time and memory usage. the tree structure with its restrictions ensures that each individual sub-graph is enumerated only once that leads us to an efficient solution. also using some powerful tools such as "revolving door ordering" algorithm in this subtask, is an advantage of our algorithm. classification is another major subtasks of motif finding algorithms. in kavosh, nauty algorithm which is the best known tool for this subtask is used. this is another feature for the efficiency of kavosh. the details of the subtasks are presented below: enumeration here we present an efficient method for enumeration of sub-graphs of size k. for counting all k-size sub-graphs of a given graph g = whose vertices are numerically labeled, all sub-graphs that include a particular vertex are discovered. subsequently, this vertex is removed from the network, and the process is repeated consecutively for successive vertices. for counting the sub-graphs of size k that include a particular vertex, trees with maximum depth of k, rooted at this vertex and based on neighborhood relationship are implicitly built. children of each vertex include both incoming and outgoing adjacent vertices. to descend the tree, a child is chosen at each level with the restriction that a particular child can be included only if it has not been included at any upper level. after having descended to the lowest level possible, the tree is again ascended and the process is repeated with the stipulation that vertices visited in earlier paths of descendent are now considered unvisited vertices. a final restriction in building trees is that all children in a particular tree must have numerical labels larger than the label of the root of the tree. the protocol for extracting sub-graphs can now be described in greater details. the protocol makes use of the composition operation of an integer. for extraction of sub-graphs of size k, all possible compositions of the integer k - must be considered. the compositions of k - consist of all possible manners of expressing k - as a sum of positive integers. summations in which the order of the summands differs are considered distinct. a composition can be expressed as k k,... km where k + k +... + km = k - to count sub-graphs based on the composition, ki vertices are selected from the i -th level of the tree to be vertices of the sub-graphs. the k - selected vertices along with the vertex at the root define a sub-graph within the network. as an example, we can consider finding sub-graphs of size. all compositions of k - = need to be considered; these are,, and. for example, sub-graphs defined by would include the root vertex and one valid child vertex at each of three subsequent levels. it is possible that for a particular level i, ki < ni, where ni is the number of vertices present at level i. at level i, c is the number of different combinations of k elements through n elements) different selection of vertices need to be considered. here, by using the "revolving door ordering" algorithm all combinations containing ki vertices from the ni vertices are selected. the "revolving door ordering" algorithm is considered the fastest algorithm for generating combinations of vertices. the pseudocode for our algorithm for the enumeration subtask, which produces all k-size sub-graphs present in an input graph g =, is presented in algorithm. in this algorithm, the vertex u defines the root of a tree. each vertex is marked as visited, if and only if it has been observed as an adjacent of any selected vertex in the upper levels. si is the set of all vertices from the i-th level included in a particular sub-graph. the subtask enumerate_vertex is described in algorithm. this algorithm enumerates all sub-graphs in which a particular vertex acts as root. in algorithm the validate function used to create list of valid vertices from which vertex selection can be made is described in algorithm the initial_comb and next_comb functions make use of the "revolving door ordering" algorithm as described earlier to make vertex combination selections at each level. the above algorithms clearly identify all k-size sub-graphs in the network. also, the constrictions placed on the manner in which trees are constructed also ensure that no single sub-graph will be counted more than once. because, if a selected vertex for the current level were allowed to be among vertices adjacent to vertices at levels before i - sub-graphs would be duplicated and enumerated more than once. this is because vertex v could be one of the vertices selected for two different compositions of a graph of size k. this possibility is precluded by algorithm because vertices adjacent to vertices at levels <i - are not allowed to be candidate vertices for level i. this step is described by an example on a given graph shown in figure for this graph, all 4-size sub-graphs containing the vertex are going to be found. this is illustrated in figure the vertex is considered as the root of the tree and its label is considered as visited. as mentioned before, all the compositions of k - = are considered as the different patterns of selection. starting with the composition as the selecting pattern, valid children of the root are found. due to its neighbors, the vertices and are the valid ones, which according to the pattern one of them have to be chosen. the labels of these three vertices are now visited. using the "revolving door ordering", the vertex is the first chosen vertex. by using this pattern, one of the valid vertices of the vertex has to be selected. the vertex has three neighbors, the vertices and but the vertex is previously visited, so it is not a valid child. so this process continues with the vertices and which are visited now. again using "revolving door ordering", the vertex is selected to be continued. as the pattern shows, one of the valid children of the vertex have to be chosen as the last vertex of the sub-graph. the vertex has five neighbors, the vertices and but just the vertex has not been visited yet, so its only valid child is the vertex the vertex is selected as the last vertex of the sub-graph. now the vertices and make a sub-graph involved in the network of size containing the vertex by recursively ascending the tree, for processing the other choices of selection, the lower vertices, are not visited anymore. so at this point, recursively ascending vertex causes that the vertex is not visited anymore. by continuing using this pattern, only one other sub-graph with vertices and is found; the details are shown in figure 2a. the composition is the next selecting pattern to be considered. the same as the previous selecting pattern, the vertices and are the valid vertices in the first level which one of them have to be chosen according to the first element of the composition. using "revolving door ordering", the vertex is selected and is processed. the same as the previous pattern, the vertices and are the valid children of the vertex here, in this step, two vertices of this level have to be chosen according to the second element of the composition which is so both the vertex and are selected now, and produce the sub-graph containing the vertices and recursively ascending to level two, the next selection is the vertex by ascending, the vertices and that became visited in the last step are reset to unvisited. among all the neighbors of the vertex the vertices and are valid. using "revolving door ordering", all different selections of two vertices from these three vertices are computed, which results in three different sub-graphs containing the vertices { 6},{, 7} and { 7}. details are shown in figure 2b. in the same manner, the selecting pattern finds the sub-graphs containing the vertices { 6}, { 7}, { 4}, { 6}, {, 7}, { 4}, { 4}, { 6} and { 7} which is shown in figure 2c. and using the pattern, the sub-graph with vertices { 5} is found, its tree is shown in figure 2d. it should be noted that the reason for the efficiency of our enumeration algorithm would be the implicit tree constructed by the underlying recursion in our algorithm. the depth of this implicit recursion tree depends on the number of elements in a composition of k. classification after discovering a sub-graph involved as a match in the input network, in order to be able to evaluate the size of each class according to the input network, there is a need to classify it into isomorphic classes. the most powerful algorithm, which is usually used for finding isomorphism is nauty. in this algorithm, a unique identifier is assigned to each class of isomorphism and called the canonical labeling. the canonical labeling is generated by the transformation of the adjacency matrix into a string by concatenating it row-by-row. as different orderings of the vertices generate different strings, an ordering of the vertices with the lexicographically largest or smallest string is chosen as canonical labeling between all possible permutations. as an example for the graph illustrated in figure with the corresponding adjacency matrix, the canonical labeling is related to the ordering of vertices, which is the lexicographically largest string among all possible strings obtained by different orderings on vertices. in this step of our approach, the adjacency matrix of each obtained sub-graph in the first step, is given to nauty as an input in order to generate its canonical labeling as the class identifier of that sub-graph. this obtained identifier causes increment of the size of the corresponding class of isomorphism, by one. random graph generation according to the definition of a motif, the proper determination of sub-graph significance, needs comparison by an ensemble of appropriate random graphs. so generation of this ensemble due to a given random graph model is a necessary step of the algorithm. one of the popular random graph models on which we also focused is to preserve the degree sequence of the original graph in random graphs. there has been some researches concerning the problem of sub-graph distribution within such graphs for directed sparse random graphs. since biological networks are scale-free networks the fraction of vertices having k edges, p, decays as a power law p ~k-λ, where λ is often between and therefore they are sparse. so using this random graph model is appropriate for them. in our approach, similar to milo's random model switching operations are applied on the edges of the input network repeatedly, until the network is well randomized. this switching operation is applied on the randomly chosen vertices of the network as it is shown in figure by applying this switching operation repeatedly on the input network, an ensemble of random networks is generated. for each network in the generated ensemble sub-graphs are found by using step of the algorithm, and then using step the size of the isomorphism classes for found sub-graphs are evaluated. this generation is necessary for comparing the real network with some random networks in order to obtain the significance of each sub-graph. motif determination by using the result of the last step, the significance of each sub-graph found in the input network is calculated. here, some statistical measures are introduced, that lead us to the probable motifs in the input network. frequency this is the simplest measurement for estimating the significance of a motif. for a given network, assume that gp is a representative of an isomorphism class involved in that class. the frequency is defined as the number of occurrence gp in the input network. zscore this measure reflects how randomly the class occurred in the input network. for the assumed motif gp, this measure is defined as below: where np is the number which gp occurred in the input network, is the mean number which gp occurred in random networks and σ is the standard deviation. the larger zscore, the more significant is the motif. pvalue this measure indicates the number of random networks in which a motif gp occurred more often than in the input network, divided by the total number of random networks. therefore, pvalue ranges from to the smaller the pvalue, the more significant is the motif. these are some statistical measures implied in our algorithm to indicate the significance of a motif. for each motif found in step according to the result obtained from step and these measures are calculated in this step. until now, motifs found in the input network are available including some statistical measures related to them. as mentioned in the previous step, three different measures are used in this algorithm. there are no exact thresholds for these measures to distinguish a motif, and the more restricted thresholds; the more precise is the motif. but according to the experimental results by milo, the following conditions may be used to describe a network motif: by using randomized network, the pvalue is smaller than. the frequency is larger than four. by using randomized network, the zscore is larger than one. according to the above conditions and with respect to the sufficient preciseness, the patterns with significant measures are the ones which describe network motifs.  in this section, we present the results of applying kavosh to some real networks. applications were made to network instances that are both biological and non-biological. the metabolic pathway of the bacteria e. coli and the transcription network of yeast s. cereviciae, a real social network, and an electronic network were targeted. these instances for testing the algorithm were up-to-date versions of the motif detection tests used by other existing algorithms. the biological networks, as reflected by the number of vertices therein, were notably larger than the non-biological networks used here. the numbers of sub-graphs of different sizes observed in each network are presented in table the numbers of different isomorphic groups of specific sizes observed are presented in table in all the networks, both the number of sub-graphs and the number of isomorphic groups increase exponentially with sub-graph size. application of the fanmod algorithm for finding sub-graphs and isomorphic groups of sizes up to eight, resulted in the identification of the same numbers as kavosh. additionally, here we present some sub-graphs, which are determined as motifs by kavosh. we present five most significant sub-graphs of size and in the e. coli network in figures and respectively. in this section, we aim to compare the efficiency and power of kavosh with three previously presented programs. we apply each of the four algorithms to the networks described. the computer system we used was equipped with a ghz amd opteron processor and gb ram. for each of the real networks, random networks were generated as described. subsequently, each of the algorithms was applied to the real and all randomly generated networks. the cpu time and memory needed to perform this task was assessed for the different algorithms. for all networks, the cpu time was maximum for mavisto. as our algorithm is a full enumeration algorithm, we apply full enumeration version of mfinder. the cpu time of mfinder, although generally at least an order of magnitude less than that of mavisto, was still an order of magnitude or larger than that of fanmod and kavosh. the cpu times of fanmod and kavosh were comparable for the e. coli network but in other networks the cpu time for kavosh is less than the time for fanmod. although their time differences are sometimes not very significant, but this is because of the limitations in implementing a general motif finder tool in comparison with a limited one. also, the time performance of kavosh according to the number of found sub-graphs and sub-graph size in four tested network is given in table this table shows the numbers of sub-graphs counted per second for each network. the largest degree is an important reason for different performances in networks. the largest degree in s. cereviciae, e. coli, electronic and social networks are respectively and as the table shows these degrees have influence in the performance. another important aspect in this performance is that as the sub-graph size increases, the classification part takes more time, and this makes the algorithm slower for larger sub-graohs. in terms of memory usage, both mavisto and mfinder were inefficient and our computer systems could not support finding even relatively small sub-graphs, particularly in the larger tested networks. the combined effects of large cpu time and large memory usage in effect precluded size sub-graph identification in even the smallest electronic network by mavisto. mfinder could not identify size sub-graphs in the tested biological networks under the conditions of our computer system. fanmod produced results for sub-graphs of size up to in all networks used. the limitation of size is inherent in the implementation protocol of fanmod. kavosh does not have this limitation, and the size of sub-graphs queried is only limited by computer power. using the system described here, sub-graphs of size up to were identified by kavosh in all the networks used. for the smaller electronic network, sub-graphs of size and could also be identified. the fanmod cpu time was generally somewhat larger than that of kavosh. importantly, fanmod memory usage was considerably higher than the memory usage of our kavosh. in all tables, the time values are in seconds and the empty cells indicate that the algorithm cannot support that specific size or its time cannot be calculated because of the complexity. additionally, we present the memory usage for both kavosh and fanmod, which was computed with the valgrind-. package. the chart in figure compares fanmod with kavosh and shows that how better kavosh works in comparison to fanmod in this case. as it is shown in figure the growth of sub-graph numbers according to its size causes large requirement in memory. so, memory usage will be one of the problems for finding motifs of larger size. as we can see in the tables and the only comparable algorithm with ours is fanmod, but still is not as efficient as our algorithm. in addition to the above results, in order to show the high performance of our algorithm on large networks, we apply both kavosh and fanmod on homo sapiens ppi network and on drosophila melanogaster ppi network, both included more than nodes. because of the high growth of the number of sub-graphs, these large networks are tested for sub-graphs of size and the results of both kavosh and fanmod on homo sapiens ppi network and drosophila melanogaster ppi network are rfespectively shown in tables and as the tables show, kavosh performs much better for larger networks.  to improve the efficiency of our algorithm the comparison of the obtained results with three well-known motif finding tools is discussed. for comparison, the cpu time, memory usage and the similarities of obtained motifs are considered. also, kavosh can be employed for finding motifs of size greater than eight, while most of the other algorithms have restriction on motifs with size greater than eight. besides, comparing with other algorithms kavosh has better performance for large networks. in conclusion, the presented method is a general motif finder that has no restrictions on motif size and also it has less time and memory consuming in comparison with other existing algorithms. authors' contributions initial idea of the research was proposed by zrmk, ha, and and amn. the kavosh is designed, implemented, and tested by es, sa, sm, and zrmk. all authors participated in designing the structure and organization of the manuscript equally. all authors read and approved the final manuscript. appendix: algorithms appendix 1 input: g: input graph. output: extract all k-size sub-graphs of graph g. 1: for each u ∈ g do 2:    visited ← true 3:    s ← u 4:    enumerate_vertex 5:    visited ← false 6: end for algorithm 1: kavosh appendix 2 input: g: input graph, u: root vertex, s: selection, remainder: number of remaining vertices to be selected, i: current depth of the tree. output: all k-size sub-graphs of graph g rooted in u. 1: if remainder = then 2:    return 3: else 4:    v allist ← validate 5:    ni ← min 6:    for ki = to ni do 7:       c ← initial_comb        8:       repeat 9:          si ← c 10:          enumerate_vertex 11:          next_comb              12:       until c = nill 13:    end for 14:    for each v ∈ v allist do 15:       visited ← false 16:    end for 17: end if algorithm 2: enumerate_vertex appendix 3 input: g: input graph, parents: selected vertices of last layer, u: root vertex. output: valid vertices of the current level. 1: v allist ← nill 2: for each v ∈ parents do 3:    for each w ∈ neighbor do 4:       if label < label and not visited then 5:          visited ← true 6:          v allist = v allist + w 7:       end if 8:    end for 9: end for 10: return vallist algorithm 3: validate 
the efficiency of our algorithm is demonstrated by comparing the obtained results with three well-known motif finding tools. existing algorithms for finding network motifs are extremely costly in cpu time and memory consumption and have practically restrictions on the size of motifs. we present a new algorithm, for finding k-size network motifs with less memory and cpu time in comparison to other existing algorithms. for comparison, the cpu time, memory usage and the similarities of obtained motifs are considered. we evaluated our algorithm on biological networks of e. coli and s. cereviciae, and also on non-biological networks: a social and an electronic network. our algorithm is based on counting all k-size sub-graphs of a given graph. motifs in networks are small connected sub-graphs that occur significantly in higher frequencies than in random networks.
 complex networks are studied across many fields of science and are particularly important to understand biological processes. motifs in networks are small connected sub-graphs that occur significantly in higher frequencies than in random networks. they have recently gathered much attention as a useful concept to uncover structural design principles of complex networks. existing algorithms for finding network motifs are extremely costly in cpu time and memory consumption and have practically restrictions on the size of motifs.  we present a new algorithm, for finding k-size network motifs with less memory and cpu time in comparison to other existing algorithms. our algorithm is based on counting all k-size sub-graphs of a given graph. we evaluated our algorithm on biological networks of e. coli and s. cereviciae, and also on non-biological networks: a social and an electronic network.  the efficiency of our algorithm is demonstrated by comparing the obtained results with three well-known motif finding tools. for comparison, the cpu time, memory usage and the similarities of obtained motifs are considered. besides, kavosh can be employed for finding motifs of size greater than eight, while most of the other algorithms have restriction on motifs with size greater than eight. the kavosh source code and help files are freely available at:. 