def new_bamm_job(next_id, example_file, peng_job): job_info, next_id = new_example_job_info(next_id, 'bamm', example_file) job_info.save() mdb = get_object_or_404(MotifDatabase, db_id=EXAMPLE_MOTIF_DB) bamm_job = BaMMJob( meta_job=job_info, Motif_Initialization="Custom File", Motif_Init_File_Format="PWM", MMcompare=True, score_Seqset=True, FDR=True, peng_job=peng_job, motif_db=mdb, ) with open(example_file) as fh: bamm_job.Input_Sequences.save(os.path.basename(example_file), File(fh)) n_motifs = 3 meme_file = path.join(get_job_output_folder(peng_job.pk), FILTERPWM_OUTPUT_FILE) motifs = get_motif_ids(meme_file)[:n_motifs] save_selected_motifs(motifs, peng_job.pk, bamm_job.meta_job.pk) copy_peng_to_bamm(peng_job.pk, bamm_job.pk, motifs) bamm_job.num_init_motifs = len(motifs) bamm_job.num_motifs = len(motifs) bamm_job.Motif_InitFile.name = get_motif_init_file(str(bamm_job.pk)) bamm_job.Motif_Initialization = "Custom File" bamm_job.Motif_Init_File_Format = "PWM" bamm_job.score_Cutoff = 0.0001 bamm_job.save() bamm_refinement_pipeline.delay(bamm_job.meta_job.pk) while not job_info.complete: job_info = get_object_or_404(JobInfo, pk=job_info.pk) time.sleep(10) return next_id, bamm_job.pk
def new_mmcompare_job(next_id, example_file, bamm_id): job_info, next_id = new_example_job_info(next_id, 'compare', example_file) job_info.save() mdb = get_object_or_404(MotifDatabase, db_id=EXAMPLE_MOTIF_DB) mmcompare_job = MMcompareJob(meta_job=job_info, motif_db=mdb, Motif_Init_File_Format="PWM" # Fill in missing data ) # Init motif_init_file motif_init_file_src = get_motif_init_file(str(bamm_id)) motif_init_file_dst = mmcompare_motif_init_file(str(mmcompare_job.pk)) motif_init_directory = os.path.splitext(motif_init_file_dst)[0] if not os.path.exists(motif_init_directory): os.makedirs(motif_init_directory) copyfile(motif_init_file_src, motif_init_file_dst) init_bname = path.basename(motif_init_file_dst) mmcompare_job.Motif_InitFile = filename_relative_to_job_dir( mmcompare_job, init_bname) mmcompare_job.save() mmcompare_pipeline.delay(mmcompare_job.meta_job.pk) while not job_info.complete: job_info = get_object_or_404(JobInfo, pk=job_info.pk) time.sleep(10) return next_id
def copy_peng_to_bamm(peng_id, bamm_id, selected_motifs): bamm_output_dir = path.join(get_job_output_folder(bamm_id), PENG_OUTPUT) bamm_plot_output_directory = path.join(bamm_output_dir, MEME_PLOT_DIRECTORY) if not path.exists(bamm_plot_output_directory): os.makedirs(bamm_plot_output_directory) # copy meme.out meme_path_src = os.path.join(peng_meme_directory(peng_id), MEME_OUTPUT_FILE) meme_path_dst = get_motif_init_file(str(bamm_id)) meme_drop_unselected_motifs(meme_path_src, meme_path_dst, selected_motifs) # copy results of filterPWM filterpwm_src = os.path.join(get_job_output_folder(peng_id), FILTERPWM_OUTPUT_FILE) logger.debug('copying %s -> %s', filterpwm_src, bamm_output_dir) shutil.copy(filterpwm_src, bamm_output_dir) # copy input file peng_input = os.path.join(get_job_input_folder(peng_id)) bamm_input = os.path.join(get_job_input_folder(bamm_id)) if not path.exists(bamm_input): os.makedirs(bamm_input) # TODO: Is this supposed to be multiple files?? for file in os.listdir(peng_input): logger.debug('copying %s -> %s', filterpwm_src, bamm_output_dir) src = os.path.join(peng_input, file) shutil.copy(src, bamm_input)
def new_bammscan_job(next_id, example_file, bamm_id): job_info, next_id = new_example_job_info(next_id, 'scan', example_file) job_info.save() mdb = get_object_or_404(MotifDatabase, db_id=EXAMPLE_MOTIF_DB) bamm_scan_job = BaMMScanJob( meta_job=job_info, motif_db=mdb, MMcompare=True, Motif_Init_File_Format="PWM", ) with open(example_file) as fh: bamm_scan_job.Input_Sequences.save(os.path.basename(example_file), File(fh)) bamm_scan_job.Motif_InitFile.name = get_motif_init_file(str(bamm_id)) bamm_scan_job.score_Cutoff = 0.0001 bamm_scan_job.save() bamm_scan_pipeline.delay(bamm_scan_job.meta_job.pk) while not job_info.complete: job_info = get_object_or_404(JobInfo, pk=job_info.pk) # Kind of dirt. time.sleep(10) return next_id
def peng_to_bamm_result_detail(request, pk): result = get_object_or_404(BaMMJob, meta_job__pk=pk) meta_job = result.meta_job relative_result_folder = get_result_folder(pk) job_output_dir = get_job_output_folder(pk) peng_path = path.join(job_output_dir, "pengoutput") meme_plots = path.join(job_output_dir, "pengoutput", "meme_plots") meme_motifs = load_meme_ids(peng_path) #meme_meta_info_list = Meme.fromfile(os.path.join(peng_path, "out.meme")) meme_meta_info_list = Meme.fromfile(get_motif_init_file(str(meta_job.job_id))) motif_db = result.motif_db db_dir = motif_db.relative_db_model_dir if meta_job.complete: num_logos = range(1, (min(2, result.model_order)+1)) return render(request, 'bamm/bamm_result_detail.html', { 'result': result, 'opath': get_result_folder(pk), 'mode': meta_job.mode, 'Output_filename': result.filename_prefix, 'num_logos': num_logos, 'db_dir': db_dir, 'meme_logo_path': path.relpath(meme_plots, relative_result_folder), 'meme_motifs': meme_motifs, 'meme_meta_info': meme_meta_info_list, }) else: log_file = get_log_file(pk) command = "tail -20 %r" % log_file output = os.popen(command).read() return render(request, 'results/result_status.html', { 'output': output, 'job_id': meta_job.pk, 'job_name': meta_job.job_name, 'status': meta_job.status })