class PDBQT_Protein(Html):
"""PDBQT Protein files, ASCII protein information files."""
MetadataElement(name = "base_name", desc = "Base name for all transformed versions of this PDBQT protein dataset", default = 'protein',
readonly = False, set_in_upload = True)
composite_type = 'auto_primary_file'
allow_datatype_change = False
file_ext = 'pdbqt_protein'
def __init__(self, **kwd):
Text.__init__(self, **kwd)
self.add_composite_file('%s.pdbqt', description = 'PDBQT Protein File', substitute_name_with_metadata = 'base_name', mimetype = 'text/plain', is_binary = False)
self.add_composite_file('%s_config.txt', description = 'PDBQT Config File', substitute_name_with_metadata = 'base_name', mimetype = 'text/plain', is_binary = False)
def generate_primary_file(self, dataset = None):
if dataset.metadata.base_name == "protein" and \
rval = ['<html><head><title>PDBQT Protein Galaxy/LiSIs Composite Dataset</title></head>']
rval.append('<body><div>This %s composite dataset is composed of the following files:<ul>' % (dataset.metadata.base_name))
for composite_name, composite_file in self.get_composite_files(dataset = dataset).iteritems():
fn = composite_name
opt_text = ''
if composite_file.optional:
opt_text = ' (optional)'
if composite_file.get('description'):
rval.append('<li><a href="%s">%s (%s)</a>%s</li>' % (fn, fn, composite_file.get('description'), opt_text))
else:
rval.append('<li><a href="%s">%s</a>%s</li>' % (fn, fn, opt_text))
rval.append('</ul></div></body></html>')
return "\n".join(rval)
def regenerate_primary_file(self, dataset):
"""
cannot do this until we are setting metadata
"""
bn = dataset.metadata.base_name
efp = dataset.extra_files_path
flist = os.listdir(efp)
rval = ['<html><head><title>PDBQT Protein Galaxy/LiSIs Composite Dataset</title></head>']
rval.append('<body><div>This %s composite dataset is composed of the following files:<ul>' % (bn))
for i, fname in enumerate(flist):
sfname = os.path.split(fname)[-1]
rval.append('<li><a href="%s">%s</a></li>' % (sfname, sfname))
rval.append('</ul></div></body></html>')
f = file(dataset.file_name, 'w')
f.write("\n".join(rval))
f.write('\n')
f.close()
def set_meta(self, dataset, **kwd):
"""
Set metadata...
"""
Text.set_meta(self, dataset, **kwd)
if dataset.metadata.base_name == "protein" and \
log.debug('@@@ PDBQT_Protein set_meta changed dataset.metadata.base_name to: %s' % (dataset.metadata.base_name))
if kwd.get('overwrite') == False:
log.debug('@@@ PDBQT_Protein set_meta called with overwrite = False')
return True
try:
efp = dataset.extra_files_path
except:
log.debug('@@@ PDBQT_Protein set_meta failed %s - dataset %s has no extra_files_path ?' % (sys.exc_info()[0],
dataset.name))
return False
try:
flist = os.listdir(efp)
except:
log.debug('@@@ PDBQT_Protein set_meta failed %s - dataset %s has no extra_files_path ?' % (sys.exc_info()[0],
dataset.name))
return False
if len(flist) == 0:
log.debug('@@@ PDBQT_Protein set_meta failed - %s extra_files_path %s is empty?' % (
dataset.name, efp))
return False
self.regenerate_primary_file(dataset)
dataset.info = 'Galaxy/LiSIs %s PDBQT Protein datatype object' % (dataset.metadata.base_name)
if not dataset.blurb:
dataset.blurb = 'Composite file - %s PDBQT Protein Galaxy/LiSIs datatype' % (dataset.metadata.base_name)
return True
Thanks in advance,
Christos