Exemplo n.º 1
0
    def test_info(self):
        '''
        Test the info module.
        '''

        for patch in self._name_list:
            test_patch = Patch(os.path.join(self._dir, patch))
            test_patch.scan()
            for index, cluster in enumerate(test_patch):
                # Testing basic information loading
                test_start = abs(cluster.start - self._patch_list[patch][index]['start'])
                if test_start > 0.0001:
                    print('Module Info "start" test failed')
                    print('Expected: {}, Obtained: {}'.format(self._patch_list[patch][index]['start'],
                    cluster.start))

                test_open_period = sum((cluster.open_period - self._patch_list[patch][index]['open_period'])**2)
                if test_open_period > 0.0001:
                    print('Module Info "open_period" test failed')
                    print('Total difference: {}'.format(test_open_period))

                test_shut_period = sum((cluster.shut_period - self._patch_list[patch][index]['shut_period'])**2)
                if test_shut_period > 0.0001:
                    print('Module Info "shut_period" test failed')
                    print('Total difference: {}'.format(test_shut_period))

                test_open_amp = sum((cluster.open_amp - self._patch_list[patch][index]['open_amp'])**2)
                if test_open_amp > 0.0001:
                    print('Module Info "open_amp" test failed')
                    print('Total difference: {}'.format(test_open_amp))

                test_shut_amp = sum((cluster.shut_amp - self._patch_list[patch][index]['shut_amp'])**2)
                if test_shut_amp > 0.0001:
                    print('Module Info "shut_amp" test failed')
                    print('Total difference: {}'.format(test_shut_amp))
Exemplo n.º 2
0
 def scan_folder(self, clear = True):
     '''
     Scan and collect all the clusters in the folder.
     '''
     if clear:
         self._cluster_list = []
     for folder in self._folder_list:
         patch_list = [csv for csv in os.listdir(folder) if csv[-4:] == '.csv']
         for patch in patch_list:
             current_path = os.path.join(folder, patch)
             current_patch = Patch(current_path)
             current_patch.scan()
             for cluster in current_patch:
                 self._cluster_list.append(cluster)
     return self._cluster_list
Exemplo n.º 3
0
 def test_PlotComputation_using_PlotMPL(self):
     '''
     Testing the PlotComputation using the PlotMPL module which uses Matplotlib as backend.
     '''
     for patch in self._name_list:
         test_patch = Patch(os.path.join(self._dir, patch))
         test_patch.scan()
         for index, cluster in enumerate(test_patch):
             cluster.compute_mode()
             cluster.compute_mode_detail()
             test_plot = PlotSingle(self._dir)
             test_plot.load_cluster(cluster)
             test_plot.plot_original()
             test_plot.plot_popen_on_original()
             test_plot.plot_open_close()
             test_plot.plot_cost_difference()
Exemplo n.º 4
0
    def scan_orded_folder(self, func = _add_cluster, clear = True, export = False):
        '''
        Scan the folder and apply the func to every clusters in the folder.
        If func is not provided, a whole list of the clusters in the folder
        will be generated.
        '''
        if clear:
            self._cluster_list = []
        for folder in self._folder_list:
            current_path = folder
            current_folder_list = list_folder(current_path)

            for receptor in current_folder_list:
                current_path_R = os.path.join(current_path, receptor)
                current_folder_list_R = list_folder(current_path_R)

                for mutation in current_folder_list_R:
                    current_path_M = os.path.join(current_path_R, mutation)
                    current_folder_list_M = list_folder(current_path_M)

                    for composition in current_folder_list_M:
                        current_path_C = os.path.join(current_path_M, composition)
                        current_folder_list_C = list_folder(current_path_C)

                        for agonist in current_folder_list_C:
                            current_path_A = os.path.join(current_path_C, agonist)
                            current_folder_list_A = list_folder(current_path_A)

                            for concentration in current_folder_list_A:
                                path = os.path.join(current_path_A, concentration)
                                patch_list = [csv for csv in os.listdir(path)
                                              if csv[-4:] == '.csv']

                                for patch in patch_list:
                                    filepath = os.path.join(path, patch)
                                    current_patch = Patch(filepath)
                                    current_patch.scan()

                                    for cluster in current_patch:
                                        func(self, cluster,
                                             receptor = receptor,
                                             mutation = mutation,
                                             composition = composition,
                                             agonist = agonist,
                                             concentration = concentration)
        if export:
            return self._cluster_list
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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')
Exemplo n.º 7
0
# -*- coding: utf-8 -*-
"""
Created on Tue Jun  7 09:32:25 2016

@author: zhiyiwu
"""


import numpy as np
import matplotlib.pyplot as plt

from info import Patch
from binary_search import BFS

patch = Patch('/Users/zhiyiwu/Documents/pharmfit/12061415.csv')
patch.scan()
cluster = patch[1]
opening = cluster.open_period
log_opening = np.log10(opening)
plt.hist(log_opening)
sep_open = sorted(BFS(log_opening[:, np.newaxis]))
print(sep_open)

shutting = cluster.shut_period
plt.hist(np.log10(shutting))
log_shutting = np.log10(shutting)
plt.hist(log_shutting)
sep_shut = sorted(BFS(log_shutting[:, np.newaxis]))
print(sep_shut)

period = cluster.period