def plot_rocs(title, rocs, num_pssms): """ Plot roc graphs. """ import pylab as P for bg_type, rocs_for_bg in rocs.iteritems(): for dataset, rocs_for_dataset in rocs_for_bg.iteritems(): tag = '%s-%s-%s' % (title, bg_type, dataset) fig = P.figure() for p in num_pssms: plot_roc_points(rocs_for_dataset[p][::-1], label='%d PSSMs' % (p+1)) P.legend(loc='lower right') P.title(tag) plot_random_classifier() label_plot() P.savefig(os.path.join(options.output_dir, 'roc-%s.png' % tag)) P.close(fig)
def plot_param_setting_rocs(test_cases, use_cumulative_dists, use_p_value, use_score, label, color, linestyle): "Test a particular setting of the biopsy module's PSSM parameters." B.PssmParameters.use_cumulative_dists = use_cumulative_dists B.PssmParameters.use_p_value = use_p_value B.PssmParameters.use_score = use_score start_time = time.time() positive_thresholds, negative_thresholds = thresholds_for_classifier(test_cases, BiFaClassifier()) elapsed = time.time() - start_time logging.info( 'Testing parameter settings: %40s : %10.3f : %10.1f secs', label, sum(positive_thresholds) + sum(negative_thresholds), elapsed ) rocs = roc.rocs_from_thresholds(positive_thresholds, negative_thresholds, num_points=100) roc.plot_roc_points(rocs, label=label, color=color, ls=linestyle) return positive_thresholds, negative_thresholds
def plot_rocs(rocs, filename, fig_title): from pylab import figure, close, savefig, plot, title, xlabel, ylabel figure() plot_roc_points( rocs, marker='s', color='black', linestyle='--' ) plot( [0,1], [0,1], color='black', linestyle=':' ) title(fig_title) xlabel('1 - specificity: 1-TN/(TN+FP)') ylabel('sensitivity: TP/(TP+FN)') logging.info('Saving ROC to %s' % filename) savefig(filename)
(method, R.area_under_curve([roc for roc, t in roc_thresholds[method]])) for method in methods ) aucs[bg]['AUC50'] = dict( (method, auc50s[method][0]) for method in methods ) # ROC curves P.figure() for method in methods: rocs = [roc for roc, t in roc_thresholds[method]] auc = aucs[bg]['AUC'][method] auc50 = aucs[bg]['AUC50'][method] R.plot_roc_points(rocs, label=method, marker=markers[method], color=colors[method]) R.plot_random_classifier(label='Random') R.label_plot() P.legend(loc='lower right') P.title('%s - %s' % (fragment_name(fragment), bg)) P.savefig(os.path.join(options.results_dir, 'ROC-%s-%s.png' % (fragment, bg))) P.savefig(os.path.join(options.results_dir, 'ROC-%s-%s.eps' % (fragment, bg))) P.close() # precision-recall curves P.figure() for method in methods: rocs = [roc for roc, t in roc_thresholds[method]] R.plot_precision_versus_recall(rocs, label=method, marker=markers[method], color=colors[method]) R.label_precision_versus_recall()
methods = [] datasets_to_ignore = set(('T99004',)) show_title = False sys.argv.pop(0) # remove script name while sys.argv: method = sys.argv.pop(0) methods.append(method) file_glob = sys.argv.pop(0) logging.info('Method: %s; glob: %s', method, file_glob) load_stat_files(glob(file_glob), overall_stats[method]) styles = [ '-', '--' ] for bg in bg_types: for dataset in datasets: P.figure() for style, method in zip(styles, methods): stats = overall_stats[method] rocs = list(stats[bg][0][dataset].iteritems()) rocs.sort() rocs = [r[1] for r in rocs] plot_roc_points(rocs, linestyle=style, color='k', label=method) label_plot() P.legend(loc='lower right') if show_title: P.title('%s - %s' % (dataset, bg)) plot_random_classifier(label='random') P.savefig('ROC-%s-%s.png' % (bg, dataset)) P.savefig('ROC-%s-%s.eps' % (bg, dataset)) P.clf()
if 'GLAM2-i7' == method: return 'GLAM2' return method for bg in backgrounds: # ROC curves P.figure() for method in methods: rocs = R.picked_rocs_from_thresholds( scores[(method,)], scores[(method, bg)], num_points=options.num_points ) auc = R.area_under_curve(rocs) R.plot_roc_points(rocs, label='%.2f %s'%(auc,name(method)), marker=markers[method]) R.plot_random_classifier(label='0.50 Random') R.label_plot() P.legend(loc='lower right') P.title('Full Sp1 - %s' % bg) P.savefig('ROC-Sp1-%s.png' % bg) P.savefig('ROC-Sp1-%s.eps' % bg) # precision-recall curves P.figure() for method in methods: rocs = R.picked_rocs_from_thresholds( scores[(method,)], scores[(method, bg)], num_points=options.num_points )
def do_pwm(tag, pwm, color, marker): roc_points = calc_or_unpickle_roc(tag, pwm, positive_seqs, negative_seqs) roc.plot_roc_points(roc_points, label=tag, color=color, marker=marker)
methods = [] datasets_to_ignore = set(('T99004', )) show_title = False sys.argv.pop(0) # remove script name while sys.argv: method = sys.argv.pop(0) methods.append(method) file_glob = sys.argv.pop(0) logging.info('Method: %s; glob: %s', method, file_glob) load_stat_files(glob(file_glob), overall_stats[method]) styles = ['-', '--'] for bg in bg_types: for dataset in datasets: P.figure() for style, method in zip(styles, methods): stats = overall_stats[method] rocs = list(stats[bg][0][dataset].iteritems()) rocs.sort() rocs = [r[1] for r in rocs] plot_roc_points(rocs, linestyle=style, color='k', label=method) label_plot() P.legend(loc='lower right') if show_title: P.title('%s - %s' % (dataset, bg)) plot_random_classifier(label='random') P.savefig('ROC-%s-%s.png' % (bg, dataset)) P.savefig('ROC-%s-%s.eps' % (bg, dataset)) P.clf()
if 'GLAM2-i7' == method: return 'GLAM2' return method for bg in backgrounds: # ROC curves P.figure() for method in methods: rocs = R.picked_rocs_from_thresholds(scores[(method, )], scores[(method, bg)], num_points=options.num_points) auc = R.area_under_curve(rocs) R.plot_roc_points(rocs, label='%.2f %s' % (auc, name(method)), marker=markers[method]) R.plot_random_classifier(label='0.50 Random') R.label_plot() P.legend(loc='lower right') P.title('Full Sp1 - %s' % bg) P.savefig('ROC-Sp1-%s.png' % bg) P.savefig('ROC-Sp1-%s.eps' % bg) # precision-recall curves P.figure() for method in methods: rocs = R.picked_rocs_from_thresholds(scores[(method, )], scores[(method, bg)], num_points=options.num_points) R.plot_precision_versus_recall(rocs,