def test_batch_analysis(self): ''' test the batch analysis. ''' 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.compute_mode() cluster.compute_mode_detail() cluster_list.append(cluster) # Test BatchAnalysis class batch_analysis = BatchAnalysis(list(cluster_list)) test_dict = batch_analysis.compute_cluster_summary() for patchname in self._name_list: for cluster_no in range(1, self.cluster_num+1): test_dict = batch_analysis.compute_cluster_summary( patchname = patchname, cluster_no = cluster_no) temp_amp = np.mean(self._patch_list[patchname][cluster_no-1]['open_amp'] - self._patch_list[patchname][cluster_no-1]['shut_amp']) if abs(test_dict['mean_amp'] - temp_amp) > 0.0001: print('Amplitude error') temp_duration = (sum(self._patch_list[patchname][cluster_no-1]['open_period']) + sum(self._patch_list[patchname][cluster_no-1]['shut_period'])) if abs(test_dict['duration'] - temp_duration) > 0.0001: print('Duration error') temp_popen = sum(self._patch_list[patchname][cluster_no-1]['open_period']) / temp_duration if abs(test_dict['popen'] - temp_popen) > 0.0001: print('Popen error') # Test StretchSummary class batch_analysis.compute_stretch_summary()
from batch_query import Batch from batch_analysis import BatchAnalysis batch = Batch('/Users/zhiyiwu/GitHub/sc_py/data') batch.scan_orded_folder() list_100 = batch.query(mutation = 'wt', agonist = 'taurine', concentration = '100') list_30 = batch.query(mutation = 'wt', agonist = 'taurine', concentration = '30') combined_list = list_100 + list_30 for cluster in combined_list: cluster.compute_mode() cluster.compute_mode_detail(output = True) batch_100 = BatchAnalysis(list_100) cluster_100 = batch_100.compute_cluster_summary() stretch_100 = batch_100.compute_stretch_summary() popen_100 = plt.figure() ax = popen_100.add_subplot(111) ax.hist(stretch_100['popen'], bins = np.arange(0,1.05,0.05), color = 'blue') ax.hist(cluster_100['popen'], bins = np.arange(0,1.05,0.05), color = 'red') ax.set_title('Popen distribution for 100mM taurine') popen_100.savefig(os.path.join('/Users/zhiyiwu/GitHub/sc_py/data','taurine_100_Popen.png'),dpi=300) plt.close(popen_100) open_shut_100 = plt.figure() ax = open_shut_100.add_subplot(111) ax.scatter(stretch_100['mean_open'], stretch_100['mean_shut'], s=1, color = 'blue') ax.scatter(cluster_100['mean_open'], cluster_100['mean_shut'], s=1, color = 'red') ax.set_xscale('log') ax.set_yscale('log')