Showing
2 changed files
with
18 additions
and
6 deletions
... | @@ -41,6 +41,8 @@ from Bio.Seq import MutableSeq | ... | @@ -41,6 +41,8 @@ from Bio.Seq import MutableSeq |
41 | from Bio.SeqRecord import SeqRecord | 41 | from Bio.SeqRecord import SeqRecord |
42 | from Bio.Align import MultipleSeqAlignment | 42 | from Bio.Align import MultipleSeqAlignment |
43 | 43 | ||
44 | +runDir = os.getcwd() | ||
45 | + | ||
44 | def trace_unhandled_exceptions(func): | 46 | def trace_unhandled_exceptions(func): |
45 | @wraps(func) | 47 | @wraps(func) |
46 | def wrapped_func(*args, **kwargs): | 48 | def wrapped_func(*args, **kwargs): |
... | @@ -2626,7 +2628,6 @@ def work_save(c, homology=True): | ... | @@ -2626,7 +2628,6 @@ def work_save(c, homology=True): |
2626 | 2628 | ||
2627 | if __name__ == "__main__": | 2629 | if __name__ == "__main__": |
2628 | 2630 | ||
2629 | - runDir = os.getcwd() | ||
2630 | fileDir = os.path.dirname(os.path.realpath(__file__)) | 2631 | fileDir = os.path.dirname(os.path.realpath(__file__)) |
2631 | ncores = read_cpu_number() | 2632 | ncores = read_cpu_number() |
2632 | pp = Pipeline() | 2633 | pp = Pipeline() | ... | ... |
... | @@ -944,7 +944,7 @@ def par_distance_matrix(filelist, f, label, consider_all_atoms, s): | ... | @@ -944,7 +944,7 @@ def par_distance_matrix(filelist, f, label, consider_all_atoms, s): |
944 | coordinates_with_gaps.append(coordinates[i - nb_gap]) | 944 | coordinates_with_gaps.append(coordinates[i - nb_gap]) |
945 | 945 | ||
946 | # Build the pairwise distances | 946 | # Build the pairwise distances |
947 | - d = np.zeros((len(s.seq), len(s.seq)), dtype=np.float16) | 947 | + d = np.zeros((len(s.seq), len(s.seq)), dtype=np.float32) |
948 | for i in range(len(s.seq)): | 948 | for i in range(len(s.seq)): |
949 | for j in range(len(s.seq)): | 949 | for j in range(len(s.seq)): |
950 | if np.isnan(coordinates_with_gaps[i]).any() or np.isnan(coordinates_with_gaps[j]).any(): | 950 | if np.isnan(coordinates_with_gaps[i]).any() or np.isnan(coordinates_with_gaps[j]).any(): |
... | @@ -1024,10 +1024,16 @@ def get_avg_std_distance_matrix(f, consider_all_atoms, multithread=False): | ... | @@ -1024,10 +1024,16 @@ def get_avg_std_distance_matrix(f, consider_all_atoms, multithread=False): |
1024 | p.join() | 1024 | p.join() |
1025 | exit(1) | 1025 | exit(1) |
1026 | 1026 | ||
1027 | - | 1027 | + with warnings.catch_warnings(record=True) as w: |
1028 | - if (counts > 1).all(): | 1028 | + warnings.simplefilter("error") |
1029 | + | ||
1029 | # Calculation of the average matrix | 1030 | # Calculation of the average matrix |
1030 | - avg = avg/counts | 1031 | + try: |
1032 | + avg = avg/counts | ||
1033 | + assert (counts >0).all() | ||
1034 | + except RuntimeWarning as e: | ||
1035 | + # there will be division by 0 if count is 0 at some position = gap only column | ||
1036 | + pass | ||
1031 | np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_average.csv' , avg, delimiter=",", fmt="%.3f") | 1037 | np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_average.csv' , avg, delimiter=",", fmt="%.3f") |
1032 | 1038 | ||
1033 | fig, ax = plt.subplots() | 1039 | fig, ax = plt.subplots() |
... | @@ -1040,7 +1046,12 @@ def get_avg_std_distance_matrix(f, consider_all_atoms, multithread=False): | ... | @@ -1040,7 +1046,12 @@ def get_avg_std_distance_matrix(f, consider_all_atoms, multithread=False): |
1040 | plt.close() | 1046 | plt.close() |
1041 | 1047 | ||
1042 | # Calculation of the standard deviation matrix by the Huygens theorem | 1048 | # Calculation of the standard deviation matrix by the Huygens theorem |
1043 | - std = np.sqrt(std/counts - np.power(avg, 2)) | 1049 | + try: |
1050 | + std = np.sqrt(std/counts - np.power(avg/counts, 2)) | ||
1051 | + assert (counts >0).all() | ||
1052 | + except RuntimeWarning as e: | ||
1053 | + # there will be division by 0 if count is 0 at some position = gap only column | ||
1054 | + pass | ||
1044 | np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_stdev.csv' , std, delimiter=",", fmt="%.3f") | 1055 | np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_stdev.csv' , std, delimiter=",", fmt="%.3f") |
1045 | 1056 | ||
1046 | fig, ax = plt.subplots() | 1057 | fig, ax = plt.subplots() | ... | ... |
-
Please register or login to post a comment