Skip to content

Commit

Permalink
adds code for figure 4g
Browse files Browse the repository at this point in the history
  • Loading branch information
skafdasschaf committed Jun 21, 2022
1 parent a4f1b3d commit 1b10c17
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `doc`: project documentation
- `literature`: relevant publications
- `metadata`: additional required data
- `misc`: miscellaneous scripts
- `plots`: generated plots
- `renv`: R environment data
- `tables`: exported tables
Expand Down Expand Up @@ -73,8 +74,8 @@ required by figures and tables.
- [compare_tumors_pseudobulk.R](compare_tumors_pseudobulk.R)
comparison of tumor samples via pseudobulk correlation



## Plotting functions

Run these R scripts in arbitrary order to generate exploratory figures:
Expand All @@ -87,7 +88,7 @@ Run these R scripts in arbitrary order to generate exploratory figures:
canonical cell type markers
- [plot_misc.R](plot_misc.R) -
miscellaneous plots


Run these R scripts in arbitrary order to generate publication figures and tables:

Expand Down
62 changes: 62 additions & 0 deletions misc/plot_figure_4g.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from statannot import add_stat_annotation
import numpy as np
import argparse
import os

def parse():
parser = argparse.ArgumentParser()
parser.add_argument('-in', dest = 'in_path', required=True, help='Path to csv file containing normalized single-cell data.')
parser.add_argument('-out', dest = 'out_path', required=True, help='Path to output folder.')
args = parser.parse_args()
return args


def split(word: str):
return [char for char in word]

def main (args):

in_path = args.in_path
out_path = args.out_path

df = pd.read_csv(in_path, delimiter=';', decimal=',')
col = [i for i in df.columns if 'MXP_c' in i or 'batch' in i or 'cluster' in i]

crtl_list = ['BM1.2', 'BM1.3', 'BM2.3']
inf_list = ['BM2.1', 'BM2.2', 'BM4.1', 'BM1.1', 'BM3.1']

df = df[col]
df = df[df['cluster']=='MO/M']
df['inf'] = ['crtl' if df.iloc[i]['batch'] in crtl_list else 'NB' for i in range(0, df.shape[0])]
df = df.drop(['batchlegend', 'batch', 'cluster'], axis=1)

col_list = list(df.columns)
col_list.remove('inf')

df.inf = df.inf.astype("category")

for marker in col_list:

medians = df.groupby(['inf'])[marker].median()
medians = medians.reindex(index=['crtl', 'NB'], copy=True)
vertical_offset = df[marker].median() * 0.05

ax = sns.boxplot(x='inf', y=marker, data=df, linewidth=0.4, fliersize=1, width=0.5, order=['crtl', 'NB'])

plot = add_stat_annotation(ax, data=df, x='inf', y=marker, box_pairs=[('crtl', 'NB')], test='Mann-Whitney', text_format='star', loc='outside', verbose=2)

for xtick in ax.get_xticks():
ax.text(xtick,medians[xtick] + vertical_offset,medians[xtick], horizontalalignment='center',size='x-small',color='black',weight='semibold')

plt.tight_layout()
plt.savefig(os.path.join(out_path, marker +'_expr_crtl_vs_NB.eps'), format='eps')
plt.savefig(os.path.join(out_path, marker +'_expr_crtl_vs_NB.pdf'), format='pdf')
plt.close()


if __name__ == "__main__":
args = parse()
main(args)

0 comments on commit 1b10c17

Please sign in to comment.