Copying Bio-python to globplot to satisfy the dependency
[jabaws.git] / binaries / src / globplot / biopython-1.50 / Bio / distance.py
1 """
2 This module provides code for various distance measures.
3
4 Functions:
5 euclidean       Euclidean distance between two points
6 euclidean_py    Pure Python implementation of euclidean.
7
8 """
9 # XXX cosine distance
10
11 import warnings
12 warnings.warn("Bio.distance is deprecated. If you use this module, please notify the Biopython developers at biopython-dev@biopython.org", DeprecationWarning)
13
14 from numpy import *
15
16 def euclidean(x, y):
17     """euclidean(x, y) -> euclidean distance between x and y"""
18     if len(x) != len(y):
19         raise ValueError("vectors must be same length")
20     #return sqrt(sum((x-y)**2))
21     # Optimization by John Corradi (JCorradi@msn.com)
22     d = x-y
23     return sqrt(dot(d, d))
24
25 def euclidean_py(x, y):
26     """euclidean_py(x, y) -> euclidean distance between x and y"""
27     # lightly modified from implementation by Thomas Sicheritz-Ponten.
28     # This works faster than the Numeric implementation on shorter
29     # vectors.
30     if len(x) != len(y):
31         raise ValueError("vectors must be same length")
32     sum = 0
33     for i in range(len(x)):
34         sum += (x[i]-y[i])**2
35     return sqrt(sum)