def print_foot(out, options, start_time):
    '''Output the foot information in the output file'''
    linesep = os.linesep
    out.append('#' * 80 + linesep)
    elapsed_time = time.time() - start_time
    
    out.append('InFile: '.rjust(42) + os.path.basename(options.infile.name))
    out.append('OutFile: '.rjust(42) + os.path.basename(options.outfile.name))


    if options.amplicon:
        out.append('OutAmpliconFile: '.rjust(42) + '%s.fa' % (options.outfile.name))

    out.append('Database: '.rjust(42) + textwrap.fill(', '.join([os.path.basename(db) for db in options.database]), 80))
    out.append('Degenerate: '.rjust(42) + degenerate.capitalize())
    out.append('k value: '.rjust(42) + str(options.k_value) + linesep)

    out.append('Concentration of monovalent cations [mM]: '.rjust(42) + str(options.mono_conc))
    out.append('Concentration of divalent cations [mM]: '.rjust(42) + str(options.diva_conc))
    out.append('Concentration of annealing oligos [nM]: '.rjust(42) + str(options.oligo_conc))
    out.append('Concentration of dNTPs [mM]: '.rjust(42) + str(options.dntp_conc) + linesep)
    out.append('PPC cutoff [%]: '.rjust(42) + str(options.ppc))
    out.append('Size start [bp]: '.rjust(42) + str(options.size_start))
    out.append('Size stop [bp]: '.rjust(42) + str(options.size_stop))

    out.append(('Tm start [%s]: ' % (u'\u2103')).rjust(41) + str(options.tm_start))

    if options.tm_stop == sys.maxint:
        tm_stop = 'Unlimited'
    else:
        tm_stop = options.tm_stop

    if options.dg_start == -sys.maxint:
        dg_start = 'Unlimited'
    else:
        dg_start = options.dg_start

    out.append(('Tm stop [%s]: ' % (u'\u2103')).rjust(41) + str(tm_stop))
    # It seems that ΔG only occupied 1.5 space
    out.append(('%sG start [kcal/mol]: ' % (u'\u0394')).rjust(41) + str(dg_start))
    out.append(('%sG stop [kcal/mol]: ' % (u'\u0394')).rjust(41) + str(options.dg_stop))

    #out.append(linesep)
    #out.append('Command and options: ')
    #full_cmd = ' '.join(sys.argv)
    #out.append('  ' + textwrap.fill(full_cmd, 80))

    out.append(linesep)
    if elapsed_time < 1:
        out.append('Time used: ' + '%.2f s' % elapsed_time)
    else:
        out.append('Time used: ' + '%s m %s s' % chilli.seconds2min_sec(int(elapsed_time)))
    out.append('Date: %s' % chilli.format_show_time())
    out.append(linesep)

    return out
Example #2
0
def print_foot(out, options, start_time):
    '''Output the foot information in the output file'''
    linesep = os.linesep
    out.append('#' * 80 + linesep)
    elapsed_time = time.time() - start_time

    out.append('InFile: '.rjust(42) + os.path.basename(options.infile.name))
    out.append('OutFile: '.rjust(42) + os.path.basename(options.outfile.name))

    if options.amplicon:
        out.append('OutAmpliconFile: '.rjust(42) + '%s.fa' %
                   (options.outfile.name))

    out.append('Database: '.rjust(42) + textwrap.fill(
        ', '.join([os.path.basename(db) for db in options.database]), 80))
    out.append('Degenerate: '.rjust(42) + degenerate.capitalize())
    out.append('k value: '.rjust(42) + str(options.k_value) + linesep)

    out.append('Concentration of monovalent cations [mM]: '.rjust(42) +
               str(options.mono_conc))
    out.append('Concentration of divalent cations [mM]: '.rjust(42) +
               str(options.diva_conc))
    out.append('Concentration of annealing oligos [nM]: '.rjust(42) +
               str(options.oligo_conc))
    out.append('Concentration of dNTPs [mM]: '.rjust(42) +
               str(options.dntp_conc) + linesep)
    out.append('PPC cutoff [%]: '.rjust(42) + str(options.ppc))
    out.append('Size start [bp]: '.rjust(42) + str(options.size_start))
    out.append('Size stop [bp]: '.rjust(42) + str(options.size_stop))

    out.append(('Tm start [%s]: ' % (u'\u2103')).rjust(41) +
               str(options.tm_start))

    if options.tm_stop == sys.maxint:
        tm_stop = 'Unlimited'
    else:
        tm_stop = options.tm_stop

    if options.dg_start == -sys.maxint:
        dg_start = 'Unlimited'
    else:
        dg_start = options.dg_start

    out.append(('Tm stop [%s]: ' % (u'\u2103')).rjust(41) + str(tm_stop))
    # It seems that ΔG only occupied 1.5 space
    out.append(('%sG start [kcal/mol]: ' % (u'\u0394')).rjust(41) +
               str(dg_start))
    out.append(('%sG stop [kcal/mol]: ' % (u'\u0394')).rjust(41) +
               str(options.dg_stop))

    #out.append(linesep)
    #out.append('Command and options: ')
    #full_cmd = ' '.join(sys.argv)
    #out.append('  ' + textwrap.fill(full_cmd, 80))

    out.append(linesep)
    if elapsed_time < 1:
        out.append('Time used: ' + '%.2f s' % elapsed_time)
    else:
        out.append('Time used: ' +
                   '%s m %s s' % chilli.seconds2min_sec(int(elapsed_time)))
    out.append('Date: %s' % chilli.format_show_time())
    out.append(linesep)

    return out
