I want to calculate the Jaccard index between two compounds. What is the algorithm? I have searched for it, it just gives the formula but how to apply it on compounds is not known to me. Can you help?


closed as unclear what you're asking by fileunderwater, Chris, WYSIWYG, Atl LED, March Ho Jun 2 '15 at 6:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Exactly how do you want to use it? In ecology, it is usually used to compare how similar communities of species are, but you are referring to only two compounds. What entities do you want to compare? As for coding it, you could probably find much useful information in the currently 345 StackOverflow questions on the Jaccard coefficient/index $\endgroup$ – fileunderwater May 29 '15 at 12:49
  • $\begingroup$ I missed the detail about "two compounds". My answer includes a reference for two sets of compounds but it would be good if you clarify what you mean exactly. $\endgroup$ – ddiez May 29 '15 at 14:24
  • $\begingroup$ How do you denote a compound? just by its composition?? For e.g. C₃H₆O₃ can be lactic acid, glyceraldehyde or trioxane. $\endgroup$ – WYSIWYG May 30 '15 at 10:34
  • $\begingroup$ Yes, denote a compound by their atoms that consists them.. $\endgroup$ – girl101 May 31 '15 at 2:28
  • $\begingroup$ or by SMILES format $\endgroup$ – girl101 Jun 3 '15 at 4:50

The Jaccard index is a measure of similarity between two sets. Take a look at the Wikipedia article here. It is very easy to compute:

The Jaccard similarity coefficient for sets X and Y is defined as:

J(X,Y) = |intersection(X,Y)| / |union(X,Y)|

Where | | indicates the size (number of elements) of the set. Imagine you have two sets X and Y defined as follows:

X = {A, B, C, D}
Y = {C, D, E, F, G}


intersection(X,Y) = {C, D} => |intersection(X,Y)| = 2
union(X,Y) = {A,B,C,D,E,F} => |union(X,Y)| = 5

Therefore: J(X,Y) = 2/5

Alternatively, the Jaccard distance would be D(X,Y) = 1 - J(X,Y) = 1 - 2/5 = 3/5

In Biology the Jaccard index has been used to compute the similarity between networks, by comparing the number of edges in common (e.g. Bass, Nature methods 2013)

Regarding applying it to compounds, if you have two sets with different compounds, you can find how similar the two sets are using this index. The elements on the sets, in this case the compounds, correspond to A, B, C, etc. in my example.

  • $\begingroup$ chemical compounds would have atoms, so basically for each compound we create a set of atoms and then find the index. Will that do? $\endgroup$ – girl101 May 31 '15 at 2:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.