Back to index

python-biopython  1.60
Classes | Functions | Variables
Bio.KDTree.KDTree Namespace Reference

Classes

class  KDTree

Functions

def _dist
def _neighbor_test
def _test

Variables

int nr_points = 100000
int dim = 3
int bucket_size = 10
int query_radius = 10
tuple coords = (200*random((nr_points, dim)))
tuple kdtree = KDTree(dim, bucket_size)
tuple indices = kdtree.all_get_indices()
tuple radii = kdtree.all_get_radii()
tuple center = random(dim)

Function Documentation

def Bio.KDTree.KDTree._dist (   p,
  q 
) [private]

Definition at line 22 of file KDTree.py.

00022 
00023 def _dist(p, q):
00024     diff=p-q
00025     return sqrt(sum(diff*diff))

Here is the caller graph for this function:

def Bio.KDTree.KDTree._neighbor_test (   nr_points,
  dim,
  bucket_size,
  radius 
) [private]
Test all fixed radius neighbor search.

Test all fixed radius neighbor search using the 
KD tree C module.

o nr_points - number of points used in test
o dim - dimension of coords
o bucket_size - nr of points per tree node
o radius - radius of search (typically 0.05 or so) 

Definition at line 26 of file KDTree.py.

00026 
00027 def _neighbor_test(nr_points, dim, bucket_size, radius):
00028     """ Test all fixed radius neighbor search.
00029 
00030     Test all fixed radius neighbor search using the 
00031     KD tree C module.
00032 
00033     o nr_points - number of points used in test
00034     o dim - dimension of coords
00035     o bucket_size - nr of points per tree node
00036     o radius - radius of search (typically 0.05 or so) 
00037     """
00038     # KD tree search
00039     kdt=_CKDTree.KDTree(dim, bucket_size)
00040     coords=random((nr_points, dim))
00041     kdt.set_data(coords)
00042     neighbors = kdt.neighbor_search(radius)
00043     r = [neighbor.radius for neighbor in neighbors]
00044     if r is None:
00045         l1=0
00046     else:
00047         l1=len(r)
00048     # now do a slow search to compare results
00049     neighbors = kdt.neighbor_simple_search(radius)
00050     r = [neighbor.radius for neighbor in neighbors]
00051     if r is None:
00052         l2=0
00053     else:
00054         l2=len(r)
00055     if l1==l2:
00056         print "Passed."
00057     else:
00058         print "Not passed: %i != %i." % (l1, l2)

def Bio.KDTree.KDTree._test (   nr_points,
  dim,
  bucket_size,
  radius 
) [private]
Test neighbor search.

Test neighbor search using the KD tree C module.

o nr_points - number of points used in test
o dim - dimension of coords
o bucket_size - nr of points per tree node
o radius - radius of search (typically 0.05 or so) 

Definition at line 59 of file KDTree.py.

00059 
00060 def _test(nr_points, dim, bucket_size, radius):
00061     """Test neighbor search.
00062 
00063     Test neighbor search using the KD tree C module.
00064 
00065     o nr_points - number of points used in test
00066     o dim - dimension of coords
00067     o bucket_size - nr of points per tree node
00068     o radius - radius of search (typically 0.05 or so) 
00069     """
00070     # kd tree search
00071     kdt=_CKDTree.KDTree(dim, bucket_size)
00072     coords=random((nr_points, dim))
00073     center=coords[0]
00074     kdt.set_data(coords)
00075     kdt.search_center_radius(center, radius)
00076     r=kdt.get_indices()
00077     if r is None:
00078         l1=0
00079     else:
00080         l1=len(r)
00081     l2=0
00082     # now do a manual search to compare results
00083     for i in range(0, nr_points):
00084         p=coords[i]
00085         if _dist(p, center)<=radius:
00086             l2=l2+1
00087     if l1==l2:
00088         print "Passed."
00089     else:
00090         print "Not passed: %i != %i." % (l1, l2)

Here is the call graph for this function:


Variable Documentation

Definition at line 225 of file KDTree.py.

tuple Bio.KDTree.KDTree.center = random(dim)

Definition at line 253 of file KDTree.py.

tuple Bio.KDTree.KDTree.coords = (200*random((nr_points, dim)))

Definition at line 228 of file KDTree.py.

Definition at line 224 of file KDTree.py.

tuple Bio.KDTree.KDTree.indices = kdtree.all_get_indices()

Definition at line 244 of file KDTree.py.

Definition at line 230 of file KDTree.py.

Definition at line 223 of file KDTree.py.

Definition at line 226 of file KDTree.py.

tuple Bio.KDTree.KDTree.radii = kdtree.all_get_radii()

Definition at line 245 of file KDTree.py.