Louis BECQUEY

Reordered steps in 3D data extraction + removed inverted numbering support

This diff is collapsed. Click to expand it.
1 +#!python3
2 +import subprocess, os, sys
3 +
4 +# Put a list of problematic chains here, they will be properly deleted and recomputed
5 +problems = [
6 +"4v7f_1_1_4-3396",
7 +"4v7f_1_1_1-3167",
8 +"4v7f_1_1_1-3255",
9 +"6g90_1_1_1-407",
10 +"3q3z_1_A_1-74",
11 +"3q3z_1_V_1-74",
12 +"4v7f_1_3_1-121"
13 +]
14 +
15 +path_to_3D_data = sys.argv[1]
16 +path_to_seq_data = sys.argv[2]
17 +
18 +for p in problems:
19 + print()
20 + print()
21 + print()
22 + print()
23 +
24 + # Remove the datapoints files and 3D files
25 + subprocess.run(["rm", '-f', path_to_3D_data + f"/rna_mapped_to_Rfam/{p}.cif"])
26 + files = [ f for f in os.listdir(path_to_3D_data + "/datapoints") if p in f ]
27 + for f in files:
28 + subprocess.run(["rm", '-f', path_to_3D_data + f"/datapoints/{f}"])
29 +
30 + # Find more information
31 + structure = p.split('_')[0]
32 + chain = p.split('_')[2]
33 + families = [ f.split('.')[1] for f in files ] # The RFAM families this chain has been mapped onto
34 +
35 + # Delete the chain from the database, and the associated nucleotides and re_mappings, using foreign keys
36 + for fam in families:
37 + command = ["sqlite3", "results/RNANet.db", f"PRAGMA foreign_keys=ON; delete from chain where structure_id=\"{structure}\" and chain_name=\"{chain}\" and rfam_acc=\"{fam}\";"]
38 + print(' '.join(command))
39 + subprocess.run(command)
40 +
41 + # Re-run RNANet
42 + command = ["python3.8", "RNAnet.py", "--3d-folder", path_to_3D_data, "--seq-folder", path_to_seq_data, "-r", "20.0", "--extract", "--only", p]
43 + print('\n',' '.join(command),'\n')
44 + subprocess.run(command)
45 +
46 +# run statistics
...@@ -139,6 +139,7 @@ def reproduce_wadley_results(show=False, carbon=4, sd_range=(1,4)): ...@@ -139,6 +139,7 @@ def reproduce_wadley_results(show=False, carbon=4, sd_range=(1,4)):
139 fig.savefig(f"results/figures/wadley_plots/wadley_hist_{angle}_{l}.png") 139 fig.savefig(f"results/figures/wadley_plots/wadley_hist_{angle}_{l}.png")
140 if show: 140 if show:
141 fig.show() 141 fig.show()
142 + fig.close()
142 143
143 # Smoothed joint distribution 144 # Smoothed joint distribution
144 fig = plt.figure() 145 fig = plt.figure()
...@@ -149,6 +150,7 @@ def reproduce_wadley_results(show=False, carbon=4, sd_range=(1,4)): ...@@ -149,6 +150,7 @@ def reproduce_wadley_results(show=False, carbon=4, sd_range=(1,4)):
149 fig.savefig(f"results/figures/wadley_plots/wadley_distrib_{angle}_{l}.png") 150 fig.savefig(f"results/figures/wadley_plots/wadley_distrib_{angle}_{l}.png")
150 if show: 151 if show:
151 fig.show() 152 fig.show()
153 + fig.close()
152 154
153 # 2D Wadley plot 155 # 2D Wadley plot
154 fig = plt.figure(figsize=(5,5)) 156 fig = plt.figure(figsize=(5,5))
...@@ -161,6 +163,7 @@ def reproduce_wadley_results(show=False, carbon=4, sd_range=(1,4)): ...@@ -161,6 +163,7 @@ def reproduce_wadley_results(show=False, carbon=4, sd_range=(1,4)):
161 fig.savefig(f"results/figures/wadley_plots/wadley_{angle}_{l}.png") 163 fig.savefig(f"results/figures/wadley_plots/wadley_{angle}_{l}.png")
162 if show: 164 if show:
163 fig.show() 165 fig.show()
166 + fig.close()
164 # print(f"[{worker_nbr}]\tComputed joint distribution of angles (C{carbon}) and saved the figures.") 167 # print(f"[{worker_nbr}]\tComputed joint distribution of angles (C{carbon}) and saved the figures.")
165 168
166 def stats_len(): 169 def stats_len():
...@@ -440,7 +443,7 @@ def to_dist_matrix(f): ...@@ -440,7 +443,7 @@ def to_dist_matrix(f):
440 idty = dm.get_distance(al).matrix # list of lists 443 idty = dm.get_distance(al).matrix # list of lists
441 del al 444 del al
442 l = len(idty) 445 l = len(idty)
443 - np.save("data/"+f+".npy", np.array([ idty[i] + [0]*(l-1-i) if i<l-1 else idty[i] for i in range(l) ])) 446 + np.save("data/"+f+".npy", np.array([ idty[i] + [0]*(l-1-i) if i<l-1 else idty[i] for i in range(l) ], dtype=object))
444 del idty 447 del idty
445 notify(f"Computed {f} distance matrix") 448 notify(f"Computed {f} distance matrix")
446 return 0 449 return 0
......