Skip to content

Commit b4c045d

Browse files
authored
Merge pull request #36 from sbslee/1.12.0-dev
1.12.0 dev
2 parents a528a83 + c926f00 commit b4c045d

14 files changed

Lines changed: 161 additions & 76 deletions

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
*********
33

4+
1.12.0 (2022-02-11)
5+
-------------------
6+
7+
* :issue:`33`: Update the :command:`make-manifest` command to ignore undetermined FASTQ files.
8+
* :issue:`34`: Update the :meth:`alpha_rarefaction_plot` method to keep 'N/A' values as string instead of NaN.
9+
* :issue:`35`: Update the methods :meth:`alpha_diversity_plot`, :meth:`beta_2d_plot`, and :meth:`beta_3d_plot` to accept :class:`pandas.DataFrame` in case the input data was not generated from QIIME 2 (e.g. shotgun sequencing).
10+
* Update the methods :meth:`beta_2d_plot` and :meth:`beta_3d_plot` to print out the proportions explained instead of embedding them in the PCoA plot.
11+
412
1.11.0 (2021-08-04)
513
-------------------
614

README.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ Your contributions (e.g. feature ideas, pull requests) are most welcome.
2020
| Email: sbstevenlee@gmail.com
2121
| License: MIT License
2222
23+
Citation
24+
========
25+
26+
If you use Dokdo in a published analysis, please report the program version
27+
and the GitHub repository (https://github.com/sbslee/dokdo). If applicable,
28+
please also consider citing the following preprint in which Dokdo was first
29+
described:
30+
31+
JY Park, H Yoon, S Lee, et al. Do Different Samples From Pregnant Women and
32+
Their Neonates Share the Common Microbiome: A Prospective Cohort Study.
33+
November 29th, 2021. Research Square.
34+
doi: https://doi.org/10.21203/rs.3.rs-1062191/v1.
35+
36+
Below is an incomplete list of publications which have used Dokdo:
37+
38+
- `Silva de Carvalho et al., 2022 <https://www.sciencedirect.com/science/article/pii/S0889159121006127>`__ in *Brain, Behavior, and Immunity*: Post-ischemic protein restriction induces sustained neuroprotection, neurological recovery, brain remodeling, and gut microbiota rebalancing.
39+
- `Park et al., 2021 <https://www.nature.com/articles/s41598-021-95789-8>`__ in *Scientific Reports*: Effect of black ginseng and silkworm supplementation on obesity, the transcriptome, and the gut microbiome of diet-induced overweight dogs.
40+
- `Reinold et al., 2021 <https://www.frontiersin.org/articles/10.3389/fcimb.2021.747816/full>`__ in *Frontiers in Cellular and Infection Microbiology*: A Pro-Inflammatory Gut Microbiome Characterizes SARS-CoV-2 Infected Patients and a Reduction in the Connectivity of an Anti-Inflammatory Bacterial Network Associates With Severe COVID-19.
41+
2342
CLI Examples
2443
============
2544

docs/images/beta_2d_plot-1.png

-2.3 KB
Loading

docs/images/beta_2d_plot-2.png

-11.6 KB
Loading

docs/images/beta_3d_plot-1.png

-4.72 KB
Loading

docs/images/beta_3d_plot-2.png

-9.26 KB
Loading

dokdo/__main__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ def main():
8282
add_help=False,
8383
help=("Create a manifest file (.tsv) from a directory containing "
8484
"FASTQ files."),
85-
description=("Create a manifest file (.tsv) from a directory "
86-
"containing FASTQ files. The file names must include "
87-
"either '_R1_001.fastq' or '_R1_002.fastq'. The word "
88-
"before the third-to-last underscore will be set "
89-
"as the sample ID. For example, a file named "
90-
"'EXAMPLE_S1_R1_001.fastq.gz' will produce 'EXAMPLE' "
91-
"as sample ID and 'EXAM_PLE_S1_R1_001.fastq.gz', "
92-
"'EXAM_PLE'."),
85+
description=("Create a manifest file (.tsv) from a directory containing FASTQ files. "
86+
"This command assumes that FASTQ filenames end with a suffix such as "
87+
"'_S0_R1_001.fastq' or '_S14_R2_001.fastq'. The word before the "
88+
"third-to-last underscore ('_') will be used as sample ID. For example, a "
89+
"file named 'EXAMPLE_S1_R1_001.fastq.gz' will set 'EXAMPLE' as sample ID. "
90+
"Undertermined reads (e.g. 'Undetermined_S0_R1_001.fastq') will not be "
91+
"included in the output file."),
9392
)
9493

9594
make_manifest_parser._optionals.title = "Arguments"