Example #3
0
def single_mode():
    """Single mode"""
    error = None
    session_dir = chilli.session(session_parent)

    if request.method == 'POST':
	database = request.form['db_selected']
	db_list = [os.path.join(MFEprimerDB, db) for db in database.split(':')]

	infile = os.path.join(session_dir, 'query.fa')
	fh = open(infile, 'w')
	seq_sn = 1
        seq_list = []
	while request.form.has_key("seq%d" % seq_sn):
	    seq = request.form["seq%d" % seq_sn]
	    seq = re.sub('^[^a-zA-Z]+|[^a-zA-Z]+$', '', seq) # Remove additional chars, such as 5'- 3'- 
	    seq = re.sub('\s', '', seq) # Remove spaces in sequence. Thanks anonymous reviewers.
	    if seq:
		seq_list.append(seq)
		fh.write(">Seq%s\n%s\n" % (seq_sn, seq))

	    seq_sn += 1

        fh.close()

	if len(seq_list) < 2:
	    error = 'Need two or more primer sequences'
	    return render_template('index.html', error=error)

	error_or_degenerate = SeqCheck.fasta_format_check(open(infile), err_path='here')
	if error_or_degenerate in ['yes', 'no']:
	    degenerate = error_or_degenerate
	else:
	    return render_template('index.html', error=error_or_degenerate)


	Tm_upper_limit = float(request.form['Tm_upper_limit'])
	Tm_lower_limit = float(request.form['Tm_lower_limit'])

	size_upper_limit = int(request.form['size_upper_limit'])
	size_lower_limit = int(request.form['size_lower_limit'])

	if size_lower_limit < 0 or size_upper_limit > 100000:
	    error = 'Size range should be in [0, 100000]'
	    return render_template('index.html', error=error)

	ppc_lower_limit = float(request.form['ppc_lower_limit'])
	if ppc_lower_limit < 0 or ppc_lower_limit > 100:
	    error = 'PPC lower cutoff should be in (0, 100)'
	    return render_template('index.html', error=error)

	mv = float(request.form['mono_conc'])
	dv = float(request.form['diva_conc'])
	dntp = float(request.form['dntp_conc'])
	oligo = float(request.form['oligo_conc'])

	session['db_selected'] = ':'.join([os.path.basename(str(db)) for db in db_list])

	options = OptionCreator(db_list, 
		infile,
		Tm_upper_limit,
		Tm_lower_limit,
		size_upper_limit,
		size_lower_limit,
		ppc_lower_limit,
		mv,
		dv,
		dntp,
		oligo,
		degenerate,
		)

	start_time = time.time()
        amp_list, oligos = MFEprimer.process_primer(options, session_dir)
        detail, size_dict, tm_dict, dg_dict = format_output_primer(amp_list, oligos, options, start_time, session_dir)
	if len(detail) > hist_cutoff:
	    size_hist_keys = size_hist.keys()
	    size_hist_keys.sort(reverse=True)
	    for size, num in size_dict.items():
		for hist_key in size_hist_keys:
		    if int(size) > hist_key:
			break

		size_hist[hist_key] += num

	    tm_hist_keys = tm_hist.keys()
	    tm_hist_keys.sort(reverse=True)
	    for tm, num in tm_dict.items():
		for hist_key in tm_hist_keys:
		    if float(tm) > hist_key:
			break

		tm_hist[hist_key] += num

	    dg_hist_keys = dg_hist.keys()
	    dg_hist_keys.sort(reverse=False)
	    for dg, num in dg_dict.items():
		for hist_key in dg_hist_keys:
		    if float(dg) < float(hist_key):
			break

		dg_hist[hist_key] += num

	new_dg_hist = {}
	for key, value in dg_hist.items():
	    new_dg_hist[str(key)] = value

        database = ', '.join([os.path.basename(db).capitalize() for db in options.database])
        oligos = format_oligos(oligos, options)
        elapsed_time = time.time() - start_time
	if elapsed_time < 1:
	    print_elapsed_time = '%.2f s' % elapsed_time
	else:
	    print_elapsed_time = '%s m %s s' % chilli.seconds2min_sec(int(elapsed_time))

	return render_template('primer_output.html', options=options, database=database, 
		oligos=oligos, amp_num=len(amp_list), time_used=print_elapsed_time, 
		date=chilli.format_show_time(), citation=Citation, detail=detail, 
		session_dir=session_dir, size_hist=size_hist, tm_hist=tm_hist, dg_hist=new_dg_hist, 
		max_size_num = max([num for num in size_hist.values()]),
		max_tm_num = max([num for num in tm_hist.values()]),
		max_dg_num = max([num for num in dg_hist.values()]),
		)

    return redirect(url_for('root'))