# HG changeset patch # User peterjc # Date 1390329200 18000 # Node ID de11e1a921c4ba077ed57ae456369d99d49ad4fa # Parent 5ec5dece43cb17a4f41870e636f110063aa08cc5 Uploaded v0.0.18, tweak display_data for running tests diff -r 5ec5dece43cb -r de11e1a921c4 README.rst --- a/README.rst Tue Jan 21 13:32:49 2014 -0500 +++ b/README.rst Tue Jan 21 13:33:20 2014 -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. ======= ====================================================================== diff -r 5ec5dece43cb -r de11e1a921c4 blast.py --- a/blast.py Tue Jan 21 13:32:49 2014 -0500 +++ b/blast.py Tue Jan 21 13:33:20 2014 -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() != '': 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 "%s
%s
" % (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."