From 152ebeee103d4c31268c2d20073e77049838214a Mon Sep 17 00:00:00 2001 From: Bjoern Gruening Date: Sat, 27 Jun 2015 10:38:27 +0200 Subject: [PATCH] pep8 lint fixes --- lib/galaxy/actions/admin.py | 8 +- lib/galaxy/datatypes/assembly.py | 76 +++++++++--------- lib/galaxy/datatypes/binary.py | 124 +++++++++++++++--------------- lib/galaxy/datatypes/checkers.py | 18 +++-- lib/galaxy/datatypes/chrominfo.py | 1 - lib/galaxy/datatypes/coverage.py | 4 +- 6 files changed, 118 insertions(+), 113 deletions(-) diff --git a/lib/galaxy/actions/admin.py b/lib/galaxy/actions/admin.py index 9a50f0868d1..458332bc98b 100644 --- a/lib/galaxy/actions/admin.py +++ b/lib/galaxy/actions/admin.py @@ -8,6 +8,7 @@ from galaxy.exceptions import ActionInputError log = logging.getLogger( __name__ ) + class AdminActions( object ): """ Mixin for controllers that provide administrative functionality. @@ -22,7 +23,7 @@ class AdminActions( object ): create_amount = False if not params.name or not params.description: raise ActionInputError( "Enter a valid name and a description." ) - elif self.sa_session.query( self.app.model.Quota ).filter( self.app.model.Quota.table.c.name==params.name ).first(): + elif self.sa_session.query( self.app.model.Quota ).filter( self.app.model.Quota.table.c.name == params.name ).first(): raise ActionInputError( "Quota names must be unique and a quota with that name already exists, so choose another name." ) elif not params.get( 'amount', None ): raise ActionInputError( "Enter a valid quota amount." ) @@ -60,7 +61,7 @@ class AdminActions( object ): def _rename_quota( self, quota, params ): if not params.name: raise ActionInputError( 'Enter a valid name' ) - elif params.name != quota.name and self.sa_session.query( self.app.model.Quota ).filter( self.app.model.Quota.table.c.name==params.name ).first(): + elif params.name != quota.name and self.sa_session.query( self.app.model.Quota ).filter( self.app.model.Quota.table.c.name == params.name ).first(): raise ActionInputError( 'A quota with that name already exists' ) else: old_name = quota.name @@ -150,7 +151,7 @@ class AdminActions( object ): message += ', '.join( names ) return message - def _undelete_quota( self, quota, params = None): + def _undelete_quota( self, quota, params=None): quotas = util.listify( quota ) names = [] for q in quotas: @@ -197,4 +198,3 @@ class AdminActions( object ): self.sa_session.flush() message += ', '.join( names ) return message - diff --git a/lib/galaxy/datatypes/assembly.py b/lib/galaxy/datatypes/assembly.py index f0232783a9d..c467226c05a 100644 --- a/lib/galaxy/datatypes/assembly.py +++ b/lib/galaxy/datatypes/assembly.py @@ -16,6 +16,7 @@ from galaxy.datatypes.metadata import MetadataElement log = logging.getLogger(__name__) + class Amos( data.Text ): """Class describing the AMOS assembly file """ edam_format = "format_2561" @@ -53,17 +54,18 @@ class Amos( data.Text ): while not isAmos: line = fh.readline() if not line: - break #EOF + break # EOF line = line.strip() - if line: #first non-empty line + if line: # first non-empty line if line.startswith( '{' ): - if re.match(r'{(RED|CTG|TLE)$',line): + if re.match(r'{(RED|CTG|TLE)$', line): isAmos = True fh.close() except: pass return isAmos + class Sequences( sequence.Fasta ): """Class describing the Sequences file generated by velveth """ @@ -83,24 +85,25 @@ class Sequences( sequence.Fasta ): while True: line = fh.readline() if not line: - break #EOF + break # EOF line = line.strip() - if line: #first non-empty line + if line: # first non-empty line if line.startswith( '>' ): - if not re.match(r'>[^\t]+\t\d+\t\d+$',line): + if not re.match(r'>[^\t]+\t\d+\t\d+$', line): break - #The next line.strip() must not be '', nor startwith '>' + # The next line.strip() must not be '', nor startwith '>' line = fh.readline().strip() if line == '' or line.startswith( '>' ): break return True else: - break #we found a non-empty line, but it's not a fasta header + break # we found a non-empty line, but it's not a fasta header fh.close() except: pass return False + class Roadmaps( data.Text ): """Class describing the Sequences file generated by velveth """ edam_format = "format_2561" @@ -119,23 +122,24 @@ class Roadmaps( data.Text ): while True: line = fh.readline() if not line: - break #EOF + break # EOF line = line.strip() - if line: #first non-empty line - if not re.match(r'\d+\t\d+\t\d+$',line): + if line: # first non-empty line + if not re.match(r'\d+\t\d+\t\d+$', line): break - #The next line.strip() should be 'ROADMAP 1' + # The next line.strip() should be 'ROADMAP 1' line = fh.readline().strip() - if not re.match(r'ROADMAP \d+$',line): + if not re.match(r'ROADMAP \d+$', line): break return True else: - break #we found a non-empty line, but it's not a fasta header + break # we found a non-empty line, but it's not a fasta header fh.close() except: pass return False + class Velvet( Html ): MetadataElement( name="base_name", desc="base name for velveth dataset", default="velvet", readonly=True, set_in_upload=True) MetadataElement( name="paired_end_reads", desc="has paired-end reads", default="False", readonly=False, set_in_upload=True) @@ -147,17 +151,17 @@ class Velvet( Html ): def __init__( self, **kwd ): Html.__init__( self, **kwd ) - self.add_composite_file( 'Sequences', mimetype = 'text/html', description = 'Sequences', substitute_name_with_metadata = None, is_binary = False ) - self.add_composite_file( 'Roadmaps', mimetype = 'text/html', description = 'Roadmaps', substitute_name_with_metadata = None, is_binary = False ) - self.add_composite_file( 'Log', mimetype = 'text/html', description = 'Log', optional = 'True', substitute_name_with_metadata = None, is_binary = False ) + self.add_composite_file( 'Sequences', mimetype='text/html', description='Sequences', substitute_name_with_metadata=None, is_binary=False ) + self.add_composite_file( 'Roadmaps', mimetype='text/html', description='Roadmaps', substitute_name_with_metadata=None, is_binary=False ) + self.add_composite_file( 'Log', mimetype='text/html', description='Log', optional='True', substitute_name_with_metadata=None, is_binary=False ) - def generate_primary_file( self, dataset = None ): - log.debug( "Velvet log info %s %s" % ('JJ generate_primary_file',dataset)) + def generate_primary_file( self, dataset=None ): + log.debug( "Velvet log info %s %s" % ('JJ generate_primary_file', dataset)) rval = ['Velvet Galaxy Composite Dataset

'] rval.append('

This composite dataset is composed of the following files:

' ) return "\n".join( rval ) - def regenerate_primary_file(self,dataset): + def regenerate_primary_file(self, dataset): """ cannot do this until we are setting metadata """ @@ -176,23 +180,23 @@ class Velvet( Html ): gen_msg = '' try: efp = dataset.extra_files_path - log_path = os.path.join(efp,'Log') - f = open(log_path,'r') + log_path = os.path.join(efp, 'Log') + f = open(log_path, 'r') log_content = f.read(1000) f.close() - log_msg = re.sub('/\S*/','',log_content) + log_msg = re.sub('/\S*/', '', log_content) log.debug( "Velveth log info %s" % log_msg) - paired_end_reads = re.search('-(short|long)Paired', log_msg) != None + paired_end_reads = re.search('-(short|long)Paired', log_msg) is not None dataset.metadata.paired_end_reads = paired_end_reads - long_reads = re.search('-long', log_msg) != None + long_reads = re.search('-long', log_msg) is not None dataset.metadata.long_reads = long_reads - short2_reads = re.search('-short(Paired)?2', log_msg) != None + short2_reads = re.search('-short(Paired)?2', log_msg) is not None dataset.metadata.short2_reads = short2_reads - dataset.info = re.sub('.*velveth \S+','hash_length',re.sub('\n',' ',log_msg)) + dataset.info = re.sub('.*velveth \S+', 'hash_length', re.sub('\n', ' ', log_msg)) if paired_end_reads: - gen_msg = gen_msg + ' Paired-End Reads' + gen_msg = gen_msg + ' Paired-End Reads' if long_reads: - gen_msg = gen_msg + ' Long Reads' + gen_msg = gen_msg + ' Long Reads' if len(gen_msg) > 0: gen_msg = 'Uses: ' + gen_msg except: @@ -200,12 +204,12 @@ class Velvet( Html ): log.debug( "Velveth log info %s" % gen_msg) rval = ['Velvet Galaxy Composite Dataset

'] # rval.append('

Generated:

%s

' %(re.sub('\n','
',log_msg))) - rval.append('
Generated:

%s

' %(gen_msg)) + rval.append('
Generated:

%s

' % (gen_msg)) rval.append('
Velveth dataset:

' ) - f = file(dataset.file_name,'w') + f = file(dataset.file_name, 'w') f.write("\n".join( rval )) f.write('\n') f.close() diff --git a/lib/galaxy/datatypes/binary.py b/lib/galaxy/datatypes/binary.py index 4fd0caf968b..1b9d23db9fe 100644 --- a/lib/galaxy/datatypes/binary.py +++ b/lib/galaxy/datatypes/binary.py @@ -11,7 +11,6 @@ import shutil import struct import subprocess import tempfile -import re import warnings import zipfile @@ -35,6 +34,7 @@ log = logging.getLogger(__name__) # Currently these supported binary data types must be manually set on upload + class Binary( data.Data ): """Binary data""" edam_format = "format_2333" @@ -89,7 +89,7 @@ class Binary( data.Data ): to_ext = dataset.extension valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' fname = ''.join(c in valid_chars and c or '_' for c in dataset.name)[0:150] - trans.response.set_content_type( "application/octet-stream" ) #force octet-stream so Safari doesn't append mime extensions to filename + trans.response.set_content_type( "application/octet-stream" ) # force octet-stream so Safari doesn't append mime extensions to filename trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (dataset.hid, fname, to_ext) return open( dataset.file_name ) @@ -100,7 +100,7 @@ class Ab1( Binary ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Binary ab1 sequence file" + dataset.peek = "Binary ab1 sequence file" dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -134,7 +134,6 @@ class Idat( Binary ): Binary.register_sniffable_binary_format("idat", "idat", Idat) - class CompressedArchive( Binary ): """ Class describing an compressed binary file @@ -145,7 +144,7 @@ class CompressedArchive( Binary ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Compressed binary file" + dataset.peek = "Compressed binary file" dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -209,7 +208,7 @@ class Bam( Binary ): if stderr: if exit_code != 0: shutil.rmtree(tmp_dir) # clean up - raise Exception, "Error merging BAM files: %s" % stderr + raise Exception( "Error merging BAM files: %s" % stderr ) else: print stderr os.unlink(stderr_name) @@ -243,11 +242,11 @@ class Bam( Binary ): # seconds to index with samtools, and 45 minutes to sort, so indexing is relatively inexpensive. if self._is_coordinate_sorted( file_name ): return False - index_name = tempfile.NamedTemporaryFile( prefix = "bam_index" ).name - stderr_name = tempfile.NamedTemporaryFile( prefix = "bam_index_stderr" ).name + index_name = tempfile.NamedTemporaryFile( prefix="bam_index" ).name + stderr_name = tempfile.NamedTemporaryFile( prefix="bam_index_stderr" ).name command = 'samtools index %s %s' % ( file_name, index_name ) proc = subprocess.Popen( args=command, shell=True, stderr=open( stderr_name, 'wb' ) ) - exit_code = proc.wait() + proc.wait() stderr = open( stderr_name ).read().strip() if stderr: try: @@ -276,28 +275,28 @@ class Bam( Binary ): on an output dataset after the content is initially generated. """ # Use samtools to sort the Bam file - ##$ samtools sort - ##Usage: samtools sort [-on] [-m ] - ## Sort alignments by leftmost coordinates. File .bam will be created. - ## This command may also create temporary files .%d.bam when the - ## whole alignment cannot be fitted into memory ( controlled by option -m ). - #do this in a unique temp directory, because of possible .%d.bam temp files + # $ samtools sort + # Usage: samtools sort [-on] [-m ] + # Sort alignments by leftmost coordinates. File .bam will be created. + # This command may also create temporary files .%d.bam when the + # whole alignment cannot be fitted into memory ( controlled by option -m ). + # do this in a unique temp directory, because of possible .%d.bam temp files if not self.dataset_content_needs_grooming( file_name ): # Don't re-sort if already sorted return tmp_dir = tempfile.mkdtemp() tmp_sorted_dataset_file_name_prefix = os.path.join( tmp_dir, 'sorted' ) - stderr_name = tempfile.NamedTemporaryFile( dir = tmp_dir, prefix = "bam_sort_stderr" ).name - samtools_created_sorted_file_name = "%s.bam" % tmp_sorted_dataset_file_name_prefix #samtools accepts a prefix, not a filename, it always adds .bam to the prefix + stderr_name = tempfile.NamedTemporaryFile( dir=tmp_dir, prefix="bam_sort_stderr" ).name + samtools_created_sorted_file_name = "%s.bam" % tmp_sorted_dataset_file_name_prefix # samtools accepts a prefix, not a filename, it always adds .bam to the prefix command = "samtools sort %s %s" % ( file_name, tmp_sorted_dataset_file_name_prefix ) proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=open( stderr_name, 'wb' ) ) exit_code = proc.wait() - #Did sort succeed? + # Did sort succeed? stderr = open( stderr_name ).read().strip() if stderr: if exit_code != 0: - shutil.rmtree( tmp_dir) #clean up - raise Exception, "Error Grooming BAM file contents: %s" % stderr + shutil.rmtree( tmp_dir) # clean up + raise Exception( "Error Grooming BAM file contents: %s" % stderr ) else: print stderr # Move samtools_created_sorted_file_name to our output dataset location @@ -309,20 +308,20 @@ class Bam( Binary ): def init_meta( self, dataset, copy_from=None ): Binary.init_meta( self, dataset, copy_from=copy_from ) - def set_meta( self, dataset, overwrite = True, **kwd ): + def set_meta( self, dataset, overwrite=True, **kwd ): """ Creates the index for the BAM file. """ # These metadata values are not accessible by users, always overwrite index_file = dataset.metadata.bam_index if not index_file: - index_file = dataset.metadata.spec['bam_index'].param.new_file( dataset = dataset ) + index_file = dataset.metadata.spec['bam_index'].param.new_file( dataset=dataset ) # Create the Bam index - ##$ samtools index - ##Usage: samtools index [] - stderr_name = tempfile.NamedTemporaryFile( prefix = "bam_index_stderr" ).name + # $ samtools index + # Usage: samtools index [] + stderr_name = tempfile.NamedTemporaryFile( prefix="bam_index_stderr" ).name command = [ 'samtools', 'index', dataset.file_name, index_file.file_name ] proc = subprocess.Popen( args=command, stderr=open( stderr_name, 'wb' ) ) exit_code = proc.wait() - #Did index succeed? + # Did index succeed? if exit_code == -6: # SIGABRT, most likely samtools 1.0+ which does not accept the index name parameter. dataset_symlink = os.path.join( os.path.dirname( index_file.file_name ), @@ -339,8 +338,8 @@ class Bam( Binary ): stderr = open( stderr_name ).read().strip() if stderr: if exit_code != 0: - os.unlink( stderr_name ) #clean up - raise Exception, "Error Setting BAM Metadata: %s" % stderr + os.unlink( stderr_name ) # clean up + raise Exception( "Error Setting BAM Metadata: %s" % stderr ) else: print stderr dataset.metadata.bam_index = index_file @@ -371,7 +370,7 @@ class Bam( Binary ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Binary bam alignments file" + dataset.peek = "Binary bam alignments file" dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -383,14 +382,12 @@ class Bam( Binary ): except: return "Binary bam alignments file (%s)" % ( data.nice_size( dataset.get_size() ) ) - - # ------------- Dataproviders # pipe through samtools view - #ALSO: (as Sam) + # ALSO: (as Sam) # bam does not use '#' to indicate comments/headers - we need to strip out those headers from the std. providers - #TODO:?? seems like there should be an easier way to do/inherit this - metadata.comment_char? - #TODO: incorporate samtools options to control output: regions first, then flags, etc. + # TODO:?? seems like there should be an easier way to do/inherit this - metadata.comment_char? + # TODO: incorporate samtools options to control output: regions first, then flags, etc. @dataproviders.decorators.dataprovider_factory( 'line', dataproviders.line.FilteredLineDataProvider.settings ) def line_dataprovider( self, dataset, **settings ): samtools_source = dataproviders.dataset.SamtoolsDataProvider( dataset ) @@ -417,13 +414,13 @@ class Bam( Binary ): # these can't be used directly - may need BamColumn, BamDict (Bam metadata -> column/dict) # OR - see genomic_region_dataprovider - #@dataproviders.decorators.dataprovider_factory( 'dataset-column', dataproviders.column.ColumnarDataProvider.settings ) - #def dataset_column_dataprovider( self, dataset, **settings ): + # @dataproviders.decorators.dataprovider_factory( 'dataset-column', dataproviders.column.ColumnarDataProvider.settings ) + # def dataset_column_dataprovider( self, dataset, **settings ): # settings[ 'comment_char' ] = '@' # return super( Sam, self ).dataset_column_dataprovider( dataset, **settings ) - #@dataproviders.decorators.dataprovider_factory( 'dataset-dict', dataproviders.column.DictDataProvider.settings ) - #def dataset_dict_dataprovider( self, dataset, **settings ): + # @dataproviders.decorators.dataprovider_factory( 'dataset-dict', dataproviders.column.DictDataProvider.settings ) + # def dataset_dict_dataprovider( self, dataset, **settings ): # settings[ 'comment_char' ] = '@' # return super( Sam, self ).dataset_dict_dataprovider( dataset, **settings ) @@ -443,10 +440,10 @@ class Bam( Binary ): @dataproviders.decorators.dataprovider_factory( 'genomic-region', dataproviders.column.ColumnarDataProvider.settings ) def genomic_region_dataprovider( self, dataset, **settings ): # GenomicRegionDataProvider currently requires a dataset as source - may not be necc. - #TODO:?? consider (at least) the possible use of a kwarg: metadata_source (def. to source.dataset), + # TODO:?? consider (at least) the possible use of a kwarg: metadata_source (def. to source.dataset), # or remove altogether... - #samtools_source = dataproviders.dataset.SamtoolsDataProvider( dataset ) - #return dataproviders.dataset.GenomicRegionDataProvider( samtools_source, metadata_source=dataset, + # samtools_source = dataproviders.dataset.SamtoolsDataProvider( dataset ) + # return dataproviders.dataset.GenomicRegionDataProvider( samtools_source, metadata_source=dataset, # 2, 3, 3, **settings ) # instead, set manually and use in-class column gen @@ -469,6 +466,7 @@ class Bam( Binary ): Binary.register_sniffable_binary_format("bam", "bam", Bam) + class Bcf( Binary): """Class describing a BCF file""" edam_format = "format_3020" @@ -487,21 +485,21 @@ class Bcf( Binary): except: return False - def set_meta( self, dataset, overwrite = True, **kwd ): + def set_meta( self, dataset, overwrite=True, **kwd ): """ Creates the index for the BCF file. """ # These metadata values are not accessible by users, always overwrite index_file = dataset.metadata.bcf_index if not index_file: - index_file = dataset.metadata.spec['bcf_index'].param.new_file( dataset = dataset ) + index_file = dataset.metadata.spec['bcf_index'].param.new_file( dataset=dataset ) # Create the bcf index - ##$ bcftools index - ##Usage: bcftools index + # $ bcftools index + # Usage: bcftools index dataset_symlink = os.path.join( os.path.dirname( index_file.file_name ), '__dataset_%d_%s' % ( dataset.id, os.path.basename( index_file.file_name ) ) ) os.symlink( dataset.file_name, dataset_symlink ) - stderr_name = tempfile.NamedTemporaryFile( prefix = "bcf_index_stderr" ).name + stderr_name = tempfile.NamedTemporaryFile( prefix="bcf_index_stderr" ).name command = [ 'bcftools', 'index', dataset_symlink ] proc = subprocess.Popen( args=command, stderr=open( stderr_name, 'wb' ) ) exit_code = proc.wait() @@ -510,8 +508,8 @@ class Bcf( Binary): stderr = open( stderr_name ).read().strip() if stderr: if exit_code != 0: - os.unlink( stderr_name ) #clean up - raise Exception, "Error Setting BCF Metadata: %s" % stderr + os.unlink( stderr_name ) # clean up + raise Exception( "Error Setting BCF Metadata: %s" % stderr ) else: print stderr dataset.metadata.bcf_index = index_file @@ -527,7 +525,7 @@ class H5( Binary ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Binary h5 file" + dataset.peek = "Binary h5 file" dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -549,7 +547,7 @@ class Scf( Binary ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Binary scf sequence file" + dataset.peek = "Binary scf sequence file" dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -585,7 +583,7 @@ class Sff( Binary ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Binary sff file" + dataset.peek = "Binary sff file" dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -627,7 +625,7 @@ class BigWig(Binary): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Binary UCSC %s file" % self._name + dataset.peek = "Binary UCSC %s file" % self._name dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -699,7 +697,7 @@ class SQlite ( Binary ): def init_meta( self, dataset, copy_from=None ): Binary.init_meta( self, dataset, copy_from=copy_from ) - def set_meta( self, dataset, overwrite = True, **kwd ): + def set_meta( self, dataset, overwrite=True, **kwd ): try: tables = [] columns = dict() @@ -708,7 +706,7 @@ class SQlite ( Binary ): c = conn.cursor() tables_query = "SELECT name,sql FROM sqlite_master WHERE type='table' ORDER BY name" rslt = c.execute(tables_query).fetchall() - for table,sql in rslt: + for table, sql in rslt: tables.append(table) try: col_query = 'SELECT * FROM %s LIMIT 0' % table @@ -742,12 +740,12 @@ class SQlite ( Binary ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "SQLite Database" + dataset.peek = "SQLite Database" lines = ['SQLite Database'] if dataset.metadata.tables: for table in dataset.metadata.tables: try: - lines.append('%s [%s]' % (table,dataset.metadata.table_row_count[table])) + lines.append('%s [%s]' % (table, dataset.metadata.table_row_count[table])) except: continue dataset.peek = '\n'.join(lines) @@ -762,7 +760,6 @@ class SQlite ( Binary ): except: return "SQLite Database (%s)" % ( data.nice_size( dataset.get_size() ) ) - @dataproviders.decorators.dataprovider_factory( 'sqlite', dataproviders.dataset.SQliteDataProvider.settings ) def sqlite_dataprovider( self, dataset, **settings ): dataset_source = dataproviders.dataset.DatasetDataProvider( dataset ) @@ -779,7 +776,7 @@ class SQlite ( Binary ): return dataproviders.dataset.SQliteDataDictProvider( dataset_source, **settings ) -#Binary.register_sniffable_binary_format("sqlite", "sqlite", SQlite) +# Binary.register_sniffable_binary_format("sqlite", "sqlite", SQlite) class GeminiSQLite( SQlite ): @@ -788,8 +785,8 @@ class GeminiSQLite( SQlite ): readonly=True, visible=True, no_value='0.10.0' ) file_ext = "gemini.sqlite" - def set_meta( self, dataset, overwrite = True, **kwd ): - super( GeminiSQLite, self ).set_meta( dataset, overwrite = overwrite, **kwd ) + def set_meta( self, dataset, overwrite=True, **kwd ): + super( GeminiSQLite, self ).set_meta( dataset, overwrite=overwrite, **kwd ) try: conn = sqlite.connect( dataset.file_name ) c = conn.cursor() @@ -821,7 +818,7 @@ class GeminiSQLite( SQlite ): def set_peek( self, dataset, is_multi_byte=False ): if not dataset.dataset.purged: - dataset.peek = "Gemini SQLite Database, version %s" % ( dataset.metadata.gemini_version or 'unknown' ) + dataset.peek = "Gemini SQLite Database, version %s" % ( dataset.metadata.gemini_version or 'unknown' ) dataset.blurb = data.nice_size( dataset.get_size() ) else: dataset.peek = 'file does not exist' @@ -841,7 +838,8 @@ Binary.register_sniffable_binary_format("sqlite", "sqlite", SQlite) class Xlsx(Binary): """Class for Excel 2007 (xlsx) files""" - file_ext="xlsx" + file_ext = "xlsx" + def sniff( self, filename ): # Xlsx is compressed in zip format and must not be uncompressed in Galaxy. try: @@ -878,7 +876,7 @@ class Sra( Binary ): def set_peek(self, dataset, is_multi_byte=False): if not dataset.dataset.purged: - dataset.peek = 'Binary sra file' + dataset.peek = 'Binary sra file' dataset.blurb = data.nice_size(dataset.get_size()) else: dataset.peek = 'file does not exist' diff --git a/lib/galaxy/datatypes/checkers.py b/lib/galaxy/datatypes/checkers.py index ae5336b376b..94e8a53d447 100644 --- a/lib/galaxy/datatypes/checkers.py +++ b/lib/galaxy/datatypes/checkers.py @@ -1,4 +1,3 @@ -import os import re import bz2 import gzip @@ -18,8 +17,9 @@ except ImportError: except: PIL = None + def check_image( file_path ): - if PIL != None: + if PIL is not None: try: im = PIL.open( file_path ) except: @@ -28,10 +28,11 @@ def check_image( file_path ): return im return False else: - if imghdr.what( file_path ) != None: + if imghdr.what( file_path ) is not None: return True return False + def check_html( file_path, chunk=None ): if chunk is None: temp = open( file_path, "U" ) @@ -58,6 +59,7 @@ def check_html( file_path, chunk=None ): temp.close() return False + def check_binary( name, file_path=True ): # Handles files if file_path is True or text if file_path is False is_binary = False @@ -65,7 +67,6 @@ def check_binary( name, file_path=True ): temp = open( name, "U" ) else: temp = StringIO( name ) - chars_read = 0 try: for char in temp.read( 100 ): if util.is_binary( char ): @@ -75,6 +76,7 @@ def check_binary( name, file_path=True ): temp.close( ) return is_binary + def check_gzip( file_path ): # This method returns a tuple of booleans representing ( is_gzipped, is_valid ) # Make sure we have a gzipped file @@ -95,7 +97,7 @@ def check_gzip( file_path ): return ( True, True ) except: return( False, False ) - CHUNK_SIZE = 2**15 # 32Kb + CHUNK_SIZE = 2 ** 15 # 32Kb gzipped_file = gzip.GzipFile( file_path, mode='rb' ) chunk = gzipped_file.read( CHUNK_SIZE ) gzipped_file.close() @@ -104,6 +106,7 @@ def check_gzip( file_path ): return ( True, False ) return ( True, True ) + def check_bz2( file_path ): try: temp = open( file_path, "U" ) @@ -113,7 +116,7 @@ def check_bz2( file_path ): return ( False, False ) except: return( False, False ) - CHUNK_SIZE = 2**15 # reKb + CHUNK_SIZE = 2 ** 15 # reKb bzipped_file = bz2.BZ2File( file_path, mode='rb' ) chunk = bzipped_file.read( CHUNK_SIZE ) bzipped_file.close() @@ -122,15 +125,18 @@ def check_bz2( file_path ): return ( True, False ) return ( True, True ) + def check_zip( file_path ): if zipfile.is_zipfile( file_path ): return True return False + def is_bz2( file_path ): is_bz2, is_valid = check_bz2( file_path ) return is_bz2 + def is_gzip( file_path ): is_gzipped, is_valid = check_gzip( file_path ) return is_gzipped diff --git a/lib/galaxy/datatypes/chrominfo.py b/lib/galaxy/datatypes/chrominfo.py index 14e73714801..edee9c79f32 100644 --- a/lib/galaxy/datatypes/chrominfo.py +++ b/lib/galaxy/datatypes/chrominfo.py @@ -7,4 +7,3 @@ class ChromInfo( Tabular ): file_ext = "len" MetadataElement( name="chrom", default=1, desc="Chrom column", param=metadata.ColumnParameter ) MetadataElement( name="length", default=2, desc="Length column", param=metadata.ColumnParameter ) - diff --git a/lib/galaxy/datatypes/coverage.py b/lib/galaxy/datatypes/coverage.py index e5f78ba9b59..840756fbaf1 100644 --- a/lib/galaxy/datatypes/coverage.py +++ b/lib/galaxy/datatypes/coverage.py @@ -13,6 +13,7 @@ from galaxy.datatypes.tabular import Tabular log = logging.getLogger(__name__) + class LastzCoverage( Tabular ): file_ext = "coverage" @@ -28,7 +29,6 @@ class LastzCoverage( Tabular ): """ # Maybe if we import here people will still be able to use Galaxy when numpy kills it eggs.require("numpy>=1.2.1") - #from numpy.lib import format import numpy range = end - start @@ -55,5 +55,3 @@ class LastzCoverage( Tabular ): resolution = min( resolution, 10000 ) resolution = max( resolution, 1 ) return resolution - -