Beispiel #1
0
def virtual_electrophoresis():
    error = None
    session_dir = chilli.session(session_parent)
    if request.method == 'POST':
	size_list_str = request.form['size_list']
	size_list = []
	try:
	    for size in [size for size in re.split('[^\d]', size_list_str)]:
		if size:
		    size_list.append(size)
	except:
	    error = 'Error: Wrong size list format'
	    return render_template('elec_index.html', error=error)

	gel_conc = float(request.form['gel_conc'])
	filename = chilli.random_string(12) + '.png'
	pic_path = os.path.join('show_img', filename)

        if len(size_list) == 0:
            error = 'Please input size list for Virtual Electrophresis'
	    return render_template('elec_index.html', error=error)
        else:
	    error = ve.paint(size_list, gel_conc, pic_path)
	    if error:
		return render_template('elec_index.html', error=error)

	    return render_template('ve.html', filename=filename)

    return render_template('elec_index.html', error=error)
Beispiel #2
0
def check_dimer():
    error = None
    session_dir = chilli.session(session_parent)
    if request.method == 'POST':
	infile = os.path.join(session_dir, 'query.fa')
	upload_seq = ''
        if request.files.has_key('upload_seq'):
            upload_seq = request.files['upload_seq'].read()

	fasta_seq = ''
        if request.form.has_key('fasta_seq'):
            fasta_seq = request.form['fasta_seq']
	
	if upload_seq:
	    seq = upload_seq
	elif fasta_seq:
	    seq = fasta_seq
	else:
	    error = 'Need two or more primer sequences in fasta-format'
	    return render_template('dimer_index.html', error=error)

        fh = open(infile, 'w')
	for line in seq.splitlines():
	    line = line.strip()
	    if line.startswith('>'):
		fh.write("%s\n" % line)
		continue

	    line = re.sub('^[^a-zA-Z]+|[^a-zA-Z]+$', '', line)
	    line = re.sub('\s', '', line)

	    fh.write("%s\n" % line)

        fh.close()
	    

	if len(open(infile).read()) == 0:
	    error = 'Need two or more primer sequences in fasta-format'
	    return render_template('batch.html', error = error)

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

	mv = float(request.form['mono_conc'])
	dv = float(request.form['diva_conc'])
	dntp = float(request.form['dntp_conc'])
	oligo = float(request.form['oligo_conc'])
	align_mode = request.form['mode']
	if align_mode == 'HAIRPIN':
	    hairpin_list = analysis_hairpin(infile, mv, dv, oligo, dntp, align_mode)
	    return render_template('show_hairpin.html', error=error, hairpin_list=hairpin_list)
	else:
	    dimer_list = analysis_dimer(infile, mv, dv, oligo, dntp, align_mode)
	    return render_template('show_dimer.html', error=error, dimer_list=dimer_list)

    return render_template('dimer_index.html', error=error)
def main():
    '''Main control function'''
    options = get_opt()

    session_dir = chilli.session()

    start_time = time.time()
    amp_list, oligos = process_primer(options, session_dir)
    if options.tab:
	tab_out(amp_list, oligos, options, start_time, session_dir)
    else:
	format_output_primer(amp_list, oligos, options, start_time, session_dir)

    # Clean session tmp directory
    try:
      shutil.rmtree(session_dir)
    except:
      pass
def main():
    '''Main control function'''
    options = get_opt()

    session_dir = chilli.session()

    start_time = time.time()
    amp_list, oligos = process_primer(options, session_dir)
    if options.tab:
        tab_out(amp_list, oligos, options, start_time, session_dir)
    else:
        format_output_primer(amp_list, oligos, options, start_time,
                             session_dir)

    # Clean session tmp directory
    try:
        shutil.rmtree(session_dir)
    except:
        pass
Beispiel #5
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'))
Beispiel #6
0
def batch_mode():
    """batch mode"""
    error = None
    session_dir = chilli.session(session_parent)
    if request.method == 'POST':
        species_list = request.form.getlist('db_selected')
	if len(species_list) == 0:
	    error = 'Need select database first'
	    return render_template('batch.html', error = error)

        db_type_list = [db_type.lower() for db_type in request.form['db_type'].split(':')]

	session['db_type'] = request.form['db_type']
	session['species_list'] = species_list

        db_list = []
        for species in species_list:
            for db_type in db_type_list:
                db = '%s.%s' % (species, db_type)
		db = db.lower()
                if db in g.db_name_dict:
                    full_db = os.path.join(MFEprimerDB, g.db_name_dict[db])
		    db_list.append(full_db)

        db_list.sort()

	infile = os.path.join(session_dir, 'query.fa')
	upload_seq = ''
        if request.files.has_key('upload_seq'):
            upload_seq = request.files['upload_seq'].read()

	fasta_seq = ''
        if request.form.has_key('fasta_seq'):
            fasta_seq = request.form['fasta_seq']
	
	if upload_seq:
	    seq = upload_seq
	elif fasta_seq:
	    seq = fasta_seq
	else:
	    error = 'Need two or more primer sequences in fasta-format'
	    return render_template('batch.html', error = error)

        fh = open(infile, 'w')
	for line in seq.splitlines():
	    line = line.strip()
	    if line.startswith('>'):
		fh.write("%s\n" % line)
		continue

	    line = re.sub('^[^a-zA-Z]+|[^a-zA-Z]+$', '', line)
	    line = re.sub('\s', '', line)

	    fh.write("%s\n" % line)

        fh.close()
	    

	if len(open(infile).read()) == 0:
	    error = 'Need two or more primer sequences in fasta-format'
	    return render_template('batch.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('batch.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('batch.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 in (0, 100)'
	    return render_template('batch.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'])


	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()
        session_key = os.path.basename(session_dir)
        args = ['database', 'infile', 'dg_stop', 'dg_start', 'tm_stop', 'tm_start', 'size_stop', 'size_start', 'ppc', 'mono_conc', 'diva_conc', 'dntp_conc', 'oligo_conc', 'degenerate', 'k_value']
        job_file = create_jobs(options, args, session_key)
	return render_template('results_notice.html', session_key=session_key, job_file=job_file + '.zip', status='Submitted')

    return redirect(url_for('batch'))