DynamiSpectra 1.0.3__py3-none-any.whl → 1.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dynamispectra/FractionSS.py +100 -0
- dynamispectra/Hbond.py +219 -0
- dynamispectra/PCA.py +118 -0
- dynamispectra/RMSD.py +218 -0
- dynamispectra/RMSF.py +216 -0
- dynamispectra/Rg.py +218 -0
- dynamispectra/SASA.py +219 -0
- dynamispectra/SecondaryStructure.py +201 -0
- dynamispectra/__init__.py +19 -0
- dynamispectra/cly.py +0 -0
- dynamispectra/main.py +4 -0
- {dynamispectra-1.0.3.dist-info → dynamispectra-1.0.5.dist-info}/METADATA +1 -1
- dynamispectra-1.0.5.dist-info/RECORD +16 -0
- {dynamispectra-1.0.3.dist-info → dynamispectra-1.0.5.dist-info}/WHEEL +0 -0
- dynamispectra-1.0.5.dist-info/top_level.txt +1 -0
- dynamispectra-1.0.3.dist-info/RECORD +0 -5
- dynamispectra-1.0.3.dist-info/top_level.txt +0 -1
- {dynamispectra-1.0.3.dist-info → dynamispectra-1.0.5.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import matplotlib.pyplot as plt
|
3
|
+
from matplotlib.patches import Patch # Para criar elementos de legenda personalizados
|
4
|
+
import os
|
5
|
+
|
6
|
+
# Mapeamento dos estados secundários para números
|
7
|
+
state_mapping = {
|
8
|
+
'H': 1, # Hélice-α
|
9
|
+
'E': 2, # Folha-β
|
10
|
+
'C': 0, # Loop/Coil
|
11
|
+
'T': 3, # Turn
|
12
|
+
'S': 4, # Bend
|
13
|
+
'G': 5, # 3-Helix
|
14
|
+
'~': -1, # Sem estrutura definida
|
15
|
+
'B': -1, # Tratar como sem estrutura
|
16
|
+
}
|
17
|
+
|
18
|
+
# Nomes das estruturas secundárias
|
19
|
+
state_names = {
|
20
|
+
0: 'Loop/Coil',
|
21
|
+
1: 'α-Helix',
|
22
|
+
2: 'β-Sheet',
|
23
|
+
3: 'Turn',
|
24
|
+
4: 'Bend',
|
25
|
+
5: '3-Helix',
|
26
|
+
}
|
27
|
+
|
28
|
+
def read_ss(file):
|
29
|
+
"""
|
30
|
+
Reads secondary structure data from a .dat file.
|
31
|
+
|
32
|
+
Parameters:
|
33
|
+
-----------
|
34
|
+
file : str
|
35
|
+
Path to the .dat file.
|
36
|
+
|
37
|
+
Returns:
|
38
|
+
--------
|
39
|
+
ss_data : numpy.ndarray
|
40
|
+
Array of secondary structure data.
|
41
|
+
"""
|
42
|
+
try:
|
43
|
+
print(f"Reading file: {file}")
|
44
|
+
|
45
|
+
# Open the file and process line by line
|
46
|
+
ss_data = []
|
47
|
+
|
48
|
+
with open(file, 'r') as f:
|
49
|
+
for line in f:
|
50
|
+
# Skip comment lines and empty lines
|
51
|
+
if line.startswith(('#', '@', ';')) or line.strip() == '':
|
52
|
+
continue
|
53
|
+
|
54
|
+
# Try to extract the secondary structure data
|
55
|
+
try:
|
56
|
+
ss_line = [state_mapping.get(char, -1) for char in line.strip()]
|
57
|
+
ss_data.append(ss_line)
|
58
|
+
except ValueError:
|
59
|
+
# Skip lines that cannot be converted to numbers
|
60
|
+
print(f"Error processing line: {line.strip()}")
|
61
|
+
continue
|
62
|
+
|
63
|
+
# Check if the data is valid
|
64
|
+
if len(ss_data) == 0:
|
65
|
+
raise ValueError(f"File {file} does not contain valid data.")
|
66
|
+
|
67
|
+
# Convert lists to numpy arrays
|
68
|
+
ss_data = np.array(ss_data)
|
69
|
+
|
70
|
+
return ss_data
|
71
|
+
|
72
|
+
except Exception as e:
|
73
|
+
print(f"Error reading file {file}: {e}")
|
74
|
+
return None
|
75
|
+
|
76
|
+
def calculate_probabilities(ss_data):
|
77
|
+
"""
|
78
|
+
Calculates the probability of each secondary structure.
|
79
|
+
|
80
|
+
Parameters:
|
81
|
+
-----------
|
82
|
+
ss_data : numpy.ndarray
|
83
|
+
Array of secondary structure data.
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
--------
|
87
|
+
probabilities : dict
|
88
|
+
Dictionary with probabilities for each secondary structure.
|
89
|
+
"""
|
90
|
+
probabilities = {state: [] for state in state_names.values()}
|
91
|
+
total_frames = ss_data.shape[0] # Total de frames
|
92
|
+
|
93
|
+
for estado, nome in state_names.items():
|
94
|
+
probabilities[nome] = np.sum(ss_data == estado, axis=1) / ss_data.shape[1] # Probabilidade por frame
|
95
|
+
|
96
|
+
return probabilities
|
97
|
+
|
98
|
+
def plot_ss_boxplot(probabilities_list, labels, colors, output_folder):
|
99
|
+
"""
|
100
|
+
Generates a boxplot for secondary structure probabilities.
|
101
|
+
|
102
|
+
Parameters:
|
103
|
+
-----------
|
104
|
+
probabilities_list : list of dict
|
105
|
+
List of dictionaries with probabilities for each simulation.
|
106
|
+
labels : list of str
|
107
|
+
Labels for each simulation.
|
108
|
+
colors : list of str
|
109
|
+
Colors for each simulation.
|
110
|
+
output_folder : str
|
111
|
+
Output folder to save the plots.
|
112
|
+
"""
|
113
|
+
# Preparar dados para o boxplot
|
114
|
+
x_labels = list(state_names.values()) # Estruturas secundárias
|
115
|
+
x = np.arange(len(x_labels)) # Posições no eixo X
|
116
|
+
|
117
|
+
# Criar figura para o boxplot
|
118
|
+
plt.figure(figsize=(7, 6))
|
119
|
+
plt.plot()
|
120
|
+
|
121
|
+
# Função para plotar boxplots
|
122
|
+
def plot_boxplot(data, positions, color, label):
|
123
|
+
box = plt.boxplot(data, positions=positions, widths=0.4, patch_artist=True, labels=[label] * len(positions), showfliers=False) # Remover outliers
|
124
|
+
for boxplot in box['boxes']:
|
125
|
+
boxplot.set_facecolor(color)
|
126
|
+
boxplot.set_alpha(0.7)
|
127
|
+
for median in box['medians']:
|
128
|
+
median.set_color('black')
|
129
|
+
return box
|
130
|
+
|
131
|
+
# Plotar boxplots para cada simulação
|
132
|
+
for i, (probabilities, label, color) in enumerate(zip(probabilities_list, labels, colors)):
|
133
|
+
data = [probabilities[name] * 100 for name in x_labels]
|
134
|
+
plot_boxplot(data, x - 0.25 + i * 0.25, color, label)
|
135
|
+
|
136
|
+
# Configuração do gráfico
|
137
|
+
plt.xlabel('', fontsize=12)
|
138
|
+
plt.ylabel('Probability (%)', fontsize=12) # Eixo y em percentual
|
139
|
+
plt.title('', fontsize=14, fontweight='bold')
|
140
|
+
plt.xticks(x, x_labels, rotation=45, fontsize=10)
|
141
|
+
plt.yticks(fontsize=10)
|
142
|
+
plt.grid(False) # Remover a grade
|
143
|
+
|
144
|
+
# Cores e rótulos para a legenda
|
145
|
+
legend_elements = [
|
146
|
+
Patch(facecolor=color, edgecolor='black', linewidth=1.2, alpha=0.7, label=label)
|
147
|
+
for label, color in zip(labels, colors)
|
148
|
+
]
|
149
|
+
|
150
|
+
# Posicionar a legenda
|
151
|
+
plt.legend(handles=legend_elements, frameon=False, fontsize=10, loc='upper right', edgecolor='black') # Borda ao redor da legenda
|
152
|
+
|
153
|
+
# Ajustar layout para evitar cortes
|
154
|
+
plt.tight_layout()
|
155
|
+
|
156
|
+
# Salvar o gráfico em 300 dpi (PNG e TIFF)
|
157
|
+
os.makedirs(output_folder, exist_ok=True) # Create the folder if it doesn't exist
|
158
|
+
|
159
|
+
# Salvar como PNG
|
160
|
+
plt.savefig(os.path.join(output_folder, 'secondary_structure_boxplot.png'), dpi=300, format='png', bbox_inches='tight')
|
161
|
+
|
162
|
+
# Salvar como TIFF
|
163
|
+
plt.savefig(os.path.join(output_folder, 'secondary_structure_boxplot.tiff'), dpi=300, format='tiff', bbox_inches='tight')
|
164
|
+
|
165
|
+
# Mostrar gráfico
|
166
|
+
plt.show()
|
167
|
+
|
168
|
+
def ss_analysis(output_folder, *simulation_files_groups):
|
169
|
+
r"""
|
170
|
+
Main function to generate secondary structure analysis and plots.
|
171
|
+
|
172
|
+
Parameters:
|
173
|
+
-----------
|
174
|
+
output_folder : str
|
175
|
+
Output folder to save the plots.
|
176
|
+
\*simulation_files_groups : list of str
|
177
|
+
List of paths to .dat files for each simulation group.
|
178
|
+
You can pass 1, 2, or 3 groups.
|
179
|
+
"""
|
180
|
+
# Helper function to process a group of files
|
181
|
+
def process_group(file_paths):
|
182
|
+
ss_data = []
|
183
|
+
for file in file_paths:
|
184
|
+
data = read_ss(file)
|
185
|
+
ss_data.append(data)
|
186
|
+
return ss_data
|
187
|
+
|
188
|
+
# Process each group of files
|
189
|
+
probabilities_list = []
|
190
|
+
labels = []
|
191
|
+
colors = ['#333333', '#6A9EDA', '#54b36a'] # Cores para cada simulação
|
192
|
+
|
193
|
+
for i, group in enumerate(simulation_files_groups):
|
194
|
+
if group: # Check if the list is not empty
|
195
|
+
ss_data = process_group(group)
|
196
|
+
probabilities = calculate_probabilities(ss_data[0]) # Assume only one file per group
|
197
|
+
probabilities_list.append(probabilities)
|
198
|
+
labels.append(f'Simulation {i + 1}')
|
199
|
+
|
200
|
+
# Generate plots
|
201
|
+
plot_ss_boxplot(probabilities_list, labels, colors[:len(probabilities_list)], output_folder)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# src/__init__.py
|
2
|
+
from .Hbond import read_hbond, hbond_analysis
|
3
|
+
from .RMSD import rmsd_analysis
|
4
|
+
from .RMSF import read_rmsf, rmsf_analysis
|
5
|
+
from .SASA import read_sasa, sasa_analysis
|
6
|
+
from .Rg import read_rg, rg_analysis
|
7
|
+
from .PCA import pca_analysis
|
8
|
+
from .SecondaryStructure import (
|
9
|
+
read_ss,
|
10
|
+
calculate_probabilities,
|
11
|
+
plot_ss_boxplot,
|
12
|
+
ss_analysis,
|
13
|
+
state_mapping,
|
14
|
+
state_names
|
15
|
+
)
|
16
|
+
from .FractionSS import fractions_ss_analysis
|
17
|
+
|
18
|
+
|
19
|
+
__all__ = ['read_hbond', 'hbond_analysis', 'read_rmsd', 'rmsd_analysis', 'read_rmsf', 'rmsf_analysis', 'read_sasa', 'sasa_analysis', 'read_rg', 'rg_analysis', 'pca_analysis', 'read_ss', 'calculate_probabilities', 'plot_ss_boxplot', 'ss_analysis', 'state_mapping', 'state_names', 'fractions_ss_analysis']
|
dynamispectra/cly.py
ADDED
File without changes
|
dynamispectra/main.py
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
dynamispectra/FractionSS.py,sha256=-4GiRsvTiwyn5rN17hNKfbmzfevnEOqOm1TxMl8gQOs,3647
|
2
|
+
dynamispectra/Hbond.py,sha256=-Mb4g-tITqxEG1VbvYae4TgmTsIRyMis3NEm3Ey9Zu0,8658
|
3
|
+
dynamispectra/PCA.py,sha256=nwQ7jEMvuhRAIvRRiGboQ8Cl0qrm15xSgHYCX0HlKiU,3482
|
4
|
+
dynamispectra/RMSD.py,sha256=EUSv1Ql0f7P3VRhx6175NxjEn-2cIXx4lbVfeI88Gbk,8622
|
5
|
+
dynamispectra/RMSF.py,sha256=M2b-KfvogfFbLUtv6PgZB4_nxWBeg9XbBpY0HjNQ9fw,8545
|
6
|
+
dynamispectra/Rg.py,sha256=4F_vjdgcRG9LNqNCig1kdaUpMIRZrtQppYwL2OpJFYk,8557
|
7
|
+
dynamispectra/SASA.py,sha256=o6_hcsmeY9yjAKUgsd0RpMikwC9VhoKAmQ1JLtPuXos,8661
|
8
|
+
dynamispectra/SecondaryStructure.py,sha256=7jiYnqRgDaiR-16Zk40aCyv060y-1R__m44AVkhvm9g,6764
|
9
|
+
dynamispectra/__init__.py,sha256=r13WozJ-uCGqA2QH84LzO-wzsv3HiMoVpZoIBydrPWk,771
|
10
|
+
dynamispectra/cly.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
dynamispectra/main.py,sha256=YhivGFXZb1qwRCPUNmST5LeejqTyHmthMhzJs9uebJY,84
|
12
|
+
dynamispectra-1.0.5.dist-info/METADATA,sha256=PvTAdyQx1tNbIMq5F0RREWuIoC7BMkg4nddVF6-KNQ8,3807
|
13
|
+
dynamispectra-1.0.5.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
14
|
+
dynamispectra-1.0.5.dist-info/entry_points.txt,sha256=aaQocKWsZi_lJ7MZMsxHmc2DpQF4BSY0fwfE1s0CLxo,37
|
15
|
+
dynamispectra-1.0.5.dist-info/top_level.txt,sha256=MDRYQBL4n7V0YVNSoOO_yf7iv_Kz3JGoVUEHiq_zT6U,14
|
16
|
+
dynamispectra-1.0.5.dist-info/RECORD,,
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
dynamispectra
|
@@ -1,5 +0,0 @@
|
|
1
|
-
dynamispectra-1.0.3.dist-info/METADATA,sha256=vjVXE6ffTuM-Z7jcabSwIHBSV8_WMvafk85Js2gfEMo,3807
|
2
|
-
dynamispectra-1.0.3.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
3
|
-
dynamispectra-1.0.3.dist-info/entry_points.txt,sha256=aaQocKWsZi_lJ7MZMsxHmc2DpQF4BSY0fwfE1s0CLxo,37
|
4
|
-
dynamispectra-1.0.3.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
5
|
-
dynamispectra-1.0.3.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
|
File without changes
|