Commits

mruffalo committed a3b93fa

Raise exceptions instead of raw strings for issue #35

Comments (0)

Files changed (11)

 
     def get_src_size( self ):
         if self._src_size == None:
-            if self._alignment == None: raise "component has no src_size"
+            if self._alignment == None:
+                raise Exception("component has no src_size")
             self._src_size = self._alignment().src_size( self.src )
         return self._src_size
     def set_src_size( self,src_size ):
         try:
             x = self.index[ pos - start ]
         except:
-            raise "Error in index."
+            raise Exception("Error in index.")
         return x
     
     
     import bx.align.maf, bx.align.axt, bx.align.lav
     if format == "maf": return bx.align.maf.Indexed( filename, index_filename, keep_open, species_to_lengths )
     elif format == "axt": return bx.align.axt.Indexed( filename, index_filename, keep_open, species_to_lengths )
-    elif format == "lav": raise "LAV support for Indexed has not been implemented"
+    elif format == "lav": raise Exception("LAV support for Indexed has not been implemented")
     else: raise "Unknown alignment format %s" % format
 
 def shuffle_columns( a ):
         self.maf_kwargs = kwargs
         # Read and verify maf header, store any attributes
         fields = self.file.readline().split()
-        if fields[0] != '##maf': raise "File does not have MAF header"
+        if fields[0] != '##maf': raise Exception("File does not have MAF header")
         self.attributes = parse_attributes( fields[1:] )
 
     def next( self ):
     line = readline( file, skip_blank=True )
     if not line: return None
     fields = line.split() 
-    if fields[0] != 'a': raise "Expected 'a ...' line"
+    if fields[0] != 'a': raise Exception("Expected 'a ...' line")
     alignment.attributes = parse_attributes( fields[1:] )
     if 'score' in alignment.attributes:
         alignment.score = alignment.attributes['score']

lib/bx/gene_reader.py

     known_formats = ( 'gff', 'gtf', 'bed')
     if format not in known_formats: 
         print >>sys.stderr,  '%s format not in %s' % (format, ",".join( known_formats ))
-        raise '?'
-    
+        raise Exception('?')
+
     if format == 'bed':
         for line in fh:    
             f = line.strip().split()
     known_formats = ( 'gff', 'gtf', 'bed')
     if format not in known_formats: 
         print >>sys.stderr,  '%s format not in %s' % (format, ",".join( known_formats ))
-        raise '?'
-    
+        raise Exception('?')
+
     if format == 'bed':
         for line in fh:    
             f = line.strip().split()
     known_formats = ( 'gff', 'gtf', 'bed')
     if format not in known_formats: 
         print >>sys.stderr,  '%s format not in %s' % (format, ",".join( known_formats ))
-        raise '?'
-    
+        raise Exception('?')
+
     if format == 'bed':
         for line in fh:    
             f = line.strip().split()

lib/bx/interval_index_file.py

         f = open( filename )
         magic, version, length = read_packed( f, ">3I" )
         if magic != MAGIC:
-            raise "File does not have expected header"
+            raise Exception("File does not have expected header")
         if version > VERSION:
             warn( "File claims version %d, I don't known anything about versions beyond %d. Attempting to continue", version, VERSION )
         self.version = version

lib/bx/pwm/position_weight_matrix.py

                     raise "Align: __init__:alignment block:row %d does not have %d columns, it has %d" % (rownum,ncol,len(row))
             except:
                 print row
-                raise ''
+                raise Exception('')
         self.ncols = ncol
         self.dims = (self.nrows,self.ncols)
         self.headers = headers
                 return degenSymbol
     else: return 'N'
     print >>sys.stderr,pattern
-    raise '?'
+    raise Exception('?')
 
 # import C extensions
 try:

lib/bx/pwm/pwm_score_maf.py

 def MafMotifSelect(mafblock,pwm,motif=None,threshold=0):
 
     if motif != None and len(motif) != len(pwm): 
-        raise "pwm and motif must be the same length"
+        raise Exception("pwm and motif must be the same length")
     # generic alignment
     alignlist = [ c.text for c in mafblock.components ]
     align = pwmx.Align( alignlist )
         magic = struct.unpack(">L", file.read(NIB_MAGIC_SIZE))[0]
         if (magic != NIB_MAGIC_NUMBER):
             if magic == NIB_MAGIC_NUMBER_SWAP: self.byte_order = "<"
-            else: raise "Not a NIB file"
+            else: raise Exception("Not a NIB file")
         self.magic = magic
         self.length = struct.unpack("%sL" % self.byte_order, file.read(NIB_LENGTH_SIZE))[0]
 
         if (name == "codebook"):
             self.codebook = QdnaCodebook(StringIO(value))
         else:
-            raise "named properties as instance variables are not implemented yet"
+            raise Exception("named properties as instance variables are not implemented yet")
             # $$$ do this by adding a properties dict and __getitem__/__setitem__
             # $$$ also need to write properties in QdnaWriter.write()
 

scripts/int_seqs_to_char_strings.py

     for line in sys.stdin:
         ints = [ int( f ) for f in line.split() ]
         if max( ints ) > len( table ):
-            raise "Alphabet size too large!"
-        print str.join( '', [ table[i] for i in ints ] )    
+            raise ValueError("Alphabet size too large!")
+        print str.join( '', [ table[i] for i in ints ] )
 
 if __name__ == "__main__": main()

scripts/maf_tile_2.py

     elif maf_status == maf.MAF_MISSING_STATUS:
         return "X"
     else:
-        raise "Unknwon maf status"
-        
+        raise ValueError("Unknwon maf status")
+
 def guess_fill_char( left_comp, right_comp ):
     """
     For the case where there is no annotated synteny we will try to guess it

scripts/maf_truncate.py

     maf_reader = maf.Reader( sys.stdin )
     maf_writer = maf.Writer( sys.stdout )
 
-    if not options.cols: raise "Cols argument is required"
+    if not options.cols: raise Exception("Cols argument is required")
     cols = int( options.cols )
 
     count = 0