commit/galaxy-central: jgoecks: Set attribute metadata for GFF and GFF3 in addition to GTF.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/0e3ecd0ea818/ changeset: 0e3ecd0ea818 user: jgoecks date: 2012-08-31 21:24:25 summary: Set attribute metadata for GFF and GFF3 in addition to GTF. affected #: 1 file diff -r 524e481298fa0977990d83bce92880caf05ceb06 -r 0e3ecd0ea81876e4d32d108be1e02e393846e4e8 lib/galaxy/datatypes/interval.py --- a/lib/galaxy/datatypes/interval.py +++ b/lib/galaxy/datatypes/interval.py @@ -576,13 +576,58 @@ """Add metadata elements""" MetadataElement( name="columns", default=9, desc="Number of columns", readonly=True, visible=False ) MetadataElement( name="column_types", default=['str','str','str','int','int','int','str','str','str'], param=metadata.ColumnTypesParameter, desc="Column types", readonly=True, visible=False ) + + MetadataElement( name="attributes", default=0, desc="Number of attributes", readonly=True, visible=False, no_value=0 ) + MetadataElement( name="attribute_types", default={}, desc="Attribute types", param=metadata.DictParameter, readonly=True, visible=False, no_value=[] ) def __init__( self, **kwd ): """Initialize datatype, by adding GBrowse display app""" Tabular.__init__(self, **kwd) self.add_display_app( 'ucsc', 'display at UCSC', 'as_ucsc_display_file', 'ucsc_links' ) self.add_display_app( 'gbrowse', 'display in Gbrowse', 'as_gbrowse_display_file', 'gbrowse_links' ) + + def set_attribute_metadata( self, dataset ): + """ + Sets metadata elements for dataset's attributes. + """ + + # Use first N lines to set metadata for dataset attributes. Attributes + # not found in the first N lines will not have metadata. + num_lines = 200 + attribute_types = {} + for i, line in enumerate( file ( dataset.file_name ) ): + if line and not line.startswith( '#' ): + elems = line.split( '\t' ) + if len( elems ) == 9: + try: + # Loop through attributes to set types. + for name, value in parse_gff_attributes( elems[8] ).items(): + # Default type is string. + value_type = "str" + try: + # Try int. + int( value ) + value_type = "int" + except: + try: + # Try float. + float( value ) + value_type = "float" + except: + pass + attribute_types[ name ] = value_type + except: + pass + if i + 1 == num_lines: + break + + # Set attribute metadata and then set additional metadata. + dataset.metadata.attribute_types = attribute_types + dataset.metadata.attributes = len( attribute_types ) + def set_meta( self, dataset, overwrite = True, **kwd ): + self.set_attribute_metadata( dataset ) + i = 0 for i, line in enumerate( file ( dataset.file_name ) ): line = line.rstrip('\r\n') @@ -596,6 +641,7 @@ except: pass Tabular.set_meta( self, dataset, overwrite = overwrite, skip = i ) + def display_peek( self, dataset ): """Returns formated html of peek""" return Tabular.make_html_table( self, dataset, column_names=self.column_names ) @@ -756,6 +802,8 @@ """Initialize datatype, by adding GBrowse display app""" Gff.__init__(self, **kwd) def set_meta( self, dataset, overwrite = True, **kwd ): + self.set_attribute_metadata( dataset ) + i = 0 for i, line in enumerate( file ( dataset.file_name ) ): line = line.rstrip('\r\n') @@ -855,9 +903,6 @@ MetadataElement( name="columns", default=9, desc="Number of columns", readonly=True, visible=False ) MetadataElement( name="column_types", default=['str','str','str','int','int','float','str','int','list'], param=metadata.ColumnTypesParameter, desc="Column types", readonly=True, visible=False ) - MetadataElement( name="attributes", default=0, desc="Number of attributes", readonly=True, visible=False, no_value=0 ) - MetadataElement( name="attribute_types", default={}, desc="Attribute types", param=metadata.DictParameter, readonly=True, visible=False, no_value=[] ) - def sniff( self, filename ): """ Determines whether the file is in gtf format @@ -917,42 +962,6 @@ return True except: return False - - def set_meta( self, dataset, overwrite = True, **kwd ): - # Use first N lines to set metadata for dataset attributes. Attributes - # not found in the first N lines will not have metadata. - num_lines = 200 - attribute_types = {} - for i, line in enumerate( file ( dataset.file_name ) ): - if line and not line.startswith( '#' ): - elems = line.split( '\t' ) - if len( elems ) == 9: - try: - # Loop through attributes to set types. - for name, value in parse_gff_attributes( elems[8] ).items(): - # Default type is string. - value_type = "str" - try: - # Try int. - int( value ) - value_type = "int" - except: - try: - # Try float. - float( value ) - value_type = "float" - except: - pass - attribute_types[ name ] = value_type - except: - pass - if i + 1 == num_lines: - break - - # Set attribute metadata and then set additional metadata. - dataset.metadata.attribute_types = attribute_types - dataset.metadata.attributes = len( attribute_types ) - Gff.set_meta( self, dataset, overwrite = overwrite, skip = i ) def get_track_type( self ): return "FeatureTrack", {"data": "interval_index", "index": "summary_tree"} Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
Bitbucket