changeset 9:e36c60d13c94 draft

Uploaded v0.0.18, tweak display_data for running tests
author peterjc
date Mon, 25 Nov 2013 10:55:07 -0500
parents 7ceb2ae30ff4
children 939a600f45e9
files README.rst blast.py
diffstat 2 files changed, 50 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/README.rst	Tue Oct 08 05:06:22 2013 -0400
+++ b/README.rst	Mon Nov 25 10:55:07 2013 -0500
@@ -39,6 +39,8 @@
         - Development moved to GitHub, https://github.com/peterjc/galaxy_blast
         - Nucleotide database definition aware of MegaBLAST index superheader
 v0.0.17 - Add maskinfo-asn1 and maskinfo-asn1-binary sub-datatypes
+v0.0.18 - Add retries to BLAST XML merge code.
+        - Modify display_data method to allow unit tests to function.
 ======= ======================================================================
 
 
--- a/blast.py	Tue Oct 08 05:06:22 2013 -0400
+++ b/blast.py	Mon Nov 25 10:55:07 2013 -0500
@@ -7,6 +7,11 @@
 from galaxy.datatypes.xml import GenericXml
 from galaxy.datatypes.metadata import MetadataElement
 
+from time import sleep
+import os
+import logging
+
+log = logging.getLogger(__name__)
 
 class BlastXml( GenericXml ):
     """NCBI Blast XML Output data"""
@@ -64,13 +69,26 @@
         out = open(output_file, "w")
         h = None
         for f in split_files:
+            if not os.path.isfile(f):
+                log.warning("BLAST XML file %s missing, retry in 1s..." % f)
+                sleep(1)
+            if not os.path.isfile(f):
+                log.error("BLAST XML file %s missing" % f)
+                raise ValueError("BLAST XML file %s missing" % f)
             h = open(f)
             body = False
             header = h.readline()
             if not header:
                 out.close()
                 h.close()
-                raise ValueError("BLAST XML file %s was empty" % f)
+                #Retry, could be transient error with networked file system...
+                log.warning("BLAST XML file %s empty, retry in 1s..." % f)
+                sleep(1)
+                h = open(f)
+                header = h.readline()
+                if not header:
+                    log.error("BLAST XML file %s was empty" % f)
+                    raise ValueError("BLAST XML file %s was empty" % f)
             if header.strip() != '<?xml version="1.0"?>':
                 out.write(header) #for diagnosis
                 out.close()
@@ -150,15 +168,34 @@
 
     def display_data(self, trans, data, preview=False, filename=None,
                      to_ext=None, size=None, offset=None, **kwd):
-        """Apparently an old display method, but still gets called.
+        """Documented as an old display method, but still gets called via tests etc
 
         This allows us to format the data shown in the central pane via the "eye" icon.
         """
-        return "This is a BLAST database."
-
-    def get_mime(self):
-        """Returns the mime type of the datatype (pretend it is text for peek)"""
-        return 'text/plain'
+        if filename is not None and filename != "index":
+            #Change nothing - important for the unit tests to access child files:
+            return Data.display_data(self, trans, data, preview, filename,
+                                     to_ext, size, offset, **kwd)
+        if self.file_ext == "blastdbn":
+            title = "This is a nucleotide BLAST database"
+        elif self.file_ext =="blastdbp":
+            title = "This is a protein BLAST database"
+        else:
+            #Error?                                                                                                                                                                     
+            title = "This is a BLAST database."
+        msg = ""
+        try:
+            #Try to use any text recorded in the dummy index file:
+            handle = open(data.file_name, "rU")
+            msg = handle.read().strip()
+            handle.close()
+        except Exception, err:
+            #msg = str(err)
+            pass
+        if not msg:
+            msg = title
+        #Galaxy assumes HTML for the display of composite datatypes,
+        return "<html><head><title>%s</title></head><body><pre>%s</pre></body></html>" % (title, msg)
 
     def merge(split_files, output_file):
         """Merge BLAST databases (not implemented for now)."""
@@ -174,7 +211,8 @@
 class BlastNucDb( _BlastDb, Data ):
     """Class for nucleotide BLAST database files."""
     file_ext = 'blastdbn'
-    composite_type ='basic'
+    allow_datatype_change = False
+    composite_type = 'basic'
 
     def __init__(self, **kwd):
         Data.__init__(self, **kwd)
@@ -197,19 +235,12 @@
 #        self.add_composite_file('blastdb.nac', is_binary=True, optional=True) # multiple byte order for a WriteDB column
 # The previous 3 lines should be repeated for each WriteDB column, with filename extensions like ('.nba', '.nbb', '.nbc'), ('.nca', '.ncb', '.ncc'), etc.
 
-    def display_data(self, trans, data, preview=False, filename=None,
-                     to_ext=None, size=None, offset=None, **kwd):
-        """Apparently an old display method, but still gets called.
-
-        This allows us to format the data shown in the central pane via the "eye" icon.
-        """
-        return "This is a BLAST nucleotide database."
-
 
 class BlastProtDb( _BlastDb, Data ):
     """Class for protein BLAST database files."""
     file_ext = 'blastdbp'
-    composite_type ='basic'
+    allow_datatype_change = False
+    composite_type = 'basic'
 
     def __init__(self, **kwd):
         Data.__init__(self, **kwd)
@@ -228,11 +259,3 @@
 #        self.add_composite_file('blastdb.pab', is_binary=True, optional=True)
 #        self.add_composite_file('blastdb.pac', is_binary=True, optional=True)
 # The last 3 lines should be repeated for each WriteDB column, with filename extensions like ('.pba', '.pbb', '.pbc'), ('.pca', '.pcb', '.pcc'), etc.
-
-    def display_data(self, trans, data, preview=False, filename=None,
-                     to_ext=None, size=None, offset=None, **kwd):
-        """Apparently an old display method, but still gets called.
-
-        This allows us to format the data shown in the central pane via the "eye" icon.
-        """
-        return "This is a BLAST protein database."