def upload_vcf(): """Write the uploaded file to a temporary directory and return its path.""" f = request.files['file'] if not f: return error_response('Missing file', 'Must post a file to /upload') if not f.filename.endswith('.vcf'): return error_response('Invalid extension', 'File must end with .vcf') tmp_dir = app.config['TEMPORARY_DIR'] dest_path = get_secure_unique_filename(f.filename, tmp_dir) f.save(dest_path) return 'file://' + dest_path
def examine(run_id): with tables(db.engine, 'vcfs', 'bams') as (con, runs, bams): q = select(runs.c).where(runs.c.id == run_id) run = q.execute().fetchone() if not run: return error_response('Invalid run', 'Invalid run: %s' % run_id) else: run = dict(run) run['spec'] = cycledash.api.genotypes.spec(run_id) run['contigs'] = cycledash.api.genotypes.contigs(run_id) # Ideally we could use e.g. cycledash.bams.Bam.get(bam_id) for bam_type in ['normal', 'tumor']: bam_id = run[bam_type + '_bam_id'] bam = bams.select(bams.c.id == bam_id).execute().fetchone() if bam: run[bam_type + '_bam'] = dict(bam) del run[bam_type + '_bam_id'] return render_template('examine.html', vcf=run, vcfs=cycledash.api.runs.get_related_vcfs(run))