1 new changeset in galaxy-central:
http://bitbucket.org/galaxy/galaxy-central/changeset/0921bff6e81a/ changeset: r5500:0921bff6e81a user: jgoecks date: 2011-05-04 22:45:10 summary: Add metadata for GTF attribute values. affected #: 1 file (2.0 KB)
--- a/lib/galaxy/datatypes/interval.py Wed May 04 10:20:54 2011 -0400 +++ b/lib/galaxy/datatypes/interval.py Wed May 04 16:45:10 2011 -0400 @@ -5,17 +5,17 @@ import pkg_resources pkg_resources.require( "bx-python" )
-import logging, os, sys, time, tempfile, shutil +import logging, os, sys, tempfile import data from galaxy import util from galaxy.datatypes.sniff import * from galaxy.web import url_for -from cgi import escape import urllib from bx.intervals.io import * from galaxy.datatypes import metadata from galaxy.datatypes.metadata import MetadataElement from galaxy.datatypes.tabular import Tabular +from galaxy.datatypes.util.gff_util import parse_gff_attributes import math
log = logging.getLogger(__name__) @@ -888,6 +888,8 @@ 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.ColumnTypesParameter, readonly=True, visible=False, no_value=[] )
def sniff( self, filename ): """ @@ -960,6 +962,42 @@ 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 )
class Wiggle( Tabular, _RemoteCallMixin ):
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.
galaxy-commits@lists.galaxyproject.org