def test_batch_query(self): ''' test the batch_query module. ''' cluster_list = [] for patch in self._name_list: test_patch = Patch(os.path.join(self._dir, patch)) test_patch.scan() for cluster in test_patch: cluster_list.append(cluster) # Test search orded folder scan choice_dict = OrderedDict([('receptor', ['NMDA', 'AMPA']), ('mutation', ['S219P', 'S200T']), ('composition', ['a1','ab']), ('agonist', ['glycine', 'taurine']), ('concentration', ['100', '0.1'])]) organisation = {keys:{key: [] for key in choice_dict[keys]} for keys in choice_dict} for index in range(len(self._name_list)): temp_filepath = self._dir for key in choice_dict: choice = random.choice(choice_dict[key]) temp_filepath = os.path.join(temp_filepath, choice) organisation[key][choice].extend([index]*self.cluster_num) try: os.makedirs(temp_filepath) except FileExistsError: pass shutil.copy2(os.path.join(self._dir, self._name_list[index]), os.path.join(temp_filepath, self._name_list[index])) test_batch = Batch(folder_list = self._dir) if len(test_batch.scan_folder()) != len(cluster_list): print('scan_folder error') test_cluster_list = test_batch.scan_orded_folder(clear = True,export = True) copy_organisation = copy.deepcopy(organisation) for cluster in test_cluster_list: index = self._name_list.index(cluster.patchname) for key in organisation: if not index in organisation[key][getattr(cluster, key)]: print('scan_orded_folder error') else: copy_organisation[key][getattr(cluster, key)].remove(index) for i in copy_organisation: for j in copy_organisation[i]: if copy_organisation[i][j]: print('scan_orded_folder error') # Test query copy_organisation = copy.deepcopy(organisation) for i in organisation: for j in organisation[i]: if organisation[i][j]: query_list = test_batch.query(**{i: j}) for cluster in query_list: index = self._name_list.index(cluster.patchname) try: copy_organisation[i][j].remove(index) except ValueError: print('query error') for i in copy_organisation: for j in copy_organisation[i]: if copy_organisation[i][j]: print('query error')
""" import os import codecs import matplotlib.pyplot as plt import numpy as np import seaborn as sns import pandas as pd from batch_query import Batch from batch_analysis import BatchAnalysis, PatchExamination sns.set(color_codes=True) batch = Batch('./data/') batch.scan_orded_folder() concentation_list = ['0.3', '1', '3', '10', '100'] for concentration in concentation_list: cluster_list = batch.query(mutation = 'S270T', concentration = concentration) cluster_summary = BatchAnalysis(cluster_list) summary = cluster_summary.compute_cluster_summary() np.savetxt(concentration+'.csv', summary, fmt= ['%s', '%i', '%.2f', '%.2f','%.2f','%i','%.2f','%.2f'], delimiter = ',')