diff --git a/.gitignore b/.gitignore index 46c3821..9b3a16f 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,6 @@ target/ # other .DS_Store + +# JupyterBook +book/q2_fmt_book/_build \ No newline at end of file diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..3f8a3d3 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,19 @@ +version: 2 + +build: + os: ubuntu-22.04 + tools: + python: "mambaforge-22.9" + jobs: + pre_build: + # Generate the Sphinx configuration for this Jupyter Book so it builds. + - "jupyter-book config sphinx book/q2_fmt_book/" + +conda: + environment: environment-files/jupyter-book-build-env.yml + +sphinx: + builder: html + +formats: + - pdf \ No newline at end of file diff --git a/book/README.md b/book/README.md new file mode 100644 index 0000000..11f942c --- /dev/null +++ b/book/README.md @@ -0,0 +1,21 @@ +# q2-fmt book + +User documentation for the q2-fmt project. + +## Usage + +### Building the book + +If you'd like to develop and/or build the q2-fmt book book, you should: + +1. Clone this repository +2. Run `pip install -r book/requirements.txt` (it is recommended you do this within a virtual environment) +3. (Optional) Edit the books source files located in the `book/q2_fmt_book/` directory +4. Run `jupyter-book clean book/q2_fmt_book/` to remove any existing builds +5. Run `jupyter-book build book/q2_fmt_book/` + +A fully-rendered HTML version of the book will be built in `book/q2_fmt_book/_build/html/`. + +## Credits + +This project is created using the excellent open source [Jupyter Book project](https://jupyterbook.org/) and the [executablebooks/cookiecutter-jupyter-book template](https://github.com/executablebooks/cookiecutter-jupyter-book). diff --git a/book/q2_fmt_book/_config.yml b/book/q2_fmt_book/_config.yml new file mode 100644 index 0000000..aa4ccdd --- /dev/null +++ b/book/q2_fmt_book/_config.yml @@ -0,0 +1,37 @@ +####################################################################################### +# A default configuration that will be loaded for all jupyter books +# See the documentation for help and more options: +# https://jupyterbook.org/customize/config.html + +####################################################################################### +# Book settings +title : q2-fmt book # The title of the book. Will be placed in the left navbar. +author : Chloe Herman # The author of the book +copyright : "2024" # Copyright year to be placed in the footer +logo : logo.png # A path to the book logo + +# Force re-execution of notebooks on each build. +# See https://jupyterbook.org/content/execute.html +execute: + execute_notebooks: force + +# Define the name of the latex output file for PDF builds +latex: + latex_documents: + targetname: book.tex + +# Add a bibtex file so that we can create citations +bibtex_bibfiles: + - references.bib + +# Information about where the book exists on the web +repository: + url: https://github.com/cherman2/q2-fmt book # Online location of your book + path_to_book: book # Optional path to your book, relative to the repository root + branch: dev # Which branch of the repository should be used when creating links (optional) + +# Add GitHub buttons to your book +# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository +html: + use_issues_button: true + use_repository_button: true \ No newline at end of file diff --git a/book/q2_fmt_book/_toc.yml b/book/q2_fmt_book/_toc.yml new file mode 100644 index 0000000..d4311d4 --- /dev/null +++ b/book/q2_fmt_book/_toc.yml @@ -0,0 +1,9 @@ +# Table of contents +# Learn more at https://jupyterbook.org/customize/toc.html + +format: jb-book +root: intro +chapters: +- file: markdown +- file: notebooks +- file: markdown-notebooks \ No newline at end of file diff --git a/book/q2_fmt_book/content.md b/book/q2_fmt_book/content.md new file mode 100644 index 0000000..0f6aca7 --- /dev/null +++ b/book/q2_fmt_book/content.md @@ -0,0 +1,5 @@ +Content in Jupyter Book +======================= + +There are many ways to write content in Jupyter Book. This short section +covers a few tips for how to do so. diff --git a/book/q2_fmt_book/intro.md b/book/q2_fmt_book/intro.md new file mode 100644 index 0000000..95577c4 --- /dev/null +++ b/book/q2_fmt_book/intro.md @@ -0,0 +1,11 @@ +# Welcome to your Jupyter Book + +This is a small sample book to give you a feel for how book content is +structured. +It shows off a few of the major file types, as well as some sample content. +It does not go in-depth into any particular topic - check out [the Jupyter Book documentation](https://jupyterbook.org) for more information. + +Check out the content pages bundled with this sample book to see more. + +```{tableofcontents} +``` \ No newline at end of file diff --git a/book/q2_fmt_book/logo.png b/book/q2_fmt_book/logo.png new file mode 100644 index 0000000..06d56f4 Binary files /dev/null and b/book/q2_fmt_book/logo.png differ diff --git a/book/q2_fmt_book/markdown-notebooks.md b/book/q2_fmt_book/markdown-notebooks.md new file mode 100644 index 0000000..6d97104 --- /dev/null +++ b/book/q2_fmt_book/markdown-notebooks.md @@ -0,0 +1,54 @@ +--- +jupytext: + cell_metadata_filter: -all + formats: md:myst + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.11.5 +kernelspec: + display_name: Python 3 + language: python + name: python3 +--- + +# Notebooks with MyST Markdown + +Jupyter Book also lets you write text-based notebooks using MyST Markdown. +See [the Notebooks with MyST Markdown documentation](https://jupyterbook.org/file-types/myst-notebooks.html) for more detailed instructions. +This page shows off a notebook written in MyST Markdown. + +## An example cell + +With MyST Markdown, you can define code cells with a directive like so: + +```{code-cell} +print(2 + 2) +``` + +When your book is built, the contents of any `{code-cell}` blocks will be +executed with your default Jupyter kernel, and their outputs will be displayed +in-line with the rest of your content. + +```{seealso} +Jupyter Book uses [Jupytext](https://jupytext.readthedocs.io/en/latest/) to convert text-based files to notebooks, and can support [many other text-based notebook files](https://jupyterbook.org/file-types/jupytext.html). +``` + +## Create a notebook with MyST Markdown + +MyST Markdown notebooks are defined by two things: + +1. YAML metadata that is needed to understand if / how it should convert text files to notebooks (including information about the kernel needed). + See the YAML at the top of this page for example. +2. The presence of `{code-cell}` directives, which will be executed with your book. + +That's all that is needed to get started! + +## Quickly add YAML metadata for MyST Notebooks + +If you have a markdown file and you'd like to quickly add YAML metadata to it, so that Jupyter Book will treat it as a MyST Markdown Notebook, run the following command: + +``` +jupyter-book myst init path/to/markdownfile.md +``` \ No newline at end of file diff --git a/book/q2_fmt_book/markdown.md b/book/q2_fmt_book/markdown.md new file mode 100644 index 0000000..deaf054 --- /dev/null +++ b/book/q2_fmt_book/markdown.md @@ -0,0 +1,55 @@ +# Markdown Files + +Whether you write your book's content in Jupyter Notebooks (`.ipynb`) or +in regular markdown files (`.md`), you'll write in the same flavor of markdown +called **MyST Markdown**. +This is a simple file to help you get started and show off some syntax. + +## What is MyST? + +MyST stands for "Markedly Structured Text". It +is a slight variation on a flavor of markdown called "CommonMark" markdown, +with small syntax extensions to allow you to write **roles** and **directives** +in the Sphinx ecosystem. + +For more about MyST, see [the MyST Markdown Overview](https://jupyterbook.org/content/myst.html). + +## Sample Roles and Directives + +Roles and directives are two of the most powerful tools in Jupyter Book. They +are kind of like functions, but written in a markup language. They both +serve a similar purpose, but **roles are written in one line**, whereas +**directives span many lines**. They both accept different kinds of inputs, +and what they do with those inputs depends on the specific role or directive +that is being called. + +Here is a "note" directive: + +```{note} +Here is a note +``` + +It will be rendered in a special box when you build your book. + +Here is an inline directive to refer to a document: {doc}`markdown-notebooks`. + + +## Citations + +You can also cite references that are stored in a `bibtex` file. For example, +the following syntax: `` {cite}`holdgraf_evidence_2014` `` will render like +this: {cite}`holdgraf_evidence_2014`. + +Moreover, you can insert a bibliography into your page with this syntax: +The `{bibliography}` directive must be used for all the `{cite}` roles to +render properly. +For example, if the references for your book are stored in `references.bib`, +then the bibliography is inserted with: + +```{bibliography} +``` + +## Learn more + +This is just a simple starter to get you started. +You can learn a lot more at [jupyterbook.org](https://jupyterbook.org). \ No newline at end of file diff --git a/book/q2_fmt_book/notebooks.ipynb b/book/q2_fmt_book/notebooks.ipynb new file mode 100644 index 0000000..fdb7176 --- /dev/null +++ b/book/q2_fmt_book/notebooks.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Content with notebooks\n", + "\n", + "You can also create content with Jupyter Notebooks. This means that you can include\n", + "code blocks and their outputs in your book.\n", + "\n", + "## Markdown + notebooks\n", + "\n", + "As it is markdown, you can embed images, HTML, etc into your posts!\n", + "\n", + "![](https://myst-parser.readthedocs.io/en/latest/_static/logo-wide.svg)\n", + "\n", + "You can also $add_{math}$ and\n", + "\n", + "$$\n", + "math^{blocks}\n", + "$$\n", + "\n", + "or\n", + "\n", + "$$\n", + "\\begin{aligned}\n", + "\\mbox{mean} la_{tex} \\\\ \\\\\n", + "math blocks\n", + "\\end{aligned}\n", + "$$\n", + "\n", + "But make sure you \\$Escape \\$your \\$dollar signs \\$you want to keep!\n", + "\n", + "## MyST markdown\n", + "\n", + "MyST markdown works in Jupyter Notebooks as well. For more information about MyST markdown, check\n", + "out [the MyST guide in Jupyter Book](https://jupyterbook.org/content/myst.html),\n", + "or see [the MyST markdown documentation](https://myst-parser.readthedocs.io/en/latest/).\n", + "\n", + "## Code blocks and outputs\n", + "\n", + "Jupyter Book will also embed your code blocks and output in your book.\n", + "For example, here's some sample Matplotlib code:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import rcParams, cycler\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "plt.ion()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Fixing random state for reproducibility\n", + "np.random.seed(19680801)\n", + "\n", + "N = 10\n", + "data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]\n", + "data = np.array(data).T\n", + "cmap = plt.cm.coolwarm\n", + "rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n", + "\n", + "\n", + "from matplotlib.lines import Line2D\n", + "custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n", + " Line2D([0], [0], color=cmap(.5), lw=4),\n", + " Line2D([0], [0], color=cmap(1.), lw=4)]\n", + "\n", + "fig, ax = plt.subplots(figsize=(10, 5))\n", + "lines = ax.plot(data)\n", + "ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is a lot more that you can do with outputs (such as including interactive outputs)\n", + "with your book. For more information about this, see [the Jupyter Book documentation](https://jupyterbook.org)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/book/q2_fmt_book/references.bib b/book/q2_fmt_book/references.bib new file mode 100644 index 0000000..87e6098 --- /dev/null +++ b/book/q2_fmt_book/references.bib @@ -0,0 +1,55 @@ +--- +--- + +@inproceedings{holdgraf_evidence_2014, + address = {Brisbane, Australia, Australia}, + title = {Evidence for {Predictive} {Coding} in {Human} {Auditory} {Cortex}}, + booktitle = {International {Conference} on {Cognitive} {Neuroscience}}, + publisher = {Frontiers in Neuroscience}, + author = {Holdgraf, Christopher Ramsay and de Heer, Wendy and Pasley, Brian N. and Knight, Robert T.}, + year = {2014} +} + +@article{holdgraf_rapid_2016, + title = {Rapid tuning shifts in human auditory cortex enhance speech intelligibility}, + volume = {7}, + issn = {2041-1723}, + url = {http://www.nature.com/doifinder/10.1038/ncomms13654}, + doi = {10.1038/ncomms13654}, + number = {May}, + journal = {Nature Communications}, + author = {Holdgraf, Christopher Ramsay and de Heer, Wendy and Pasley, Brian N. and Rieger, Jochem W. and Crone, Nathan and Lin, Jack J. and Knight, Robert T. and Theunissen, Frédéric E.}, + year = {2016}, + pages = {13654}, + file = {Holdgraf et al. - 2016 - Rapid tuning shifts in human auditory cortex enhance speech intelligibility.pdf:C\:\\Users\\chold\\Zotero\\storage\\MDQP3JWE\\Holdgraf et al. - 2016 - Rapid tuning shifts in human auditory cortex enhance speech intelligibility.pdf:application/pdf} +} + +@inproceedings{holdgraf_portable_2017, + title = {Portable learning environments for hands-on computational instruction using container-and cloud-based technology to teach data science}, + volume = {Part F1287}, + isbn = {978-1-4503-5272-7}, + doi = {10.1145/3093338.3093370}, + abstract = {© 2017 ACM. There is an increasing interest in learning outside of the traditional classroom setting. This is especially true for topics covering computational tools and data science, as both are challenging to incorporate in the standard curriculum. These atypical learning environments offer new opportunities for teaching, particularly when it comes to combining conceptual knowledge with hands-on experience/expertise with methods and skills. Advances in cloud computing and containerized environments provide an attractive opportunity to improve the effciency and ease with which students can learn. This manuscript details recent advances towards using commonly-Available cloud computing services and advanced cyberinfrastructure support for improving the learning experience in bootcamp-style events. We cover the benets (and challenges) of using a server hosted remotely instead of relying on student laptops, discuss the technology that was used in order to make this possible, and give suggestions for how others could implement and improve upon this model for pedagogy and reproducibility.}, + author = {Holdgraf, Christopher Ramsay and Culich, A. and Rokem, A. and Deniz, F. and Alegro, M. and Ushizima, D.}, + year = {2017}, + keywords = {Teaching, Bootcamps, Cloud computing, Data science, Docker, Pedagogy} +} + +@article{holdgraf_encoding_2017, + title = {Encoding and decoding models in cognitive electrophysiology}, + volume = {11}, + issn = {16625137}, + doi = {10.3389/fnsys.2017.00061}, + abstract = {© 2017 Holdgraf, Rieger, Micheli, Martin, Knight and Theunissen. Cognitive neuroscience has seen rapid growth in the size and complexity of data recorded from the human brain as well as in the computational tools available to analyze this data. This data explosion has resulted in an increased use of multivariate, model-based methods for asking neuroscience questions, allowing scientists to investigate multiple hypotheses with a single dataset, to use complex, time-varying stimuli, and to study the human brain under more naturalistic conditions. These tools come in the form of “Encoding” models, in which stimulus features are used to model brain activity, and “Decoding” models, in which neural features are used to generated a stimulus output. Here we review the current state of encoding and decoding models in cognitive electrophysiology and provide a practical guide toward conducting experiments and analyses in this emerging field. Our examples focus on using linear models in the study of human language and audition. We show how to calculate auditory receptive fields from natural sounds as well as how to decode neural recordings to predict speech. The paper aims to be a useful tutorial to these approaches, and a practical introduction to using machine learning and applied statistics to build models of neural activity. The data analytic approaches we discuss may also be applied to other sensory modalities, motor systems, and cognitive systems, and we cover some examples in these areas. In addition, a collection of Jupyter notebooks is publicly available as a complement to the material covered in this paper, providing code examples and tutorials for predictive modeling in python. The aimis to provide a practical understanding of predictivemodeling of human brain data and to propose best-practices in conducting these analyses.}, + journal = {Frontiers in Systems Neuroscience}, + author = {Holdgraf, Christopher Ramsay and Rieger, J.W. and Micheli, C. and Martin, S. and Knight, R.T. and Theunissen, F.E.}, + year = {2017}, + keywords = {Decoding models, Encoding models, Electrocorticography (ECoG), Electrophysiology/evoked potentials, Machine learning applied to neuroscience, Natural stimuli, Predictive modeling, Tutorials} +} + +@book{ruby, + title = {The Ruby Programming Language}, + author = {Flanagan, David and Matsumoto, Yukihiro}, + year = {2008}, + publisher = {O'Reilly Media} +} \ No newline at end of file diff --git a/book/requirements.txt b/book/requirements.txt new file mode 100644 index 0000000..7e821e4 --- /dev/null +++ b/book/requirements.txt @@ -0,0 +1,3 @@ +jupyter-book +matplotlib +numpy diff --git a/environment-files/jupyter-book-build-env.yml b/environment-files/jupyter-book-build-env.yml new file mode 100644 index 0000000..b35c94d --- /dev/null +++ b/environment-files/jupyter-book-build-env.yml @@ -0,0 +1,8 @@ +name: q2-fmt-jupyter-book +channels: +- https://packages.qiime2.org/qiime2/2024.10/amplicon/passed +- conda-forge +- bioconda +dependencies: + - qiime2-amplicon + - jupyter-book \ No newline at end of file diff --git a/q2_fmt/__init__.py b/q2_fmt/__init__.py index 128078b..c5ddb7e 100644 --- a/q2_fmt/__init__.py +++ b/q2_fmt/__init__.py @@ -11,6 +11,7 @@ from ._engraftment import cc, group_timepoints from ._peds import (sample_peds, feature_peds, peds, heatmap, peds_simulation, sample_pprs) +from ._ancombc import detect_donor_indicators __version__ = get_versions()['version'] del get_versions @@ -18,4 +19,4 @@ __all__ = ['cc', 'sample_peds', 'feature_peds', 'peds', 'heatmap', 'group_timepoints', 'peds_simulation', - 'sample_pprs'] + 'sample_pprs', 'detect_donor_indicators'] diff --git a/q2_fmt/_ancombc.py b/q2_fmt/_ancombc.py new file mode 100644 index 0000000..2b76169 --- /dev/null +++ b/q2_fmt/_ancombc.py @@ -0,0 +1,86 @@ +# ---------------------------------------------------------------------------- +# Copyright (c) 2022-2023, QIIME 2 development team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file LICENSE, distributed with this software. +# ---------------------------------------------------------------------------- +import pandas as pd +from qiime2 import Metadata + +# TODO: Change Import path. +from q2_fmt._peds import _check_for_time_column, _check_reference_column + + +def detect_donor_indicators(ctx, table, reference_column, time_column, + baseline_timepoint, metadata, + level_delimiter=None): + filter = ctx.get_action('feature_table', 'filter_samples') + ancombc = ctx.get_action('composition', 'ancombc') + da_barplot = ctx.get_action('composition', 'da_barplot') + results = [] + + _check_for_time_column(metadata.to_dataframe(), + time_column) + _check_reference_column(metadata.to_dataframe(), + reference_column) + + ids_to_keep = get_baseline_donor_md(metadata=metadata, + reference_column=reference_column, + time_column=time_column, + baseline_timepoint=baseline_timepoint) + + filtered_table, = filter(table=table, + metadata=Metadata(ids_to_keep)) + dataloaf, = ancombc(table=filtered_table, metadata=Metadata(ids_to_keep), + reference_levels=["type::donor"], formula='type') + results.append(dataloaf) + viz, = da_barplot(data=dataloaf, significance_threshold=0.05, + level_delimiter=level_delimiter) + results.append(viz) + return tuple(results) + + +def get_baseline_donor_md(metadata, reference_column, time_column, + baseline_timepoint): + """Creates a metadata for differentiating baseline and donor + ---------- + metadata: pd.Dataframe + Study `Metadata` + reference_column: str + name of reference column in `Metadata` column + time_column: str + name of reference column in `Metadata` column + baseline_timepoint: str + timepoint that represents baseline + Examples + -------- + >>> metadata = pd.DataFrame({'id': ['sample1', 'sample2', 'donor1'], + 'reference': ['donor1', 'donor1', np.nan], + 'time': [1, 2, np.nan], + 'subject': ['sub1','sub1', np.nan]}).set_index('id') + >>> time_column = 'time' + >>> reference_column = 'reference' + >>> baseline_timepoint = '1' + >>> get_baseline_donor_md(metadata, reference_column, time_column, + baseline_timepoint) + pd.DataFrame({'id': ['sample1', 'donor1'], + 'reference': ['donor1', np.nan], + 'time': [1,np.nan], + 'subject': ['sub1',np.nan]}).set_index('id') + """ + md_df = metadata.to_dataframe() + ids_to_keep =\ + pd.Series(index=md_df[reference_column].dropna().unique(), + data='donor', name='type') + ids_to_keep =\ + pd.concat([ids_to_keep, + pd.Series(index=md_df[md_df[time_column] == + float(baseline_timepoint) + ].index.to_list(), + data='baseline', name=type)]) + + ids_to_keep = ids_to_keep.to_frame() + ids_to_keep.index.name = 'id' + ids_to_keep = ids_to_keep.rename({0: "type"}, axis=1) + return ids_to_keep diff --git a/q2_fmt/_examples.py b/q2_fmt/_examples.py index edaef55..b4233af 100644 --- a/q2_fmt/_examples.py +++ b/q2_fmt/_examples.py @@ -292,3 +292,27 @@ def pprs_method(use): pprs_group_dists.assert_output_type("Dist1D[Ordered, Matched] %" " Properties('pprs')") + + +def detect_donor_indicators_method(use): + md = use.init_metadata('md', peds_md_factory) + table = use.init_artifact('table', feature_table_factory) + + differentials, da_barplot = use.action( + use.UsageAction('fmt', 'detect_donor_indicators'), + use.UsageInputs( + table=table, + metadata=md, + time_column='time_point', + reference_column='Donor', + baseline_timepoint='1', + ), + use.UsageOutputNames( + differentials='differentials', + da_barplot='da_barplot' + ) + + ) + + differentials.assert_output_type("FeatureData[DifferentialAbundance]") + da_barplot.assert_output_type("Visualization") diff --git a/q2_fmt/plugin_setup.py b/q2_fmt/plugin_setup.py index 91deb24..88c8dd5 100644 --- a/q2_fmt/plugin_setup.py +++ b/q2_fmt/plugin_setup.py @@ -17,6 +17,8 @@ import q2_fmt from q2_types.feature_table import ( FeatureTable, Frequency, RelativeFrequency, PresenceAbsence) +from q2_types.feature_data import FeatureData +from q2_composition import DifferentialAbundance from q2_stats.types import (Dist1D, Matched, Independent, Ordered, Unordered, StatsTable, Pairwise, NestedOrdered) @@ -452,4 +454,37 @@ } ) +plugin.pipelines.register_function( + function=q2_fmt.detect_donor_indicators, + inputs={'table': FeatureTable[Frequency]}, + parameters={'metadata': Metadata, + 'time_column': Str, + 'reference_column': Str, + 'level_delimiter': Str, + 'baseline_timepoint': Str}, + outputs=[('differentials', FeatureData[DifferentialAbundance]), + ('da_barplot', Visualization)], + input_descriptions={'table': peds_table}, + parameter_descriptions={ + 'metadata': metadata, + 'time_column': time_column, + 'reference_column': reference_column, + 'level_delimiter': level_delimiter, + 'baseline_timepoint': baseline_timepoint}, + output_descriptions={'da_barplot': 'A diverging barplot showing' + ' differiental abundant microbes' + ' between baseline recipient samples' + ' and donor samples.', + 'differentials': 'The calculated per-feature' + ' differentials.'}, + name='Detect Donor Indicators Features', + description='Runs a pipeline to indentify differetial features between the' + ' donor and the baseline recipient. This is done by filtering' + ' the feature table to donor and baseline timepoints and' + ' running ancombc comparing those groups', + examples={ + 'detect_methods': ex.detect_donor_indicators_method + } +) + importlib.import_module('q2_fmt._transformer') diff --git a/q2_fmt/tests/test_engraftment.py b/q2_fmt/tests/test_engraftment.py index f7e4005..32b9526 100644 --- a/q2_fmt/tests/test_engraftment.py +++ b/q2_fmt/tests/test_engraftment.py @@ -29,6 +29,7 @@ from q2_fmt._engraftment import group_timepoints from q2_fmt._peds import (_compute_peds, sample_peds, feature_peds, peds_simulation, sample_pprs) +from q2_fmt._ancombc import get_baseline_donor_md class TestBase(TestPluginBase): @@ -2009,3 +2010,21 @@ def test_peds_sim_stats_99_iters(self): self.assertEqual(count_gte, exp_count_gte) self.assertEqual(count_less, exp_count_less) self.assertEqual(per_subject_p, exp_per_subject_p) + + +class detect(TestBase): + def test_baseline_donor_md(self): + metadata = pd.DataFrame({'id': ['sample1', 'sample2', 'donor1'], + 'reference': ['donor1', 'donor1', np.nan], + 'time': [1, 2, np.nan], + 'subject': ['sub1', 'sub1', + np.nan]}).set_index('id') + time_column = 'time' + reference_column = 'reference' + baseline_timepoint = '1' + b_d_md = get_baseline_donor_md(Metadata(metadata), reference_column, + time_column, baseline_timepoint) + exp_b_d_md = pd.DataFrame({'id': ['donor1', 'sample1'], + 'type': ['donor', + 'baseline']}).set_index('id') + pd.testing.assert_frame_equal(b_d_md, exp_b_d_md)