diff --git a/config/datatypes_conf.xml.sample b/config/datatypes_conf.xml.sample index 5efdf169e3e..7b84868bee1 100644 --- a/config/datatypes_conf.xml.sample +++ b/config/datatypes_conf.xml.sample @@ -322,6 +322,7 @@ + diff --git a/lib/galaxy/datatypes/gis.py b/lib/galaxy/datatypes/gis.py new file mode 100644 index 00000000000..276de5cb97c --- /dev/null +++ b/lib/galaxy/datatypes/gis.py @@ -0,0 +1,64 @@ +""" +GIS classes +""" + +from galaxy.datatypes.binary import Binary + + +class Shapefile(Binary): + """ The Shapefile data format: + For more information please see http://en.wikipedia.org/wiki/Shapefile + """ + + composite_type = 'auto_primary_file' + file_ext = "shp" + allow_datatype_change = False + + def __init__(self, **kwd): + Binary.__init__(self, **kwd) + self.add_composite_file('shapefile.shp', description='Geometry File (shp)', is_binary=True, optional=False) + self.add_composite_file('shapefile.shx', description='Geometry index File (shx)', is_binary=True, optional=False) + self.add_composite_file('shapefile.dbf', description='Columnar attributes for each shape (dbf)', is_binary=True, optional=False) + # optional + self.add_composite_file('shapefile.prj', description='Projection description (prj)', is_binary=False, optional=True) + self.add_composite_file('shapefile.sbn', description='Spatial index of the features (sbn)', is_binary=True, optional=True) + self.add_composite_file('shapefile.sbx', description='Spatial index of the features (sbx)', is_binary=True, optional=True) + self.add_composite_file('shapefile.fbn', description='Read only spatial index of the features (fbn)', is_binary=True, optional=True) + self.add_composite_file('shapefile.fbx', description='Read only spatial index of the features (fbx)', is_binary=True, optional=True) + self.add_composite_file('shapefile.ain', description='Attribute index of the active fields in a table (ain)', is_binary=True, optional=True) + self.add_composite_file('shapefile.aih', description='Attribute index of the active fields in a table (aih)', is_binary=True, optional=True) + self.add_composite_file('shapefile.atx', description='Attribute index for the dbf file (atx)', is_binary=True, optional=True) + self.add_composite_file('shapefile.ixs', description='Geocoding index (ixs)', is_binary=True, optional=True) + self.add_composite_file('shapefile.mxs', description='Geocoding index in ODB format (mxs)', is_binary=True, optional=True) + self.add_composite_file('shapefile.shp.xml', description='Geospatial metadata in XML format (xml)', is_binary=False, optional=True) + + def generate_primary_file(self, dataset=None): + rval = ['Shapefile Galaxy Composite Dataset

'] + rval.append('

This composite dataset is composed of the following files:

    ') + for composite_name, composite_file in self.get_composite_files(dataset=dataset).items(): + fn = composite_name + opt_text = '' + if composite_file.optional: + opt_text = ' (optional)' + if composite_file.get('description'): + rval.append('
  • %s (%s)%s
  • ' % (fn, fn, composite_file.get('description'), opt_text)) + else: + rval.append('
  • %s%s
  • ' % (fn, fn, opt_text)) + rval.append('
\n') + return "\n".join(rval) + + def set_peek(self, dataset, is_multi_byte=False): + """Set the peek and blurb text.""" + if not dataset.dataset.purged: + dataset.peek = "Shapefile data" + dataset.blurb = "Shapefile data" + else: + dataset.peek = "file does not exist" + dataset.blurb = "file purged from disk" + + def display_peek(self, dataset): + """Create HTML content, used for displaying peek.""" + try: + return dataset.peek + except Exception: + return "Shapefile data" diff --git a/lib/galaxy/jobs/__init__.py b/lib/galaxy/jobs/__init__.py index 13cc8767373..ca1c5b3b4ce 100644 --- a/lib/galaxy/jobs/__init__.py +++ b/lib/galaxy/jobs/__init__.py @@ -1348,7 +1348,7 @@ class JobWrapper(HasResourceParameters): # Handle composite datatypes of auto_primary_file type if dataset.datatype.composite_type == 'auto_primary_file' and not dataset.has_data(): try: - with NamedTemporaryFile() as temp_fh: + with NamedTemporaryFile(mode='w') as temp_fh: temp_fh.write(dataset.datatype.generate_primary_file(dataset)) temp_fh.flush() self.object_store.update_from_file(dataset.dataset, file_name=temp_fh.name, create=True) diff --git a/test/functional/tools/composite_shapefile.xml b/test/functional/tools/composite_shapefile.xml new file mode 100644 index 00000000000..34caff62a46 --- /dev/null +++ b/test/functional/tools/composite_shapefile.xml @@ -0,0 +1,39 @@ + + + fiona + + '$output' && + cp '$input.extra_files_path'/* '$output_shapefile.extra_files_path' + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/sample_datatypes_conf.xml b/test/functional/tools/sample_datatypes_conf.xml index 6b9c6d5326c..ba5dbdcf9cb 100644 --- a/test/functional/tools/sample_datatypes_conf.xml +++ b/test/functional/tools/sample_datatypes_conf.xml @@ -42,6 +42,7 @@ + diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index 28798011dcb..c40a545f144 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -52,6 +52,7 @@ +