Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Update alpha-diversity (#18)
Browse files Browse the repository at this point in the history
Add mean symbol
  • Loading branch information
Fumire committed Feb 8, 2023
1 parent 954d3ba commit 2629e5f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
10 changes: 8 additions & 2 deletions jwlee230/Program/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,14 @@ Output/Step30/First.Macrogen.tar: Python/step30-1.py Output/TSV/Macrogen.tsv Out
Output/Step30/Second_Third.Macrogen.tar: Python/step30-1.py Output/TSV/Macrogen.tsv Output/Metadata/everything.tsv | Output/Step30 build.log
$(DOCKER) $(PYTHON) $(addprefix /,$^ $@) --cpus $(CPUS) --second 1> $@.stdout 2> $@.stderr

step30-DADA2: Output/Step30/DADA2/everything.evenness.tsv Output/Step30/DADA2/everything.faith_pd.tsv Output/Step30/DADA2/everything.observed_features.tsv Output/Step30/DADA2/everything.shannon.tsv Output/Step30/everything.DADA2.tar Output/Step30/First.DADA2.tar Output/Step30/Second_Third.DADA2.tar
step30-Deblur: Output/Step30/Deblur/everything.evenness.tsv Output/Step30/Deblur/everything.faith_pd.tsv Output/Step30/Deblur/everything.observed_features.tsv Output/Step30/Deblur/everything.shannon.tsv Output/Step30/everything.Deblur.tar Output/Step30/First.Deblur.tar Output/Step30/Second_Third.Deblur.tar
Output/Step30/singleton.DADA2.tar: Python/step30.py Output/Step30/DADA2/everything.evenness.tsv Output/Step30/DADA2/everything.faith_pd.tsv Output/Step30/DADA2/everything.observed_features.tsv Output/Step30/DADA2/everything.shannon.tsv Output/Metadata/singleton.tsv | build.log
$(DOCKER) $(PYTHON) $(addprefix /,$^ $@) --cpus $(CPUS) 1> $@.stdout 2> $@.stderr

Output/Step30/singleton.Deblur.tar: Python/step30.py Output/Step30/Deblur/everything.evenness.tsv Output/Step30/Deblur/everything.faith_pd.tsv Output/Step30/Deblur/everything.observed_features.tsv Output/Step30/Deblur/everything.shannon.tsv Output/Metadata/singleton.tsv | build.log
$(DOCKER) $(PYTHON) $(addprefix /,$^ $@) --cpus $(CPUS) 1> $@.stdout 2> $@.stderr

step30-DADA2: Output/Step30/DADA2/everything.evenness.tsv Output/Step30/DADA2/everything.faith_pd.tsv Output/Step30/DADA2/everything.observed_features.tsv Output/Step30/DADA2/everything.shannon.tsv Output/Step30/everything.DADA2.tar Output/Step30/First.DADA2.tar Output/Step30/Second_Third.DADA2.tar Output/Step30/singleton.DADA2.tar
step30-Deblur: Output/Step30/Deblur/everything.evenness.tsv Output/Step30/Deblur/everything.faith_pd.tsv Output/Step30/Deblur/everything.observed_features.tsv Output/Step30/Deblur/everything.shannon.tsv Output/Step30/everything.Deblur.tar Output/Step30/First.Deblur.tar Output/Step30/Second_Third.Deblur.tar Output/Step30/singleton.Deblur.tar
step30-Macrogen: Output/Step30/Macrogen.tar Output/Step30/First.Macrogen.tar Output/Step30/Second_Third.Macrogen.tar
step30: step30-DADA2 step30-Deblur
.PHONY: step30-DADA2 step30-Deblur step30-Macrogen step30
Expand Down
2 changes: 1 addition & 1 deletion jwlee230/Program/Python/step00.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
numeric_columns = {"Gestational Week", "Weight", "Mother Age", "Hospitalized Day", "Apgar Score", "Weight gain", "Cholesterol", "TG", "HDL", "LDL", "Glucose", "WBC", "Hb", "Hct", "ESR", "hsCRP", "AST", "ALT", "SBP", "DBP"}
detailed_PTB = ("Early PTB", "Late PTB", "Normal")
PTB_colors = {"Early PTB": "tab:red", "Late PTB": "tab:pink", "Normal": "w"}
PTB_two_colors = {"PTB": "tab:red", "Normal": "tab:green", "FTB": "tab:green"}
PTB_two_colors = {"PTB": "tab:red", "Normal": "tab:green"}

selected_sites = ("M", "C", "V")
selected_long_sites = ("Mouth", "Cervix", "Vagina")
Expand Down
31 changes: 23 additions & 8 deletions jwlee230/Program/Python/step30.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tarfile
import matplotlib
import matplotlib.pyplot
import numpy
import pandas
import seaborn
import statannotations.Annotator
Expand All @@ -28,12 +29,19 @@ def draw(alpha: str, disease: str, site: str) -> str:

fig, ax = matplotlib.pyplot.subplots(figsize=(18, 18))

seaborn.violinplot(data=drawing_data, x=disease, y=alpha, order=order, inner="box", ax=ax)
if disease == "Premature":
seaborn.violinplot(data=drawing_data, x=disease, y=alpha, order=order, inner="box", linewidth=5, palette=step00.PTB_two_colors, ax=ax)
else:
seaborn.violinplot(data=drawing_data, x=disease, y=alpha, order=order, inner="box", linewidth=5, ax=ax)

if len(order) > 1:
statannotations.Annotator.Annotator(ax, list(itertools.combinations(order, 2)), data=drawing_data, x=disease, y=alpha, order=order).configure(test="Mann-Whitney", text_format="star", loc="inside", verbose=0).apply_and_annotate()
statannotations.Annotator.Annotator(ax, list(itertools.combinations(order, 2)), data=drawing_data, x=disease, y=alpha, order=order).configure(test="Mann-Whitney", text_format="simple", loc="inside", verbose=0).apply_and_annotate()

matplotlib.pyplot.scatter(x=range(len(order)), y=[numpy.mean(drawing_data.loc[(drawing_data[disease] == d), alpha]) for d in order], marker="*", c="white", s=400, zorder=10)

matplotlib.pyplot.xlabel("")
matplotlib.pyplot.ylabel(alpha.replace("_", " "))
matplotlib.pyplot.title(site)
matplotlib.pyplot.title(disease)
matplotlib.pyplot.tight_layout()

file_name = "{2}+{1}+{0}.pdf".format(alpha, disease.replace(" ", "_"), site)
Expand All @@ -49,12 +57,19 @@ def draw_all(alpha: str, disease: str) -> str:

fig, ax = matplotlib.pyplot.subplots(figsize=(18, 18))

seaborn.violinplot(data=data, x=disease, y=alpha, order=order, inner="box", ax=ax)
if disease == "Premature":
seaborn.violinplot(data=data, x=disease, y=alpha, order=order, inner="box", linewidth=5, palette=step00.PTB_two_colors, ax=ax)
else:
seaborn.violinplot(data=data, x=disease, y=alpha, order=order, inner="box", linewidth=5, ax=ax)

if len(order) > 1:
statannotations.Annotator.Annotator(ax, list(itertools.combinations(order, 2)), data=data, x=disease, y=alpha, order=order).configure(test="Mann-Whitney", text_format="star", loc="inside", verbose=0).apply_and_annotate()
statannotations.Annotator.Annotator(ax, list(itertools.combinations(order, 2)), data=data, x=disease, y=alpha, order=order).configure(test="Mann-Whitney", text_format="simple", loc="inside", verbose=0).apply_and_annotate()

matplotlib.pyplot.scatter(x=range(len(order)), y=[numpy.mean(data.loc[(data[disease] == d), alpha]) for d in order], marker="*", c="white", s=400, zorder=10)

matplotlib.pyplot.xlabel("")
matplotlib.pyplot.ylabel(alpha.replace("_", " "))
matplotlib.pyplot.title("All")
matplotlib.pyplot.title(disease)
matplotlib.pyplot.tight_layout()

file_name = "All+{1}+{0}.pdf".format(alpha, disease.replace(" ", "_"))
Expand Down Expand Up @@ -84,7 +99,7 @@ def draw_all(alpha: str, disease: str) -> str:
elif not args.output.endswith(".tar"):
raise ValueError("Output file must end with .TAR!!")
elif args.cpus < 1:
raise ValueError("CPUS must be positive!!")
raise ValueError("CPUs must be positive!!")

matplotlib.use("Agg")
matplotlib.rcParams.update(step00.matplotlib_parameters)
Expand All @@ -102,7 +117,7 @@ def draw_all(alpha: str, disease: str) -> str:
print(sorted(alphas))

metadata = pandas.read_csv(args.metadata, sep="\t", skiprows=[1], dtype=str).dropna(axis="columns", how="all").set_index(keys=["#SampleID"], verify_integrity=True)
metadata = metadata.loc[list(raw_data.index), sorted(set(metadata.columns) - step00.numeric_columns)].replace(to_replace=-1, value=None)
metadata = metadata.loc[sorted(set(raw_data.index) & set(metadata.index)), sorted(set(metadata.columns) - step00.numeric_columns)].replace(to_replace=-1, value=None)
diseases = set(metadata.columns) - step00.numeric_columns - {"Mother", "Neonate", "Site"}
print(metadata)
print(sorted(diseases))
Expand Down

0 comments on commit 2629e5f

Please sign in to comment.