def form_submit(): # ENH: pick a unique, informative name -- e.g. date or hostname name = bottle.request.forms.name seqfile1 = bottle.request.files.seqfile1 if not hasattr(seqfile1, 'file'): return "Error: You need to specify at least one sequence file." seq1fname = handle2temp(seqfile1.file, suffix=('.cma' if seqfile1.filename.endswith('.cma') else '.seq')) # Optional second sequence set -- if missing, do single mode seqfile2 = bottle.request.files.seqfile2 if hasattr(seqfile2, 'file'): seq2fname = handle2temp(seqfile2.file, suffix=('.cma' if seqfile2.filename.endswith('.cma') else '.seq')) if not name: name = "%s-vs-%s" % (seqfile1.filename.rsplit('.', 1)[0], seqfile2.filename.rsplit('.', 1)[0]) else: seq2fname = '' if not name: name = seqfile1.filename # Optional HMM profile for alignment profile = bottle.request.files.profile # Optional HMM profile for alignment profile = bottle.request.files.profile if hasattr(profile, 'file'): if not profile.filename.endswith('.hmm'): return "HMM profile file name must end in .hmm" profname = handle2temp(profile.file, suffix='.hmm') logging.info("Aligning %s with profile %s", seq1fname, profname) fg_aln = core.hmm_align_and_read(profname, seq1fname) if seq2fname: logging.info("Aligning %s with profile %s", seq2fname, profname) bg_aln = core.hmm_align_and_read(profname, seq2fname) else: profname = '' fg_aln = core.read_aln(seq1fname, 'fasta') if seq2fname: bg_aln = core.read_aln(seq2fname, 'fasta') pdbfile = bottle.request.files.pdbfile if hasattr(pdbfile, 'file'): if not profname: return ("Error: to generate a PyMOL script for a PDB file you must" "also specify an HMM profile") pdbfname = handle2temp(pdbfile.file) logging.info("Aligning %s with profile %s", pdbfile.filename, profname) pdb_rec, pdb_resnums, pdb_inserts = core.pdb_hmm(profname, pdbfname) pdb_data = [(pdbfname, pdb_rec, pdb_resnums, pdb_inserts)] else: pdbfname = '' pdb_data = None # Mutually exclusive with pdbfname (above): pdbid = bottle.request.forms.pdbid if pdbid: # If PDB ID: .pml should use "fetch" instead of "load"? # Can get this info w/o dl'ing actual PDB file (e.g. via FASTA)? pass stat_module = dict(gtest=gtest, urn=urn, jsd=jsd, phospho=phospho, )[bottle.request.forms.strategy] try: alpha = float(bottle.request.forms.alpha) if not 0.0 <= alpha <= 1.0: raise ValueError except ValueError: return "Error: alpha must be a number between 0 and 1" _fdo, tmp_output = tempfile.mkstemp(suffix='.out') os.close(_fdo) _fdp, tmp_pattern = tempfile.mkstemp(suffix='.pttrn') os.close(_fdp) # Run the algorithms... if seq2fname: # Pair mode fg_clean, bg_clean, hits = core.process_pair(fg_aln, bg_aln, stat_module) core.process_output(fg_clean, bg_clean, hits, alpha, tmp_output, tmp_pattern, pdb_data) else: # Single mode aln, hits = core.process_one(fg_aln, stat_module) core.process_output(aln, None, hits, alpha, tmp_output, tmp_pattern, pdb_data) # Get the HTML report data contents = report.do_single(tmp_output, tmp_pattern)[1] cleanup(seq1fname) cleanup(seq2fname) cleanup(profname) cleanup(tmp_output) cleanup(tmp_pattern) return report.html_page_tpl % dict(title=name, contents=contents)
import argparse import logging from cladecomparelib.report import do_single, do_multi, html_page_tpl logging.basicConfig(level=logging.INFO, format="%(module)s [@%(lineno)s]: %(message)s") AP = argparse.ArgumentParser(__doc__) AP.add_argument('outfiles', nargs='+', help="Output file(s) generated by cladecompare.py") AP.add_argument('-p', '--pattern', help="Pattern file (.pttrn) generated by cladecompare.py") AP.add_argument('-o', '--output', help="HTML output file name. (Default: stdout)") args = AP.parse_args() if len(args.outfiles) == 1: title, contents = do_single(args.outfiles[0], args.pattern) else: title, contents = do_multi(args.outfiles, args.pattern) html_report = html_page_tpl % dict(title=title, contents=contents) if args.output: with open(args.output, 'w') as handle: handle.write(html_report) else: print(html_report)
import logging from cladecomparelib.report import do_single, do_multi, html_page_tpl logging.basicConfig(level=logging.INFO, format="%(module)s [@%(lineno)s]: %(message)s") AP = argparse.ArgumentParser(__doc__) AP.add_argument('outfiles', nargs='+', help="Output file(s) generated by cladecompare.py") AP.add_argument('-p', '--pattern', help="Pattern file (.pttrn) generated by cladecompare.py") AP.add_argument('-o', '--output', help="HTML output file name. (Default: stdout)") args = AP.parse_args() if len(args.outfiles) == 1: title, contents = do_single(args.outfiles[0], args.pattern) else: title, contents = do_multi(args.outfiles, args.pattern) html_report = html_page_tpl % dict(title=title, contents=contents) if args.output: with open(args.output, 'w') as handle: handle.write(html_report) else: print(html_report)
def form_submit(): # ENH: pick a unique, informative name -- e.g. date or hostname name = bottle.request.forms.name seqfile1 = bottle.request.files.seqfile1 if not hasattr(seqfile1, 'file'): return "Error: You need to specify at least one sequence file." seq1fname = handle2temp( seqfile1.file, suffix=('.cma' if seqfile1.filename.endswith('.cma') else '.seq')) # Optional second sequence set -- if missing, do single mode seqfile2 = bottle.request.files.seqfile2 if hasattr(seqfile2, 'file'): seq2fname = handle2temp( seqfile2.file, suffix=('.cma' if seqfile2.filename.endswith('.cma') else '.seq')) if not name: name = "%s-vs-%s" % (seqfile1.filename.rsplit( '.', 1)[0], seqfile2.filename.rsplit('.', 1)[0]) else: seq2fname = '' if not name: name = seqfile1.filename # Optional HMM profile for alignment profile = bottle.request.files.profile # Optional HMM profile for alignment profile = bottle.request.files.profile if hasattr(profile, 'file'): if not profile.filename.endswith('.hmm'): return "HMM profile file name must end in .hmm" profname = handle2temp(profile.file, suffix='.hmm') logging.info("Aligning %s with profile %s", seq1fname, profname) fg_aln = core.hmm_align_and_read(profname, seq1fname) if seq2fname: logging.info("Aligning %s with profile %s", seq2fname, profname) bg_aln = core.hmm_align_and_read(profname, seq2fname) else: profname = '' fg_aln = core.read_aln(seq1fname, 'fasta') if seq2fname: bg_aln = core.read_aln(seq2fname, 'fasta') pdbfile = bottle.request.files.pdbfile if hasattr(pdbfile, 'file'): if not profname: return ("Error: to generate a PyMOL script for a PDB file you must" "also specify an HMM profile") pdbfname = handle2temp(pdbfile.file) logging.info("Aligning %s with profile %s", pdbfile.filename, profname) pdb_rec, pdb_resnums, pdb_inserts = core.pdb_hmm(profname, pdbfname) pdb_data = [(pdbfname, pdb_rec, pdb_resnums, pdb_inserts)] else: pdbfname = '' pdb_data = None # Mutually exclusive with pdbfname (above): pdbid = bottle.request.forms.pdbid if pdbid: # If PDB ID: .pml should use "fetch" instead of "load"? # Can get this info w/o dl'ing actual PDB file (e.g. via FASTA)? pass stat_module = dict( gtest=gtest, urn=urn, jsd=jsd, phospho=phospho, )[bottle.request.forms.strategy] try: alpha = float(bottle.request.forms.alpha) if not 0.0 <= alpha <= 1.0: raise ValueError except ValueError: return "Error: alpha must be a number between 0 and 1" _fdo, tmp_output = tempfile.mkstemp(suffix='.out') os.close(_fdo) _fdp, tmp_pattern = tempfile.mkstemp(suffix='.pttrn') os.close(_fdp) # Run the algorithms... if seq2fname: # Pair mode fg_clean, bg_clean, hits = core.process_pair(fg_aln, bg_aln, stat_module, False) core.process_output(fg_clean, bg_clean, hits, alpha, tmp_output, tmp_pattern, pdb_data) else: # Single mode aln, hits = core.process_one(fg_aln, stat_module, False) core.process_output(aln, None, hits, alpha, tmp_output, tmp_pattern, pdb_data) # Get the HTML report data contents = report.do_single(tmp_output, tmp_pattern)[1] cleanup(seq1fname) cleanup(seq2fname) cleanup(profname) cleanup(tmp_output) cleanup(tmp_pattern) return report.html_page_tpl % dict(title=name, contents=contents)