def test_calc_prot_drug_contacts_per_motif(self): contacts_per_cluster, _ = histogram.parse_contacts(TestDataManaging.small_contacts_file_name) motifs = parse_motifs(os.path.join(Test.__path__[0], "data", "motifs.txt")) ordered_motifs = ['F/I-II', 'A/IV', 'B/V', 'C/VI', 'D', 'E/VII', 'Priming Loop'] prot_drug_contacts_per_motif = calc_contacts_per_cluster_per_motif(contacts_per_cluster, motifs["WNV"], ordered_motifs, 1.) correct_prot_drug_contacts_per_motif = { 'cluster_8': {'F/I-II': 4.0, 'B/V': 2.0}, 'cluster_6': {'A/IV': 2.0, 'B/V': 4.0, 'Priming Loop': 4.0}, 'cluster_7': {'A/IV': 15.0, 'Priming Loop': 1.0}, 'cluster_4': {'C/VI': 6.0, 'Priming Loop': 4.0, 'B/V': 6.0}, 'cluster_5': {'E/VII': 6.0}, 'cluster_2': {'C/VI': 4.0, 'D': 5.0, 'Priming Loop': 3.0}, 'cluster_3': {'Priming Loop': 6.0, 'B/V': 7.0}, 'cluster_0': {'C/VI': 7.0, 'E/VII': 7.0, 'Priming Loop': 2.0}, 'cluster_1': {'E/VII': 2.0, 'A/IV': 10.0, 'Priming Loop': 1.0, 'D': 2.0} } self.assertDictEqual(correct_prot_drug_contacts_per_motif, prot_drug_contacts_per_motif) correct_contacts_per_motif = { 'F/I-II': 4., 'A/IV': 27., 'B/V': 19., 'C/VI': 17., 'D': 7., 'E/VII': 15., 'Priming Loop': 21. } contacts_per_motif = calc_contacts_per_motif(correct_prot_drug_contacts_per_motif, ordered_motifs) self.assertDictEqual(correct_contacts_per_motif,contacts_per_motif)
plt.savefig(os.path.join(options.results, "contacts_per_residue_histogram.svg"), bbox_extra_artists=(lgd,)) # COMBO HISTOGRAMS PER MOTIF f, axes = plt.subplots(3, 2, sharey='row') f.subplots_adjust(hspace=0.4, wspace=0.1 ) f.set_size_inches(10, 18, forward=True) for i, protein in enumerate(proteins): n_groups = len(ordered_motifs) bar_width = 0.30 index = numpy.arange(n_groups) + bar_width/2 legend_labels = [] # remove "cluster_id" info for j, drug in enumerate(drugs): contacts_per_motif = calc_contacts_per_motif(contacts_per_motif_and_cluster[protein][drug], ordered_motifs) values = data["contacts_per_residue"][protein][drug] weight = num_atoms_per_drug[drug]*frames_per_prot_drug[protein][drug] x = numpy.array([ float(contacts_per_motif[motif]) for motif in ordered_motifs]) rects = axes[i/2,i%2].bar(index, x, bar_width, color = colors[j]) index = index + bar_width legend_labels.append(drug) if i==3: lgd = axes[i/2,i%2].legend(legend_labels, loc='center right', bbox_to_anchor=(1.3, 0.5)) axes[i/2,i%2].xaxis.grid() axes[i/2,i%2].set_title(protein) axes[i/2,i%2].set_xticklabels(ordered_motifs, rotation= 45) axes[i/2,i%2].set_xticks(numpy.arange(n_groups)+bar_width/2) # axes[i/2,i%2].autoscale(tight=True) scale_axes_to_max_val(axes, 3, 2) plt.savefig(os.path.join(options.results, "contacts_per_motif_histogram.svg"),