Mercurial > repos > sanbi-uwc > neo4j_datatypes
comparison neo4j.py @ 19:2287178087eb draft
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc/tree/master/datatypes/neo4j_datatypes commit 0f90b9e2eae026ccea40bcc164f142313af7d397
| author | sanbi-uwc |
|---|---|
| date | Thu, 09 Jun 2016 05:52:56 -0400 |
| parents | 3472a853df10 |
| children | 45b969e6ff9a |
comparison
equal
deleted
inserted
replaced
| 18:3472a853df10 | 19:2287178087eb |
|---|---|
| 1 """ | 1 """ |
| 2 Neo4j Composite Dataset | 2 Neo4j Composite Dataset |
| 3 """ | 3 """ |
| 4 import logging | 4 import logging |
| 5 import sys | 5 import sys |
| 6 import os | |
| 7 | 6 |
| 8 from galaxy.datatypes.images import Html | 7 from galaxy.datatypes.images import Html |
| 9 from galaxy.datatypes.data import Data, Text | 8 from galaxy.datatypes.data import Data, Text |
| 10 #from galaxy.datatypes.metadata import MetadataElement | 9 from galaxy.datatypes.metadata import MetadataElement |
| 10 import shutil | |
| 11 import os | |
| 11 | 12 |
| 12 gal_Log = logging.getLogger(__name__) | 13 gal_Log = logging.getLogger(__name__) |
| 13 verbose = True | 14 verbose = True |
| 14 | 15 |
| 15 | 16 |
| 17 """ | 18 """ |
| 18 base class to use for neostore datatypes | 19 base class to use for neostore datatypes |
| 19 derived from html - composite datatype elements | 20 derived from html - composite datatype elements |
| 20 stored in extra files path | 21 stored in extra files path |
| 21 """ | 22 """ |
| 23 MetadataElement( name='neostore', default=None, desc='Neo4j NeoStore File', readonly=True, visible=True, set_in_upload=True, no_value=None ) | |
| 24 MetadataElement( name='neostore_count_file', default=None, desc='Neo4j Count File', readonly=True, visible=True, set_in_upload=True, no_value=None ) | |
| 25 MetadataElement( name="neostore_labeltokenstore_db_file", default=None, desc="Neostore LabelTokenStore File", readonly=True, visible=True, no_value=None ) | |
| 26 MetadataElement( name="neostore_nodestore_file", default=None, desc="Neostore NodeStore File", readonly=True, visible=True, no_value=None) | |
| 27 MetadataElement( name="neostore_propertystore_file", default=None, desc="Neostore Property Store File", readonly=True, visible=True, no_value=None) | |
| 28 MetadataElement( name="neostore_relationship_group_file", default=None, desc="Neostore Relationship Group File", readonly=True, visible=True, no_value=None) | |
| 29 MetadataElement( name="neostore_relationship_file", default=None, desc="Neostore Relationship File", readonly=True, visible=True, no_value=None) | |
| 30 MetadataElement( name="neostore_relationship_type_file", default=None, desc="Neostore Relationship Type File", readonly=True, visible=True, no_value=None) | |
| 31 MetadataElement( name="neostore_schema_store_file", default=None, desc="Neostore Schema Store File", readonly=True, visible=True, no_value=None) | |
| 32 MetadataElement( name="neostore_transaction_db_file", default=None, desc="Neostore Transaction File", readonly=True, visible=True, no_value=None) | |
| 22 | 33 |
| 23 def get_mime(self): | 34 def get_mime(self): |
| 24 """Returns the mime type of the datatype""" | 35 """Returns the mime type of the datatype""" |
| 25 return 'text/html' | 36 return 'text/html' |
| 26 | 37 |
| 43 def display_data(self, trans, data, preview=False, filename=None, | 54 def display_data(self, trans, data, preview=False, filename=None, |
| 44 to_ext=None, size=None, offset=None, **kwd): | 55 to_ext=None, size=None, offset=None, **kwd): |
| 45 """Documented as an old display method, but still gets called via tests etc | 56 """Documented as an old display method, but still gets called via tests etc |
| 46 This allows us to format the data shown in the central pane via the "eye" icon. | 57 This allows us to format the data shown in the central pane via the "eye" icon. |
| 47 """ | 58 """ |
| 48 if filename is not None and filename != "index": | 59 trans.response.set_content_type(data.get_mime()) |
| 49 # Change nothing - important for the unit tests to access child files: | 60 trans.log_event( "Display dataset id: %s" % str( data.id ) ) |
| 50 return Data.display_data(self, trans, data, preview, filename, | |
| 51 to_ext, size, offset, **kwd) | |
| 52 if self.file_ext == "neostore": | |
| 53 title = "This is a NEO4J database" | |
| 54 msg = "" | |
| 55 try: | |
| 56 # Try to use any text recorded in the dummy index file: | |
| 57 handle = open(data.file_name, "rU") | |
| 58 msg = handle.read().strip() | |
| 59 handle.close() | |
| 60 except Exception: | |
| 61 pass | |
| 62 if not msg: | |
| 63 msg = title | |
| 64 # Galaxy assumes HTML for the display of composite datatypes, | |
| 65 return "<html><head><title>%s</title></head><body><pre>%s</pre></body></html>" % (title, msg) | |
| 66 | 61 |
| 62 # the target directory name | |
| 63 dir_name = str(os.path.dirname( trans.app.object_store.get_filename(data.dataset) )) + '/dataset_{}_files/neo4jdb'.format( data.dataset.id ) | |
| 64 | |
| 65 # generate unique filename for this dataset | |
| 66 valid_chars = '.,^_-()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
| 67 fname = ''.join(c in valid_chars and c or '_' for c in data.name)[0:150] | |
| 68 | |
| 69 # zip the target directory (dir_name) using the fname | |
| 70 shutil.make_archive(fname, 'zip', dir_name) | |
| 71 download_zip = fname + '.zip' | |
| 72 | |
| 73 # setup headers for the download | |
| 74 trans.response.headers['Content-Length'] = int( os.stat( download_zip ).st_size ) | |
| 75 trans.response.set_content_type( "application/octet-stream" ) # force octet-stream so Safari doesn't append mime extensions to filename | |
| 76 trans.response.headers["Content-Disposition"] = 'attachment; filename="Galaxy%s-[%s].%s"' % (data.hid, download_zip , "zip") | |
| 77 | |
| 78 return open( download_zip ) | |
| 67 | 79 |
| 68 class Neo4jDB(Neo4j, Data): | 80 class Neo4jDB(Neo4j, Data): |
| 69 """Class for neo4jDB database files.""" | 81 """Class for neo4jDB database files.""" |
| 70 file_ext = 'neostore' | 82 file_ext = 'neostore' |
| 71 composite_type = 'basic' | 83 composite_type = 'basic' |
