-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomparative_immune_profiling.py
More file actions
executable file
·46 lines (40 loc) · 1.89 KB
/
comparative_immune_profiling.py
File metadata and controls
executable file
·46 lines (40 loc) · 1.89 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
import pandas as pd
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import seaborn as sns
#LOAD DATA
tcell_exp = pd.read_csv('transcriptomics/tcell_exp/results/tcell_marker_comparison_16.csv', index_col=0)
# GENERATE T-CELL INFILTRATION SCORING (BAR CHART)
tcell_scores = tcell_exp.mean(axis=0)
score_df = pd.DataFrame({'Score': tcell_scores, 'Histology': ['LUAD']*8 + ['LUSC']*8})
score_df = score_df.sort_values('Score')
plt.figure(figsize=(12, 6))
colors = {'LUAD': 'steelblue', 'LUSC': 'darkorange'}
sns.barplot(data=score_df, x=score_df.index, y='Score', hue='Histology', palette=colors, dodge=False)
plt.xticks(rotation=90)
plt.title("T-cell Infiltration Score per Sample (LUAD vs LUSC)")
plt.ylabel("Mean log2(CPM + 1)")
plt.tight_layout()
plt.savefig('transcriptomics/tcell_exp/figures/tcell_infiltration_scores.png')
plt.close()
#GENERATE COMPARATIVE HEATMAP
plt.figure(figsize=(14, 8))
# Cluster samples to see if LUAD and LUSC group separately based ONLY on T-cell markers
sns.clustermap(tcell_exp, cmap='YlGnBu', annot=True, figsize=(15, 10),
col_colors=['steelblue']*8 + ['darkorange']*8, # Blue for LUAD, Orange for LUSC
standard_scale=1) # Scale genes for better visual contrast
plt.title("Heatmap: T-cell Marker Expression Profile")
plt.savefig('transcriptomics/tcell_exp/figures/tcell_heatmap.png')
plt.close()
#SUBTYPE-SPECIFIC INFILTRATION BOXPLOT
plt.figure(figsize=(8, 6))
sns.boxplot(data=score_df, x='Histology', y='Score', palette=colors)
sns.stripplot(data=score_df, x='Histology', y='Score', color='black', alpha=0.5)
plt.title("Comparison of T-cell Infiltration: LUAD vs LUSC")
plt.ylabel("Immune Score (Mean Expression)")
plt.tight_layout()
plt.savefig('transcriptomics/tcell_exp/figures/tcell_subtype_comparison_boxplot.png')
plt.close()
print("Immune profiling figures generated: Scores Bar Chart, Heatmap, and Subtype Boxplot.")