scripts/manuela_hotspots/hotspot_table_script.py
... ...
@@ -0,0 +1,58 @@
1
+import pandas as pd
2
+import os
3
+
4
+# Config
5
+input_file = "hotspot_amino_acids_full_chrpos.tsv"
6
+parent_dir = "lymphopedia"
7
+output_dir = os.path.join(parent_dir, "tables", "hotspots")
8
+
9
+# Create output directory
10
+os.makedirs(output_dir, exist_ok=True)
11
+
12
+# Read TSV file
13
+df = pd.read_csv(input_file, sep="\t")
14
+
15
+# Lymphopedia format: select and rename columns
16
+df = df.rename(columns={
17
+ "Start_Position": "Coordinate (hg19)",
18
+ "HGVSp_Short": "HGVSp",
19
+ "Hugo_Symbol": "Gene",
20
+
21
+})[["Gene", "Chromosome", "Coordinate (hg19)", "DLBCL", "FL", "BL", "HGVSp"]]
22
+
23
+# Strip the "p." prefix from HGVSp
24
+df["HGVSp"] = df["HGVSp"].fillna("").astype(str).str.lstrip("p.")
25
+
26
+# List of genes --> per gene
27
+all_genes = df["Gene"].unique()
28
+
29
+#Iterate over each gene ID rather than group
30
+for gene_id in all_genes:
31
+
32
+ gene_df = df[df["Gene"] == gene_id]
33
+ #remove gene column for md table
34
+ gene_df = gene_df.drop(columns=["Gene"])
35
+
36
+ # md table header
37
+ md_table = "| " + " | ".join(gene_df.columns) + " |\n"
38
+ md_table += "| " + " | ".join(["------"] * len(gene_df.columns)) + " |\n"
39
+ for _, row in gene_df.iterrows():
40
+ md_table += "| " + " | ".join(map(str, row.values)) + " |\n"
41
+
42
+ # Per gene md file
43
+ file_name = f"hotspot_{gene_id}.md"
44
+ output_path = os.path.join(output_dir, file_name)
45
+ with open(output_path, "w", encoding="utf-8") as f:
46
+ f.write(f"## {gene_id} Hotspots\n\n")
47
+ f.write(md_table)
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+