def plot_info(mode, tf, score_method, results_folder): job_no = results_folder.split("/")[-1] if mode == "ASSESS": files_path = '%s/%s/%s' % (results_folder, tf, tf) score_ext = Assess_by_score.score_extensions[score_method] display_img = '/static/files/score/%s/%s/%s_assess' % (job_no, tf, tf) file_in = "%s/%s/%s.%s" % (results_folder, tf, tf, score_ext) utils.extract_scored_meme(files_path + ".meme", files_path + "_assess_ranked_by_" + score_ext + "_auc.meme", utils.get_dict_assess(files_path + "." + score_ext, "AUC")) t_head = get_table(file_in)[0] gomer_list = get_table(file_in)[1] context = {'tf': tf, 'mode': mode, 'display_img': display_img, 'gomer_list': gomer_list, 't_head': t_head, 'score_method': Assess_by_score.score_extensions[score_method]} else: files_path = '%s/%s/%s' % (results_folder, tf, tf) MARSTools.run_gimme.plot_histogram_gimme(files_path + "_gimme_metrics.txt", files_path + ".gimme", files_path + '_gimme.png') MARSTools.run_gimme.plot_histogram_gimme(files_path + "_gimme_metrics.txt", files_path + ".gimme", files_path + '_gimme.eps') rotate_image(files_path + '_gimme.png', files_path + '_gimme_rot.png') display_img = '/static/files/score/%s/%s/%s_gimme' % (job_no, tf, tf) file_in = "%s/%s/%s.gimme" % (results_folder, tf, tf) t_head = get_table(file_in)[0] gomer_list = get_table(file_in)[1] utils.extract_scored_meme(files_path + ".meme", files_path + "_gimme_ranked_by_" + mode.lower() + "_auc.meme", utils.get_dict_assess(files_path + "." + mode.lower(), "AUC")) context = {'tf': tf, 'mode': mode, 'display_img': display_img, 'gomer_list': gomer_list, 't_head': t_head, 'score_method': Assess_by_score.score_extensions[score_method]} return context
def get(self, request, slug, *args, **kwargs): job_no = request.path_info.split("job")[-1] results_folder = "%s/enrich/%s" % (get_path()[0], str(job_no)) par_name = "%s/parameter_file" % results_folder if os.path.isfile(par_name): parameters = get_parameter_dict(par_name) tf = parameters['tf'] mode = parameters['mode'] centrimo_raw = "%s/%s/%s_centrimo.txt" % (results_folder, tf, tf) t_head = get_table(centrimo_raw)[0] t_body = get_table(centrimo_raw)[1] job_no = results_folder.split("/")[-1] display_img = '/static/files/enrich/%s/%s/' % (job_no, tf) data = {'display_img': display_img, 'tf': tf, 'mode': mode, 't_body': t_body, 't_head': t_head} return render(request, 'MATOM/assess_by_enrichment_results.html', context=data) else: return render(request, '404.html')
def plot_info(mode, tf, score_method, results_folder): job_no = results_folder.split("/")[-1] if mode == "ASSESS": score_ext = Assess_by_score.score_extensions[score_method] display_img = '/static/files/score/%s/%s/%s_assess' % (job_no, tf, tf) file_in = "%s/%s/%s.%s" % (results_folder, tf, tf, score_ext) t_head = get_table(file_in)[0] gomer_list = get_table(file_in)[1] context = {'tf': tf, 'mode': mode, 'display_img': display_img, 'gomer_list': gomer_list, 't_head': t_head, 'score_method': Assess_by_score.score_extensions[score_method]} else: display_img = '/static/files/score/%s/%s/%s_gimme' % (job_no, tf, tf) file_in = "%s/%s/%s.gimme" % (results_folder, tf, tf) t_head = get_table(file_in)[0] gomer_list = get_table(file_in)[1] context = {'tf': tf, 'mode': mode, 'display_img': display_img, 'gomer_list': gomer_list, 't_head': t_head, 'score_method': Assess_by_score.score_extensions[score_method]} return context
def post(self, request, *args, **kwargs): # print "checking here" form = self.form_class(request.POST) if form.is_valid(): print "then here" # print request.FILES['uploaded_motif'] query_string = request.POST.get('search') #selected_project_id = query_string tf_details_dict = { } entry_query = get_query(query_string, ['tf_name', 'alt_tf_name', ]) found_entries = TranscriptionFactor.objects.filter(entry_query) if len(found_entries) == 1: tf_class_id = found_entries[0].tf_id Tf_exists = Matrix.objects.filter(tf_id=tf_class_id).exists() chip_seq_exist = ChipSeq.objects.filter(tf_id=tf_class_id).exists() pbm_exitst = Pbm.objects.filter(tf_id=tf_class_id).exists() # TODO: Most of these should be in the models since they query DB. Keep business logic out import re if chip_seq_exist: chipid = ChipSeq.objects.filter(tf_id=tf_class_id)[0].chip_id chip_data = ChipData.objects.filter(chip_id=chipid).all() chip_summary = [] for tf in chip_data: a = str(tf.raw) raw_file = re.split(r'([A-Z][a-z]*)', str(a)) cell_line = ''.join([raw_file[9], raw_file[10]]) lab = raw_file[7] chip_summary.append([a, cell_line, lab]) else: chip_summary = [] if pbm_exitst: pbmid = Pbm.objects.filter(tf_id=tf_class_id)[0].pbm_id pbm_data = PbmData.objects.filter(pbm_id=pbmid).all() pbm_summary = [] for tf in pbm_data: a = str(tf.source) pbm_summary.append([a]) else: pbm_summary = [] # Write a function, that uses these data to get the summary information. #results_folder = '%s/MATOM/static/files/temp' % BASE_DIR #results_folder = '%s/www/MARS/static/files/%s' % (home, method) results_folder = "%stemp" % get_path()[0] mkdir_p(results_folder) if Tf_exists: meme_out = '%s/temp.meme' % results_folder with open(meme_out, "w") as out_file: print "Lets get mmeme" out_file.write(meme_head) run_get_meme_id(tf_class_id, meme_out) raw_out_file = '%s/temp_ic.txt' % results_folder motif_ic.get_motif_summary_tfid(meme_out, raw_out_file, meme_path, results_folder) t_head = get_table(raw_out_file)[0] t_body = get_table(raw_out_file)[1] else: t_head = [] t_body = [] data = {'t_body': t_body, 't_head': t_head, 'chip_summary': chip_summary, 'pbm_summary': pbm_summary} return render(request, template_name='MATOM/search_summary.html', context=data) elif len(found_entries) == 0: return redirect('/search/') else: for items in found_entries: if found_entries is not None: tf_details_dict[items.tf_id] = items.tf_name #data = serializers.serialize('json', found_entries) request.session['selected_project_id'] = tf_details_dict # tf = request.POST.get('tf').lower() # score_method = request.POST.get("score") # mode = request.POST.get('mode') # formats = request.POST.get('formats') # pasted_motif = request.POST.get('test_motif') # uploaded_motif = self.request.FILES.get('uploaded_motif') # uploaded_chip = self.request.FILES.get('uploaded_chipseq') # data = { # 'found_entries': found_entries # } #form_html = render_to_string('search/search_results.html', context=data, request=request) #return {'success': True, 'form_html': form_html} return redirect('/search/select/') ctx = {} ctx.update(csrf(request)) form_html = render_crispy_form(form, context=ctx) print "We got the form up and running" return {'success': False, 'form_html': form_html}
def post(self, request, *args, **kwargs): form = self.form_class(request.POST, request.FILES) meme_error = None if request.is_ajax(): print "We got here " mode = request.POST.get('mode') tf = request.POST.get('tf').lower() pasted_motif = request.POST.get('test_motif') uploaded_motif = self.request.FILES.get('uploaded_motif') formats = request.POST.get('formats') if formats: if formats == 'upload' and uploaded_motif is None: formats = False print "Uploaded" if formats == 'paste' and pasted_motif == "": formats = False print "pasted" uploaded_chip = self.request.FILES.get('uploaded_chipseq') tf_exists = Matrix.objects.filter(motif_name=tf).exists() if tf != "": if tf_exists or formats: static_files = get_path(method="enrich")[0] results_folder = static_files motif_present_and_correct = self.handle_motifs(tf, pasted_motif, formats, results_folder, tf_exists) if not motif_present_and_correct: if tf_exists: tf_class_id = MATOM.models.get_tf(tf)[0] chipseq_exists = ChipSeq.objects.filter(tf_id=tf_class_id).exists() chip_okay = self.process_chip(chipseq_exists, tf, results_folder) if chip_okay: chip_seq_list = chip_okay results_folder_path = '%s/%s' % (results_folder, tf) user_motif = "%s/%s/%s.meme" % (results_folder, tf, tf) if mode == "CENTRIMO": run_centrimo(tf, chip_seq_list, user_motif, results_folder_path, figure=True) meme_file = "%s/%s/%s.meme" % (results_folder, tf, tf) meme_out_file = "%s/%s/%s_ranked_by_%s.meme" % (results_folder, tf, tf, mode.lower()) centrimo_raw = "%s/%s/%s_centrimo_norm.txt" % (results_folder, tf, tf) utils.extract_scored_meme(meme_file, meme_out_file, utils.get_dict(centrimo_raw)) centrimo_raw = "%s/%s/%s_centrimo.txt" % (results_folder, tf, tf) t_head = get_table(centrimo_raw)[0] t_body = get_table(centrimo_raw)[1] job_no = results_folder.split("/")[-1] display_img = '/static/files/enrich/%s/%s/%s_centrimo' % (job_no, tf, tf) data = {'display_img': display_img, 'tf': tf, 'mode': mode, 't_body': t_body, 't_head': t_head} form_html = render_to_string('MATOM/assess_by_enrichment_results.html', context=data, request=request) ctx = {} ctx.update(csrf(request)) par_name = "%s/parameter_file" % results_folder create_parameter_file(par_name, tf, mode) return {'success': True, 'form_html': form_html, 'success_url': '/enrichment/job%s' % job_no} else: meme_error = 'NOT_AVAILABLE' #context = {'message': error_message, 'form': form, 'tf': tf} #return render(request, 'MATOM/assess_by_enrichment.html', context) else: meme_error = "BED_ERROR" else: meme_error = 'NO_CHIP' else: meme_error = motif_present_and_correct else: meme_error = "NO_TF" else: meme_error = "REQUIRED" if os.path.exists(self.static_files): import shutil shutil.rmtree(self.static_files) ctx = {} ctx.update(csrf(request)) form_html = render_crispy_form(form, context=ctx) return {'success': False, 'form_html': form_html, 'error_message': self.error_message, 'meme_error': meme_error}
def post(self, request, *args, **kwargs): """ """ #static_files = self.static_files if request.method == 'POST': meme_error = None print "pased here" form = self.form_class(request.POST, request.FILES) if request.is_ajax(): print "This is ajax" mode = request.POST.get('mode') tf = request.POST.get('tf') formats = request.POST.get('formats') pasted_motif = request.POST.get('test_motif') uploaded_motif = self.request.FILES.get('uploaded_motif') tf_exists = Matrix.objects.filter(motif_name=tf).exists() print formats if formats: if formats == 'upload' and uploaded_motif is None: formats = False print "Uploaded" if formats == 'paste' and pasted_motif == "": formats = False print "pasted" # Ensure some form of motif has been entered by the user # pasted_motif is not u"" or uploaded_motif if tf != "": if tf_exists or formats: static_files = get_path(method="compare")[0] results_folder = static_files motif_present_and_correct = self.handle_motifs(tf, pasted_motif, formats, results_folder, tf_exists) if not motif_present_and_correct: if mode == "FISIM": meme_file = "%s/%s/%s.meme" % (results_folder, tf, tf) file_path = "%s/%s" % (results_folder, tf) run_fisim(tf, meme_file, file_path, figure=True) meme_out_file = "%s/%s/%s_ranked_by_fisim.meme" % (results_folder, tf, tf) raw_file = "%s/%s/%s.fisim" % (results_folder, tf, tf) # TODO: These are not being properly ranked, check it out utils.extract_scored_meme(meme_file, meme_out_file, utils.get_dict(raw_file)) raw_out_file = "%s/%s/%s_ic.txt" % (results_folder, tf, tf) motif_ic.get_motif_summary(meme_file, raw_file, tf, raw_out_file, meme_path, results_folder) t_head = get_table(raw_out_file)[0] t_body = get_table(raw_out_file)[1] else: meme_file = "%s/%s/%s.meme" % (results_folder, tf, tf) file_path = "%s/%s" % (results_folder, tf) run_tomtom(tf, meme_file, file_path, figure=True) meme_out_file = "%s/%s/%s_ranked_by_tomtom.meme" % (results_folder, tf, tf) raw_file = "%s/%s/%s.tomtom" % (results_folder, tf, tf) needed_dict = utils.get_dict(raw_file) utils.extract_scored_meme(meme_file, meme_out_file, needed_dict) raw_out_file = "%s/%s/%s_ic.txt" % (results_folder, tf, tf) motif_ic.get_motif_summary(meme_file, raw_file, tf, raw_out_file, meme_path, results_folder) t_head = get_table(raw_out_file)[0] t_body = get_table(raw_out_file)[1] job_no = results_folder.split("/")[-1] display_img = '/static/files/compare/%s/%s/%s_%s.png' % (job_no, tf, tf, mode.lower()) data = {'tf': tf, 'mode': mode, 'display_img': display_img, 't_body': t_body, 't_head': t_head} form_html = render_to_string('MATOM/assess_by_comparison_results.html', context=data, request=request) ctx = {} ctx.update(csrf(request)) par_name = "%s/parameter_file" % results_folder create_parameter_file(par_name, tf, mode) return {'success': True, 'form_html': form_html, 'success_url': '/comparison/job%s' % job_no} else: meme_error = motif_present_and_correct else: meme_error = "NO_TF" else: meme_error = 'REQUIRED' if os.path.exists(self.static_files): import shutil shutil.rmtree(self.static_files) ctx = {} ctx.update(csrf(request)) form_html = render_crispy_form(form, context=ctx) return {'success': False, 'form_html': form_html, 'error_message': self.error_message, 'meme_error': meme_error}
def post(self, request, *args, **kwargs): # print "checking here" form = self.form_class(request.POST) print form.is_valid() # TODO: Assuming for now that the form is valid #if form.is_valid(): # print request.FILES['uploaded_motif'] tf_class_id = request.POST.get('tf_choices') #Now lets validate available options Tf_exists = Matrix.objects.filter(tf_id=tf_class_id).exists() chip_seq_exist = ChipSeq.objects.filter(tf_id=tf_class_id).exists() pbm_exitst = Pbm.objects.filter(tf_id=tf_class_id).exists() # TODO: Most of these should be in the models since they query DB. Keep business logic out import re if chip_seq_exist: chipid = ChipSeq.objects.filter(tf_id=tf_class_id)[0].chip_id chip_data = ChipData.objects.filter(chip_id=chipid).all() chip_summary = [] for tf in chip_data: a = str(tf.raw) raw_file = re.split(r'([A-Z][a-z]*)', str(a)) cell_line = ''.join([raw_file[9], raw_file[10]]) lab = raw_file[7] chip_summary.append([a, cell_line, lab]) else: chip_summary = [] if pbm_exitst: pbmid = Pbm.objects.filter(tf_id=tf_class_id)[0].pbm_id pbm_data = PbmData.objects.filter(pbm_id=pbmid).all() pbm_summary = [] for tf in pbm_data: a = str(tf.source) pbm_summary.append([a]) else: pbm_summary = [] # Write a function, that uses these data to get the summary information. results_folder = "%s/temp" % get_path()[0] print results_folder if Tf_exists: meme_out = '%stemp.meme' % results_folder with open(meme_out, "w") as out_file: print "Lets get mmeme" out_file.write(meme_head) run_get_meme_id(tf_class_id, meme_out) raw_out_file = '%s/temp_ic.txt' % results_folder motif_ic.get_motif_summary_tfid(meme_out, raw_out_file, meme_path, results_folder) t_head = get_table(raw_out_file)[0] t_body = get_table(raw_out_file)[1] else: t_head = [] t_body = [] data = {'t_body': t_body, 't_head': t_head, 'chip_summary': chip_summary, 'pbm_summary': pbm_summary} return render(request, template_name='MATOM/search_summary.html', context=data)