db = pd.DataFrame.from_dict(t_c_p_d) sns.barplot(x="Protein", y="Contacts", hue="Drug", data = db) plt.savefig(os.path.join(options.results, "total_contacts.svg")) # PLOT CONTACTS PER RESIDUE f, axes = plt.subplots(len(proteins), len(drugs), sharey='row') f.subplots_adjust(hspace=0.3, wspace=0.1 ) f.set_size_inches(9, 18, forward=True) colors = sns.color_palette("hls", 15) for i, protein in enumerate(proteins): for j, drug in enumerate(drugs): contacts_per_cluster = data["contacts_per_cluster"][protein][drug] contact_residue_labels = get_labels(contacts_per_cluster) weight = num_atoms_per_drug[drug]*frames_per_prot_drug[protein][drug] filtered_contact_residue_labels = filter_less_contacts_than(THRESHOLD, contact_residue_labels, data["contacts_per_residue"][protein][drug]) plot_histogram_to_axis(axes[i,j], protein, drug, contacts_per_cluster, filtered_contact_residue_labels, colors, weight, False) axes[i,j].xaxis.grid() axes[i,j].set_aspect("auto") if i == 0: axes[i,j].set_title(drug) if j == 0: axes[i,j].set_ylabel(protein) axes[i,j].autoscale(tight=True) scale_axes_to_max_val(axes, len(proteins), len(drugs)) plt.savefig(os.path.join(options.results, "contacts_per_residue_and_cluster_histogram.svg"))
def test_filter(self): _, contacts_per_residue = histogram.parse_contacts(TestDataManaging.small_contacts_file_name) ordered_labels = ['181:TYR:A', '266:GLY:A', '268:ASP:A', '329:ARG:A', '333:GLN:A', '337:TYR:A', '340:ASN:A', '395:ASP:A', '421:LYS:A', '442:SER:A', '461:ARG:A', '527:TRP:A', '528:SER:A'] filtered_labels = filter_less_contacts_than( 15, ordered_labels, contacts_per_residue) self.assertItemsEqual(['266:GLY:A', '395:ASP:A', '442:SER:A', '528:SER:A'], filtered_labels)
residues_file.write("%s %s \n"%(cluster_id, " ".join(residues))) contacts_per_cluster[cluster_id] = residues residues_file.close() if options.do_plots: #-------------------------------- # Plot distribution of the residues #-------------------------------- contacts_per_residue = get_num_contacts_per_residue(contacts_per_cluster) contact_residue_labels = get_labels (contacts_per_cluster) # A normal plot target = os.path.join(RESULTS_PATH, "histogram.svg") plot_histogram(contacts_per_cluster, contact_residue_labels, target, False) # A plot averaging target = os.path.join(RESULTS_PATH, "histogram_a.svg") plot_histogram(contacts_per_cluster, contact_residue_labels, target, True) # A plot filtering filtered_contact_residue_labels = filter_less_contacts_than(2000, contact_residue_labels, contacts_per_residue) target = os.path.join(RESULTS_PATH, "histogram_f.svg") plot_histogram(contacts_per_cluster, filtered_contact_residue_labels, target, False) # A plot filtering + averaging filtered_contact_residue_labels = filter_less_contacts_than(2000, contact_residue_labels, contacts_per_residue) target = os.path.join(RESULTS_PATH, "histogram_fa.svg") plot_histogram(contacts_per_cluster, filtered_contact_residue_labels, target, True)