dokdo/api/alpha_diversity_plot.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ def alpha_diversity_plot(
2222
2323
Parameters
2424
----------
25-
artifact : str or qiime2.Artifact
25+
artifact : str, qiime2.Artifact, or pandas.DataFrame
2626
Artifact file or object from the q2-diversity plugin with the
27-
semantic type ``SampleData[AlphaDiversity]``.
27+
semantic type ``SampleData[AlphaDiversity]``. If you are importing
28+
data from a software tool other than QIIME 2, then you can provide a
29+
:class:`pandas.DataFrame` object in which the row index is sample
30+
names and the only column is diversity values with its header being
31+
the name of metrics used (e.g. 'faith_pd').
2832
metadata : str or qiime2.Metadata
2933
Metadata file or object.
3034
where : str
@@ -65,10 +69,12 @@ def alpha_diversity_plot(
6569
"""
6670
if isinstance(artifact, str):
6771
_alpha_diversity = Artifact.load(artifact)
72+
df = _alpha_diversity.view(pd.Series).to_frame()
73+
elif isinstance(artifact, pd.DataFrame):
74+
df = artifact
6875
else:
6976
_alpha_diversity = artifact
70-
71-
df = _alpha_diversity.view(pd.Series).to_frame()
77+
df = _alpha_diversity.view(pd.Series).to_frame()
7278

7379
mf = common.get_mf(metadata)
7480
df = pd.concat([df, mf], axis=1, join='inner')

dokdo/api/alpha_rarefaction_plot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def alpha_rarefaction_plot(
103103

104104
with tempfile.TemporaryDirectory() as t:
105105
common.export(visualization, t)
106-
df = pd.read_csv(f'{t}/{metric}.csv', index_col=0)
106+
df = pd.read_csv(f'{t}/{metric}.csv', index_col=0,
107+
keep_default_na=False, na_values=[''])
108+
df.to_csv('test.csv')
107109

108110
metadata_columns = [x for x in df.columns if 'iter' not in x]
109111

dokdo/api/beta_2d_plot.py

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ def beta_2d_plot(
2424
2525
Parameters
2626
----------
27-
artifact : str or qiime2.Artifact
27+
artifact : str, qiime2.Artifact, or pandas.DataFrame
2828
Artifact file or object from the q2-diversity plugin with the
2929
semantic type ``PCoAResults`` or
30-
``PCoAResults % Properties('biplot')``.
30+
``PCoAResults % Properties('biplot')``. If you are importing
31+
data from a software tool other than QIIME 2, then you can provide a
32+
:class:`pandas.DataFrame` object in which the row index is sample
33+
names and the first and second columns indicate the first and second
34+
PCoA axes, respectively.
3135
metadata : str or qiime2.Metadata, optional
3236
Metadata file or object.
3337
hue : str, optional
@@ -81,6 +85,12 @@ def beta_2d_plot(
8185
figsize=(5, 5))
8286
plt.tight_layout()
8387
88+
.. code-block:: text
89+
90+
# Explained proportions computed by QIIME 2:
91+
# 33.94% for Axis 1
92+
# 25.90% for Axis 2
93+
8494
.. image:: images/beta_2d_plot-1.png
8595
8696
We can color the datapoints with ``hue``. We can also change the
@@ -120,43 +130,52 @@ def beta_2d_plot(
120130
ax.legend(loc='upper left')
121131
plt.tight_layout()
122132
133+
.. code-block:: text
134+
135+
# Explained proportions computed by QIIME 2:
136+
# 33.94% for Axis 1
137+
# 25.90% for Axis 2
138+
# Explained proportions computed by QIIME 2:
139+
# 33.94% for Axis 1
140+
# 25.90% for Axis 2
141+
# Explained proportions computed by QIIME 2:
142+
# 33.94% for Axis 1
143+
# 25.90% for Axis 2
144+
# Explained proportions computed by QIIME 2:
145+
# 33.94% for Axis 1
146+
# 25.90% for Axis 2
147+
123148
.. image:: images/beta_2d_plot-2.png
124149
"""
125-
if isinstance(artifact, str):
126-
_pcoa_results = Artifact.load(artifact)
150+
if isinstance(artifact, pd.DataFrame):
151+
df = artifact
127152
else:
128-
_pcoa_results = artifact
129-
130-
ordination_results = _pcoa_results.view(OrdinationResults)
131-
132-
df1 = ordination_results.samples.iloc[:, :2]
133-
df1.columns = ['A1', 'A2']
153+
if isinstance(artifact, str):
154+
_pcoa_results = Artifact.load(artifact)
155+
else:
156+
_pcoa_results = artifact
157+
ordination_results = _pcoa_results.view(OrdinationResults)
158+
df = ordination_results.samples.iloc[:, :2]
159+
props = ordination_results.proportion_explained
160+
print('# Explained proportions computed by QIIME 2:')
161+
print(f'# {props[0]*100:.2f}% for Axis 1')
162+
print(f'# {props[1]*100:.2f}% for Axis 2')
163+
164+
df.columns = ['Axis 1', 'Axis 2']
134165

135166
if metadata is None:
136-
df2 = df1
167+
pass
137168
else:
138169
mf = common.get_mf(metadata)
139-
df2 = pd.concat([df1, mf], axis=1, join='inner')
140-
141-
props = ordination_results.proportion_explained
170+
df = pd.concat([df, mf], axis=1, join='inner')
142171

143172
if ax is None:
144173
fig, ax = plt.subplots(figsize=figsize)
145174

146-
sns.scatterplot(data=df2,
147-
x='A1',
148-
y='A2',
149-
hue=hue,
150-
hue_order=hue_order,
151-
style=style,
152-
style_order=style_order,
153-
size=size,
154-
ax=ax,
155-
s=s,
156-
alpha=alpha,
157-
legend=legend)
158-
159-
ax.set_xlabel(f'Axis 1 ({props[0]*100:.2f} %)')
160-
ax.set_ylabel(f'Axis 2 ({props[1]*100:.2f} %)')
175+
sns.scatterplot(
176+
x='Axis 1', y='Axis 2', data=df, hue=hue, hue_order=hue_order,
177+
style=style, style_order=style_order, size=size, ax=ax,
178+
s=s, alpha=alpha, legend=legend
179+
)
161180

162181
return ax

0 commit comments

Comments
 (0)