annotate registry.py @ 1:646b05282962

Uploaded
author jorrit
date Tue, 12 Feb 2013 13:46:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
646b05282962 Uploaded
jorrit
parents:
diff changeset
1 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
2 Provides mapping between extensions and datatypes, mime-types, etc.
646b05282962 Uploaded
jorrit
parents:
diff changeset
3 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
4 import os, sys, tempfile, threading, logging
646b05282962 Uploaded
jorrit
parents:
diff changeset
5 import data, tabular, interval, images, sequence, qualityscore, genetics, xml, coverage, tracks, chrominfo, binary, assembly, ngsindex, wsf, annotation, ontology, termenrichment
646b05282962 Uploaded
jorrit
parents:
diff changeset
6 import galaxy.util
646b05282962 Uploaded
jorrit
parents:
diff changeset
7 from galaxy.util.odict import odict
646b05282962 Uploaded
jorrit
parents:
diff changeset
8 from display_applications.application import DisplayApplication
646b05282962 Uploaded
jorrit
parents:
diff changeset
9
646b05282962 Uploaded
jorrit
parents:
diff changeset
10 class ConfigurationError( Exception ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
11 pass
646b05282962 Uploaded
jorrit
parents:
diff changeset
12
646b05282962 Uploaded
jorrit
parents:
diff changeset
13 class Registry( object ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
14 def __init__( self ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
15 self.log = logging.getLogger(__name__)
646b05282962 Uploaded
jorrit
parents:
diff changeset
16 self.log.addHandler( logging.NullHandler() )
646b05282962 Uploaded
jorrit
parents:
diff changeset
17 self.datatypes_by_extension = {}
646b05282962 Uploaded
jorrit
parents:
diff changeset
18 self.mimetypes_by_extension = {}
646b05282962 Uploaded
jorrit
parents:
diff changeset
19 self.datatype_converters = odict()
646b05282962 Uploaded
jorrit
parents:
diff changeset
20 # Converters defined in local datatypes_conf.xml
646b05282962 Uploaded
jorrit
parents:
diff changeset
21 self.converters = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
22 # Converters defined in datatypes_conf.xml included in installed tool shed repositories.
646b05282962 Uploaded
jorrit
parents:
diff changeset
23 self.proprietary_converters = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
24 self.converter_deps = {}
646b05282962 Uploaded
jorrit
parents:
diff changeset
25 self.available_tracks = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
26 self.set_external_metadata_tool = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
27 self.sniff_order = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
28 self.upload_file_formats = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
29 # Datatype elements defined in local datatypes_conf.xml that contain display applications.
646b05282962 Uploaded
jorrit
parents:
diff changeset
30 self.display_app_containers = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
31 # Datatype elements in datatypes_conf.xml included in installed
646b05282962 Uploaded
jorrit
parents:
diff changeset
32 # tool shed repositories that contain display applications.
646b05282962 Uploaded
jorrit
parents:
diff changeset
33 self.proprietary_display_app_containers = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
34 # Map a display application id to a display application
646b05282962 Uploaded
jorrit
parents:
diff changeset
35 self.display_applications = odict()
646b05282962 Uploaded
jorrit
parents:
diff changeset
36 # The following 2 attributes are used in the to_xml_file()
646b05282962 Uploaded
jorrit
parents:
diff changeset
37 # method to persist the current state into an xml file.
646b05282962 Uploaded
jorrit
parents:
diff changeset
38 self.display_path_attr = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
39 self.converters_path_attr = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
40 # The 'default' converters_path defined in local datatypes_conf.xml
646b05282962 Uploaded
jorrit
parents:
diff changeset
41 self.converters_path = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
42 # The 'default' display_path defined in local datatypes_conf.xml
646b05282962 Uploaded
jorrit
parents:
diff changeset
43 self.display_applications_path = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
44 self.inherit_display_application_by_class = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
45 # Keep a list of imported proprietary datatype class modules.
646b05282962 Uploaded
jorrit
parents:
diff changeset
46 self.imported_modules = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
47 self.datatype_elems = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
48 self.sniffer_elems = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
49 self.xml_filename = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
50 def load_datatypes( self, root_dir=None, config=None, deactivate=False, override=True ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
51 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
52 Parse a datatypes XML file located at root_dir/config. If deactivate is True, an installed tool shed
646b05282962 Uploaded
jorrit
parents:
diff changeset
53 repository that includes proprietary datatypes is being deactivated, so appropriate loaded datatypes
646b05282962 Uploaded
jorrit
parents:
diff changeset
54 will be removed from the registry. The value of override will be False when a tool shed repository is
646b05282962 Uploaded
jorrit
parents:
diff changeset
55 being installed. Since installation is occurring after the datatypes registry has been initialized, its
646b05282962 Uploaded
jorrit
parents:
diff changeset
56 contents cannot be overridden by new introduced conflicting data types.
646b05282962 Uploaded
jorrit
parents:
diff changeset
57 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
58 def __import_module( full_path, datatype_module ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
59 sys.path.insert( 0, full_path )
646b05282962 Uploaded
jorrit
parents:
diff changeset
60 imported_module = __import__( datatype_module )
646b05282962 Uploaded
jorrit
parents:
diff changeset
61 sys.path.pop( 0 )
646b05282962 Uploaded
jorrit
parents:
diff changeset
62 return imported_module
646b05282962 Uploaded
jorrit
parents:
diff changeset
63 if root_dir and config:
646b05282962 Uploaded
jorrit
parents:
diff changeset
64 handling_proprietary_datatypes = False
646b05282962 Uploaded
jorrit
parents:
diff changeset
65 # Parse datatypes_conf.xml
646b05282962 Uploaded
jorrit
parents:
diff changeset
66 tree = galaxy.util.parse_xml( config )
646b05282962 Uploaded
jorrit
parents:
diff changeset
67 root = tree.getroot()
646b05282962 Uploaded
jorrit
parents:
diff changeset
68 # Load datatypes and converters from config
646b05282962 Uploaded
jorrit
parents:
diff changeset
69 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
70 self.log.debug( 'Deactivating datatypes from %s' % config )
646b05282962 Uploaded
jorrit
parents:
diff changeset
71 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
72 self.log.debug( 'Loading datatypes from %s' % config )
646b05282962 Uploaded
jorrit
parents:
diff changeset
73 registration = root.find( 'registration' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
74 # Set default paths defined in local datatypes_conf.xml.
646b05282962 Uploaded
jorrit
parents:
diff changeset
75 if not self.converters_path:
646b05282962 Uploaded
jorrit
parents:
diff changeset
76 self.converters_path_attr = registration.get( 'converters_path', 'lib/galaxy/datatypes/converters' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
77 self.converters_path = os.path.join( root_dir, self.converters_path_attr )
646b05282962 Uploaded
jorrit
parents:
diff changeset
78 if not os.path.isdir( self.converters_path ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
79 raise ConfigurationError( "Directory does not exist: %s" % self.converters_path )
646b05282962 Uploaded
jorrit
parents:
diff changeset
80 if not self.display_applications_path:
646b05282962 Uploaded
jorrit
parents:
diff changeset
81 self.display_path_attr = registration.get( 'display_path', 'display_applications' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
82 self.display_applications_path = os.path.join( root_dir, self.display_path_attr )
646b05282962 Uploaded
jorrit
parents:
diff changeset
83 # Proprietary datatype's <registration> tag may have special attributes, proprietary_converter_path and proprietary_display_path.
646b05282962 Uploaded
jorrit
parents:
diff changeset
84 proprietary_converter_path = registration.get( 'proprietary_converter_path', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
85 proprietary_display_path = registration.get( 'proprietary_display_path', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
86 if proprietary_converter_path or proprietary_display_path and not handling_proprietary_datatypes:
646b05282962 Uploaded
jorrit
parents:
diff changeset
87 handling_proprietary_datatypes = True
646b05282962 Uploaded
jorrit
parents:
diff changeset
88 for elem in registration.findall( 'datatype' ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
89 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
90 extension = elem.get( 'extension', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
91 dtype = elem.get( 'type', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
92 type_extension = elem.get( 'type_extension', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
93 mimetype = elem.get( 'mimetype', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
94 display_in_upload = elem.get( 'display_in_upload', False )
646b05282962 Uploaded
jorrit
parents:
diff changeset
95 make_subclass = galaxy.util.string_as_bool( elem.get( 'subclass', False ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
96 # Proprietary datatypes included in installed tool shed repositories will include two special attributes
646b05282962 Uploaded
jorrit
parents:
diff changeset
97 # (proprietary_path and proprietary_datatype_module) if they depend on proprietary datatypes classes.
646b05282962 Uploaded
jorrit
parents:
diff changeset
98 proprietary_path = elem.get( 'proprietary_path', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
99 proprietary_datatype_module = elem.get( 'proprietary_datatype_module', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
100 if proprietary_path or proprietary_datatype_module and not handling_proprietary_datatypes:
646b05282962 Uploaded
jorrit
parents:
diff changeset
101 handling_proprietary_datatypes = True
646b05282962 Uploaded
jorrit
parents:
diff changeset
102 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
103 # We are deactivating an installed tool shed repository, so eliminate the
646b05282962 Uploaded
jorrit
parents:
diff changeset
104 # datatype elem from the in-memory list of datatype elems.
646b05282962 Uploaded
jorrit
parents:
diff changeset
105 for in_memory_elem in self.datatype_elems:
646b05282962 Uploaded
jorrit
parents:
diff changeset
106 in_memory_extension = in_memory_elem.get( 'extension', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
107 if in_memory_extension == extension:
646b05282962 Uploaded
jorrit
parents:
diff changeset
108 in_memory_dtype = elem.get( 'type', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
109 in_memory_type_extension = elem.get( 'type_extension', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
110 in_memory_mimetype = elem.get( 'mimetype', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
111 in_memory_display_in_upload = elem.get( 'display_in_upload', False )
646b05282962 Uploaded
jorrit
parents:
diff changeset
112 in_memory_make_subclass = galaxy.util.string_as_bool( elem.get( 'subclass', False ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
113 if in_memory_dtype == dtype and in_memory_type_extension == type_extension and in_memory_mimetype == mimetype \
646b05282962 Uploaded
jorrit
parents:
diff changeset
114 and in_memory_display_in_upload == display_in_upload and in_memory_make_subclass == make_subclass:
646b05282962 Uploaded
jorrit
parents:
diff changeset
115 self.datatype_elems.remove( in_memory_elem )
646b05282962 Uploaded
jorrit
parents:
diff changeset
116 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
117 # Keep an in-memory list of datatype elems to enable persistence.
646b05282962 Uploaded
jorrit
parents:
diff changeset
118 self.datatype_elems.append( elem )
646b05282962 Uploaded
jorrit
parents:
diff changeset
119 if extension and extension in self.datatypes_by_extension and deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
120 # We are deactivating an installed tool shed repository, so eliminate the datatype from the registry.
646b05282962 Uploaded
jorrit
parents:
diff changeset
121 # TODO: Handle deactivating datatype converters, etc before removing from self.datatypes_by_extension.
646b05282962 Uploaded
jorrit
parents:
diff changeset
122 self.log.debug( "Removing datatype with extension '%s' from the registry." % extension )
646b05282962 Uploaded
jorrit
parents:
diff changeset
123 del self.datatypes_by_extension[ extension ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
124 can_process_datatype = False
646b05282962 Uploaded
jorrit
parents:
diff changeset
125 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
126 can_process_datatype = ( extension and ( dtype or type_extension ) ) and ( extension not in self.datatypes_by_extension or override )
646b05282962 Uploaded
jorrit
parents:
diff changeset
127 if can_process_datatype:
646b05282962 Uploaded
jorrit
parents:
diff changeset
128 if dtype:
646b05282962 Uploaded
jorrit
parents:
diff changeset
129 fields = dtype.split( ':' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
130 datatype_module = fields[0]
646b05282962 Uploaded
jorrit
parents:
diff changeset
131 datatype_class_name = fields[1]
646b05282962 Uploaded
jorrit
parents:
diff changeset
132 datatype_class = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
133 if proprietary_path and proprietary_datatype_module:
646b05282962 Uploaded
jorrit
parents:
diff changeset
134 # We need to change the value of sys.path, so do it in a way that is thread-safe.
646b05282962 Uploaded
jorrit
parents:
diff changeset
135 lock = threading.Lock()
646b05282962 Uploaded
jorrit
parents:
diff changeset
136 lock.acquire( True )
646b05282962 Uploaded
jorrit
parents:
diff changeset
137 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
138 imported_module = __import_module( proprietary_path, proprietary_datatype_module )
646b05282962 Uploaded
jorrit
parents:
diff changeset
139 if imported_module not in self.imported_modules:
646b05282962 Uploaded
jorrit
parents:
diff changeset
140 self.imported_modules.append( imported_module )
646b05282962 Uploaded
jorrit
parents:
diff changeset
141 if hasattr( imported_module, datatype_class_name ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
142 datatype_class = getattr( imported_module, datatype_class_name )
646b05282962 Uploaded
jorrit
parents:
diff changeset
143 except Exception, e:
646b05282962 Uploaded
jorrit
parents:
diff changeset
144 full_path = os.path.join( full_path, proprietary_datatype_module )
646b05282962 Uploaded
jorrit
parents:
diff changeset
145 self.log.debug( "Exception importing proprietary code file %s: %s" % ( str( full_path ), str( e ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
146 finally:
646b05282962 Uploaded
jorrit
parents:
diff changeset
147 lock.release()
646b05282962 Uploaded
jorrit
parents:
diff changeset
148 if datatype_class is None:
646b05282962 Uploaded
jorrit
parents:
diff changeset
149 # The datatype class name must be contained in one of the datatype modules in the Galaxy distribution.
646b05282962 Uploaded
jorrit
parents:
diff changeset
150 fields = datatype_module.split( '.' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
151 module = __import__( fields.pop(0) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
152 for mod in fields:
646b05282962 Uploaded
jorrit
parents:
diff changeset
153 module = getattr( module, mod )
646b05282962 Uploaded
jorrit
parents:
diff changeset
154 datatype_class = getattr( module, datatype_class_name )
646b05282962 Uploaded
jorrit
parents:
diff changeset
155 elif type_extension:
646b05282962 Uploaded
jorrit
parents:
diff changeset
156 datatype_class = self.datatypes_by_extension[type_extension].__class__
646b05282962 Uploaded
jorrit
parents:
diff changeset
157 if make_subclass:
646b05282962 Uploaded
jorrit
parents:
diff changeset
158 datatype_class = type( datatype_class_name, (datatype_class,), {} )
646b05282962 Uploaded
jorrit
parents:
diff changeset
159 if extension in self.datatypes_by_extension:
646b05282962 Uploaded
jorrit
parents:
diff changeset
160 self.log.warning( "Overriding conflicting datatype with extension '%s', using datatype from %s." % ( extension, config ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
161 self.datatypes_by_extension[ extension ] = datatype_class()
646b05282962 Uploaded
jorrit
parents:
diff changeset
162 if mimetype is None:
646b05282962 Uploaded
jorrit
parents:
diff changeset
163 # Use default mime type as per datatype spec
646b05282962 Uploaded
jorrit
parents:
diff changeset
164 mimetype = self.datatypes_by_extension[ extension ].get_mime()
646b05282962 Uploaded
jorrit
parents:
diff changeset
165 self.mimetypes_by_extension[ extension ] = mimetype
646b05282962 Uploaded
jorrit
parents:
diff changeset
166 if hasattr( datatype_class, "get_track_type" ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
167 self.available_tracks.append( extension )
646b05282962 Uploaded
jorrit
parents:
diff changeset
168 if display_in_upload:
646b05282962 Uploaded
jorrit
parents:
diff changeset
169 self.upload_file_formats.append( extension )
646b05282962 Uploaded
jorrit
parents:
diff changeset
170 # Max file size cut off for setting optional metadata
646b05282962 Uploaded
jorrit
parents:
diff changeset
171 self.datatypes_by_extension[ extension ].max_optional_metadata_filesize = elem.get( 'max_optional_metadata_filesize', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
172 for converter in elem.findall( 'converter' ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
173 # Build the list of datatype converters which will later be loaded into the calling app's toolbox.
646b05282962 Uploaded
jorrit
parents:
diff changeset
174 converter_config = converter.get( 'file', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
175 target_datatype = converter.get( 'target_datatype', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
176 depends_on = converter.get( 'depends_on', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
177 if depends_on and target_datatype:
646b05282962 Uploaded
jorrit
parents:
diff changeset
178 if extension not in self.converter_deps:
646b05282962 Uploaded
jorrit
parents:
diff changeset
179 self.converter_deps[extension] = {}
646b05282962 Uploaded
jorrit
parents:
diff changeset
180 self.converter_deps[extension][target_datatype] = depends_on.split(',')
646b05282962 Uploaded
jorrit
parents:
diff changeset
181 if converter_config and target_datatype:
646b05282962 Uploaded
jorrit
parents:
diff changeset
182 #if imported_modules:
646b05282962 Uploaded
jorrit
parents:
diff changeset
183 if proprietary_converter_path:
646b05282962 Uploaded
jorrit
parents:
diff changeset
184 self.proprietary_converters.append( ( converter_config, extension, target_datatype ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
185 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
186 self.converters.append( ( converter_config, extension, target_datatype ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
187 for composite_file in elem.findall( 'composite_file' ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
188 # add composite files
646b05282962 Uploaded
jorrit
parents:
diff changeset
189 name = composite_file.get( 'name', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
190 if name is None:
646b05282962 Uploaded
jorrit
parents:
diff changeset
191 self.log.warning( "You must provide a name for your composite_file (%s)." % composite_file )
646b05282962 Uploaded
jorrit
parents:
diff changeset
192 optional = composite_file.get( 'optional', False )
646b05282962 Uploaded
jorrit
parents:
diff changeset
193 mimetype = composite_file.get( 'mimetype', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
194 self.datatypes_by_extension[extension].add_composite_file( name, optional=optional, mimetype=mimetype )
646b05282962 Uploaded
jorrit
parents:
diff changeset
195 for display_app in elem.findall( 'display' ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
196 #if imported_modules:
646b05282962 Uploaded
jorrit
parents:
diff changeset
197 if proprietary_display_path:
646b05282962 Uploaded
jorrit
parents:
diff changeset
198 if elem not in self.proprietary_display_app_containers:
646b05282962 Uploaded
jorrit
parents:
diff changeset
199 self.proprietary_display_app_containers.append( elem )
646b05282962 Uploaded
jorrit
parents:
diff changeset
200 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
201 if elem not in self.display_app_containers:
646b05282962 Uploaded
jorrit
parents:
diff changeset
202 self.display_app_containers.append( elem )
646b05282962 Uploaded
jorrit
parents:
diff changeset
203 elif not deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
204 # A new tool shed repository that contains proprietary datatypes is being installed, and since installation
646b05282962 Uploaded
jorrit
parents:
diff changeset
205 # is occurring after the datatypes registry has been initialized, its contents cannot be overridden by new
646b05282962 Uploaded
jorrit
parents:
diff changeset
206 # introduced conflicting data types.
646b05282962 Uploaded
jorrit
parents:
diff changeset
207 self.log.warning( "Ignoring conflicting datatype with extension '%s' from %s." % ( extension, config ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
208 except Exception, e:
646b05282962 Uploaded
jorrit
parents:
diff changeset
209 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
210 self.log.warning( "Error deactivating datatype with extension '%s': %s" % ( extension, str( e ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
211 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
212 self.log.warning( "Error loading datatype with extension '%s': %s" % ( extension, str( e ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
213 # Load datatype sniffers from the config
646b05282962 Uploaded
jorrit
parents:
diff changeset
214 sniffers = root.find( 'sniffers' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
215 if sniffers:
646b05282962 Uploaded
jorrit
parents:
diff changeset
216 for elem in sniffers.findall( 'sniffer' ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
217 # Keep an in-memory list of sniffer elems to enable persistence.
646b05282962 Uploaded
jorrit
parents:
diff changeset
218 self.sniffer_elems.append( elem )
646b05282962 Uploaded
jorrit
parents:
diff changeset
219 dtype = elem.get( 'type', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
220 if dtype:
646b05282962 Uploaded
jorrit
parents:
diff changeset
221 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
222 fields = dtype.split( ":" )
646b05282962 Uploaded
jorrit
parents:
diff changeset
223 datatype_module = fields[0]
646b05282962 Uploaded
jorrit
parents:
diff changeset
224 datatype_class_name = fields[1]
646b05282962 Uploaded
jorrit
parents:
diff changeset
225 module = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
226 #if imported_modules:
646b05282962 Uploaded
jorrit
parents:
diff changeset
227 if handling_proprietary_datatypes:
646b05282962 Uploaded
jorrit
parents:
diff changeset
228 # See if one of the imported modules contains the datatype class name.
646b05282962 Uploaded
jorrit
parents:
diff changeset
229 for imported_module in self.imported_modules:
646b05282962 Uploaded
jorrit
parents:
diff changeset
230 if hasattr( imported_module, datatype_class_name ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
231 module = imported_module
646b05282962 Uploaded
jorrit
parents:
diff changeset
232 break
646b05282962 Uploaded
jorrit
parents:
diff changeset
233 if module is None:
646b05282962 Uploaded
jorrit
parents:
diff changeset
234 # The datatype class name must be contained in one of the datatype modules in the Galaxy distribution.
646b05282962 Uploaded
jorrit
parents:
diff changeset
235 module = __import__( datatype_module )
646b05282962 Uploaded
jorrit
parents:
diff changeset
236 for comp in datatype_module.split( '.' )[ 1: ]:
646b05282962 Uploaded
jorrit
parents:
diff changeset
237 module = getattr( module, comp )
646b05282962 Uploaded
jorrit
parents:
diff changeset
238 aclass = getattr( module, datatype_class_name )()
646b05282962 Uploaded
jorrit
parents:
diff changeset
239 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
240 for sniffer_class in self.sniff_order:
646b05282962 Uploaded
jorrit
parents:
diff changeset
241 if sniffer_class.__class__ == aclass.__class__:
646b05282962 Uploaded
jorrit
parents:
diff changeset
242 self.sniff_order.remove( sniffer_class )
646b05282962 Uploaded
jorrit
parents:
diff changeset
243 break
646b05282962 Uploaded
jorrit
parents:
diff changeset
244 self.log.debug( "Deactivated sniffer for datatype '%s'" % dtype )
646b05282962 Uploaded
jorrit
parents:
diff changeset
245 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
246 # See if we have a conflicting sniffer already loaded.
646b05282962 Uploaded
jorrit
parents:
diff changeset
247 conflict = False
646b05282962 Uploaded
jorrit
parents:
diff changeset
248 for conflict_loc, sniffer_class in enumerate( self.sniff_order ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
249 if sniffer_class.__class__ == aclass.__class__:
646b05282962 Uploaded
jorrit
parents:
diff changeset
250 # We have a conflicting sniffer, so replace the one previously loaded.
646b05282962 Uploaded
jorrit
parents:
diff changeset
251 conflict = True
646b05282962 Uploaded
jorrit
parents:
diff changeset
252 if override:
646b05282962 Uploaded
jorrit
parents:
diff changeset
253 del self.sniff_order[ conflict_loc ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
254 self.log.debug( "Replaced conflicting sniffer for datatype '%s'" % dtype )
646b05282962 Uploaded
jorrit
parents:
diff changeset
255 break
646b05282962 Uploaded
jorrit
parents:
diff changeset
256 if conflict:
646b05282962 Uploaded
jorrit
parents:
diff changeset
257 if override:
646b05282962 Uploaded
jorrit
parents:
diff changeset
258 self.sniff_order.append( aclass )
646b05282962 Uploaded
jorrit
parents:
diff changeset
259 self.log.debug( "Loaded sniffer for datatype '%s'" % dtype )
646b05282962 Uploaded
jorrit
parents:
diff changeset
260 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
261 self.sniff_order.append( aclass )
646b05282962 Uploaded
jorrit
parents:
diff changeset
262 self.log.debug( "Loaded sniffer for datatype '%s'" % dtype )
646b05282962 Uploaded
jorrit
parents:
diff changeset
263 except Exception, exc:
646b05282962 Uploaded
jorrit
parents:
diff changeset
264 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
265 self.log.warning( "Error deactivating sniffer for datatype '%s': %s" % ( dtype, str( exc ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
266 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
267 self.log.warning( "Error appending sniffer for datatype '%s' to sniff_order: %s" % ( dtype, str( exc ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
268 self.upload_file_formats.sort()
646b05282962 Uploaded
jorrit
parents:
diff changeset
269 # Persist the xml form of the registry into a temporary file so that it
646b05282962 Uploaded
jorrit
parents:
diff changeset
270 # can be loaded from the command line by tools and set_metadata processing.
646b05282962 Uploaded
jorrit
parents:
diff changeset
271 self.to_xml_file()
646b05282962 Uploaded
jorrit
parents:
diff changeset
272 # Default values.
646b05282962 Uploaded
jorrit
parents:
diff changeset
273 if not self.datatypes_by_extension:
646b05282962 Uploaded
jorrit
parents:
diff changeset
274 self.datatypes_by_extension = {
646b05282962 Uploaded
jorrit
parents:
diff changeset
275 ## required for galaxy-obo:
646b05282962 Uploaded
jorrit
parents:
diff changeset
276 'obo' : ontology.Obo(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
277 'owl' : ontology.Owl(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
278 'ontology' : ontology.Ontology(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
279 'gaf' : annotation.Gaf(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
280 'terf' : termenrichment.TerfTab(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
281
646b05282962 Uploaded
jorrit
parents:
diff changeset
282 'ab1' : binary.Ab1(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
283 'axt' : sequence.Axt(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
284 'bam' : binary.Bam(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
285 'bed' : interval.Bed(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
286 'blastxml' : xml.BlastXml(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
287 'coverage' : coverage.LastzCoverage(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
288 'customtrack' : interval.CustomTrack(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
289 'csfasta' : sequence.csFasta(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
290 'fasta' : sequence.Fasta(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
291 'eland' : tabular.Eland(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
292 'fastq' : sequence.Fastq(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
293 'fastqsanger' : sequence.FastqSanger(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
294 'gtf' : interval.Gtf(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
295 'gff' : interval.Gff(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
296 'gff3' : interval.Gff3(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
297 'genetrack' : tracks.GeneTrack(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
298 'interval' : interval.Interval(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
299 'laj' : images.Laj(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
300 'lav' : sequence.Lav(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
301 'maf' : sequence.Maf(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
302 'pileup' : tabular.Pileup(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
303 'qualsolid' : qualityscore.QualityScoreSOLiD(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
304 'qualsolexa' : qualityscore.QualityScoreSolexa(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
305 'qual454' : qualityscore.QualityScore454(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
306 'sam' : tabular.Sam(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
307 'scf' : binary.Scf(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
308 'sff' : binary.Sff(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
309 'tabular' : tabular.Tabular(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
310 'taxonomy' : tabular.Taxonomy(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
311 'txt' : data.Text(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
312 'wig' : interval.Wiggle(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
313 'xml' : xml.GenericXml(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
314 }
646b05282962 Uploaded
jorrit
parents:
diff changeset
315 self.mimetypes_by_extension = {
646b05282962 Uploaded
jorrit
parents:
diff changeset
316 'ab1' : 'application/octet-stream',
646b05282962 Uploaded
jorrit
parents:
diff changeset
317 'axt' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
318 'bam' : 'application/octet-stream',
646b05282962 Uploaded
jorrit
parents:
diff changeset
319 'bed' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
320 'blastxml' : 'application/xml',
646b05282962 Uploaded
jorrit
parents:
diff changeset
321 'customtrack' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
322 'csfasta' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
323 'eland' : 'application/octet-stream',
646b05282962 Uploaded
jorrit
parents:
diff changeset
324 'fasta' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
325 'fastq' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
326 'fastqsanger' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
327 'gtf' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
328 'gff' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
329 'gff3' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
330 'interval' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
331 'laj' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
332 'lav' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
333 'maf' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
334 'memexml' : 'application/xml',
646b05282962 Uploaded
jorrit
parents:
diff changeset
335 'pileup' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
336 'qualsolid' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
337 'qualsolexa' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
338 'qual454' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
339 'sam' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
340 'scf' : 'application/octet-stream',
646b05282962 Uploaded
jorrit
parents:
diff changeset
341 'sff' : 'application/octet-stream',
646b05282962 Uploaded
jorrit
parents:
diff changeset
342 'tabular' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
343 'taxonomy' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
344 'txt' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
345 'wig' : 'text/plain',
646b05282962 Uploaded
jorrit
parents:
diff changeset
346 'xml' : 'application/xml',
646b05282962 Uploaded
jorrit
parents:
diff changeset
347 }
646b05282962 Uploaded
jorrit
parents:
diff changeset
348 # super supertype fix for input steps in workflows.
646b05282962 Uploaded
jorrit
parents:
diff changeset
349 if 'data' not in self.datatypes_by_extension:
646b05282962 Uploaded
jorrit
parents:
diff changeset
350 self.datatypes_by_extension['data'] = data.Data()
646b05282962 Uploaded
jorrit
parents:
diff changeset
351 self.mimetypes_by_extension['data'] = 'application/octet-stream'
646b05282962 Uploaded
jorrit
parents:
diff changeset
352 # Default values - the order in which we attempt to determine data types is critical
646b05282962 Uploaded
jorrit
parents:
diff changeset
353 # because some formats are much more flexibly defined than others.
646b05282962 Uploaded
jorrit
parents:
diff changeset
354 if len(self.sniff_order) < 1:
646b05282962 Uploaded
jorrit
parents:
diff changeset
355 self.sniff_order = [
646b05282962 Uploaded
jorrit
parents:
diff changeset
356 binary.Bam(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
357 binary.Sff(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
358 xml.BlastXml(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
359 xml.GenericXml(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
360 sequence.Maf(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
361 sequence.Lav(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
362 sequence.csFasta(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
363 qualityscore.QualityScoreSOLiD(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
364 qualityscore.QualityScore454(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
365 sequence.Fasta(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
366 sequence.Fastq(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
367 interval.Wiggle(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
368 images.Html(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
369 sequence.Axt(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
370 interval.Bed(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
371 interval.CustomTrack(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
372 interval.Gtf(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
373 interval.Gff(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
374 interval.Gff3(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
375 tabular.Pileup(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
376 interval.Interval(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
377 tabular.Sam(),
646b05282962 Uploaded
jorrit
parents:
diff changeset
378 tabular.Eland()
646b05282962 Uploaded
jorrit
parents:
diff changeset
379 ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
380 def append_to_sniff_order():
646b05282962 Uploaded
jorrit
parents:
diff changeset
381 # Just in case any supported data types are not included in the config's sniff_order section.
646b05282962 Uploaded
jorrit
parents:
diff changeset
382 for ext in self.datatypes_by_extension:
646b05282962 Uploaded
jorrit
parents:
diff changeset
383 datatype = self.datatypes_by_extension[ext]
646b05282962 Uploaded
jorrit
parents:
diff changeset
384 included = False
646b05282962 Uploaded
jorrit
parents:
diff changeset
385 for atype in self.sniff_order:
646b05282962 Uploaded
jorrit
parents:
diff changeset
386 if isinstance(atype, datatype.__class__):
646b05282962 Uploaded
jorrit
parents:
diff changeset
387 included = True
646b05282962 Uploaded
jorrit
parents:
diff changeset
388 break
646b05282962 Uploaded
jorrit
parents:
diff changeset
389 if not included:
646b05282962 Uploaded
jorrit
parents:
diff changeset
390 self.sniff_order.append(datatype)
646b05282962 Uploaded
jorrit
parents:
diff changeset
391 append_to_sniff_order()
646b05282962 Uploaded
jorrit
parents:
diff changeset
392 def get_available_tracks(self):
646b05282962 Uploaded
jorrit
parents:
diff changeset
393 return self.available_tracks
646b05282962 Uploaded
jorrit
parents:
diff changeset
394 def get_mimetype_by_extension(self, ext, default = 'application/octet-stream' ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
395 """Returns a mimetype based on an extension"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
396 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
397 mimetype = self.mimetypes_by_extension[ext]
646b05282962 Uploaded
jorrit
parents:
diff changeset
398 except KeyError:
646b05282962 Uploaded
jorrit
parents:
diff changeset
399 #datatype was never declared
646b05282962 Uploaded
jorrit
parents:
diff changeset
400 mimetype = default
646b05282962 Uploaded
jorrit
parents:
diff changeset
401 self.log.warning('unknown mimetype in data factory %s' % ext)
646b05282962 Uploaded
jorrit
parents:
diff changeset
402 return mimetype
646b05282962 Uploaded
jorrit
parents:
diff changeset
403 def get_datatype_by_extension(self, ext ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
404 """Returns a datatype based on an extension"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
405 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
406 builder = self.datatypes_by_extension[ext]
646b05282962 Uploaded
jorrit
parents:
diff changeset
407 except KeyError:
646b05282962 Uploaded
jorrit
parents:
diff changeset
408 builder = data.Text()
646b05282962 Uploaded
jorrit
parents:
diff changeset
409 return builder
646b05282962 Uploaded
jorrit
parents:
diff changeset
410 def change_datatype(self, data, ext, set_meta = True ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
411 data.extension = ext
646b05282962 Uploaded
jorrit
parents:
diff changeset
412 # call init_meta and copy metadata from itself. The datatype
646b05282962 Uploaded
jorrit
parents:
diff changeset
413 # being converted *to* will handle any metadata copying and
646b05282962 Uploaded
jorrit
parents:
diff changeset
414 # initialization.
646b05282962 Uploaded
jorrit
parents:
diff changeset
415 if data.has_data():
646b05282962 Uploaded
jorrit
parents:
diff changeset
416 data.set_size()
646b05282962 Uploaded
jorrit
parents:
diff changeset
417 data.init_meta( copy_from=data )
646b05282962 Uploaded
jorrit
parents:
diff changeset
418 if set_meta:
646b05282962 Uploaded
jorrit
parents:
diff changeset
419 #metadata is being set internally
646b05282962 Uploaded
jorrit
parents:
diff changeset
420 data.set_meta( overwrite = False )
646b05282962 Uploaded
jorrit
parents:
diff changeset
421 data.set_peek()
646b05282962 Uploaded
jorrit
parents:
diff changeset
422 return data
646b05282962 Uploaded
jorrit
parents:
diff changeset
423 def old_change_datatype(self, data, ext):
646b05282962 Uploaded
jorrit
parents:
diff changeset
424 """Creates and returns a new datatype based on an existing data and an extension"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
425 newdata = factory(ext)(id=data.id)
646b05282962 Uploaded
jorrit
parents:
diff changeset
426 for key, value in data.__dict__.items():
646b05282962 Uploaded
jorrit
parents:
diff changeset
427 setattr(newdata, key, value)
646b05282962 Uploaded
jorrit
parents:
diff changeset
428 newdata.ext = ext
646b05282962 Uploaded
jorrit
parents:
diff changeset
429 return newdata
646b05282962 Uploaded
jorrit
parents:
diff changeset
430 def load_datatype_converters( self, toolbox, installed_repository_dict=None, deactivate=False ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
431 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
432 If deactivate is False, add datatype converters from self.converters or self.proprietary_converters
646b05282962 Uploaded
jorrit
parents:
diff changeset
433 to the calling app's toolbox. If deactivate is True, eliminates relevant converters from the calling
646b05282962 Uploaded
jorrit
parents:
diff changeset
434 app's toolbox.
646b05282962 Uploaded
jorrit
parents:
diff changeset
435 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
436 if installed_repository_dict:
646b05282962 Uploaded
jorrit
parents:
diff changeset
437 # Load converters defined by datatypes_conf.xml included in installed tool shed repository.
646b05282962 Uploaded
jorrit
parents:
diff changeset
438 converters = self.proprietary_converters
646b05282962 Uploaded
jorrit
parents:
diff changeset
439 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
440 # Load converters defined by local datatypes_conf.xml.
646b05282962 Uploaded
jorrit
parents:
diff changeset
441 converters = self.converters
646b05282962 Uploaded
jorrit
parents:
diff changeset
442 for elem in converters:
646b05282962 Uploaded
jorrit
parents:
diff changeset
443 tool_config = elem[0]
646b05282962 Uploaded
jorrit
parents:
diff changeset
444 source_datatype = elem[1]
646b05282962 Uploaded
jorrit
parents:
diff changeset
445 target_datatype = elem[2]
646b05282962 Uploaded
jorrit
parents:
diff changeset
446 if installed_repository_dict:
646b05282962 Uploaded
jorrit
parents:
diff changeset
447 converter_path = installed_repository_dict[ 'converter_path' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
448 config_path = os.path.join( converter_path, tool_config )
646b05282962 Uploaded
jorrit
parents:
diff changeset
449 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
450 config_path = os.path.join( self.converters_path, tool_config )
646b05282962 Uploaded
jorrit
parents:
diff changeset
451 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
452 converter = toolbox.load_tool( config_path )
646b05282962 Uploaded
jorrit
parents:
diff changeset
453 if installed_repository_dict:
646b05282962 Uploaded
jorrit
parents:
diff changeset
454 # If the converter is included in an installed tool shed repository, set the tool
646b05282962 Uploaded
jorrit
parents:
diff changeset
455 # shed related tool attributes.
646b05282962 Uploaded
jorrit
parents:
diff changeset
456 converter.tool_shed = installed_repository_dict[ 'tool_shed' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
457 converter.repository_name = installed_repository_dict[ 'repository_name' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
458 converter.repository_owner = installed_repository_dict[ 'repository_owner' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
459 converter.installed_changeset_revision = installed_repository_dict[ 'installed_changeset_revision' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
460 converter.old_id = converter.id
646b05282962 Uploaded
jorrit
parents:
diff changeset
461 # The converter should be included in the list of tools defined in tool_dicts.
646b05282962 Uploaded
jorrit
parents:
diff changeset
462 tool_dicts = installed_repository_dict[ 'tool_dicts' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
463 for tool_dict in tool_dicts:
646b05282962 Uploaded
jorrit
parents:
diff changeset
464 if tool_dict[ 'id' ] == converter.id:
646b05282962 Uploaded
jorrit
parents:
diff changeset
465 converter.guid = tool_dict[ 'guid' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
466 converter.id = tool_dict[ 'guid' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
467 break
646b05282962 Uploaded
jorrit
parents:
diff changeset
468 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
469 del toolbox.tools_by_id[ converter.id ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
470 if source_datatype in self.datatype_converters:
646b05282962 Uploaded
jorrit
parents:
diff changeset
471 del self.datatype_converters[ source_datatype ][ target_datatype ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
472 self.log.debug( "Deactivated converter: %s", converter.id )
646b05282962 Uploaded
jorrit
parents:
diff changeset
473 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
474 toolbox.tools_by_id[ converter.id ] = converter
646b05282962 Uploaded
jorrit
parents:
diff changeset
475 if source_datatype not in self.datatype_converters:
646b05282962 Uploaded
jorrit
parents:
diff changeset
476 self.datatype_converters[ source_datatype ] = odict()
646b05282962 Uploaded
jorrit
parents:
diff changeset
477 self.datatype_converters[ source_datatype ][ target_datatype ] = converter
646b05282962 Uploaded
jorrit
parents:
diff changeset
478 self.log.debug( "Loaded converter: %s", converter.id )
646b05282962 Uploaded
jorrit
parents:
diff changeset
479 except Exception, e:
646b05282962 Uploaded
jorrit
parents:
diff changeset
480 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
481 self.log.exception( "Error deactivating converter (%s): %s" % ( config_path, str( e ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
482 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
483 self.log.exception( "Error loading converter (%s): %s" % ( config_path, str( e ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
484 def load_display_applications( self, installed_repository_dict=None, deactivate=False ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
485 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
486 If deactivate is False, add display applications from self.display_app_containers or
646b05282962 Uploaded
jorrit
parents:
diff changeset
487 self.proprietary_display_app_containers to appropriate datatypes. If deactivate is
646b05282962 Uploaded
jorrit
parents:
diff changeset
488 True, eliminates relevant display applications from appropriate datatypes.
646b05282962 Uploaded
jorrit
parents:
diff changeset
489 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
490 if installed_repository_dict:
646b05282962 Uploaded
jorrit
parents:
diff changeset
491 # Load display applications defined by datatypes_conf.xml included in installed tool shed repository.
646b05282962 Uploaded
jorrit
parents:
diff changeset
492 datatype_elems = self.proprietary_display_app_containers
646b05282962 Uploaded
jorrit
parents:
diff changeset
493 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
494 # Load display applications defined by local datatypes_conf.xml.
646b05282962 Uploaded
jorrit
parents:
diff changeset
495 datatype_elems = self.display_app_containers
646b05282962 Uploaded
jorrit
parents:
diff changeset
496 for elem in datatype_elems:
646b05282962 Uploaded
jorrit
parents:
diff changeset
497 extension = elem.get( 'extension', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
498 for display_app in elem.findall( 'display' ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
499 display_file = display_app.get( 'file', None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
500 if installed_repository_dict:
646b05282962 Uploaded
jorrit
parents:
diff changeset
501 display_path = installed_repository_dict[ 'display_path' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
502 display_file_head, display_file_tail = os.path.split( display_file )
646b05282962 Uploaded
jorrit
parents:
diff changeset
503 config_path = os.path.join( display_path, display_file_tail )
646b05282962 Uploaded
jorrit
parents:
diff changeset
504 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
505 config_path = os.path.join( self.display_applications_path, display_file )
646b05282962 Uploaded
jorrit
parents:
diff changeset
506 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
507 inherit = galaxy.util.string_as_bool( display_app.get( 'inherit', 'False' ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
508 display_app = DisplayApplication.from_file( config_path, self )
646b05282962 Uploaded
jorrit
parents:
diff changeset
509 if display_app:
646b05282962 Uploaded
jorrit
parents:
diff changeset
510 if display_app.id in self.display_applications:
646b05282962 Uploaded
jorrit
parents:
diff changeset
511 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
512 del self.display_applications[ display_app.id ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
513 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
514 # If we already loaded this display application, we'll use the first one loaded.
646b05282962 Uploaded
jorrit
parents:
diff changeset
515 display_app = self.display_applications[ display_app.id ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
516 elif installed_repository_dict:
646b05282962 Uploaded
jorrit
parents:
diff changeset
517 # If the display application is included in an installed tool shed repository,
646b05282962 Uploaded
jorrit
parents:
diff changeset
518 # set the tool shed related tool attributes.
646b05282962 Uploaded
jorrit
parents:
diff changeset
519 display_app.tool_shed = installed_repository_dict[ 'tool_shed' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
520 display_app.repository_name = installed_repository_dict[ 'repository_name' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
521 display_app.repository_owner = installed_repository_dict[ 'repository_owner' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
522 display_app.installed_changeset_revision = installed_repository_dict[ 'installed_changeset_revision' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
523 display_app.old_id = display_app.id
646b05282962 Uploaded
jorrit
parents:
diff changeset
524 # The display application should be included in the list of tools defined in tool_dicts.
646b05282962 Uploaded
jorrit
parents:
diff changeset
525 tool_dicts = installed_repository_dict[ 'tool_dicts' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
526 for tool_dict in tool_dicts:
646b05282962 Uploaded
jorrit
parents:
diff changeset
527 if tool_dict[ 'id' ] == display_app.id:
646b05282962 Uploaded
jorrit
parents:
diff changeset
528 display_app.guid = tool_dict[ 'guid' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
529 display_app.id = tool_dict[ 'guid' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
530 break
646b05282962 Uploaded
jorrit
parents:
diff changeset
531 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
532 del self.display_applications[ display_app.id ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
533 del self.datatypes_by_extension[ extension ].display_applications[ display_app.id ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
534 if inherit and ( self.datatypes_by_extension[ extension ], display_app ) in self.inherit_display_application_by_class:
646b05282962 Uploaded
jorrit
parents:
diff changeset
535 self.inherit_display_application_by_class.remove( ( self.datatypes_by_extension[ extension ], display_app ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
536 self.log.debug( "Deactivated display application '%s' for datatype '%s'." % ( display_app.id, extension ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
537 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
538 self.display_applications[ display_app.id ] = display_app
646b05282962 Uploaded
jorrit
parents:
diff changeset
539 self.datatypes_by_extension[ extension ].add_display_application( display_app )
646b05282962 Uploaded
jorrit
parents:
diff changeset
540 if inherit and ( self.datatypes_by_extension[ extension ], display_app ) not in self.inherit_display_application_by_class:
646b05282962 Uploaded
jorrit
parents:
diff changeset
541 self.inherit_display_application_by_class.append( ( self.datatypes_by_extension[ extension ], display_app ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
542 self.log.debug( "Loaded display application '%s' for datatype '%s', inherit=%s." % ( display_app.id, extension, inherit ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
543 except Exception, e:
646b05282962 Uploaded
jorrit
parents:
diff changeset
544 if deactivate:
646b05282962 Uploaded
jorrit
parents:
diff changeset
545 self.log.exception( "Error deactivating display application (%s): %s" % ( config_path, str( e ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
546 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
547 self.log.exception( "Error loading display application (%s): %s" % ( config_path, str( e ) ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
548 # Handle display_application subclass inheritance.
646b05282962 Uploaded
jorrit
parents:
diff changeset
549 for extension, d_type1 in self.datatypes_by_extension.iteritems():
646b05282962 Uploaded
jorrit
parents:
diff changeset
550 for d_type2, display_app in self.inherit_display_application_by_class:
646b05282962 Uploaded
jorrit
parents:
diff changeset
551 current_app = d_type1.get_display_application( display_app.id, None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
552 if current_app is None and isinstance( d_type1, type( d_type2 ) ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
553 self.log.debug( "Adding inherited display application '%s' to datatype '%s'" % ( display_app.id, extension ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
554 d_type1.add_display_application( display_app )
646b05282962 Uploaded
jorrit
parents:
diff changeset
555 def load_external_metadata_tool( self, toolbox ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
556 """Adds a tool which is used to set external metadata"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
557 # We need to be able to add a job to the queue to set metadata. The queue will currently only accept jobs with an associated
646b05282962 Uploaded
jorrit
parents:
diff changeset
558 # tool. We'll create a special tool to be used for Auto-Detecting metadata; this is less than ideal, but effective
646b05282962 Uploaded
jorrit
parents:
diff changeset
559 # Properly building a tool without relying on parsing an XML file is near impossible...so we'll create a temporary file
646b05282962 Uploaded
jorrit
parents:
diff changeset
560 tool_xml_text = """
646b05282962 Uploaded
jorrit
parents:
diff changeset
561 <tool id="__SET_METADATA__" name="Set External Metadata" version="1.0.1" tool_type="set_metadata">
646b05282962 Uploaded
jorrit
parents:
diff changeset
562 <type class="SetMetadataTool" module="galaxy.tools"/>
646b05282962 Uploaded
jorrit
parents:
diff changeset
563 <action module="galaxy.tools.actions.metadata" class="SetMetadataToolAction"/>
646b05282962 Uploaded
jorrit
parents:
diff changeset
564 <command>$__SET_EXTERNAL_METADATA_COMMAND_LINE__</command>
646b05282962 Uploaded
jorrit
parents:
diff changeset
565 <inputs>
646b05282962 Uploaded
jorrit
parents:
diff changeset
566 <param format="data" name="input1" type="data" label="File to set metadata on."/>
646b05282962 Uploaded
jorrit
parents:
diff changeset
567 <param name="__ORIGINAL_DATASET_STATE__" type="hidden" value=""/>
646b05282962 Uploaded
jorrit
parents:
diff changeset
568 <param name="__SET_EXTERNAL_METADATA_COMMAND_LINE__" type="hidden" value=""/>
646b05282962 Uploaded
jorrit
parents:
diff changeset
569 </inputs>
646b05282962 Uploaded
jorrit
parents:
diff changeset
570 </tool>
646b05282962 Uploaded
jorrit
parents:
diff changeset
571 """
646b05282962 Uploaded
jorrit
parents:
diff changeset
572 tmp_name = tempfile.NamedTemporaryFile()
646b05282962 Uploaded
jorrit
parents:
diff changeset
573 tmp_name.write( tool_xml_text )
646b05282962 Uploaded
jorrit
parents:
diff changeset
574 tmp_name.flush()
646b05282962 Uploaded
jorrit
parents:
diff changeset
575 set_meta_tool = toolbox.load_tool( tmp_name.name )
646b05282962 Uploaded
jorrit
parents:
diff changeset
576 toolbox.tools_by_id[ set_meta_tool.id ] = set_meta_tool
646b05282962 Uploaded
jorrit
parents:
diff changeset
577 self.set_external_metadata_tool = set_meta_tool
646b05282962 Uploaded
jorrit
parents:
diff changeset
578 self.log.debug( "Loaded external metadata tool: %s", self.set_external_metadata_tool.id )
646b05282962 Uploaded
jorrit
parents:
diff changeset
579 def get_converters_by_datatype(self, ext):
646b05282962 Uploaded
jorrit
parents:
diff changeset
580 """Returns available converters by source type"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
581 converters = odict()
646b05282962 Uploaded
jorrit
parents:
diff changeset
582 source_datatype = type(self.get_datatype_by_extension(ext))
646b05282962 Uploaded
jorrit
parents:
diff changeset
583 for ext2, dict in self.datatype_converters.items():
646b05282962 Uploaded
jorrit
parents:
diff changeset
584 converter_datatype = type(self.get_datatype_by_extension(ext2))
646b05282962 Uploaded
jorrit
parents:
diff changeset
585 if issubclass(source_datatype, converter_datatype):
646b05282962 Uploaded
jorrit
parents:
diff changeset
586 converters.update(dict)
646b05282962 Uploaded
jorrit
parents:
diff changeset
587 #Ensure ext-level converters are present
646b05282962 Uploaded
jorrit
parents:
diff changeset
588 if ext in self.datatype_converters.keys():
646b05282962 Uploaded
jorrit
parents:
diff changeset
589 converters.update(self.datatype_converters[ext])
646b05282962 Uploaded
jorrit
parents:
diff changeset
590 return converters
646b05282962 Uploaded
jorrit
parents:
diff changeset
591 def get_converter_by_target_type(self, source_ext, target_ext):
646b05282962 Uploaded
jorrit
parents:
diff changeset
592 """Returns a converter based on source and target datatypes"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
593 converters = self.get_converters_by_datatype(source_ext)
646b05282962 Uploaded
jorrit
parents:
diff changeset
594 if target_ext in converters.keys():
646b05282962 Uploaded
jorrit
parents:
diff changeset
595 return converters[target_ext]
646b05282962 Uploaded
jorrit
parents:
diff changeset
596 return None
646b05282962 Uploaded
jorrit
parents:
diff changeset
597 def find_conversion_destination_for_dataset_by_extensions( self, dataset, accepted_formats, converter_safe = True ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
598 """Returns ( target_ext, existing converted dataset )"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
599 for convert_ext in self.get_converters_by_datatype( dataset.ext ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
600 if isinstance( self.get_datatype_by_extension( convert_ext ), accepted_formats ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
601 converted_dataset = dataset.get_converted_files_by_type( convert_ext )
646b05282962 Uploaded
jorrit
parents:
diff changeset
602 if converted_dataset:
646b05282962 Uploaded
jorrit
parents:
diff changeset
603 ret_data = converted_dataset
646b05282962 Uploaded
jorrit
parents:
diff changeset
604 elif not converter_safe:
646b05282962 Uploaded
jorrit
parents:
diff changeset
605 continue
646b05282962 Uploaded
jorrit
parents:
diff changeset
606 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
607 ret_data = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
608 return ( convert_ext, ret_data )
646b05282962 Uploaded
jorrit
parents:
diff changeset
609 return ( None, None )
646b05282962 Uploaded
jorrit
parents:
diff changeset
610 def get_composite_extensions( self ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
611 return [ ext for ( ext, d_type ) in self.datatypes_by_extension.iteritems() if d_type.composite_type is not None ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
612 def get_upload_metadata_params( self, context, group, tool ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
613 """Returns dict of case value:inputs for metadata conditional for upload tool"""
646b05282962 Uploaded
jorrit
parents:
diff changeset
614 rval = {}
646b05282962 Uploaded
jorrit
parents:
diff changeset
615 for ext, d_type in self.datatypes_by_extension.iteritems():
646b05282962 Uploaded
jorrit
parents:
diff changeset
616 inputs = []
646b05282962 Uploaded
jorrit
parents:
diff changeset
617 for meta_name, meta_spec in d_type.metadata_spec.iteritems():
646b05282962 Uploaded
jorrit
parents:
diff changeset
618 if meta_spec.set_in_upload:
646b05282962 Uploaded
jorrit
parents:
diff changeset
619 help_txt = meta_spec.desc
646b05282962 Uploaded
jorrit
parents:
diff changeset
620 if not help_txt or help_txt == meta_name:
646b05282962 Uploaded
jorrit
parents:
diff changeset
621 help_txt = ""
646b05282962 Uploaded
jorrit
parents:
diff changeset
622 inputs.append( '<param type="text" name="%s" label="Set metadata value for &quot;%s&quot;" value="%s" help="%s"/>' % ( meta_name, meta_name, meta_spec.default, help_txt ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
623 rval[ ext ] = "\n".join( inputs )
646b05282962 Uploaded
jorrit
parents:
diff changeset
624 if 'auto' not in rval and 'txt' in rval: #need to manually add 'auto' datatype
646b05282962 Uploaded
jorrit
parents:
diff changeset
625 rval[ 'auto' ] = rval[ 'txt' ]
646b05282962 Uploaded
jorrit
parents:
diff changeset
626 return rval
646b05282962 Uploaded
jorrit
parents:
diff changeset
627 @property
646b05282962 Uploaded
jorrit
parents:
diff changeset
628 def integrated_datatypes_configs( self ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
629 if self.xml_filename and os.path.isfile( self.xml_filename ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
630 return self.xml_filename
646b05282962 Uploaded
jorrit
parents:
diff changeset
631 self.to_xml_file()
646b05282962 Uploaded
jorrit
parents:
diff changeset
632 return self.xml_filename
646b05282962 Uploaded
jorrit
parents:
diff changeset
633 def to_xml_file( self ):
646b05282962 Uploaded
jorrit
parents:
diff changeset
634 if self.xml_filename is not None:
646b05282962 Uploaded
jorrit
parents:
diff changeset
635 # If persisted previously, attempt to remove
646b05282962 Uploaded
jorrit
parents:
diff changeset
636 # the temporary file in which we were written.
646b05282962 Uploaded
jorrit
parents:
diff changeset
637 try:
646b05282962 Uploaded
jorrit
parents:
diff changeset
638 os.unlink( self.xml_filename )
646b05282962 Uploaded
jorrit
parents:
diff changeset
639 except:
646b05282962 Uploaded
jorrit
parents:
diff changeset
640 pass
646b05282962 Uploaded
jorrit
parents:
diff changeset
641 self.xml_filename = None
646b05282962 Uploaded
jorrit
parents:
diff changeset
642 fd, filename = tempfile.mkstemp()
646b05282962 Uploaded
jorrit
parents:
diff changeset
643 self.xml_filename = os.path.abspath( filename )
646b05282962 Uploaded
jorrit
parents:
diff changeset
644 if self.converters_path_attr:
646b05282962 Uploaded
jorrit
parents:
diff changeset
645 converters_path_str = ' converters_path="%s"' % self.converters_path_attr
646b05282962 Uploaded
jorrit
parents:
diff changeset
646 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
647 converters_path_str = ''
646b05282962 Uploaded
jorrit
parents:
diff changeset
648 if self.display_path_attr:
646b05282962 Uploaded
jorrit
parents:
diff changeset
649 display_path_str = ' display_path="%s"' % self.display_path_attr
646b05282962 Uploaded
jorrit
parents:
diff changeset
650 else:
646b05282962 Uploaded
jorrit
parents:
diff changeset
651 display_path_str = ''
646b05282962 Uploaded
jorrit
parents:
diff changeset
652 os.write( fd, '<?xml version="1.0"?>\n' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
653 os.write( fd, '<datatypes>\n' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
654 os.write( fd, '<registration%s%s>\n' % ( converters_path_str, display_path_str ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
655 for elem in self.datatype_elems:
646b05282962 Uploaded
jorrit
parents:
diff changeset
656 os.write( fd, '%s' % galaxy.util.xml_to_string( elem ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
657 os.write( fd, '</registration>\n' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
658 os.write( fd, '<sniffers>\n' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
659 for elem in self.sniffer_elems:
646b05282962 Uploaded
jorrit
parents:
diff changeset
660 os.write( fd, '%s' % galaxy.util.xml_to_string( elem ) )
646b05282962 Uploaded
jorrit
parents:
diff changeset
661 os.write( fd, '</sniffers>\n' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
662 os.write( fd, '</datatypes>\n' )
646b05282962 Uploaded
jorrit
parents:
diff changeset
663 os.close( fd )
646b05282962 Uploaded
jorrit
parents:
diff changeset
664 os.chmod( self.xml_filename, 0644 )