def test_parse_motifs(self):
     motifs = parse_motifs(os.path.join(Test.__path__[0], "data", "motifs.txt"))
     self.assertDictEqual({
                           'C/VI': (389, 402), 
                           'D': (405, 429), 
                           'F/I-II': (180, 206), 
                           'E/VII': (430, 446), 
                           'B/V': (335, 355), 
                           'A/IV': (259, 270), 
                           'Priming Loop': (519, 538)
                           }, 
                          motifs["WNV"])
    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)
 parser.add_option("--results", dest="results")
 parser.add_option("--drug-atoms", dest="drug_atoms")
 parser.add_option("--frames-per-drug", dest="frames_per_drug")
 
 (options, args) = parser.parse_args()
 check_options(options)
 
 tools.create_dir(options.results)
 
 THRESHOLD = 1000
 
 # Parse all files
 num_atoms_per_drug = parse_drug_info(options.drug_atoms)
 frames_per_prot_drug = parse_frames_info(options.frames_per_drug)
 data, proteins, drugs = parse_contacts_file(options.contacts)
 motifs = parse_motifs(options.motifs)
 
 # Override order for stuff
 ordered_motifs = ['F/I-II', 'A/IV', 'B/V', 'C/VI', 'D', 'E/VII', 'Priming Loop']
 drugs.sort() 
 proteins = ["JEV", "WNV", "TBEV", "BVDV", "HCV", "Polio"]
 
 # PLOT TOTAL NUMBER OF CONTACTS PER PROTEIN
 t_c_p_d = get_total_contacts_per_protein_and_drug(data["contacts_per_residue"], 
                                                   proteins, drugs,
                                                   num_atoms_per_drug, frames_per_prot_drug)
 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
'''
Created on Dec 10, 2015

@author: victor
'''
from prody.proteins.pdbfile import parsePDB, writePDB
import sys
from histogram import parse_motifs
import urllib

if __name__ == '__main__':
    pdb = parsePDB(sys.argv[1])
    motifs = parse_motifs(sys.argv[2])
    prot_name = sys.argv[3]
    for motif in motifs[prot_name]:
        motif_struct = pdb.select("resid %d to %d"%motifs[prot_name][motif])
        writePDB("%s.pdb"%urllib.quote(motif, safe=""),motif_struct)
        print motif, sorted(list(set(motif_struct.getResnums())))