Commits

Kanwei Li committed 8bd2e84

Use instanceof() instead of type()

  • Participants
  • Parent commits 2b8119f

Comments (0)

Files changed (8)

lib/bx/bbi/bigbed_file.so

Binary file modified.

lib/bx/intervals/io.py

         last_bitset = None
         bitsets = dict()
         for interval in self:
-            if type( interval ) == GenomicInterval:
+            if isinstance(interval, GenomicInterval):
                 chrom = interval[self.chrom_col]
                 if chrom != last_chrom:
                     if chrom not in bitsets:
     def next( self ):
         while True:
             rval = NiceReaderWrapper.next( self )
-            if type( rval ) == GenomicInterval and rval.end > self.lens.get( rval.chrom, MAX ): # MAX_INT is defined in bx.bitset
+            if isinstance(rval, GenomicInterval) and rval.end > self.lens.get( rval.chrom, MAX ): # MAX_INT is defined in bx.bitset
                 try:
                     # This will only work if reader is a NiceReaderWrapper
                     self.skipped += 1

lib/bx/intervals/operations/concat.py

     output = False
     for intervals in readers:
         for interval in intervals:
-            if type( interval ) is GenomicInterval:
+            if isinstance(interval, GenomicInterval):
                 if not nfields: nfields = interval.nfields
                 out_interval = interval.copy()
                 if sameformat or firstdataset:
                     if strand_col < len( out_interval.fields ):
                         out_interval.fields[strand_col] = strand
                     yield out_interval
-            elif type( interval ) is Header and header:
+            elif isinstance(interval, Header) and header:
                 yield interval
-            elif type( interval ) is Comment and comments:
+            elif isinstance(interval, Comment) and comments:
                 yield interval
         if output and firstdataset: firstdataset = False

lib/bx/intervals/operations/coverage.py

 
     # Read remaining intervals and give coverage
     for interval in primary:
-        if type( interval ) is Header:
+        if isinstance(interval, Header):
             yield interval
-        if type( interval ) is Comment and comments:
+        if isinstance(interval, Comment) and comments:
             yield interval
-        elif type( interval ) == GenomicInterval:
+        elif isinstance(interval, GenomicInterval):
             chrom = interval.chrom
             start = int(interval.start)
             end = int(interval.end)

lib/bx/intervals/operations/find_clusters.py

     linenum = -1
     for interval in reader:
         linenum += 1
-        if not type( interval ) is GenomicInterval:
+        if not isinstance(interval, GenomicInterval):
             extra[linenum] = interval
         else:
             if interval.chrom not in chroms:

lib/bx/intervals/operations/intersect.py

     
     # Read remaining intervals and intersect
     for interval in primary:
-        if type( interval ) is Header:
+        if isinstance(interval, Header):
             yield interval
-        if type( interval ) is Comment and comments:
+        if isinstance(interval, Comment) and comments:
             yield interval
-        elif type( interval ) == GenomicInterval:
+        elif isinstance(interval, GenomicInterval):
             chrom = interval.chrom
             start = int( interval.start )
             end = int( interval.end )

lib/bx/intervals/operations/join.py

     leftlen = 0
     rightTree = IntervalTree()
     for item in rightSet:
-        if type( item ) is GenomicInterval:
+        if isinstance(item, GenomicInterval):
             rightTree.insert( item, rightSet.linenum, item.fields )
             if rightlen == 0: rightlen = item.nfields
 
     for interval in leftSet:
-        if leftlen == 0 and type( interval ) is GenomicInterval:
+        if leftlen == 0 and isinstance(interval, GenomicInterval):
             leftlen = interval.nfields
-        if not (type( interval ) is GenomicInterval):
+        if not isinstance(interval, GenomicInterval):
             yield interval
         else:
             result = []
 def interval_cmp(a, b):
     interval1 = a[0]
     interval2 = b[0]
-    if not (type( interval1 ) is GenomicInterval and type( interval2 ) is GenomicInterval):
+    if not (isinstance(interval1, GenomicInterval) and isinstance(interval2, GenomicInterval)):
         return 0
     # Both are intervals
     if interval1.chrom == interval2.chrom:

lib/bx/intervals/operations/subtract.py

     
     # Read remaining intervals and subtract
     for interval in primary:
-        if type( interval ) is Header:
+        if isinstance(interval, Header):
             yield interval
-        if type( interval ) is Comment and comments:
+        if isinstance(interval, Comment) and comments:
             yield interval
-        elif type( interval ) == GenomicInterval:
+        elif isinstance(interval, GenomicInterval):
             chrom = interval.chrom
             if chrom not in bitsets:
                 yield interval