-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeast_visualiser.py
More file actions
55 lines (45 loc) · 1.98 KB
/
beast_visualiser.py
File metadata and controls
55 lines (45 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# **📌 BEAST log dosyasını oku**
log_file = "/home/analysis/Desktop/re_root/new_dawn/_1739865905/new_analysis2_BEAST.log"
# **BEAST log dosyasını DataFrame'e çevir**
df = pd.read_csv(log_file, sep="\t", comment="#")
# **Gerekli sütunları al**
df_filtered = df[["dN", "dS", "dN/dS", "posterior"]].dropna()
# **Ka/Ks oranına göre seçilim sınıflandırması**
df_filtered["Selection Type"] = df_filtered["dN/dS"].apply(lambda x:
"Positive Selection" if x > 1 else ("Neutral" if 0.9 <= x <= 1.1 else "Negative Selection")
)
# **Ortalama Ka/Ks hesapla**
mean_dnds = df_filtered["dN/dS"].mean()
# **Bayes faktörü ile dN/dS arasındaki ilişkiyi görselleştir**
plt.figure(figsize=(10, 6))
sns.scatterplot(x=df_filtered["posterior"], y=df_filtered["dN/dS"], hue=df_filtered["Selection Type"], palette="coolwarm", alpha=0.7)
plt.axhline(1, color="red", linestyle="--", label="Neutral Evolution (Ka/Ks = 1)")
plt.xlabel("Bayesian Posterior Probability")
plt.ylabel("Ka/Ks (dN/dS) Ratio")
plt.title("Bayesian Support vs Ka/Ks (dN/dS) Ratio")
plt.legend()
plt.show()
# **Histogram: Ka/Ks Dağılımı**
plt.figure(figsize=(10, 6))
sns.histplot(df_filtered["dN/dS"], bins=20, kde=True, color="blue")
plt.axvline(1, color="red", linestyle="--", label="Neutral Evolution (Ka/Ks = 1)")
plt.xlabel("Ka/Ks (dN/dS) Ratio")
plt.ylabel("Frequency")
plt.title(f"Ka/Ks (dN/dS) Distribution - Mean: {mean_dnds:.2f}")
plt.legend()
plt.show()
# **Boxplot ile Seçilim Tiplerini Göster**
plt.figure(figsize=(8, 6))
sns.boxplot(x=df_filtered["Selection Type"], y=df_filtered["dN/dS"], palette="coolwarm")
plt.axhline(1, color="red", linestyle="--", label="Neutral Evolution (Ka/Ks = 1)")
plt.ylabel("Ka/Ks Ratio")
plt.xlabel("Selection Type")
plt.title("Selection Pressure on Genes")
plt.legend()
plt.show()
# **Sonuçları göster**
import ace_tools as tools
tools.display_dataframe_to_user(name="Advanced BEAST dN/dS Analysis", dataframe=df_filtered)