Commits

Brent Pedersen  committed 781f33f

cleanup in intersection, remove old code, micro optimization checking for is None, rather than bool
fix spelling of my name. :-)

  • Participants
  • Parent commits 679dc63

Comments (0)

Files changed (2)

File lib/bx/intervals/intersection.pyx

 
 :Authors: James Taylor (james@jamestaylor.org),
           Ian Schenk (ian.schenck@gmail.com),
-          Brent Pederson (bpederse@gmail.com)
+          Brent Pedersen (bpederse@gmail.com)
 """
 
 # Historical note:
     return a
 
 cdef inline int imax3(int a, int b, int c):
-    if b > a: 
+    if b > a:
         if c > b:
             return c
         return b
     return c
 
 cdef inline int imin3(int a, int b, int c):
-    if b < a: 
+    if b < a:
         if c < b:
             return c
         return b
           `IntervalTree` rather than using this directly. 
     """
     cdef float priority
-    cdef public object interval 
+    cdef public object interval
     cdef public int start, end
     cdef int minend, maxend, minstart
     cdef IntervalNode cleft, cright, croot
         # uniform into a binomial because it naturally scales with
         # tree size.  Also, python's uniform is perfect since the
         # upper limit is not inclusive, which gives us undefined here.
-        self.priority   = ceil(nlog * log(-1.0/(1.0 * rand()/RAND_MAX - 1)))
-        self.start      = start
-        self.end       = end
-        self.interval   = interval
-        self.maxend    = end
-        self.minstart   = start
-        self.minend    = end
-        self.cleft       = EmptyNode
-        self.cright      = EmptyNode
-        self.croot       = EmptyNode
+        self.priority = ceil(nlog * log(-1.0/(1.0 * rand()/RAND_MAX - 1)))
+        self.start    = start
+        self.end      = end
+        self.interval = interval
+        self.maxend   = end
+        self.minstart = start
+        self.minend   = end
+        self.cleft    = EmptyNode
+        self.cright   = EmptyNode
+        self.croot    = EmptyNode
         
     cpdef IntervalNode insert(IntervalNode self, int start, int end, object interval):
         """
                 self.cright._seek_right(position, results, n, max_dist)
 
     
-    ## This doesn't appear to use any of its arguments, something not right?
-    ## 
-    ## def neighbors(self, Interval f, int n=1, int max_dist=2500):
-    ##     cdef list neighbors = []
-    ## 
-    ##     cdef IntervalNode right = self.cright
-    ##     while right.cleft is not EmptyNode:
-    ##         right = right.cleft
-    ## 
-    ##     cdef IntervalNode left = self.cleft
-    ##     while left.cright is not EmptyNode:
-    ##         left = left.cright
-    ##     return [left, right]
-    
     cpdef left(self, position, int n=1, int max_dist=2500):
         """
         find n features with a start > than `position`
     def __init__(self, int start, int end, object value=None, object strand=None ):
         assert start <= end, "start must be less than end"
         self.start  = start
-        self.end   = end      
+        self.end   = end
         self.value = value
         self.strand = strand
 
         """
         Insert the interval [start,end) associated with value `value`.
         """
-        if self.root:
+        if self.root is None:
+            self.root = IntervalNode( start, end, value )
+        else:
             self.root = self.root.insert( start, end, value )
-        else:
-            self.root = IntervalNode( start, end, value )
         
+    add = insert
+
+
     def find( self, start, end ):
         """
         Return a sorted list of all intervals overlapping [start,end).
         """
         self.insert( interval.start, interval.end, interval )
 
+    add_interval = insert_interval
+
     def before_interval( self, interval, num_intervals=1, max_dist=2500 ):
         """
         Find `num_intervals` intervals that lie completely before `interval`
         else:
             return self.root.right( interval.end, num_intervals, max_dist )
     
-    # ---- Old 'Intersecter' interface ----------------------------------------
-
-    def add( self, start, end, value=None ):
-        """
-        Synonym for `insert`.
-        """
-        self.insert( start, end, value )
-    
-    def add_interval( self, interval ):
-        """
-        Synonym for `insert_interval`.
-        """
-        self.insert_interval( interval )
-    
     def traverse(self, fn):
         """
         call fn for each element in the tree
 except:
     have_numpy = False
        
-def main():                       
+def main():
     setup(  name = "bx-python",
             version = "0.5.0",
             py_modules = [ 'psyco_full' ],
             ext_modules = get_extension_modules(),
             test_suite = 'nose.collector',
             setup_requires = ['nose>=0.10.4'],
-            author = "James Taylor, Bob Harris, David King, Brent Pederson, and others",
+            author = "James Taylor, Bob Harris, David King, Brent Pedersen, and others",
             author_email = "james@jamestaylor.org",
             description = "Tools for manipulating biological data, particularly multiple sequence alignments",
             url = "http://bx-python.trac.bx.psu.edu",