Louis BECQUEY

prevent div by zero if no 3D structures in the folder

...@@ -944,7 +944,6 @@ def par_distance_matrix(filelist, f, label, consider_all_atoms, s): ...@@ -944,7 +944,6 @@ 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 - print("> Computing distances for", s.id)
948 d = np.zeros((len(s.seq), len(s.seq)), dtype=np.float16) 947 d = np.zeros((len(s.seq), len(s.seq)), dtype=np.float16)
949 for i in range(len(s.seq)): 948 for i in range(len(s.seq)):
950 for j in range(len(s.seq)): 949 for j in range(len(s.seq)):
...@@ -953,7 +952,6 @@ def par_distance_matrix(filelist, f, label, consider_all_atoms, s): ...@@ -953,7 +952,6 @@ def par_distance_matrix(filelist, f, label, consider_all_atoms, s):
953 else: 952 else:
954 d[i,j] = get_euclidian_distance(coordinates_with_gaps[i], coordinates_with_gaps[j]) 953 d[i,j] = get_euclidian_distance(coordinates_with_gaps[i], coordinates_with_gaps[j])
955 954
956 - print("> finished.")
957 np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/'+ s.id.strip("\'") + '.csv', d, delimiter=",", fmt="%.3f") 955 np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/'+ s.id.strip("\'") + '.csv', d, delimiter=",", fmt="%.3f")
958 return 1-np.isnan(d).astype(int), np.nan_to_num(d), np.nan_to_num(d*d) 956 return 1-np.isnan(d).astype(int), np.nan_to_num(d), np.nan_to_num(d*d)
959 957
...@@ -1026,31 +1024,32 @@ def get_avg_std_distance_matrix(f, consider_all_atoms, multithread=False): ...@@ -1026,31 +1024,32 @@ def get_avg_std_distance_matrix(f, consider_all_atoms, multithread=False):
1026 exit(1) 1024 exit(1)
1027 1025
1028 1026
1029 - # Calculation of the average matrix 1027 + if (counts > 1).all():
1030 - avg = avg/counts 1028 + # Calculation of the average matrix
1031 - np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_average.csv' , avg, delimiter=",", fmt="%.3f") 1029 + avg = avg/counts
1032 - 1030 + np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_average.csv' , avg, delimiter=",", fmt="%.3f")
1033 - fig, ax = plt.subplots() 1031 +
1034 - im = ax.imshow(avg) 1032 + fig, ax = plt.subplots()
1035 - cbar = ax.figure.colorbar(im, ax=ax) 1033 + im = ax.imshow(avg)
1036 - cbar.ax.set_ylabel("Angströms", rotation=-90, va="bottom") 1034 + cbar = ax.figure.colorbar(im, ax=ax)
1037 - ax.set_title(f"Average distance between {f} residues (Angströms)") 1035 + cbar.ax.set_ylabel("Angströms", rotation=-90, va="bottom")
1038 - fig.tight_layout() 1036 + ax.set_title(f"Average distance between {f} residues (Angströms)")
1039 - fig.savefig(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_average.png', dpi=300) 1037 + fig.tight_layout()
1040 - plt.close() 1038 + fig.savefig(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_average.png', dpi=300)
1039 + plt.close()
1041 1040
1042 - # Calculation of the standard deviation matrix by the Huygens theorem 1041 + # Calculation of the standard deviation matrix by the Huygens theorem
1043 - std = np.sqrt(std/counts - np.power(avg, 2)) 1042 + std = np.sqrt(std/counts - np.power(avg, 2))
1044 - np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_stdev.csv' , std, delimiter=",", fmt="%.3f") 1043 + np.savetxt(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_stdev.csv' , std, delimiter=",", fmt="%.3f")
1045 - 1044 +
1046 - fig, ax = plt.subplots() 1045 + fig, ax = plt.subplots()
1047 - im = ax.imshow(std) 1046 + im = ax.imshow(std)
1048 - cbar = ax.figure.colorbar(im, ax=ax) 1047 + cbar = ax.figure.colorbar(im, ax=ax)
1049 - cbar.ax.set_ylabel("Angströms", rotation=-90, va="bottom") 1048 + cbar.ax.set_ylabel("Angströms", rotation=-90, va="bottom")
1050 - ax.set_title(f"Standard deviation of distances between {f} residues (Angströms)") 1049 + ax.set_title(f"Standard deviation of distances between {f} residues (Angströms)")
1051 - fig.tight_layout() 1050 + fig.tight_layout()
1052 - fig.savefig(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_std.png', dpi=300) 1051 + fig.savefig(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '_std.png', dpi=300)
1053 - plt.close() 1052 + plt.close()
1054 1053
1055 # Save log 1054 # Save log
1056 with open(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '.log', 'a') as logfile: 1055 with open(runDir + '/results/distance_matrices/' + f + '_'+ label + '/' + f + '.log', 'a') as logfile:
......